Example #1
0
async def handle_general_state_tests(fixture_data):
    # Start from Genesis
    params = [fixture_data]
    request_msg = build_request('evm_resetToGenesisFixture', params)
    response = await Connection.get_ipc_response(request_msg)

    if "result" in response:
        assert response[
            "result"] is True, "Unable to Reset Genesis - %s" % response
    else:
        print(response)
        assert False

    # Validate the fixture_data["pre"] states
    await validate_accounts(fixture_data['pre'])

    # Mine the fixture_data["blocks"] on the chain initialized above with genesis
    await mine_and_validate_fixture_blocks(fixture_data["blocks"])

    if fixture_data.get('lastblockhash', None):
        for block_fixture in fixture_data['blocks']:
            if get_in(['blockHeader', 'hash'],
                      block_fixture) == fixture_data['lastblockhash']:
                await validate_last_block(block_fixture)

    # Validate the fixture_data["post"] states
    await validate_accounts(fixture_data['postState'])
    # Validate that mining of above block didn't alter the previous state
    await validate_accounts(fixture_data['pre'], 'earliest')
Example #2
0
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)
Example #3
0
def get_linked_deployments(deployments: Dict[str, Any]) -> Dict[str, Any]:
    """
    Returns all deployments found in a chain URI's deployment data that contain link dependencies.
    """
    linked_deployments = {
        dep: data
        for dep, data in deployments.items()
        if get_in(("runtimeBytecode", "linkDependencies"), data)
    }
    for deployment, data in linked_deployments.items():
        if any(link_dep["value"] == deployment
               for link_dep in data["runtimeBytecode"]["linkDependencies"]):
            raise BytecodeLinkingError(
                f"Link dependency found in {deployment} deployment that references its "
                "own contract instance, which is disallowed")
    return linked_deployments
Example #4
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)
async def test_rpc_against_fixtures(event_bus, chain_fixture, fixture_data):
    rpc = await setup_rpc_server(event_bus, chain_fixture, fixture_data[0])

    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)