Skip to content

Commit

Permalink
fix receipt insertion on tests setup
Browse files Browse the repository at this point in the history
  • Loading branch information
joshieDo committed Sep 2, 2024
1 parent 212a6a0 commit 6803935
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions crates/storage/provider/src/providers/blockchain_provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1444,7 +1444,9 @@ mod tests {
use crate::{
providers::BlockchainProvider2,
test_utils::{create_test_provider_factory, create_test_provider_factory_with_chain_spec},
BlockWriter, CanonChainTracker, StaticFileWriter,
writer::UnifiedStorageWriter,
BlockWriter, CanonChainTracker, StaticFileProviderFactory,
StaticFileWriter,
};
use itertools::Itertools;
use rand::Rng;
Expand Down Expand Up @@ -1547,21 +1549,25 @@ mod tests {
let factory = create_test_provider_factory_with_chain_spec(chain_spec);
let provider_rw = factory.provider_rw()?;

// Insert blocks and receipts into the database
// Insert blocks into the database
for block in &database_blocks {
provider_rw.insert_historical_block(
block.clone().seal_with_senders().expect("failed to seal block with senders"),
)?;

// Insert the receipts into the database using the writer from the provider_rw
let mut writer =
provider_rw.static_file_provider().latest_writer(StaticFileSegment::Receipts)?;
let block_number = block.number as usize;
for receipt in receipts.get(block_number).unwrap() {
writer.append_receipt(block.number, receipt)?;
}
}
provider_rw.commit()?;

// Insert receipts into the static files
UnifiedStorageWriter::new(
&provider_rw,
Some(factory.static_file_provider().latest_writer(StaticFileSegment::Receipts)?),
)
.append_receipts_from_blocks(
database_blocks.first().map(|b| b.number).unwrap_or_default(),
receipts.iter().map(|vec| vec.clone().into_iter().map(Some).collect::<Vec<_>>()),
)?;

// Commit to both storages: database and static files
UnifiedStorageWriter::commit(provider_rw, factory.static_file_provider())?;

let provider = BlockchainProvider2::new(factory)?;

Expand Down

0 comments on commit 6803935

Please sign in to comment.