async def test_rpc_against_fixtures(chain, ipc_server, chain_fixture, fixture_data): rpc = RPCServer(MainnetFullChain(None)) setup_result, setup_error = await call_rpc(rpc, 'evm_resetToGenesisFixture', [chain_fixture]) assert setup_error is None and setup_result is True, "cannot load chain for {0}".format(fixture_data) # noqa: E501 await validate_accounts(rpc, chain_fixture['pre']) for block_fixture in chain_fixture['blocks']: should_be_good_block = 'blockHeader' in block_fixture if 'rlp_error' in block_fixture: assert not should_be_good_block continue block_result, block_error = await call_rpc(rpc, 'evm_applyBlockFixture', [block_fixture]) if should_be_good_block: assert block_error is None assert block_result == block_fixture['rlp'] await validate_block(rpc, block_fixture, block_fixture['blockHeader']['hash']) else: assert block_error is not None if chain_fixture.get('lastblockhash', None): for block_fixture in chain_fixture['blocks']: if get_in(['blockHeader', 'hash'], block_fixture) == chain_fixture['lastblockhash']: await validate_last_block(rpc, block_fixture) await validate_accounts(rpc, chain_fixture['postState']) await validate_accounts(rpc, chain_fixture['pre'], 'earliest') await validate_accounts(rpc, chain_fixture['pre'], 0)
async def setup_rpc_server(event_bus, chain_fixture, fixture_path): chain = MainnetFullChain(None) rpc = RPCServer(initialize_eth1_modules(chain, event_bus), chain, event_bus) setup_result, setup_error = await call_rpc(rpc, 'evm_resetToGenesisFixture', [chain_fixture]) # We need to advance the event loop for modules to be able to pickup the new chain await asyncio.sleep(0) assert setup_error is None and setup_result is True, f"cannot load chain for {fixture_path}" return rpc
async def test_access_control(event_bus, api, param, disabled_modules, expected_result, expected_error): chain = MainnetFullChain(None) trinity_config = TrinityConfig(app_identifier="eth1", network_id=1) rpc = RPCServer(initialize_eth1_modules(chain, event_bus, trinity_config), chain, event_bus) request = build_request(api, param) response = await rpc.execute_with_access_control(disabled_modules, request) result, error = result_from_response(response) assert result == expected_result assert error == expected_error
async def test_rpc_against_fixtures(event_bus, chain_fixture, fixture_data): chain = MainnetFullChain(None) rpc = RPCServer(initialize_eth1_modules(chain, event_bus), chain, event_bus) setup_result, setup_error = await call_rpc(rpc, 'evm_resetToGenesisFixture', [chain_fixture]) # We need to advance the event loop for modules to be able to pickup the new chain await asyncio.sleep(0) assert setup_error is None and setup_result is True, "cannot load chain for {0}".format( fixture_data) # noqa: E501 await validate_accounts(rpc, chain_fixture['pre']) for block_fixture in chain_fixture['blocks']: should_be_good_block = 'blockHeader' in block_fixture if 'rlp_error' in block_fixture: assert not should_be_good_block continue block_result, block_error = await call_rpc(rpc, 'evm_applyBlockFixture', [block_fixture]) if should_be_good_block: assert block_error is None assert block_result == block_fixture['rlp'] await validate_block(rpc, block_fixture, block_fixture['blockHeader']['hash']) else: assert block_error is not None if chain_fixture.get('lastblockhash', None): for block_fixture in chain_fixture['blocks']: if get_in(['blockHeader', 'hash'], block_fixture) == chain_fixture['lastblockhash']: await validate_last_block(rpc, block_fixture) # Fixtures do not include the `postState` field when its size would be past a certain limit. # https://github.com/ethereum/tests/issues/637#issuecomment-534072897 if chain_fixture.get('postState', None): await validate_accounts(rpc, chain_fixture['postState']) await validate_accounts(rpc, chain_fixture['pre'], 'earliest') await validate_accounts(rpc, chain_fixture['pre'], 0)
async def test_rpc_against_fixtures(event_bus, chain_fixture, fixture_data): rpc = RPCServer(initialize_eth1_modules(MainnetFullChain(None), event_bus)) setup_result, setup_error = await call_rpc(rpc, 'evm_resetToGenesisFixture', [chain_fixture]) # We need to advance the event loop for modules to be able to pickup the new chain await asyncio.sleep(0) assert setup_error is None and setup_result is True, "cannot load chain for {0}".format( fixture_data) # noqa: E501 await validate_accounts(rpc, chain_fixture['pre']) for block_fixture in chain_fixture['blocks']: should_be_good_block = 'blockHeader' in block_fixture if 'rlp_error' in block_fixture: assert not should_be_good_block continue block_result, block_error = await call_rpc(rpc, 'evm_applyBlockFixture', [block_fixture]) if should_be_good_block: assert block_error is None assert block_result == block_fixture['rlp'] await validate_block(rpc, block_fixture, block_fixture['blockHeader']['hash']) else: assert block_error is not None if chain_fixture.get('lastblockhash', None): for block_fixture in chain_fixture['blocks']: if get_in(['blockHeader', 'hash'], block_fixture) == chain_fixture['lastblockhash']: await validate_last_block(rpc, block_fixture) await validate_accounts(rpc, chain_fixture['postState']) await validate_accounts(rpc, chain_fixture['pre'], 'earliest') await validate_accounts(rpc, chain_fixture['pre'], 0)