mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-18 04:13:00 +00:00
Add test
This commit is contained in:
@@ -711,3 +711,80 @@ mod http {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
mod fast {
|
||||
use super::*;
|
||||
|
||||
// Adds deposits into deposit cache and matches deposit_count and deposit_root
|
||||
// with the deposit count and root computed from the deposit cache.
|
||||
#[test]
|
||||
fn deposit_cache_query() {
|
||||
let mut env = new_env();
|
||||
let log = env.core_context().log;
|
||||
let runtime = env.runtime();
|
||||
|
||||
let eth1 = runtime
|
||||
.block_on(GanacheEth1Instance::new())
|
||||
.expect("should start eth1 environment");
|
||||
let deposit_contract = ð1.deposit_contract;
|
||||
let web3 = eth1.web3();
|
||||
|
||||
let now = get_block_number(runtime, &web3);
|
||||
let service = Service::new(
|
||||
Config {
|
||||
endpoint: eth1.endpoint(),
|
||||
deposit_contract_address: deposit_contract.address(),
|
||||
deposit_contract_deploy_block: now,
|
||||
lowest_cached_block_number: now,
|
||||
follow_distance: 0,
|
||||
block_cache_truncation: None,
|
||||
..Config::default()
|
||||
},
|
||||
log,
|
||||
);
|
||||
let n = 10;
|
||||
let deposits: Vec<_> = (0..n).into_iter().map(|_| random_deposit_data()).collect();
|
||||
for deposit in &deposits {
|
||||
deposit_contract
|
||||
.deposit(runtime, deposit.clone())
|
||||
.expect("should perform a deposit");
|
||||
// Mine an extra block between deposits to test for corner cases
|
||||
runtime
|
||||
.block_on(eth1.ganache.evm_mine())
|
||||
.expect("should mine block");
|
||||
}
|
||||
|
||||
runtime
|
||||
.block_on(service.update_deposit_cache())
|
||||
.expect("should perform update");
|
||||
|
||||
assert!(
|
||||
service.deposit_cache_len() >= n,
|
||||
"should have imported n deposits"
|
||||
);
|
||||
|
||||
for block_num in 1..=get_block_number(runtime, &web3) {
|
||||
let expected_deposit_count = blocking_deposit_count(runtime, ð1, block_num);
|
||||
let expected_deposit_root = blocking_deposit_root(runtime, ð1, block_num);
|
||||
|
||||
let deposit_count = service
|
||||
.deposits()
|
||||
.read()
|
||||
.cache
|
||||
.get_deposit_count_from_cache(block_num);
|
||||
let deposit_root = service
|
||||
.deposits()
|
||||
.read()
|
||||
.cache
|
||||
.get_deposit_root_from_cache(block_num);
|
||||
assert_eq!(
|
||||
expected_deposit_count, deposit_count,
|
||||
"deposit count from cache should match queried"
|
||||
);
|
||||
assert_eq!(
|
||||
expected_deposit_root, deposit_root,
|
||||
"deposit root from cache should match queried"
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user