Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,4 @@ output1.txt
.zed

**/.claude/**/*
**/~/
3 changes: 1 addition & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ light-registry = { path = "programs/registry", version = "2.0.0", features = [
create-address-test-program = { path = "program-tests/create-address-test-program", version = "1.0.0", features = [
"cpi",
] }
light-program-test = { path = "sdk-libs/program-test", version = "0.13.1" }
light-program-test = { path = "sdk-libs/program-test", version = "0.13.2" }
light-batched-merkle-tree = { path = "program-libs/batched-merkle-tree", version = "0.3.0" }
light-merkle-tree-metadata = { path = "program-libs/merkle-tree-metadata", version = "0.3.0" }
aligned-sized = { path = "program-libs/aligned-sized", version = "1.1.0" }
Expand Down
34 changes: 1 addition & 33 deletions forester-utils/src/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use light_registry::{
create_rollover_state_merkle_tree_instruction, CreateRolloverMerkleTreeInstructionInputs,
},
protocol_config::state::ProtocolConfig,
sdk::{create_register_forester_instruction, create_update_forester_pda_instruction},
sdk::create_update_forester_pda_instruction,
utils::get_forester_pda,
ForesterConfig, ForesterPda,
};
Expand All @@ -27,38 +27,6 @@ use crate::{
instructions::create_account::create_account_instruction,
};

/// Creates and asserts forester account creation.
pub async fn register_test_forester<R: Rpc>(
rpc: &mut R,
governance_authority: &Keypair,
forester_authority: &Pubkey,
config: ForesterConfig,
) -> Result<(), RpcError> {
let ix = create_register_forester_instruction(
&governance_authority.pubkey(),
&governance_authority.pubkey(),
forester_authority,
config,
);
rpc.create_and_send_transaction(
&[ix],
&governance_authority.pubkey(),
&[governance_authority],
)
.await?;
assert_registered_forester(
rpc,
forester_authority,
ForesterPda {
authority: *forester_authority,
config,
active_weight: 1,
..Default::default()
},
)
.await
}

pub async fn update_test_forester<R: Rpc>(
rpc: &mut R,
forester_authority: &Keypair,
Expand Down
2 changes: 1 addition & 1 deletion forester/tests/legacy/batched_address_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::{sync::Arc, time::Duration};

use forester::run_pipeline;
use forester_utils::{
registry::{register_test_forester, update_test_forester},
registry::update_test_forester,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wdyt about moving update_test_forester too?

rpc_pool::SolanaRpcPoolBuilder,
};
Comment on lines 4 to 7
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

register_test_forester no longer imported – will not compile

You removed the old import but calls at lines 87-93 still use the function. Add the new path import from light_program_test (or qualify the call).

-use forester_utils::{
-    registry::update_test_forester,
-    rpc_pool::SolanaRpcPoolBuilder,
-};
+use forester_utils::{
+    registry::update_test_forester,
+    rpc_pool::SolanaRpcPoolBuilder,
+};
+use light_program_test::utils::register_test_forester;
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
use forester_utils::{
registry::{register_test_forester, update_test_forester},
registry::update_test_forester,
rpc_pool::SolanaRpcPoolBuilder,
};
use forester_utils::{
registry::update_test_forester,
rpc_pool::SolanaRpcPoolBuilder,
};
use light_program_test::utils::register_test_forester;
🤖 Prompt for AI Agents
In forester/tests/legacy/batched_address_test.rs around lines 4 to 7, the
function register_test_forester is no longer imported but is still called at
lines 87-93. To fix this, add the correct import for register_test_forester from
the light_program_test module at the top of the file or fully qualify the calls
to register_test_forester where used. This will ensure the code compiles
successfully.

use light_batched_merkle_tree::{
Expand Down
32 changes: 31 additions & 1 deletion program-tests/registry-test/tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ use light_test_utils::{
e2e_test_env::init_program_test_env,
register_test_forester,
setup_accounts::setup_accounts,
setup_forester_and_advance_to_epoch,
test_batch_forester::{
assert_perform_state_mt_roll_over, create_append_batch_ix_data,
create_batch_update_address_tree_instruction_data_with_proof, perform_batch_append,
Expand Down Expand Up @@ -193,6 +194,7 @@ async fn test_initialize_protocol_config() {
payer,
config: ProgramTestConfig::default(),
};

let payer = rpc.get_payer().insecure_clone();
let program_account_keypair = Keypair::from_bytes(&OLD_REGISTRY_ID_TEST_KEYPAIR).unwrap();
let protocol_config = ProtocolConfig::default();
Expand Down Expand Up @@ -550,6 +552,10 @@ async fn test_custom_forester() {
let mut rpc = LightProgramTest::new(ProgramTestConfig::default_with_batched_trees(true))
.await
.unwrap();
let protocol_config = rpc.config.protocol_config;
setup_forester_and_advance_to_epoch(&mut rpc, &protocol_config)
.await
.unwrap();
rpc.indexer = None;

let env = rpc.test_accounts.clone();
Expand Down Expand Up @@ -629,6 +635,10 @@ async fn test_custom_forester_batched() {
let mut rpc = LightProgramTest::new(ProgramTestConfig::default_test_forester(true))
.await
.unwrap();
let protocol_config = rpc.config.protocol_config;
setup_forester_and_advance_to_epoch(&mut rpc, &protocol_config)
.await
.unwrap();
rpc.indexer = None;
let env = rpc.test_accounts.clone();
let tree_params = ProgramTestConfig::default_with_batched_trees(true)
Expand Down Expand Up @@ -749,7 +759,6 @@ async fn test_register_and_update_forester_pda() {
let config = ProgramTestConfig {
protocol_config: ProtocolConfig::default(),
with_prover: false,
register_forester_and_advance_to_active_phase: false,
..Default::default()
};

Expand Down Expand Up @@ -1018,6 +1027,10 @@ async fn failing_test_forester() {
let mut rpc = LightProgramTest::new(ProgramTestConfig::default_with_batched_trees(true))
.await
.unwrap();
let protocol_config = rpc.config.protocol_config;
setup_forester_and_advance_to_epoch(&mut rpc, &protocol_config)
.await
.unwrap();
rpc.indexer = None;
let env = rpc.test_accounts.clone();
let payer = rpc.get_payer().insecure_clone();
Expand Down Expand Up @@ -1409,6 +1422,10 @@ async fn test_migrate_state() {
let mut rpc = LightProgramTest::new(ProgramTestConfig::default_with_batched_trees(true))
.await
.unwrap();
let protocol_config = rpc.config.protocol_config;
setup_forester_and_advance_to_epoch(&mut rpc, &protocol_config)
.await
.unwrap();
rpc.indexer = None;
let test_accounts = rpc.test_accounts.clone();
let payer = rpc.get_payer().insecure_clone();
Expand Down Expand Up @@ -1678,6 +1695,10 @@ async fn test_rollover_batch_state_tree() {
config.v2_state_tree_config = Some(params);

let mut rpc = LightProgramTest::new(config).await.unwrap();
let protocol_config = rpc.config.protocol_config;
setup_forester_and_advance_to_epoch(&mut rpc, &protocol_config)
.await
.unwrap();
rpc.indexer = None;
let test_accounts = rpc.test_accounts.clone();
let payer = rpc.get_payer().insecure_clone();
Expand Down Expand Up @@ -1869,6 +1890,11 @@ async fn test_batch_address_tree() {
CREATE_ADDRESS_TEST_PROGRAM_ID,
)]);
let mut rpc = LightProgramTest::new(config).await.unwrap();
let protocol_config = rpc.config.protocol_config;
setup_forester_and_advance_to_epoch(&mut rpc, &protocol_config)
.await
.unwrap();

rpc.indexer = None;
let env = rpc.test_accounts.clone();

Expand Down Expand Up @@ -2044,6 +2070,10 @@ async fn test_rollover_batch_address_tree() {
)]);
config.v2_address_tree_config = Some(tree_params);
let mut rpc = LightProgramTest::new(config).await.unwrap();
let protocol_config = rpc.config.protocol_config;
setup_forester_and_advance_to_epoch(&mut rpc, &protocol_config)
.await
.unwrap();
rpc.indexer = None;
let env = rpc.test_accounts.clone();

Expand Down
11 changes: 9 additions & 2 deletions program-tests/system-cpi-test/tests/test_program_owned_trees.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ use light_registry::{
};
use light_test_utils::{
airdrop_lamports, assert_custom_error_or_program_error, create_account_instruction,
get_concurrent_merkle_tree, spl::create_mint_helper, FeeConfig, Rpc, RpcError,
TransactionParams,
get_concurrent_merkle_tree, setup_forester_and_advance_to_epoch, spl::create_mint_helper,
FeeConfig, Rpc, RpcError, TransactionParams,
};
use serial_test::serial;
use solana_sdk::{
Expand Down Expand Up @@ -211,6 +211,13 @@ async fn test_invalid_registered_program() {
airdrop_lamports(&mut rpc, &payer.pubkey(), 100_000_000_000)
.await
.unwrap();

// Setup forester to ensure registered_forester_pda is initialized
let protocol_config = rpc.config.protocol_config;
setup_forester_and_advance_to_epoch(&mut rpc, &protocol_config)
.await
.unwrap();

let group_seed_keypair = Keypair::new();
let program_id_keypair = Keypair::from_bytes(&CPI_SYSTEM_TEST_PROGRAM_ID_KEYPAIR).unwrap();
println!("program_id_keypair: {:?}", program_id_keypair.pubkey());
Expand Down
25 changes: 12 additions & 13 deletions program-tests/system-test/tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ use light_system_program::{
use light_test_utils::{
airdrop_lamports,
assert_compressed_tx::assert_created_compressed_accounts,
assert_custom_error_or_program_error,
assert_custom_error_or_program_error, setup_forester_and_advance_to_epoch,
system_program::{
compress_sol_test, create_addresses_test, create_invoke_instruction,
create_invoke_instruction_data_and_remaining_accounts, decompress_sol_test,
Expand Down Expand Up @@ -1674,6 +1674,11 @@ async fn regenerate_accounts() {
.unwrap();
let keypairs = for_regenerate_accounts();

// Setup forester and get epoch information
let forester_epoch = setup_forester_and_advance_to_epoch(&mut rpc, &protocol_config)
.await
.unwrap();

// List of public keys to fetch and export
let pubkeys = vec![
("merkle_tree_pubkey", env.v1_state_trees[0].merkle_tree),
Expand Down Expand Up @@ -1707,18 +1712,8 @@ async fn regenerate_accounts() {
"registered_forester_pda",
env.protocol.registered_forester_pda,
),
(
"forester_epoch_pda",
env.protocol
.forester_epoch
.as_ref()
.unwrap()
.forester_epoch_pda,
),
(
"epoch_pda",
env.protocol.forester_epoch.as_ref().unwrap().epoch_pda,
),
("forester_epoch_pda", forester_epoch.forester_epoch_pda),
("epoch_pda", forester_epoch.epoch_pda),
("batch_state_merkle_tree", env.v2_state_trees[0].merkle_tree),
("batched_output_queue", env.v2_state_trees[0].output_queue),
("batch_address_merkle_tree", env.v2_address_trees[0]),
Expand Down Expand Up @@ -1845,6 +1840,10 @@ async fn batch_invoke_test() {
let config = ProgramTestConfig::default_test_forester(false);

let mut rpc = LightProgramTest::new(config).await.unwrap();
let protocol_config = rpc.config.protocol_config;
setup_forester_and_advance_to_epoch(&mut rpc, &protocol_config)
.await
.unwrap();

let env = rpc.test_accounts.clone();
let payer = rpc.get_payer().insecure_clone();
Expand Down
22 changes: 4 additions & 18 deletions program-tests/utils/src/e2e_test_env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ use forester_utils::{
account_zero_copy::AccountZeroCopy,
address_merkle_tree_config::{address_tree_ready_for_rollover, state_tree_ready_for_rollover},
forester_epoch::{Epoch, Forester, TreeAccounts},
registry::register_test_forester,
utils::airdrop_lamports,
};
use light_batched_merkle_tree::{
Expand Down Expand Up @@ -132,6 +131,7 @@ use light_program_test::{
TestIndexerExtensions,
},
program_test::{LightProgramTest, TestRpc},
utils::register_test_forester::register_test_forester,
};
use light_prover_client::{
constants::{PROVE_PATH, SERVER_ADDRESS},
Expand Down Expand Up @@ -394,23 +394,9 @@ where
.config;
// TODO: add clear test env enum
// register foresters is only compatible with ProgramTest environment
let (foresters, epoch_config) =
if let Some(registered_epoch) = test_accounts.protocol.forester_epoch.as_ref() {
let _forester = Forester {
registration: registered_epoch.clone(),
active: registered_epoch.clone(),
..Default::default()
};
// Forester epoch account is assumed to exist (is inited with test program deployment)
let forester = TestForester {
keypair: test_accounts.protocol.forester.insecure_clone(),
forester: _forester.clone(),
is_registered: Some(0),
};
(vec![forester], _forester)
} else {
(Vec::<TestForester>::new(), Forester::default())
};
// Default forester setup - tests that need forester functionality should call
// setup_forester_and_advance_to_epoch explicitly and manage their own forester state
let (foresters, epoch_config) = (Vec::<TestForester>::new(), Forester::default());
Self {
payer,
indexer,
Expand Down
6 changes: 4 additions & 2 deletions program-tests/utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ pub mod mock_batched_forester;
pub mod pack;
pub mod registered_program_accounts_v1;
pub mod setup_accounts;
pub mod setup_forester;
#[allow(unused)]
pub mod spl;
pub mod state_tree_rollover;
Expand All @@ -46,8 +47,7 @@ pub use forester_utils::{
forester_epoch::{Epoch, TreeAccounts},
registry::{
create_rollover_address_merkle_tree_instructions,
create_rollover_state_merkle_tree_instructions, register_test_forester,
update_test_forester,
create_rollover_state_merkle_tree_instructions, update_test_forester,
},
};
pub use light_client::{
Expand All @@ -56,7 +56,9 @@ pub use light_client::{
};
use light_hasher::Poseidon;
use light_program_test::accounts::address_tree::create_address_merkle_tree_and_queue_account;
pub use light_program_test::utils::register_test_forester::register_test_forester;
use light_registry::account_compression_cpi::sdk::get_registered_program_pda;
pub use setup_forester::setup_forester_and_advance_to_epoch;

use crate::assert_queue::assert_address_queue_initialized;

Expand Down
Loading