Skip to content

Commit

Permalink
chore: add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Romsters committed Dec 10, 2024
1 parent 0805a56 commit b4980c3
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 2 deletions.
34 changes: 33 additions & 1 deletion src/fork.rs
Original file line number Diff line number Diff line change
Expand Up @@ -874,7 +874,7 @@ mod serde_from {
mod tests {
use zksync_multivm::interface::storage::ReadStorage;
use zksync_types::{api::TransactionVariant, StorageKey};
use zksync_types::{AccountTreeId, L1BatchNumber, H256};
use zksync_types::{AccountTreeId, L1BatchNumber, L2ChainId, H256};

use crate::config::{
cache::CacheConfig,
Expand Down Expand Up @@ -962,4 +962,36 @@ mod tests {

assert_eq!(actual_result, expected_result);
}

#[test]
fn test_fork_storage_set_chain_id() {
let fork_details = ForkDetails {
fork_source: Box::new(testing::ExternalStorage {
raw_storage: InMemoryStorage::default(),
}),
chain_id: TEST_NODE_NETWORK_ID.into(),
l1_block: L1BatchNumber(0),
l2_block: zksync_types::api::Block::<TransactionVariant>::default(),
l2_miniblock: 0,
l2_miniblock_hash: H256::zero(),
block_timestamp: 0,
overwrite_chain_id: None,
l1_gas_price: 0,
l2_fair_gas_price: 0,
fair_pubdata_price: 0,
estimate_gas_price_scale_factor: 0.0,
estimate_gas_scale_factor: 0.0,
fee_params: None,
cache_config: CacheConfig::None,
};
let mut fork_storage: ForkStorage<testing::ExternalStorage> =
ForkStorage::new(Some(fork_details), &system_contracts::Options::default(), false, None);
let new_chain_id = L2ChainId::from(261);
fork_storage.set_chain_id(new_chain_id);

let str = fork_storage.inner.read().unwrap();

assert_eq!(new_chain_id, fork_storage.chain_id);
assert_eq!(new_chain_id, str.fork.as_ref().and_then(|f| Some(f.chain_id)).unwrap());
}
}
14 changes: 13 additions & 1 deletion src/node/in_memory_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@ mod tests {
use std::sync::{Arc, RwLock};
use zksync_multivm::interface::storage::ReadStorage;
use zksync_types::{api::BlockNumber, fee::Fee, l2::L2Tx, PackedEthSignature};
use zksync_types::{Nonce, H256};
use zksync_types::{Nonce, H256, L2ChainId};
use zksync_utils::h256_to_u256;

#[tokio::test]
Expand Down Expand Up @@ -1077,4 +1077,16 @@ mod tests {
let result = node.revert_snapshot(U64::from(100));
assert!(result.is_err());
}

#[tokio::test]
async fn test_node_set_chain_id() {
let node = InMemoryNode::<HttpForkSource>::default();
let new_chain_id = 261;

let _ = node.set_chain_id(new_chain_id);

let node_inner = node.inner.read().unwrap();
assert_eq!(new_chain_id, node_inner.config.chain_id.unwrap());
assert_eq!(L2ChainId::from(new_chain_id), node_inner.fork_storage.chain_id);
}
}

0 comments on commit b4980c3

Please sign in to comment.