test(eth1/service): make tests use references

This commit is contained in:
Georgios Konstantopoulos 2020-06-25 08:48:32 +03:00
parent 81a89fb773
commit 4ddfc032e2
No known key found for this signature in database
GPG Key ID: FA607837CD26EDBC
2 changed files with 33 additions and 24 deletions

View File

@ -143,14 +143,17 @@ mod eth1_cache {
eth1.ganache.evm_mine().await.expect("should mine block"); eth1.ganache.evm_mine().await.expect("should mine block");
} }
Service::update_deposit_cache(service.clone()) service
.update_deposit_cache()
.await .await
.expect("should update deposit cache"); .expect("should update deposit cache");
Service::update_block_cache(service.clone()) service
.update_block_cache()
.await .await
.expect("should update block cache"); .expect("should update block cache");
Service::update_block_cache(service.clone()) service
.update_block_cache()
.await .await
.expect("should update cache when nothing has changed"); .expect("should update cache when nothing has changed");
@ -202,10 +205,12 @@ mod eth1_cache {
eth1.ganache.evm_mine().await.expect("should mine block") eth1.ganache.evm_mine().await.expect("should mine block")
} }
Service::update_deposit_cache(service.clone()) service
.update_deposit_cache()
.await .await
.expect("should update deposit cache"); .expect("should update deposit cache");
Service::update_block_cache(service.clone()) service
.update_block_cache()
.await .await
.expect("should update block cache"); .expect("should update block cache");
@ -246,10 +251,12 @@ mod eth1_cache {
for _ in 0..cache_len / 2 { for _ in 0..cache_len / 2 {
eth1.ganache.evm_mine().await.expect("should mine block") eth1.ganache.evm_mine().await.expect("should mine block")
} }
Service::update_deposit_cache(service.clone()) service
.update_deposit_cache()
.await .await
.expect("should update deposit cache"); .expect("should update deposit cache");
Service::update_block_cache(service.clone()) service
.update_block_cache()
.await .await
.expect("should update block cache"); .expect("should update block cache");
} }
@ -288,14 +295,11 @@ mod eth1_cache {
eth1.ganache.evm_mine().await.expect("should mine block") eth1.ganache.evm_mine().await.expect("should mine block")
} }
futures::try_join!( futures::try_join!(
Service::update_deposit_cache(service.clone()), service.update_deposit_cache(),
Service::update_deposit_cache(service.clone()) service.update_deposit_cache()
) )
.expect("should perform two simultaneous updates of deposit cache"); .expect("should perform two simultaneous updates of deposit cache");
futures::try_join!( futures::try_join!(service.update_block_cache(), service.update_block_cache())
Service::update_block_cache(service.clone()),
Service::update_block_cache(service.clone())
)
.expect("should perform two simultaneous updates of block cache"); .expect("should perform two simultaneous updates of block cache");
assert!(service.block_cache_len() >= n, "should grow the cache"); assert!(service.block_cache_len() >= n, "should grow the cache");
@ -340,11 +344,13 @@ mod deposit_tree {
.expect("should perform a deposit"); .expect("should perform a deposit");
} }
Service::update_deposit_cache(service.clone()) service
.update_deposit_cache()
.await .await
.expect("should perform update"); .expect("should perform update");
Service::update_deposit_cache(service.clone()) service
.update_deposit_cache()
.await .await
.expect("should perform update when nothing has changed"); .expect("should perform update when nothing has changed");
@ -413,8 +419,8 @@ mod deposit_tree {
} }
futures::try_join!( futures::try_join!(
Service::update_deposit_cache(service.clone()), service.update_deposit_cache(),
Service::update_deposit_cache(service.clone()) service.update_deposit_cache()
) )
.expect("should perform two updates concurrently"); .expect("should perform two updates concurrently");
@ -651,7 +657,8 @@ mod fast {
eth1.ganache.evm_mine().await.expect("should mine block"); eth1.ganache.evm_mine().await.expect("should mine block");
} }
Service::update_deposit_cache(service.clone()) service
.update_deposit_cache()
.await .await
.expect("should perform update"); .expect("should perform update");
@ -718,7 +725,8 @@ mod persist {
.expect("should perform a deposit"); .expect("should perform a deposit");
} }
Service::update_deposit_cache(service.clone()) service
.update_deposit_cache()
.await .await
.expect("should perform update"); .expect("should perform update");
@ -729,7 +737,8 @@ mod persist {
let deposit_count = service.deposit_cache_len(); let deposit_count = service.deposit_cache_len();
Service::update_block_cache(service.clone()) service
.update_block_cache()
.await .await
.expect("should perform update"); .expect("should perform update");

View File

@ -113,7 +113,8 @@ impl Eth1GenesisService {
); );
loop { loop {
let update_result = Eth1Service::update_deposit_cache(eth1_service.clone()) let update_result = eth1_service
.update_deposit_cache()
.await .await
.map_err(|e| format!("{:?}", e)); .map_err(|e| format!("{:?}", e));
@ -154,8 +155,7 @@ impl Eth1GenesisService {
} }
// Download new eth1 blocks into the cache. // Download new eth1 blocks into the cache.
let blocks_imported = match Eth1Service::update_block_cache(eth1_service.clone()).await let blocks_imported = match eth1_service.update_block_cache().await {
{
Ok(outcome) => { Ok(outcome) => {
debug!( debug!(
log, log,