Skip to content

Commit

Permalink
test(provider): RequestsProvider of BlockchainProvider2 (#10356)
Browse files Browse the repository at this point in the history
  • Loading branch information
shekhirin authored Aug 21, 2024
1 parent 302ce7f commit 3da119b
Show file tree
Hide file tree
Showing 30 changed files with 236 additions and 133 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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);
let block = random_block(rng, number, Some(parent), None, None, None);
block.seal_with_senders().unwrap()
}

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

let genesis = random_block(&mut rng, 0, None, None, Some(0));
let block1 = random_block(&mut rng, 1, Some(genesis.hash()), None, Some(0));
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 (_static_dir, static_dir_path) = create_test_static_files_dir();

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

let genesis = random_block(&mut rng, 0, None, None, Some(0));
let block1 = random_block(&mut rng, 1, Some(genesis.hash()), None, Some(0));
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 (_static_dir, static_dir_path) = create_test_static_files_dir();

Expand All @@ -2304,7 +2304,7 @@ 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));
let next_head = random_block(&mut rng, 2, Some(block1.hash()), None, Some(0), None);
let next_forkchoice_state = ForkchoiceState {
head_block_hash: next_head.hash(),
finalized_block_hash: block1.hash(),
Expand Down Expand Up @@ -2356,8 +2356,8 @@ mod tests {
.disable_blockchain_tree_sync()
.build();

let genesis = random_block(&mut rng, 0, None, None, Some(0));
let block1 = random_block(&mut rng, 1, Some(genesis.hash()), None, Some(0));
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 (_static_dir, static_dir_path) = create_test_static_files_dir();

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

let genesis = random_block(&mut rng, 0, None, None, Some(0));
let mut block1 = random_block(&mut rng, 1, Some(genesis.hash()), None, Some(0));
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);
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));
let mut block2 = random_block(&mut rng, 1, Some(genesis.hash()), None, Some(0), 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));
let mut block3 = random_block(&mut rng, 1, Some(genesis.hash()), None, Some(0), None);
block3.header.set_difficulty(U256::from(1));

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

let genesis = random_block(&mut rng, 0, None, None, Some(0));
let block1 = random_block(&mut rng, 1, Some(genesis.hash()), None, Some(0));
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 (_temp_dir, temp_dir_path) = create_test_static_files_dir();

Expand Down Expand Up @@ -2524,7 +2524,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))),
block_to_payload_v1(random_block(&mut rng, 0, None, None, Some(0), None)),
None,
)
.await;
Expand All @@ -2535,7 +2535,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))),
block_to_payload_v1(random_block(&mut rng, 1, None, None, Some(0), None)),
None,
)
.await;
Expand Down Expand Up @@ -2564,9 +2564,9 @@ mod tests {
})]))
.build();

let genesis = random_block(&mut rng, 0, None, None, Some(0));
let block1 = random_block(&mut rng, 1, Some(genesis.hash()), None, Some(0));
let block2 = random_block(&mut rng, 2, Some(block1.hash()), None, Some(0));
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 (_static_dir, static_dir_path) = create_test_static_files_dir();
insert_blocks(
Expand Down Expand Up @@ -2634,7 +2634,8 @@ 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));
let block1 =
random_block(&mut rng, 1, Some(chain_spec.genesis_hash()), None, Some(0), None);

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

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

let (_static_dir, static_dir_path) = create_test_static_files_dir();

Expand Down Expand Up @@ -2713,7 +2714,7 @@ mod tests {

// Send new payload
let parent = rng.gen();
let block = random_block(&mut rng, 2, Some(parent), None, Some(0));
let block = random_block(&mut rng, 2, Some(parent), None, Some(0), 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);
let blocks = random_block_range(&mut rng, 0..=199, B256::ZERO, 1..2, 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);
let blocks = random_block_range(&mut rng, range, B256::ZERO, 0..2, 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);
let blocks = random_block_range(&mut rng, 1..=10, B256::ZERO, 2..3, 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);
let blocks = random_block_range(&mut rng, 1..=100, B256::ZERO, 2..3, 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);
let blocks = random_block_range(&mut rng, 1..=5000, B256::ZERO, 0..1, 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),
random_block_range(&mut rng, (100 + 1)..=(tip - 100), B256::ZERO, 0..1),
random_block_range(&mut rng, (tip - 100 + 1)..=tip, B256::ZERO, 1..5),
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),
]
.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);
let blocks = random_block_range(&mut rng, 1..=10, B256::ZERO, 2..3, 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);
let blocks = random_block_range(&mut rng, 0..=5000, B256::ZERO, 0..1, 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);
let blocks = random_block_range(&mut rng, 1..=10, B256::ZERO, 2..3, None);
db.insert_blocks(blocks.iter(), StorageKind::Database(None)).expect("insert blocks");

