Skip to content
This repository has been archived by the owner on Jan 8, 2025. It is now read-only.

Commit

Permalink
Add hardcoded block header with base fee (#1345)
Browse files Browse the repository at this point in the history
* mongo-fuzzer: rm add_hardcoded_block_header_with_base_fee

* clean up

* fix missed arbitrary_with_optional_fields

---------

Co-authored-by: greged93 <[email protected]>
Co-authored-by: Gregory Edison <[email protected]>
  • Loading branch information
3 people authored Aug 23, 2024
1 parent af43887 commit 2bf12da
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 24 deletions.
7 changes: 0 additions & 7 deletions src/test_utils/katana/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,13 +121,6 @@ impl<'a> Katana {
mongo_fuzzer.add_random_transactions(10).expect("Failed to add documents in the database");
// Add a hardcoded logs to the MongoDB database.
mongo_fuzzer.add_random_logs(2).expect("Failed to logs in the database");
// Add a hardcoded header to the MongoDB database.
let max_block_number =
mongo_fuzzer.headers.iter().map(|header| header.number.unwrap_or_default()).max().unwrap_or_default();
mongo_fuzzer
.add_hardcoded_block_header_with_base_fee(max_block_number + 1, 0)
.expect("Failed to add header in the database");

// Finalize the MongoDB database initialization and get the database instance.
let database = mongo_fuzzer.finalize().await;

Expand Down
29 changes: 12 additions & 17 deletions src/test_utils/mongo/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,23 +127,6 @@ impl MongoFuzzer {
self.finalize().await
}

/// Adds a hardcoded block header with a base fee to the collection of headers.
pub fn add_hardcoded_block_header_with_base_fee(
&mut self,
block_number: u64,
base_fee: u128,
) -> Result<(), Box<dyn std::error::Error>> {
let bytes: Vec<u8> = (0..self.rnd_bytes_size).map(|_| rand::random()).collect();
let mut unstructured = arbitrary::Unstructured::new(&bytes);
let mut header = StoredHeader::arbitrary(&mut unstructured).unwrap();

header.header.number = Some(block_number);
header.header.base_fee_per_gas = Some(base_fee);

self.headers.push(header);
Ok(())
}

/// Adds random logs to the collection of logs.
pub fn add_random_logs(&mut self, n_logs: usize) -> Result<(), Box<dyn std::error::Error>> {
for _ in 0..n_logs {
Expand Down Expand Up @@ -203,6 +186,18 @@ impl MongoFuzzer {
// Add the receipt to the receipts collection.
self.receipts.push(receipt);
}

// At the end of our transaction list, for our tests, we need to add a block header with a base fee.
let mut header_with_base_fee = StoredHeader::arbitrary(&mut arbitrary::Unstructured::new(
&(0..self.rnd_bytes_size).map(|_| rand::random::<u8>()).collect::<Vec<_>>(),
))
.unwrap();

header_with_base_fee.header.number = Some(self.max_block_number() + 1);
header_with_base_fee.header.base_fee_per_gas = Some(0);

self.headers.push(header_with_base_fee);

Ok(())
}

Expand Down

0 comments on commit 2bf12da

Please sign in to comment.