Skip to content

Commit

Permalink
Add tests for withdrawals provider (#10428)
Browse files Browse the repository at this point in the history
  • Loading branch information
jenpaff authored Aug 22, 2024
1 parent 70a1015 commit 24495cd
Show file tree
Hide file tree
Showing 28 changed files with 293 additions and 98 deletions.
2 changes: 1 addition & 1 deletion crates/blockchain-tree/src/block_buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ mod tests {

/// Create random block with specified number and parent hash.
fn create_block<R: Rng>(rng: &mut R, number: u64, parent: BlockHash) -> SealedBlockWithSenders {
let block = random_block(rng, number, Some(parent), None, None, None);
let block = random_block(rng, number, Some(parent), None, None, None, None);
block.seal_with_senders().unwrap()
}

Expand Down
55 changes: 33 additions & 22 deletions crates/consensus/beacon/src/engine/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2230,8 +2230,8 @@ mod tests {
})]))
.build();

let genesis = random_block(&mut rng, 0, None, None, Some(0), None);
let block1 = random_block(&mut rng, 1, Some(genesis.hash()), None, Some(0), None);
let genesis = random_block(&mut rng, 0, None, None, Some(0), None, None);
let block1 = random_block(&mut rng, 1, Some(genesis.hash()), None, Some(0), None, None);
let (_static_dir, static_dir_path) = create_test_static_files_dir();

insert_blocks(
Expand Down Expand Up @@ -2289,8 +2289,8 @@ mod tests {
.disable_blockchain_tree_sync()
.build();

let genesis = random_block(&mut rng, 0, None, None, Some(0), None);
let block1 = random_block(&mut rng, 1, Some(genesis.hash()), None, Some(0), None);
let genesis = random_block(&mut rng, 0, None, None, Some(0), None, None);
let block1 = random_block(&mut rng, 1, Some(genesis.hash()), None, Some(0), None, None);

let (_static_dir, static_dir_path) = create_test_static_files_dir();

Expand All @@ -2305,7 +2305,8 @@ mod tests {

let mut engine_rx = spawn_consensus_engine(consensus_engine);

let next_head = random_block(&mut rng, 2, Some(block1.hash()), None, Some(0), None);
let next_head =
random_block(&mut rng, 2, Some(block1.hash()), None, Some(0), None, None);
let next_forkchoice_state = ForkchoiceState {
head_block_hash: next_head.hash(),
finalized_block_hash: block1.hash(),
Expand Down Expand Up @@ -2357,8 +2358,8 @@ mod tests {
.disable_blockchain_tree_sync()
.build();

let genesis = random_block(&mut rng, 0, None, None, Some(0), None);
let block1 = random_block(&mut rng, 1, Some(genesis.hash()), None, Some(0), None);
let genesis = random_block(&mut rng, 0, None, None, Some(0), None, None);
let block1 = random_block(&mut rng, 1, Some(genesis.hash()), None, Some(0), None, None);

let (_static_dir, static_dir_path) = create_test_static_files_dir();

Expand Down Expand Up @@ -2404,16 +2405,19 @@ mod tests {
]))
.build();

let genesis = random_block(&mut rng, 0, None, None, Some(0), None);
let mut block1 = random_block(&mut rng, 1, Some(genesis.hash()), None, Some(0), None);
let genesis = random_block(&mut rng, 0, None, None, Some(0), None, None);
let mut block1 =
random_block(&mut rng, 1, Some(genesis.hash()), None, Some(0), None, None);
block1.header.set_difficulty(U256::from(1));

// a second pre-merge block
let mut block2 = random_block(&mut rng, 1, Some(genesis.hash()), None, Some(0), None);
let mut block2 =
random_block(&mut rng, 1, Some(genesis.hash()), None, Some(0), None, None);
block2.header.set_difficulty(U256::from(1));

// a transition block
let mut block3 = random_block(&mut rng, 1, Some(genesis.hash()), None, Some(0), None);
let mut block3 =
random_block(&mut rng, 1, Some(genesis.hash()), None, Some(0), None, None);
block3.header.set_difficulty(U256::from(1));

let (_static_dir, static_dir_path) = create_test_static_files_dir();
Expand Down Expand Up @@ -2461,8 +2465,8 @@ mod tests {
]))
.build();

let genesis = random_block(&mut rng, 0, None, None, Some(0), None);
let block1 = random_block(&mut rng, 1, Some(genesis.hash()), None, Some(0), None);
let genesis = random_block(&mut rng, 0, None, None, Some(0), None, None);
let block1 = random_block(&mut rng, 1, Some(genesis.hash()), None, Some(0), None, None);

let (_temp_dir, temp_dir_path) = create_test_static_files_dir();

Expand Down Expand Up @@ -2525,7 +2529,7 @@ mod tests {
// Send new payload
let res = env
.send_new_payload(
block_to_payload_v1(random_block(&mut rng, 0, None, None, Some(0), None)),
block_to_payload_v1(random_block(&mut rng, 0, None, None, Some(0), None, None)),
None,
)
.await;
Expand All @@ -2536,7 +2540,7 @@ mod tests {
// Send new payload
let res = env
.send_new_payload(
block_to_payload_v1(random_block(&mut rng, 1, None, None, Some(0), None)),
block_to_payload_v1(random_block(&mut rng, 1, None, None, Some(0), None, None)),
None,
)
.await;
Expand Down Expand Up @@ -2565,9 +2569,9 @@ mod tests {
})]))
.build();