let mut tx_hash_numbers = Vec::new();
Expand Down
24 changes: 17 additions & 7 deletions crates/rpc/rpc-engine-api/src/engine_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1030,8 +1030,13 @@ mod tests {
let (handle, api) = setup_engine_api();

let (start, count) = (1, 10);
let blocks =
random_block_range(&mut rng, start..=start + count - 1, B256::default(), 0..2);
let blocks = random_block_range(
&mut rng,
start..=start + count - 1,
B256::default(),
0..2,
None,
);
handle.provider.extend_blocks(blocks.iter().cloned().map(|b| (b.hash(), b.unseal())));

let expected = blocks
Expand All @@ -1050,8 +1055,13 @@ mod tests {
let (handle, api) = setup_engine_api();

let (start, count) = (1, 100);
let blocks =
random_block_range(&mut rng, start..=start + count - 1, B256::default(), 0..2);
let blocks = random_block_range(
&mut rng,
start..=start + count - 1,
B256::default(),
0..2,
None,
);

// Insert only blocks in ranges 1-25 and 50-75
let first_missing_range = 26..=50;
Expand Down Expand Up @@ -1143,9 +1153,9 @@ mod tests {

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

let transition_config = TransitionConfiguration {
terminal_total_difficulty: handle
Expand Down Expand Up @@ -1187,7 +1197,7 @@ mod tests {

let terminal_block_number = 1000;
let terminal_block =
random_block(&mut generators::rng(), terminal_block_number, None, None, None);
random_block(&mut generators::rng(), terminal_block_number, 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) {
for block in random_block_range(&mut rng, 0..=99, B256::default(), 0..2, 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));
let block = random_block(&mut rng, 100, Some(parent), Some(3), Some(0), None);

// Valid extra data
let block_with_valid_extra_data = transform_block(block.clone(), |mut b| {
Expand Down
2 changes: 1 addition & 1 deletion crates/stages/stages/benches/setup/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ 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);
let mut blocks = random_block_range(&mut rng, 0..=num_blocks, B256::ZERO, txs_range, 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);
let blocks = random_block_range(&mut rng, 0..=end, GENESIS_HASH, 0..2, 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
2 changes: 1 addition & 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,7 @@ impl AccountHashingStage {

let mut rng = generators::rng();

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

for block in blocks {
provider.insert_historical_block(block.try_seal_with_senders().unwrap()).unwrap();
Expand Down
2 changes: 1 addition & 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,7 @@ 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);
let blocks = random_block_range(&mut rng, stage_progress..=end, B256::ZERO, 0..3, 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);
let blocks = random_block_range(&mut rng, start..=end, B256::ZERO, 0..3, 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);
let blocks = random_block_range(&mut rng, start..=end, B256::ZERO, 0..3, 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 @@ -501,6 +501,7 @@ mod tests {
0..=stage_progress - 1,
B256::ZERO,
0..1,
None,
));
self.db.insert_blocks(preblocks.iter(), StorageKind::Static)?;
}
Expand All @@ -520,6 +521,7 @@ mod tests {
preblocks.last().map(|b| b.hash()),
Some(0),
None,
None,
);
let mut header = header.unseal();

Expand All @@ -534,7 +536,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));
blocks.extend(random_block_range(&mut rng, start..=end, head_hash, 0..3, None));
let last_block = blocks.last().cloned().unwrap();
self.db.insert_blocks(blocks.iter(), StorageKind::Static)?;

Expand Down
Loading

0 comments on commit 3da119b

Please sign in to comment.