Skip to content

dev: Better test state isolation between origin and forked devnet#825

Merged
FabijanC merged 7 commits into0xSpaceShard:mainfrom
Abeeujah:old-block-better-tested
Aug 27, 2025
Merged

dev: Better test state isolation between origin and forked devnet#825
FabijanC merged 7 commits into0xSpaceShard:mainfrom
Abeeujah:old-block-better-tested

Conversation

@Abeeujah
Copy link
Copy Markdown
Contributor

@Abeeujah Abeeujah commented Aug 12, 2025

Usage related changes

Development related changes

Checklist:

  • Checked out the contribution guidelines
  • Applied formatting - ./scripts/format.sh
  • No linter errors - ./scripts/clippy_check.sh
  • No unused dependencies - ./scripts/check_unused_deps.sh
  • No spelling errors - ./scripts/check_spelling.sh
  • Performed code self-review
  • Rebased to the latest commit of the target branch (or merged it into my branch)
    • Once you make the PR reviewable, please avoid force-pushing
  • Updated the docs if needed - ./website/README.md
  • Linked the issues resolvable by this PR - linking info
  • Updated the tests if needed; all passing - execution info

Copy link
Copy Markdown
Contributor

@FabijanC FabijanC left a comment

Choose a reason for hiding this comment

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

These test functions are too long

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Aug 12, 2025

Important

Review skipped

Auto reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

✨ Finishing Touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.
    • 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.
  • 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 the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

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

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

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.

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • 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.

@Abeeujah
Copy link
Copy Markdown
Contributor Author

Apologies, has been made less verbose

@Abeeujah Abeeujah requested a review from FabijanC August 12, 2025 12:08
@Abeeujah
Copy link
Copy Markdown
Contributor Author

Hi @FabijanC Can you please review, so I can be able to proceed to resolving another issue on this repo?

Copy link
Copy Markdown
Contributor

@FabijanC FabijanC left a comment

Choose a reason for hiding this comment

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

Please re-read the described scenario in #773.

It requires forking from block m when the latest origin block is n, where n > m. It also requires state changes at m+1, where n > m+1. Can you inspect the existing tests (added by your or older) and see if these tests already exist?

@Abeeujah
Copy link
Copy Markdown
Contributor Author

Abeeujah commented Aug 18, 2025

