Skip to content

Commit

Permalink
chore: make requested changes
Browse files Browse the repository at this point in the history
  • Loading branch information
dutterbutter committed Dec 19, 2024
1 parent 495dba4 commit d62332d
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 27 deletions.
11 changes: 3 additions & 8 deletions crates/cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -297,21 +297,16 @@ async fn main() -> anyhow::Result<()> {
.unwrap_or(Duration::from_secs(60)); // Default to 60 seconds
let preserve_historical_states = config.preserve_historical_states;
let node_for_dumper = node.clone();
let state_dumper = tokio::task::spawn(PeriodicStateDumper::new(
let state_dumper = PeriodicStateDumper::new(
node_for_dumper,
state_path,
dump_interval,
preserve_historical_states,
));
);

let system_contracts =
SystemContracts::from_options(&config.system_contracts_options, config.use_evm_emulator);
let block_producer_handle = tokio::task::spawn(BlockProducer::new(
node,
pool,
block_sealer,
system_contracts,
));
let block_producer_handle = BlockProducer::new(node, pool, block_sealer, system_contracts);

config.print(fork_print_info.as_ref());

Expand Down
1 change: 1 addition & 0 deletions e2e-tests-rust/Cargo.lock

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

1 change: 1 addition & 0 deletions e2e-tests-rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ http = "1.1.0"
anvil_zksync_core = { path = "../crates/core" }
tempdir = "0.3.7"
flate2 = "1.0"
hex = "0.4"

[dev-dependencies]

Expand Down
53 changes: 34 additions & 19 deletions e2e-tests-rust/tests/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use alloy::{
primitives::U256,
signers::local::PrivateKeySigner,
};
use anyhow::Context;
use anvil_zksync_e2e_tests::{
init_testing_provider, init_testing_provider_with_client, AnvilZKsyncApi, ReceiptExt,
ZksyncWalletProviderExt, DEFAULT_TX_VALUE, get_node_binary_path
Expand All @@ -15,17 +16,16 @@ use http::header::{
HeaderMap, HeaderValue, ACCESS_CONTROL_ALLOW_HEADERS, ACCESS_CONTROL_ALLOW_METHODS,
ACCESS_CONTROL_ALLOW_ORIGIN, ORIGIN,
};

const SOME_ORIGIN: HeaderValue = HeaderValue::from_static("http://some.origin");
const OTHER_ORIGIN: HeaderValue = HeaderValue::from_static("http://other.origin");
const ANY_ORIGIN: HeaderValue = HeaderValue::from_static("*");

use anvil_zksync_core::node::VersionedState;
use std::{ fs, convert::identity, thread::sleep, time::Duration };
use tempdir::TempDir;
use flate2::read::GzDecoder;
use std::io::Read;

const SOME_ORIGIN: HeaderValue = HeaderValue::from_static("http://some.origin");
const OTHER_ORIGIN: HeaderValue = HeaderValue::from_static("http://other.origin");
const ANY_ORIGIN: HeaderValue = HeaderValue::from_static("*");

#[tokio::test]
async fn interval_sealing_finalization() -> anyhow::Result<()> {
// Test that we can submit a transaction and wait for it to finalize when anvil-zksync is
Expand Down Expand Up @@ -534,11 +534,11 @@ async fn dump_state_on_run() -> anyhow::Result<()> {
})
.await?;

provider.tx().finalize().await?;
let receipt = provider.tx().finalize().await?;
let tx_hash = receipt.transaction_hash().to_string();

// Allow some time for the state to be dumped
sleep(Duration::from_secs(2));

drop(provider);

assert!(
Expand All @@ -549,8 +549,8 @@ async fn dump_state_on_run() -> anyhow::Result<()> {

let dumped_data = fs::read_to_string(&dump_path)?;
let state: VersionedState = serde_json::from_str(&dumped_data)
.map_err(|e| anyhow::anyhow!("Failed to deserialize state: {}", e))?;
.context("Failed to deserialize state")?;

match state {
VersionedState::V1 { version: _, state } => {
assert!(
Expand All @@ -561,6 +561,16 @@ async fn dump_state_on_run() -> anyhow::Result<()> {
!state.transactions.is_empty(),
"state_dump.json should contain at least one transaction"
);
let tx_exists = state.transactions.iter().any(|tx| {
let tx_hash_full = format!("0x{}", hex::encode(tx.receipt.transaction_hash.as_bytes()));
tx_hash_full == tx_hash
});

assert!(
tx_exists,
"The state dump should contain the transaction with hash: {:?}",
tx_hash
);
},
VersionedState::Unknown { version } => {
panic!("Encountered unknown state version: {}", version);
Expand All @@ -587,11 +597,11 @@ async fn dump_state_on_fork() -> anyhow::Result<()> {
})
.await?;

provider.tx().finalize().await?;
let receipt = provider.tx().finalize().await?;
let tx_hash = receipt.transaction_hash().to_string();

// Allow some time for the state to be dumped
sleep(Duration::from_secs(2));

drop(provider);

assert!(
Expand All @@ -602,8 +612,8 @@ async fn dump_state_on_fork() -> anyhow::Result<()> {

let dumped_data = fs::read_to_string(&dump_path)?;
let state: VersionedState = serde_json::from_str(&dumped_data)
.map_err(|e| anyhow::anyhow!("Failed to deserialize state: {}", e))?;
.context("Failed to deserialize state")?;

match state {
VersionedState::V1 { version: _, state } => {
assert!(
Expand All @@ -614,6 +624,15 @@ async fn dump_state_on_fork() -> anyhow::Result<()> {
!state.transactions.is_empty(),
"state_dump_fork.json should contain at least one transaction"
);
let tx_exists = state.transactions.iter().any(|tx| {
let tx_hash_full = format!("0x{}", hex::encode(tx.receipt.transaction_hash.as_bytes()));
tx_hash_full == tx_hash
});
assert!(
tx_exists,
"The state dump should contain the transaction with hash: {:?}",
tx_hash
);
},
VersionedState::Unknown { version } => {
panic!("Encountered unknown state version: {}", version);
Expand Down Expand Up @@ -653,8 +672,6 @@ async fn load_state_on_run() -> anyhow::Result<()> {
})
.await?;

sleep(Duration::from_secs(2));

new_provider.assert_has_receipts(&receipts).await?;
new_provider.assert_has_blocks(&blocks).await?;
new_provider
Expand Down Expand Up @@ -706,8 +723,6 @@ async fn load_state_on_fork() -> anyhow::Result<()> {
})
.await?;

sleep(Duration::from_secs(2));

new_provider.assert_has_receipts(&receipts).await?;
new_provider.assert_has_blocks(&blocks).await?;
new_provider
Expand Down

0 comments on commit d62332d

Please sign in to comment.