def test_state_sync(): raw_db, state_root, contents = make_random_state(1000) dest_db = MemoryDB() scheduler = StateSync(state_root, dest_db) requests = scheduler.next_batch(10) while requests: results = [] for request in requests: results.append([request.node_key, raw_db[request.node_key]]) scheduler.process(results) requests = scheduler.next_batch(10) result_account_db = AccountDB(dest_db, state_root) for addr, account_data in contents.items(): balance, nonce, storage, code = account_data assert result_account_db.get_balance(addr) == balance assert result_account_db.get_nonce(addr) == nonce assert result_account_db.get_storage(addr, 0) == storage assert result_account_db.get_code(addr) == code
async def test_state_sync(): raw_db, state_root, contents = make_random_state(1000) dest_db = FakeAsyncAtomicDB() nodes_cache = AtomicDB() scheduler = StateSync(state_root, dest_db, nodes_cache, ExtendedDebugLogger('test')) requests = scheduler.next_batch(10) while requests: results = [] for request in requests: results.append([request.node_key, raw_db[request.node_key]]) await scheduler.process(results) requests = scheduler.next_batch(10) result_account_db = AccountDB(dest_db, state_root) for addr, account_data in contents.items(): balance, nonce, storage, code = account_data assert result_account_db.get_balance(addr) == balance assert result_account_db.get_nonce(addr) == nonce assert result_account_db.get_storage(addr, 0) == storage assert result_account_db.get_code(addr) == code