async def test_regular_syncer(request, event_loop, chaindb_fresh, chaindb_20): client_peer, server_peer = await get_directly_linked_peers( request, event_loop, ETHPeer, FakeAsyncHeaderDB(chaindb_fresh.db), ETHPeer, FakeAsyncHeaderDB(chaindb_20.db)) client = RegularChainSyncer( FrontierTestChain(chaindb_fresh.db), chaindb_fresh, MockPeerPoolWithConnectedPeers([client_peer])) server = RegularChainSyncer( FrontierTestChain(chaindb_20.db), chaindb_20, MockPeerPoolWithConnectedPeers([server_peer])) asyncio.ensure_future(server.run()) def finalizer(): event_loop.run_until_complete(asyncio.gather(client.cancel(), server.cancel())) # Yield control so that client/server.run() returns, otherwise asyncio will complain. event_loop.run_until_complete(asyncio.sleep(0.1)) request.addfinalizer(finalizer) asyncio.ensure_future(client.run()) await wait_for_head(client.db, server.db.get_canonical_head()) head = client.db.get_canonical_head() assert head.state_root in client.db.db
async def test_fast_syncer(request, event_loop, chaindb_fresh, chaindb_20): client_peer, server_peer = await get_directly_linked_peers( request, event_loop, ETHPeer, FakeAsyncHeaderDB(chaindb_fresh.db), ETHPeer, FakeAsyncHeaderDB(chaindb_20.db)) client_peer_pool = MockPeerPoolWithConnectedPeers([client_peer]) client = FastChainSyncer(chaindb_fresh, client_peer_pool) server = RegularChainSyncer(FrontierTestChain(chaindb_20.db), chaindb_20, MockPeerPoolWithConnectedPeers([server_peer])) asyncio.ensure_future(server.run()) def finalizer(): event_loop.run_until_complete(server.cancel()) # Yield control so that server.run() returns, otherwise asyncio will complain. event_loop.run_until_complete(asyncio.sleep(0.1)) request.addfinalizer(finalizer) # FastChainSyncer.run() will return as soon as it's caught up with the peer. await asyncio.wait_for(client.run(), timeout=2) head = chaindb_fresh.get_canonical_head() assert head == chaindb_20.get_canonical_head() # Now download the state for the chain's head. state_downloader = StateDownloader(chaindb_fresh.db, head.state_root, client_peer_pool) await asyncio.wait_for(state_downloader.run(), timeout=2) assert head.state_root in chaindb_fresh.db