Skip to content

refactor: program test reduce forester utils dep#1867

Merged
ananas-block merged 10 commits intomainfrom
jorrit/refactor-program-test-reduce-forester-utils-dep
Jul 14, 2025
Merged

refactor: program test reduce forester utils dep#1867
ananas-block merged 10 commits intomainfrom
jorrit/refactor-program-test-reduce-forester-utils-dep

Conversation

@ananas-block
Copy link
Contributor

@ananas-block ananas-block commented Jul 14, 2025

Summary by CodeRabbit

  • New Features

    • Introduced new utilities for account creation and forester registration in test environments.
    • Added a new struct for managing tree account data in tests.
    • Added a streamlined function to set up forester and advance epoch state in test environments.
    • Added functionality to update forester accounts in tests.
  • Refactor

    • Updated import paths and reorganized utility modules for improved clarity and modularity.
    • Replaced and relocated forester registration test utilities to a new module.
    • Removed direct forester epoch initialization from test environment setup, requiring explicit setup calls.
  • Chores

    • Removed unused or redundant code and imports related to forester registration.
    • Cleaned up configuration flags and fields related to forester registration and epoch advancement.
    • Updated .gitignore to exclude directories named ~ at any depth.
  • Bug Fixes

    • Improved safety in epoch progress calculation to prevent runtime panics from underflow.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jul 14, 2025

Walkthrough

The changes refactor the test utilities for registering a "forester" account by moving the register_test_forester function from the forester-utils crate to the sdk-libs/program-test crate. Related imports and re-exports are updated across several modules. New utility modules and helper structs are introduced for account creation and tree account management. The test environment setup is adjusted to use a new helper function setup_forester_and_advance_to_epoch. Import paths for account creation instructions are updated to local modules, and references to forester epoch fields and flags are removed from configurations and test accounts. Additionally, a method in ProtocolConfig is made more robust against underflow.

Changes

File(s) Change Summary
forester-utils/src/registry.rs Removed the register_test_forester function and its associated import.
forester/tests/legacy/batched_address_test.rs Removed import of register_test_forester from forester_utils::registry.
program-tests/utils/src/e2e_test_env.rs Changed import of register_test_forester to source from light_program_test::utils; simplified forester initialization logic.
program-tests/utils/src/lib.rs Added new public module setup_forester; re-exported register_test_forester and setup_forester_and_advance_to_epoch from new locations; removed old re-export from forester_utils.
sdk-libs/program-test/src/accounts/address_tree.rs
sdk-libs/program-test/src/accounts/state_tree.rs
Changed import paths for create_account_instruction to local module.
sdk-libs/program-test/src/accounts/address_tree_v2.rs
sdk-libs/program-test/src/accounts/state_tree_v2.rs
Changed import paths for create_account_instruction to local module.
sdk-libs/program-test/src/accounts/initialize.rs Removed all forester-related imports and logic, including register_test_forester calls and forester_epoch field usage.
sdk-libs/program-test/src/accounts/test_accounts.rs Removed forester_epoch field from ProtocolAccounts struct and related initializations.
sdk-libs/program-test/src/program_test/config.rs Removed register_forester_and_advance_to_active_phase flag from ProgramTestConfig.
sdk-libs/program-test/src/utils/create_account.rs Added new utility function create_account_instruction to create Solana system program account creation instructions.
sdk-libs/program-test/src/utils/mod.rs Added new public modules: create_account, register_test_forester, and tree_accounts.
sdk-libs/program-test/src/utils/register_test_forester.rs Added new module implementing register_test_forester function and helper for asserting forester registration.
sdk-libs/program-test/src/utils/tree_accounts.rs Added new struct TreeAccounts with constructor method.
program-tests/utils/src/setup_forester.rs Added new async function setup_forester_and_advance_to_epoch to register forester, create epoch, advance slot, add trees, and finalize registration.
program-tests/registry-test/tests/tests.rs Added calls to setup_forester_and_advance_to_epoch in multiple tests to initialize forester state.
program-tests/system-test/tests/test.rs Added calls to setup_forester_and_advance_to_epoch in test functions; replaced direct forester epoch field usage.
xtask/src/new_deployment.rs Removed explicit setting of register_forester_and_advance_to_active_phase flag in deployment config.
sdk-libs/program-test/Cargo.toml Removed forester-utils crate from dependencies and feature groups.
sdk-libs/program-test/src/program_test/config.rs Modified get_current_active_epoch_progress method to avoid panic on underflow by returning 0 instead.