@FabijanC as regards to the OG issue description, the first commit I made covered that scenario

    // Block 1 => Origin Devnet
    let (_, contract_address) =
        declare_v3_deploy_v3(&predeployed_account, contract_class.clone(), casm_hash, &ctor_args)
            .await
            .unwrap();
    let entry_point_selector = get_selector_from_name("get_balance").unwrap();
    let call_result = origin_devnet
        .json_rpc_client
        .call(
            FunctionCall { contract_address, entry_point_selector, calldata: vec![] },
            BlockId::Tag(BlockTag::Latest),
        )
        .await
        .unwrap();

    assert_eq!(call_result, vec![initial_value]);

    // Block 2 => Origin Devnet
    let increment_value = Felt::from(7_u32);
    let contract_invoke = vec![Call {
        to: contract_address,
        selector: get_selector_from_name("increase_balance").unwrap(),
        calldata: vec![increment_value, Felt::ZERO],
    }];

    let invoke_result = predeployed_account
        .execute_v3(contract_invoke.clone())
        .l1_gas(0)
        .l1_data_gas(1e3 as u64)
        .l2_gas(1e7 as u64)
        .send()
        .await
        .unwrap();

    assert_tx_succeeded_accepted(&invoke_result.transaction_hash, &origin_devnet.json_rpc_client)
        .await;
    assert_eq!(
        get_contract_balance(&origin_devnet, contract_address).await,
        initial_value + increment_value
    );

    let fork_devnet = origin_devnet.fork().await.unwrap();
    assert_eq!(
        get_contract_balance(&fork_devnet, contract_address).await,
        initial_value + increment_value
    );

    // Block 3 => Origin Devnet
    let increment_value_ii = Felt::from(19_u32);
    let contract_invoke_ii = vec![Call {
        to: contract_address,
        selector: get_selector_from_name("increase_balance").unwrap(),
        calldata: vec![increment_value_ii, Felt::ZERO],
    }];

    let invoke_result_ii = predeployed_account
        .execute_v3(contract_invoke_ii.clone())
        .l1_gas(0)
        .l1_data_gas(1e3 as u64)
        .l2_gas(1e7 as u64)
        .send()
        .await
        .unwrap();

    assert_tx_succeeded_accepted(
        &invoke_result_ii.transaction_hash,
        &origin_devnet.json_rpc_client,
    )
    .await;
    assert_eq!(
        get_contract_balance(&origin_devnet, contract_address).await,
        initial_value + increment_value + increment_value_ii
    );

    // Asserting here that forked devnet balance didn't change
    assert_eq!(
        get_contract_balance(&fork_devnet, contract_address).await,
        initial_value + increment_value
    );

    // Block 4 => Origin Devnet
    let increment_value_iii = Felt::from(57_u32);
    let contract_invoke_iii = vec![Call {
        to: contract_address,
        selector: get_selector_from_name("increase_balance").unwrap(),
        calldata: vec![increment_value_iii, Felt::ZERO],
    }];

    let invoke_result_iii = predeployed_account
        .execute_v3(contract_invoke_iii.clone())
        .l1_gas(0)
        .l1_data_gas(1e3 as u64)
        .l2_gas(1e7 as u64)
        .send()
        .await
        .unwrap();

    assert_tx_succeeded_accepted(
        &invoke_result_iii.transaction_hash,
        &origin_devnet.json_rpc_client,
    )
    .await;
    assert_eq!(
        get_contract_balance(&origin_devnet, contract_address).await,
        initial_value + increment_value + increment_value_ii + increment_value_iii
    );

    // Asserting here that forked devnet balance didn't change
    assert_eq!(
        get_contract_balance(&fork_devnet, contract_address).await,
        initial_value + increment_value
    );

Only removed it when you complained the tests were too long

And if this particular issue description has been tested before, no.

The first commit in this pull request was as straight as the issue described

Imagine an origin with n blocks
- We fork from block `m < n`
- The storage of a contract state is changed at `m+1 < n`
- We assert that calling the contract in the fork with block_id = latest (or pending) returns the same as origin at `m` (and not at `m+1`)

@FabijanC
Copy link
Copy Markdown
Contributor

Saying the test functions are too long doesn't mean you ought to remove logic, rather refactor it to be more readable.

@Abeeujah
Copy link
Copy Markdown
Contributor Author

Rightly So @FabijanC done that currently, looking forward to your review

@Abeeujah Abeeujah requested a review from FabijanC August 19, 2025 22:23
@Abeeujah Abeeujah requested a review from FabijanC August 20, 2025 18:42
@FabijanC
Copy link
Copy Markdown
Contributor

Which AI tool are you using for generating the code?

@Abeeujah
Copy link
Copy Markdown
Contributor Author

None, I'm being as honest as possible here.

@Abeeujah Abeeujah requested a review from FabijanC August 22, 2025 10:42
@Abeeujah Abeeujah requested a review from FabijanC August 22, 2025 11:12
@Abeeujah
Copy link
Copy Markdown
Contributor Author

GM @FabijanC any update, on the PR Review?

@FabijanC FabijanC merged commit c0d931e into 0xSpaceShard:main Aug 27, 2025
1 check passed
@Abeeujah
Copy link
Copy Markdown
Contributor Author

Hi @FabijanC I just want to say thank you for how graceful you were through out the review process, One key takeaway I got from this is to focus solely on the issue I'm resolving, and not try to include unneccessary overhead/difficulty in my implementation;
Thank you so much.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Forking at old block should be better tested

2 participants