Port genesis tests to stable futures

This commit is contained in:
pawan
2020-03-01 01:56:44 +05:30
committed by Age Manning
parent a80f40f155
commit d778e7346e

View File

@@ -5,7 +5,7 @@
#![cfg(test)] #![cfg(test)]
use environment::{Environment, EnvironmentBuilder}; use environment::{Environment, EnvironmentBuilder};
use eth1_test_rig::{DelayThenDeposit, GanacheEth1Instance}; use eth1_test_rig::{DelayThenDeposit, GanacheEth1Instance};
use futures::Future; use futures::compat::Future01CompatExt;
use genesis::{Eth1Config, Eth1GenesisService}; use genesis::{Eth1Config, Eth1GenesisService};
use state_processing::is_valid_genesis_state; use state_processing::is_valid_genesis_state;
use std::time::Duration; use std::time::Duration;
@@ -21,21 +21,24 @@ pub fn new_env() -> Environment<MinimalEthSpec> {
.expect("should build env") .expect("should build env")
} }
#[test] #[tokio::test]
fn basic() { async fn basic() {
let mut env = new_env(); let mut env = new_env();
let log = env.core_context().log; let log = env.core_context().log;
let mut spec = env.eth2_config().spec.clone(); let mut spec = env.eth2_config().spec.clone();
let runtime = env.runtime();
let eth1 = runtime let eth1 = GanacheEth1Instance::new()
.block_on(GanacheEth1Instance::new()) .await
.expect("should start eth1 environment"); .expect("should start eth1 environment");
let deposit_contract = &eth1.deposit_contract; let deposit_contract = &eth1.deposit_contract;
let web3 = eth1.web3(); let web3 = eth1.web3();
let now = runtime let now = web3
.block_on(web3.eth().block_number().map(|v| v.as_u64())) .eth()
.block_number()
.compat()
.await
.map(|v| v.as_u64())
.expect("should get block number"); .expect("should get block number");
let service = Eth1GenesisService::new( let service = Eth1GenesisService::new(
@@ -77,8 +80,7 @@ fn basic() {
let wait_future = let wait_future =
service.wait_for_genesis_state::<MinimalEthSpec>(update_interval, spec.clone()); service.wait_for_genesis_state::<MinimalEthSpec>(update_interval, spec.clone());
let state = runtime let state = futures::try_join!(deposit_future, wait_future)
.block_on(deposit_future.join(wait_future))
.map(|(_, state)| state) .map(|(_, state)| state)
.expect("should finish waiting for genesis"); .expect("should finish waiting for genesis");