Sequence Diagram(s)

sequenceDiagram
    participant Test as Test Code
    participant Utils as register_test_forester (Utility)
    participant RPC as RPC Interface
    participant Chain as Solana Chain

    Test->>Utils: register_test_forester(governance_authority, forester_authority, config)
    Utils->>RPC: send registration instruction
    RPC->>Chain: submit transaction
    Chain-->>RPC: transaction result
    Utils->>RPC: fetch forester account data
    RPC-->>Utils: return account data
    Utils->>Test: assert registration result
Loading

Suggested reviewers

  • sergeytimoshin
  • SwenSchaeferjohann

Poem

In the forest of code, where the test rabbits leap,
Utilities moved burrows, but promises they keep.
With new roots and branches, the helpers now grow,
Tree accounts and foresters, all in a row.
Refactored and tidy, the test woods delight—
Hippity-hop! Everything’s working just right.
🐇🌲


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c0c78cf and e7560c5.

📒 Files selected for processing (2)
  • program-tests/utils/src/setup_forester.rs (1 hunks)
  • program-tests/utils/src/update_test_forester.rs (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • program-tests/utils/src/setup_forester.rs
  • program-tests/utils/src/update_test_forester.rs
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (25)
  • GitHub Check: Test program-libs-slow
  • GitHub Check: Test concurrent-merkle-tree
  • GitHub Check: Test batched-merkle-tree-simulate
  • GitHub Check: Test program-libs-fast
  • GitHub Check: Test sdk-libs
  • GitHub Check: lint
  • GitHub Check: cli-v2
  • GitHub Check: Forester e2e test
  • GitHub Check: system-programs (sdk-test-program, ["cargo-test-sbf -p sdk-test"])
  • GitHub Check: system-programs (sdk-anchor-test-program, ["cargo-test-sbf -p sdk-anchor-test", "cargo-test-sbf -...
  • GitHub Check: system-programs (token-escrow-test, [ "cargo test-sbf -p token-escrow" ])
  • GitHub Check: system-programs (counter-test, ["cargo test-sbf -p counter"])
  • GitHub Check: system-programs (random-e2e-test, ["cargo-test-sbf -p e2e-test"])
  • GitHub Check: system-programs (system-cpi-test-v2-other, ["cargo-test-sbf -p system-cpi-v2-test -- --skip funct...
  • GitHub Check: system-programs (light-registry, ["cargo-test-sbf -p registry-test"])
  • GitHub Check: system-programs (system-cpi-test-v2-functional, ["cargo-test-sbf -p system-cpi-v2-test -- functio...
  • GitHub Check: system-programs (system-cpi-test, ["cargo-test-sbf -p system-cpi-test"])
  • GitHub Check: system-programs (system-cpi-test-v2-event, ["cargo-test-sbf -p system-cpi-v2-test -- event::parse"])
  • GitHub Check: system-programs (light-system-program, ["cargo-test-sbf -p system-test"])
  • GitHub Check: system-programs (light-compressed-token, ["cargo-test-sbf -p compressed-token-test"])
  • GitHub Check: system-programs (account-compression, ["cargo-test-sbf -p account-compression-test"])
  • GitHub Check: stateless-js-v2
  • GitHub Check: stateless-js-v1
  • GitHub Check: cli-v1
  • GitHub Check: Analyze (javascript-typescript)
✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🧹 Nitpick comments (5)
program-tests/utils/src/e2e_test_env.rs (1)

81-81: Import can be shortened to avoid the double register_test_forester repetition

Bringing the function in with the full module → function path

use light_program_test::utils::register_test_forester::register_test_forester;

leads to the somewhat verbose call‐site pattern
register_test_forester(/* … */).

If no other symbols from register_test_forester are needed, you could import it with an alias and keep the intent clear:

-use light_program_test::utils::register_test_forester::register_test_forester;
+use light_program_test::utils::register_test_forester::register_test_forester as register_forester;

and later

-            register_test_forester(
+            register_forester(

Purely cosmetic, but reduces the cognitive load when scanning the file.

sdk-libs/program-test/src/utils/create_account.rs (1)

13-13: Consider security implications of insecure_clone().

The use of insecure_clone() may be acceptable in test utilities but should be carefully considered. Ensure this function is only used in test contexts where security is not a concern.

sdk-libs/program-test/src/utils/tree_accounts.rs (1)

13-25: Consider reordering parameters to match struct field order.

The parameter order in the constructor doesn't match the struct field order, which could be confusing for maintainability.

Apply this diff to align parameter order with struct fields:

 pub fn new(
     merkle_tree: Pubkey,
     queue: Pubkey,
-    tree_type: TreeType,
     is_rolledover: bool,
+    tree_type: TreeType,
 ) -> Self {
sdk-libs/program-test/src/utils/register_test_forester.rs (2)

31-42: Consider adding a small delay before assertion.

The function immediately asserts the forester registration after sending the transaction. In blockchain environments, there might be a small delay before the transaction is confirmed and the account state is updated.

Consider adding a small delay or retry mechanism:

 )
 .await?;
+// Small delay to ensure transaction is processed
+tokio::time::sleep(tokio::time::Duration::from_millis(100)).await;
 assert_registered_forester(

34-39: Consider explicit field initialization over Default::default().

Using ..Default::default() might hide important fields that should be explicitly set in tests. Consider initializing all fields explicitly for better test clarity.

 ForesterPda {
     authority: *forester_authority,
     config,
     active_weight: 1,
-    ..Default::default()
+    // Add explicit initialization for remaining fields
+    epoch: 0,
+    total_weight: 0,
+    // ... other fields
 }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b5e7363 and 06aec11.

📒 Files selected for processing (13)
  • forester-utils/src/registry.rs (1 hunks)
  • forester/tests/legacy/batched_address_test.rs (1 hunks)
  • program-tests/utils/src/e2e_test_env.rs (1 hunks)
  • program-tests/utils/src/lib.rs (1 hunks)
  • sdk-libs/program-test/src/accounts/address_tree.rs (1 hunks)
  • sdk-libs/program-test/src/accounts/address_tree_v2.rs (1 hunks)
  • sdk-libs/program-test/src/accounts/initialize.rs (2 hunks)
  • sdk-libs/program-test/src/accounts/state_tree.rs (1 hunks)
  • sdk-libs/program-test/src/accounts/state_tree_v2.rs (1 hunks)
  • sdk-libs/program-test/src/utils/create_account.rs (1 hunks)
  • sdk-libs/program-test/src/utils/mod.rs (1 hunks)
  • sdk-libs/program-test/src/utils/register_test_forester.rs (1 hunks)
  • sdk-libs/program-test/src/utils/tree_accounts.rs (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (3)
sdk-libs/program-test/src/utils/mod.rs (3)
sdk-libs/macros/tests/hasher.rs (1)
  • create_account (116-124)
sdk-libs/program-test/src/utils/register_test_forester.rs (1)
  • register_test_forester (13-42)
sdk-libs/program-test/src/utils/setup_light_programs.rs (1)
  • setup_light_programs (26-114)
program-tests/utils/src/e2e_test_env.rs (1)
sdk-libs/program-test/src/utils/register_test_forester.rs (1)
  • register_test_forester (13-42)
forester/tests/legacy/batched_address_test.rs (1)
forester-utils/src/registry.rs (1)
  • update_test_forester (31-64)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (24)
  • GitHub Check: system-programs (sdk-test-program, ["cargo-test-sbf -p sdk-test"])
  • GitHub Check: Forester e2e test
  • GitHub Check: system-programs (counter-test, ["cargo test-sbf -p counter"])
  • GitHub Check: system-programs (sdk-anchor-test-program, ["cargo-test-sbf -p sdk-anchor-test", "cargo-test-sbf -...
  • GitHub Check: system-programs (system-cpi-test-v2-event, ["cargo-test-sbf -p system-cpi-v2-test -- event::parse"])
  • GitHub Check: system-programs (token-escrow-test, [ "cargo test-sbf -p token-escrow" ])
  • GitHub Check: system-programs (light-registry, ["cargo-test-sbf -p registry-test"])
  • GitHub Check: system-programs (random-e2e-test, ["cargo-test-sbf -p e2e-test"])
  • GitHub Check: system-programs (system-cpi-test-v2-other, ["cargo-test-sbf -p system-cpi-v2-test -- --skip funct...
  • GitHub Check: system-programs (system-cpi-test-v2-functional, ["cargo-test-sbf -p system-cpi-v2-test -- functio...
  • GitHub Check: system-programs (light-system-program, ["cargo-test-sbf -p system-test"])
  • GitHub Check: system-programs (light-compressed-token, ["cargo-test-sbf -p compressed-token-test"])
  • GitHub Check: system-programs (system-cpi-test, ["cargo-test-sbf -p system-cpi-test"])
  • GitHub Check: system-programs (account-compression, ["cargo-test-sbf -p account-compression-test"])
  • GitHub Check: Test program-libs-fast
  • GitHub Check: Test program-libs-slow
  • GitHub Check: Test concurrent-merkle-tree
  • GitHub Check: Test sdk-libs
  • GitHub Check: Test batched-merkle-tree-simulate
  • GitHub Check: cli-v2
  • GitHub Check: stateless-js-v2
  • GitHub Check: stateless-js-v1
  • GitHub Check: cli-v1
  • GitHub Check: lint
🔇 Additional comments (13)
sdk-libs/program-test/src/accounts/address_tree_v2.rs (1)

1-1: Same visibility caveat as above

Make sure create_account_instruction is publicly reachable from crate::utils::create_account; otherwise this new import will break.

sdk-libs/program-test/src/accounts/state_tree_v2.rs (1)

2-2: Confirm utils subtree is exported

This file now depends on the same symbol. Ensure the utils module hierarchy doesn’t accidentally hide the function behind pub(crate).

sdk-libs/program-test/src/accounts/state_tree.rs (1)

6-6: Visibility check again

Identical comment: verify create_account_instruction is publicly exported so external callers (e.g. integration tests) compile.

program-tests/utils/src/lib.rs (1)

49-53: LGTM! Clean import path refactoring.

The import path change from forester_utils::registry to light_program_test::utils::register_test_forester is consistent with the PR objective to reduce forester-utils dependencies. The public API remains unchanged while the implementation is now sourced locally.

forester-utils/src/registry.rs (1)

14-14: LGTM! Appropriate cleanup of test utilities.

The removal of the register_test_forester function and its associated import aligns with the PR objective to move test utilities out of forester-utils and into the program-test crate. This improves separation of concerns between production and test code.

sdk-libs/program-test/src/utils/mod.rs (1)

2-6: LGTM! Well-organized utility module expansion.

The addition of create_account, register_test_forester, and tree_accounts modules appropriately expands the local utility capabilities and supports the dependency reduction objective. The module names are descriptive and the organization is logical.

sdk-libs/program-test/src/accounts/initialize.rs (2)

2-4: LGTM! Consistent import refactoring.

The import changes properly utilize local utilities (register_test_forester and TreeAccounts) instead of external forester-utils dependencies, maintaining consistency with the PR objective to reduce external dependencies.


235-238: LGTM! Proper type conversion handling.

The conversion from local TreeAccounts to forester_utils::forester_epoch::TreeAccounts using the to_forester_utils() method maintains compatibility while allowing for local type definitions. This is a clean approach to handling type boundaries between modules.

sdk-libs/program-test/src/utils/tree_accounts.rs (2)

4-10: LGTM: Well-structured struct with appropriate traits.

The struct design is clean with proper field visibility and derives appropriate traits for a data structure used in testing scenarios.


27-35: Constructor signature verified

The external TreeAccounts::new(merkle_tree: Pubkey, queue: Pubkey, tree_type: TreeType, is_rolledover: bool) exactly matches the arguments passed in to_forester_utils(). No changes required.

sdk-libs/program-test/src/utils/register_test_forester.rs (3)

12-18: LGTM: Well-documented function signature.

The function signature is clear and the documentation accurately describes the function's purpose.


44-58: LGTM: Proper error handling and account verification.

The assertion function correctly fetches the account data and compares it with the expected values, providing meaningful error messages on failure.


19-24: No action needed for duplicate governance authority usage

The first argument to create_register_forester_instruction is the fee payer, and throughout the codebase—including xtask/src/new_deployment.rs—we intentionally pass the same governance_authority.pubkey() for both fee payer and governance authority. This duplication is by design and does not require changes.

Likely an incorrect or invalid review comment.

};
use anchor_lang::InstructionData;
use forester_utils::instructions::create_account::create_account_instruction;
use crate::utils::create_account::create_account_instruction;
Copy link
Contributor

Choose a reason for hiding this comment

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

💡 Verification agent

🧩 Analysis chain

Import path looks correct—just confirm the module is publicly re-exported

The switch to crate::utils::create_account::create_account_instruction will compile only if mod utils; is declared at the crate root and pub mod create_account; (or pub use) exposes the function. Double-check that visibility is set; otherwise downstream crates/tests won’t see it.

Run a quick grep to verify the public re-export:


🏁 Script executed:

#!/bin/bash
# Expect at least one `pub` re-export of `create_account_instruction`
rg --line-number "pub .*create_account_instruction" | head

Length of output: 327


🏁 Script executed:

#!/bin/bash
# Verify that `mod utils;` is declared at the crate root of program-test
echo "== Checking for `mod utils;` in sdk-libs/program-test/src/lib.rs =="
rg --line-number "^mod utils;" -n sdk-libs/program-test/src/lib.rs || echo "— mod utils; not found in lib.rs"

# If no lib.rs, check main.rs
echo "== Checking for `mod utils;` in sdk-libs/program-test/src/main.rs =="
rg --line-number "^mod utils;" -n sdk-libs/program-test/src/main.rs || echo "— mod utils; not found in main.rs"

# Verify that `pub mod create_account;` is exposed in utils
echo "== Checking for `pub mod create_account;` in sdk-libs/program-test/src/utils/mod.rs =="
rg --line-number "^pub mod create_account;" -n sdk-libs/program-test/src/utils/mod.rs || echo "— pub mod create_account; not found in utils/mod.rs"

Length of output: 1190


Add and expose the utils module in the crate root

It looks like you’ve got pub mod create_account; in
sdk-libs/program-test/src/utils/mod.rs and a pub fn create_account_instruction,
but there’s no mod utils; in your crate root, so crate::utils::… won’t resolve.

Please update sdk-libs/program-test/src/lib.rs to include:

 mod accounts;
+mod utils;

+// If you need this function accessible to downstream crates:
+pub use utils::create_account::create_account_instruction;

This ensures:

  • crate::utils::create_account::create_account_instruction compiles internally
  • External consumers can import create_account_instruction directly, if required.
🤖 Prompt for AI Agents
In sdk-libs/program-test/src/lib.rs, add the line `pub mod utils;` to declare
and expose the utils module at the crate root. This will allow
`crate::utils::create_account::create_account_instruction` to resolve correctly
within the crate and enable external consumers to import
`create_account_instruction` directly if needed.

Comment on lines 4 to 7
use forester_utils::{
registry::{register_test_forester, update_test_forester},
registry::update_test_forester,
rpc_pool::SolanaRpcPoolBuilder,
};
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.

@@ -0,0 +1,17 @@
use account_compression::processor::initialize_address_merkle_tree::Pubkey;
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

Fix the incorrect Pubkey import.

The import path for Pubkey from account_compression::processor::initialize_address_merkle_tree::Pubkey is incorrect. Pubkey should be imported from the standard Solana SDK location.

Apply this diff to fix the import:

-use account_compression::processor::initialize_address_merkle_tree::Pubkey;
+use solana_sdk::pubkey::Pubkey;
📝 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 account_compression::processor::initialize_address_merkle_tree::Pubkey;
-use account_compression::processor::initialize_address_merkle_tree::Pubkey;
+use solana_sdk::pubkey::Pubkey;
🤖 Prompt for AI Agents
In sdk-libs/program-test/src/utils/create_account.rs at line 1, the import path
for Pubkey is incorrect. Replace the current import from
account_compression::processor::initialize_address_merkle_tree::Pubkey with the
correct import from the standard Solana SDK, typically
solana_program::pubkey::Pubkey, to ensure the correct Pubkey type is used.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
program-tests/utils/src/setup_forester.rs (1)

50-63: Consider making tree accounts configurable.

The function creates hardcoded tree accounts using test keypairs. This might not be flexible enough for all test scenarios that require different tree configurations.

Consider adding an optional parameter to allow custom tree accounts:

 pub async fn setup_forester_and_advance_to_epoch<R: Rpc + TestRpc>(
     context: &mut R,
     protocol_config: &ProtocolConfig,
+    custom_tree_accounts: Option<Vec<TreeAccounts>>,
 ) -> Result<Epoch, RpcError> {

Then use the custom accounts if provided, or fall back to the default ones:

-    // Create tree accounts for the epoch using test keypairs
-    let tree_accounts = vec![
-        TreeAccounts::new(
-            test_keypairs.state_merkle_tree.pubkey(),
-            test_keypairs.nullifier_queue.pubkey(),
-            TreeType::StateV1,
-            false,
-        ),
-        TreeAccounts::new(
-            test_keypairs.address_merkle_tree.pubkey(),
-            test_keypairs.address_merkle_tree_queue.pubkey(),
-            TreeType::AddressV1,
-            false,
-        ),
-    ];
+    let tree_accounts = custom_tree_accounts.unwrap_or_else(|| vec![
+        TreeAccounts::new(
+            test_keypairs.state_merkle_tree.pubkey(),
+            test_keypairs.nullifier_queue.pubkey(),
+            TreeType::StateV1,
+            false,
+        ),
+        TreeAccounts::new(
+            test_keypairs.address_merkle_tree.pubkey(),
+            test_keypairs.address_merkle_tree_queue.pubkey(),
+            TreeType::AddressV1,
+            false,
+        ),
+    ]);
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 06aec11 and 0a094fd.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (11)
  • program-tests/registry-test/tests/tests.rs (9 hunks)
  • program-tests/system-test/tests/test.rs (4 hunks)
  • program-tests/utils/src/e2e_test_env.rs (2 hunks)
  • program-tests/utils/src/lib.rs (2 hunks)
  • program-tests/utils/src/setup_forester.rs (1 hunks)
  • sdk-libs/program-test/Cargo.toml (1 hunks)
  • sdk-libs/program-test/src/accounts/initialize.rs (0 hunks)
  • sdk-libs/program-test/src/accounts/test_accounts.rs (0 hunks)
  • sdk-libs/program-test/src/program_test/config.rs (0 hunks)
  • sdk-libs/program-test/src/utils/tree_accounts.rs (1 hunks)
  • xtask/src/new_deployment.rs (0 hunks)
💤 Files with no reviewable changes (4)
  • sdk-libs/program-test/src/program_test/config.rs
  • sdk-libs/program-test/src/accounts/test_accounts.rs
  • sdk-libs/program-test/src/accounts/initialize.rs
  • xtask/src/new_deployment.rs
✅ Files skipped from review due to trivial changes (1)
  • sdk-libs/program-test/Cargo.toml
🚧 Files skipped from review as they are similar to previous changes (3)
  • program-tests/utils/src/lib.rs
  • sdk-libs/program-test/src/utils/tree_accounts.rs
  • program-tests/utils/src/e2e_test_env.rs
🧰 Additional context used
🧬 Code Graph Analysis (1)
program-tests/registry-test/tests/tests.rs (1)
program-tests/utils/src/setup_forester.rs (1)
  • setup_forester_and_advance_to_epoch (22-85)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (24)
  • GitHub Check: lint
  • GitHub Check: cli-v1
  • GitHub Check: Test concurrent-merkle-tree
  • GitHub Check: Test program-libs-fast
  • GitHub Check: system-programs (system-cpi-test-v2-other, ["cargo-test-sbf -p system-cpi-v2-test -- --skip funct...
  • GitHub Check: Test sdk-libs
  • GitHub Check: system-programs (random-e2e-test, ["cargo-test-sbf -p e2e-test"])
  • GitHub Check: Test program-libs-slow
  • GitHub Check: Test batched-merkle-tree-simulate
  • GitHub Check: system-programs (system-cpi-test-v2-functional, ["cargo-test-sbf -p system-cpi-v2-test -- functio...
  • GitHub Check: system-programs (light-registry, ["cargo-test-sbf -p registry-test"])
  • GitHub Check: system-programs (system-cpi-test, ["cargo-test-sbf -p system-cpi-test"])
  • GitHub Check: stateless-js-v1
  • GitHub Check: system-programs (account-compression, ["cargo-test-sbf -p account-compression-test"])
  • GitHub Check: system-programs (light-system-program, ["cargo-test-sbf -p system-test"])
  • GitHub Check: system-programs (system-cpi-test-v2-event, ["cargo-test-sbf -p system-cpi-v2-test -- event::parse"])
  • GitHub Check: system-programs (light-compressed-token, ["cargo-test-sbf -p compressed-token-test"])
  • GitHub Check: stateless-js-v2
  • GitHub Check: Forester e2e test
  • GitHub Check: system-programs (sdk-anchor-test-program, ["cargo-test-sbf -p sdk-anchor-test", "cargo-test-sbf -...
  • GitHub Check: system-programs (sdk-test-program, ["cargo-test-sbf -p sdk-test"])
  • GitHub Check: system-programs (token-escrow-test, [ "cargo test-sbf -p token-escrow" ])
  • GitHub Check: cli-v2
  • GitHub Check: system-programs (counter-test, ["cargo test-sbf -p counter"])
🔇 Additional comments (13)
program-tests/system-test/tests/test.rs (3)

37-37: LGTM - Clean import of the new utility function.

The import properly brings in the new forester setup utility function that consolidates the previously scattered forester initialization logic.


677-680: LGTM - Proper usage of the new forester setup utility.

The function is correctly awaited and the returned forester_epoch is used to access epoch information on subsequent lines (717, 721). This replaces the previous implicit forester setup logic.


849-852: LGTM - Consistent usage of the forester setup utility.

The function usage is consistent with the other test function, properly awaiting the result and using the returned epoch information.

program-tests/utils/src/setup_forester.rs (2)

12-25: LGTM - Well-documented function with clear purpose.

The documentation clearly explains the function's purpose and parameters, making it easy to understand how to use this utility function.


22-85: LGTM - Well-structured forester setup function.

The function effectively consolidates the forester setup process into a single reusable utility. The logical flow is clear: register forester → register epoch → advance to active phase → create tree accounts → add trees → finalize registration.

program-tests/registry-test/tests/tests.rs (8)

77-77: LGTM: Import addition is properly placed

The import for setup_forester_and_advance_to_epoch is correctly added to the imports section and aligns with the refactoring objective to centralize forester setup logic.


556-558: LGTM: Consistent setup pattern implemented

The helper function call follows the established pattern with proper parameter passing and error handling. The protocol config is correctly cloned from the RPC context.


639-641: LGTM: Consistent setup pattern implemented

The helper function call follows the established pattern with proper parameter passing and error handling. The protocol config is correctly cloned from the RPC context.


1031-1033: LGTM: Consistent setup pattern implemented

The helper function call follows the established pattern with proper parameter passing and error handling. The protocol config is correctly cloned from the RPC context.


1426-1428: LGTM: Consistent setup pattern implemented

The helper function call follows the established pattern with proper parameter passing and error handling. The protocol config is correctly cloned from the RPC context.


1699-1701: LGTM: Consistent setup pattern implemented

The helper function call follows the established pattern with proper parameter passing and error handling. The protocol config is correctly cloned from the RPC context.


1894-1896: LGTM: Consistent setup pattern implemented

The helper function call follows the established pattern with proper parameter passing and error handling. The protocol config is correctly cloned from the RPC context.


2074-2076: LGTM: Consistent setup pattern implemented

The helper function call follows the established pattern with proper parameter passing and error handling. The protocol config is correctly cloned from the RPC context.

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?

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (3)
program-tests/utils/src/update_test_forester.rs (3)

11-17: Add function documentation.

The function lacks documentation explaining its purpose, parameters, and behavior. This would improve maintainability and help other developers understand the API.

+/// Updates a forester PDA account with new configuration and optionally a new authority.
+///
+/// # Arguments
+/// * `rpc` - RPC client for blockchain operations
+/// * `forester_authority` - Current authority keypair for the forester
+/// * `derivation_key` - Key used to derive the forester PDA
+/// * `new_forester_authority` - Optional new authority to transfer ownership to
+/// * `config` - New configuration to apply to the forester
+///
+/// # Returns
+/// Result indicating success or RPC error
 pub async fn update_test_forester<R: Rpc>(

18-21: Consider handling missing account more gracefully.

The unwrap() on line 21 will panic if the forester account doesn't exist. While this might be acceptable for test utilities, consider providing a more descriptive error message.

-    let mut pre_account_state = rpc
-        .get_anchor_account::<ForesterPda>(&get_forester_pda(derivation_key).0)
-        .await?
-        .unwrap();
+    let mut pre_account_state = rpc
+        .get_anchor_account::<ForesterPda>(&get_forester_pda(derivation_key).0)
+        .await?
+        .ok_or_else(|| RpcError::AssertRpcError(
+            "Forester account not found. Ensure the forester is registered before updating.".to_string()
+        ))?;

22-31: Clarify variable naming to avoid confusion.

The variable new_authority in the tuple destructuring (line 27) shadows the parameter new_forester_authority, which could be confusing. Consider using a more descriptive name.

     let (signers, new_forester_authority) = if let Some(new_authority) = new_forester_authority {
         pre_account_state.authority = new_authority.pubkey();
 
         (
             vec![forester_authority, &new_authority],
-            Some(new_authority.pubkey()),
+            Some(new_authority.pubkey()),
         )
     } else {
         (vec![forester_authority], None)
     };

Actually, the variable naming is acceptable since it's scoped within the if-let. The code is correct as written.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3631d00 and c0c78cf.

📒 Files selected for processing (1)
  • program-tests/utils/src/update_test_forester.rs (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (24)
  • GitHub Check: stateless-js-v1
  • GitHub Check: lint
  • GitHub Check: Test program-libs-slow
  • GitHub Check: Test sdk-libs
  • GitHub Check: Test batched-merkle-tree-simulate
  • GitHub Check: Test program-libs-fast
  • GitHub Check: Test concurrent-merkle-tree
  • GitHub Check: cli-v1
  • GitHub Check: system-programs (sdk-anchor-test-program, ["cargo-test-sbf -p sdk-anchor-test", "cargo-test-sbf -...
  • GitHub Check: system-programs (sdk-test-program, ["cargo-test-sbf -p sdk-test"])
  • GitHub Check: system-programs (counter-test, ["cargo test-sbf -p counter"])
  • GitHub Check: system-programs (token-escrow-test, [ "cargo test-sbf -p token-escrow" ])
  • GitHub Check: system-programs (light-compressed-token, ["cargo-test-sbf -p compressed-token-test"])
  • GitHub Check: cli-v2
  • GitHub Check: system-programs (system-cpi-test-v2-functional, ["cargo-test-sbf -p system-cpi-v2-test -- functio...
  • GitHub Check: system-programs (light-registry, ["cargo-test-sbf -p registry-test"])
  • GitHub Check: system-programs (system-cpi-test-v2-event, ["cargo-test-sbf -p system-cpi-v2-test -- event::parse"])
  • GitHub Check: system-programs (random-e2e-test, ["cargo-test-sbf -p e2e-test"])
  • GitHub Check: Forester e2e test
  • GitHub Check: system-programs (system-cpi-test, ["cargo-test-sbf -p system-cpi-test"])
  • GitHub Check: system-programs (system-cpi-test-v2-other, ["cargo-test-sbf -p system-cpi-v2-test -- --skip funct...
  • GitHub Check: stateless-js-v2
  • GitHub Check: system-programs (account-compression, ["cargo-test-sbf -p account-compression-test"])
  • GitHub Check: system-programs (light-system-program, ["cargo-test-sbf -p system-test"])
🔇 Additional comments (2)
program-tests/utils/src/update_test_forester.rs (2)

32-44: LGTM! Transaction creation and verification logic is sound.

The instruction creation, transaction sending, and post-update verification follow proper patterns. The approach of updating the expected state and then asserting against it is appropriate for test utilities.


46-60: LGTM! Helper function provides clear error reporting.

The assertion function correctly fetches the account data and provides meaningful error messages when the actual state doesn't match expectations. The error format clearly shows both expected and actual values for debugging.

@ananas-block ananas-block force-pushed the jorrit/refactor-program-test-reduce-forester-utils-dep branch from c0c78cf to e7560c5 Compare July 14, 2025 21:27
@ananas-block ananas-block merged commit 5490ea1 into main Jul 14, 2025
33 checks passed
@ananas-block ananas-block deleted the jorrit/refactor-program-test-reduce-forester-utils-dep branch July 14, 2025 22:53
@coderabbitai coderabbitai bot mentioned this pull request Sep 2, 2025
@coderabbitai coderabbitai bot mentioned this pull request Oct 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants