Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: determine an better solution to e2e test against fork mode #508

Open
dutterbutter opened this issue Dec 19, 2024 · 0 comments
Open

Comments

@dutterbutter
Copy link
Collaborator

Description

Current tests running against fork mode has some flakiness during initialization. We need an improved approach to test against fork mode without introducing inconsistent e2e tests. Example of such test:

#[tokio::test]
#[ignore]
// TODO: Investigate a better way to test against fork to avoid flakiness
async fn load_state_on_fork() -> anyhow::Result<()> {
    let temp_dir = TempDir::new("load-state-fork-test").expect("failed creating temporary dir");
    let dump_path = temp_dir.path().join("load_state_fork.json");
    let provider = init_testing_provider(identity).await?;
    let receipts = [
        provider.tx().finalize().await?,
        provider.tx().finalize().await?,
    ];
    let blocks = provider.get_blocks_by_receipts(&receipts).await?;
    let state_bytes = provider.anvil_dump_state().await?;
    drop(provider);

    let mut decoder = GzDecoder::new(&state_bytes.0[..]);
    let mut json_str = String::new();
    decoder.read_to_string(&mut json_str).unwrap();
    let state: VersionedState = serde_json::from_str(&json_str).unwrap();
    write_json_file(&dump_path, &state)?;

    let dump_path_clone = dump_path.clone();
    let new_provider = init_testing_provider(move |node| {
        node.path(get_node_binary_path())
            .arg("--state-interval")
            .arg("1")
            .arg("--load-state")
            .arg(dump_path_clone.to_str().unwrap())
            .fork("sepolia-testnet")
    })
    .await?;

    new_provider.assert_has_receipts(&receipts).await?;
    new_provider.assert_has_blocks(&blocks).await?;
    new_provider
        .assert_balance(receipts[0].sender()?, DEFAULT_TX_VALUE)
        .await?;
    new_provider
        .assert_balance(receipts[1].sender()?, DEFAULT_TX_VALUE)
        .await?;

    drop(new_provider);

    assert!(
        dump_path.exists(),
        "State dump file should still exist at {:?}",
        dump_path
    );

    Ok(())
}

@itegulov has suggested the following to investigate:

  • To minimize flakiness we should set up a real local ZKsync enviornment and use as forking source in all of the fork e2e tests. For example we could spin up dockerized zksync-era node and then seal some blocks.
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

No branches or pull requests

1 participant