Skip to content

Commit

Permalink
Merge pull request #2161 from eqlabs/sistemd/class-and-storage-trie-t…
Browse files Browse the repository at this point in the history
…ests

p2p: use mainnet blocks in state diff stream tests
  • Loading branch information
sistemd committed Aug 14, 2024
2 parents 4c49514 + 172ebaa commit 9625019
Show file tree
Hide file tree
Showing 2 changed files with 1,721 additions and 10 deletions.
22 changes: 12 additions & 10 deletions crates/pathfinder/src/sync/checkpoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ use crate::sync::error::SyncError;
use crate::sync::stream::{InfallibleSource, Source, SyncReceiver, SyncResult};
use crate::sync::{class_definitions, events, headers, state_updates, transactions};

#[cfg(test)]
mod fixture;

/// Provides P2P sync capability for blocks secured by L1.
#[derive(Clone)]
pub struct Sync {
Expand Down Expand Up @@ -1128,7 +1131,7 @@ mod tests {

async fn setup(num_blocks: usize) -> Setup {
tokio::task::spawn_blocking(move || {
let mut blocks = fake_storage::init::with_n_blocks(num_blocks);
let mut blocks = super::fixture::blocks()[..num_blocks].to_vec();
let streamed_state_diffs = blocks
.iter()
.map(|block| {
Expand All @@ -1138,10 +1141,12 @@ mod tests {
)))
})
.collect::<Vec<_>>();
let mut implicit_declarations = HashSet::new();
let expected_state_diffs = blocks
.iter()
.map(|block| {
// Cairo0 Deploy should also count as implicit declaration
// Cairo0 Deploy should also count as implicit declaration the first time
// it happens
let mut state_diff: StateUpdateData = block.state_update.clone().into();
block
.state_update
Expand All @@ -1150,19 +1155,16 @@ mod tests {
.for_each(|(_, v)| {
v.class.as_ref().inspect(|class_update| {
if let ContractClassUpdate::Deploy(class_hash) = class_update {
state_diff.declared_cairo_classes.insert(*class_hash);
if !implicit_declarations.contains(class_hash) {
state_diff.declared_cairo_classes.insert(*class_hash);
implicit_declarations.insert(*class_hash);
}
}
});
});
state_diff
})
.collect::<Vec<_>>();
blocks.iter_mut().for_each(|block| {
// Purge state diff data and class definitions.
block.state_update = Default::default();
block.sierra_defs = Default::default();
block.cairo_defs = Default::default();
});

let storage = StorageBuilder::in_memory().unwrap();
fake_storage::fill(&storage, &blocks);
Expand All @@ -1178,7 +1180,7 @@ mod tests {

#[tokio::test]
async fn happy_path() {
const NUM_BLOCKS: usize = 10;
const NUM_BLOCKS: usize = 2;
let Setup {
streamed_state_diffs,
expected_state_diffs,
Expand Down
Loading

0 comments on commit 9625019

Please sign in to comment.