let genesis = random_block(&mut rng, 0, None, None, Some(0), None);
let block1 = random_block(&mut rng, 1, Some(genesis.hash()), None, Some(0), None);
let block2 = random_block(&mut rng, 2, Some(block1.hash()), None, Some(0), None);
let genesis = random_block(&mut rng, 0, None, None, Some(0), None, None);
let block1 = random_block(&mut rng, 1, Some(genesis.hash()), None, Some(0), None, None);
let block2 = random_block(&mut rng, 2, Some(block1.hash()), None, Some(0), None, None);

let (_static_dir, static_dir_path) = create_test_static_files_dir();
insert_blocks(
Expand Down Expand Up @@ -2635,8 +2639,15 @@ mod tests {

let genesis =
SealedBlock { header: chain_spec.sealed_genesis_header(), ..Default::default() };
let block1 =
random_block(&mut rng, 1, Some(chain_spec.genesis_hash()), None, Some(0), None);
let block1 = random_block(
&mut rng,
1,
Some(chain_spec.genesis_hash()),
None,
Some(0),
None,
None,
);

// TODO: add transactions that transfer from the alloc accounts, generating the new
// block tx and state root
Expand Down Expand Up @@ -2686,7 +2697,7 @@ mod tests {
})]))
.build();

let genesis = random_block(&mut rng, 0, None, None, Some(0), None);
let genesis = random_block(&mut rng, 0, None, None, Some(0), None, None);

let (_static_dir, static_dir_path) = create_test_static_files_dir();

Expand Down Expand Up @@ -2715,7 +2726,7 @@ mod tests {

// Send new payload
let parent = rng.gen();
let block = random_block(&mut rng, 2, Some(parent), None, Some(0), None);
let block = random_block(&mut rng, 2, Some(parent), None, Some(0), None, None);
let res = env.send_new_payload(block_to_payload_v1(block), None).await;
let expected_result = PayloadStatus::from_status(PayloadStatusEnum::Syncing);
assert_matches!(res, Ok(result) => assert_eq!(result, expected_result));
Expand Down
2 changes: 1 addition & 1 deletion crates/net/downloaders/src/bodies/bodies.rs
Original file line number Diff line number Diff line change
Expand Up @@ -652,7 +652,7 @@ mod tests {
// Generate some random blocks
let db = create_test_rw_db();
let mut rng = generators::rng();
let blocks = random_block_range(&mut rng, 0..=199, B256::ZERO, 1..2, None);
let blocks = random_block_range(&mut rng, 0..=199, B256::ZERO, 1..2, None, None);

let headers = blocks.iter().map(|block| block.header.clone()).collect::<Vec<_>>();
let bodies = blocks
Expand Down
2 changes: 1 addition & 1 deletion crates/net/downloaders/src/test_utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub(crate) fn generate_bodies(
range: RangeInclusive<u64>,
) -> (Vec<SealedHeader>, HashMap<B256, BlockBody>) {
let mut rng = generators::rng();
let blocks = random_block_range(&mut rng, range, B256::ZERO, 0..2, None);
let blocks = random_block_range(&mut rng, range, B256::ZERO, 0..2, None, None);

let headers = blocks.iter().map(|block| block.header.clone()).collect();
let bodies = blocks
Expand Down
2 changes: 1 addition & 1 deletion crates/prune/prune/src/segments/receipts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ mod tests {
let db = TestStageDB::default();
let mut rng = generators::rng();

let blocks = random_block_range(&mut rng, 1..=10, B256::ZERO, 2..3, None);
let blocks = random_block_range(&mut rng, 1..=10, B256::ZERO, 2..3, None, None);
db.insert_blocks(blocks.iter(), StorageKind::Database(None)).expect("insert blocks");

let mut receipts = Vec::new();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ mod tests {
let db = TestStageDB::default();
let mut rng = generators::rng();

let blocks = random_block_range(&mut rng, 1..=100, B256::ZERO, 2..3, None);
let blocks = random_block_range(&mut rng, 1..=100, B256::ZERO, 2..3, None, None);
db.insert_blocks(blocks.iter(), StorageKind::Database(None)).expect("insert blocks");

let transactions = blocks.iter().flat_map(|block| &block.body).collect::<Vec<_>>();
Expand Down
2 changes: 1 addition & 1 deletion crates/prune/prune/src/segments/user/account_history.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ mod tests {
let db = TestStageDB::default();
let mut rng = generators::rng();

let blocks = random_block_range(&mut rng, 1..=5000, B256::ZERO, 0..1, None);
let blocks = random_block_range(&mut rng, 1..=5000, B256::ZERO, 0..1, None, None);
db.insert_blocks(blocks.iter(), StorageKind::Database(None)).expect("insert blocks");

let accounts = random_eoa_accounts(&mut rng, 2).into_iter().collect::<BTreeMap<_, _>>();
Expand Down
6 changes: 3 additions & 3 deletions crates/prune/prune/src/segments/user/receipts_by_logs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,9 +242,9 @@ mod tests {

let tip = 20000;
let blocks = [
random_block_range(&mut rng, 0..=100, B256::ZERO, 1..5, None),
random_block_range(&mut rng, (100 + 1)..=(tip - 100), B256::ZERO, 0..1, None),
random_block_range(&mut rng, (tip - 100 + 1)..=tip, B256::ZERO, 1..5, None),
random_block_range(&mut rng, 0..=100, B256::ZERO, 1..5, None, None),
random_block_range(&mut rng, (100 + 1)..=(tip - 100), B256::ZERO, 0..1, None, None),
random_block_range(&mut rng, (tip - 100 + 1)..=tip, B256::ZERO, 1..5, None, None),
]
.concat();
db.insert_blocks(blocks.iter(), StorageKind::Database(None)).expect("insert blocks");
Expand Down
2 changes: 1 addition & 1 deletion crates/prune/prune/src/segments/user/sender_recovery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ mod tests {
let db = TestStageDB::default();
let mut rng = generators::rng();

let blocks = random_block_range(&mut rng, 1..=10, B256::ZERO, 2..3, None);
let blocks = random_block_range(&mut rng, 1..=10, B256::ZERO, 2..3, None, None);
db.insert_blocks(blocks.iter(), StorageKind::Database(None)).expect("insert blocks");

let mut transaction_senders = Vec::new();
Expand Down
2 changes: 1 addition & 1 deletion crates/prune/prune/src/segments/user/storage_history.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ mod tests {
let db = TestStageDB::default();
let mut rng = generators::rng();

let blocks = random_block_range(&mut rng, 0..=5000, B256::ZERO, 0..1, None);
let blocks = random_block_range(&mut rng, 0..=5000, B256::ZERO, 0..1, None, None);
db.insert_blocks(blocks.iter(), StorageKind::Database(None)).expect("insert blocks");

let accounts = random_eoa_accounts(&mut rng, 2).into_iter().collect::<BTreeMap<_, _>>();
Expand Down
2 changes: 1 addition & 1 deletion crates/prune/prune/src/segments/user/transaction_lookup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ mod tests {
let db = TestStageDB::default();
let mut rng = generators::rng();

let blocks = random_block_range(&mut rng, 1..=10, B256::ZERO, 2..3, None);
let blocks = random_block_range(&mut rng, 1..=10, B256::ZERO, 2..3, None, None);
db.insert_blocks(blocks.iter(), StorageKind::Database(None)).expect("insert blocks");

let mut tx_hash_numbers = Vec::new();
Expand Down
17 changes: 13 additions & 4 deletions crates/rpc/rpc-engine-api/src/engine_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1036,6 +1036,7 @@ mod tests {
B256::default(),
0..2,
None,
None,
);
handle.provider.extend_blocks(blocks.iter().cloned().map(|b| (b.hash(), b.unseal())));

Expand All @@ -1061,6 +1062,7 @@ mod tests {
B256::default(),
0..2,
None,
None,
);

// Insert only blocks in ranges 1-25 and 50-75
Expand Down Expand Up @@ -1153,9 +1155,9 @@ mod tests {

let terminal_block_number = 1000;
let consensus_terminal_block =
random_block(&mut rng, terminal_block_number, None, None, None, None);
random_block(&mut rng, terminal_block_number, None, None, None, None, None);
let execution_terminal_block =
random_block(&mut rng, terminal_block_number, None, None, None, None);
random_block(&mut rng, terminal_block_number, None, None, None, None, None);

let transition_config = TransitionConfiguration {
terminal_total_difficulty: handle
Expand Down Expand Up @@ -1196,8 +1198,15 @@ mod tests {
let (handle, api) = setup_engine_api();

let terminal_block_number = 1000;
let terminal_block =
random_block(&mut generators::rng(), terminal_block_number, None, None, None, None);
let terminal_block = random_block(
&mut generators::rng(),
terminal_block_number,
None,
None,
None,
None,
None,
);

let transition_config = TransitionConfiguration {
terminal_total_difficulty: handle
Expand Down
4 changes: 2 additions & 2 deletions crates/rpc/rpc-engine-api/tests/it/payload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ fn transform_block<F: FnOnce(Block) -> Block>(src: SealedBlock, f: F) -> Executi
#[test]
fn payload_body_roundtrip() {
let mut rng = generators::rng();
for block in random_block_range(&mut rng, 0..=99, B256::default(), 0..2, None) {
for block in random_block_range(&mut rng, 0..=99, B256::default(), 0..2, None, None) {
let unsealed = block.clone().unseal();
let payload_body: ExecutionPayloadBodyV1 = convert_to_payload_body_v1(unsealed);

Expand All @@ -53,7 +53,7 @@ fn payload_body_roundtrip() {
fn payload_validation() {
let mut rng = generators::rng();
let parent = rng.gen();
let block = random_block(&mut rng, 100, Some(parent), Some(3), Some(0), None);
let block = random_block(&mut rng, 100, Some(parent), Some(3), Some(0), None, None);

// Valid extra data
let block_with_valid_extra_data = transform_block(block.clone(), |mut b| {
Expand Down
3 changes: 2 additions & 1 deletion crates/stages/stages/benches/setup/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,8 @@ pub(crate) fn txs_testdata(num_blocks: u64) -> TestStageDB {
.into_iter()
.collect();

let mut blocks = random_block_range(&mut rng, 0..=num_blocks, B256::ZERO, txs_range, None);
let mut blocks =
random_block_range(&mut rng, 0..=num_blocks, B256::ZERO, txs_range, None, None);

let (transitions, start_state) = random_changeset_range(
&mut rng,
Expand Down
2 changes: 1 addition & 1 deletion crates/stages/stages/src/stages/bodies.rs
Original file line number Diff line number Diff line change
Expand Up @@ -719,7 +719,7 @@ mod tests {
let mut rng = generators::rng();

// Static files do not support gaps in headers, so we need to generate 0 to end
let blocks = random_block_range(&mut rng, 0..=end, GENESIS_HASH, 0..2, None);
let blocks = random_block_range(&mut rng, 0..=end, GENESIS_HASH, 0..2, None, None);
self.db.insert_headers_with_td(blocks.iter().map(|block| &block.header))?;
if let Some(progress) = blocks.get(start as usize) {
// Insert last progress data
Expand Down
3 changes: 2 additions & 1 deletion crates/stages/stages/src/stages/hashing_account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ impl AccountHashingStage {

let mut rng = generators::rng();

let blocks = random_block_range(&mut rng, opts.blocks.clone(), B256::ZERO, opts.txs, None);
let blocks =
random_block_range(&mut rng, opts.blocks.clone(), B256::ZERO, opts.txs, None, None);

for block in blocks {
provider.insert_historical_block(block.try_seal_with_senders().unwrap()).unwrap();
Expand Down
3 changes: 2 additions & 1 deletion crates/stages/stages/src/stages/hashing_storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,8 @@ mod tests {
let n_accounts = 31;
let mut accounts = random_contract_account_range(&mut rng, &mut (0..n_accounts));

let blocks = random_block_range(&mut rng, stage_progress..=end, B256::ZERO, 0..3, None);
let blocks =
random_block_range(&mut rng, stage_progress..=end, B256::ZERO, 0..3, None, None);

self.db.insert_headers(blocks.iter().map(|block| &block.header))?;

Expand Down
2 changes: 1 addition & 1 deletion crates/stages/stages/src/stages/index_account_history.rs
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,7 @@ mod tests {
.into_iter()
.collect::<BTreeMap<_, _>>();

let blocks = random_block_range(&mut rng, start..=end, B256::ZERO, 0..3, None);
let blocks = random_block_range(&mut rng, start..=end, B256::ZERO, 0..3, None, None);

let (changesets, _) = random_changeset_range(
&mut rng,
Expand Down
2 changes: 1 addition & 1 deletion crates/stages/stages/src/stages/index_storage_history.rs
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,7 @@ mod tests {
.into_iter()
.collect::<BTreeMap<_, _>>();

let blocks = random_block_range(&mut rng, start..=end, B256::ZERO, 0..3, None);
let blocks = random_block_range(&mut rng, start..=end, B256::ZERO, 0..3, None, None);

let (changesets, _) = random_changeset_range(
&mut rng,
Expand Down
4 changes: 3 additions & 1 deletion crates/stages/stages/src/stages/merkle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,7 @@ mod tests {
B256::ZERO,
0..1,
None,
None,
));
self.db.insert_blocks(preblocks.iter(), StorageKind::Static)?;
}
Expand All @@ -522,6 +523,7 @@ mod tests {
Some(0),
None,
None,
None,
);
let mut header = header.unseal();

Expand All @@ -536,7 +538,7 @@ mod tests {

let head_hash = sealed_head.hash();
let mut blocks = vec![sealed_head];
blocks.extend(random_block_range(&mut rng, start..=end, head_hash, 0..3, None));
blocks.extend(random_block_range(&mut rng, start..=end, head_hash, 0..3, None, None));
let last_block = blocks.last().cloned().unwrap();
self.db.insert_blocks(blocks.iter(), StorageKind::Static)?;

Expand Down
Loading

0 comments on commit 24495cd

Please sign in to comment.