Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update state tests #1396

Merged
merged 4 commits into from
Oct 17, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
506 changes: 506 additions & 0 deletions eth/tools/_utils/normalization.py

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions eth/tools/builder/chain/builders.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@
from eth.validation import (
validate_vm_configuration,
)
from eth.tools.fixtures.normalization import (
normalize_state,
)
from eth.tools.mining import POWMiningMixin
from eth.tools._utils.mappings import (
deep_merge,
)
from eth.tools._utils.normalization import (
normalize_state,
)
from eth.vm.forks import (
FrontierVM,
HomesteadVM,
Expand Down
2 changes: 1 addition & 1 deletion eth/tools/fixtures/fillers/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
from eth.tools.fixtures.helpers import (
get_test_name,
)
from eth.tools.fixtures.normalization import (
from eth.tools._utils.normalization import (
normalize_environment,
normalize_execution,
normalize_state,
Expand Down
2 changes: 1 addition & 1 deletion eth/tools/fixtures/fillers/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from eth.tools.fixtures.helpers import (
get_test_name,
)
from eth.tools.fixtures.normalization import (
from eth.tools._utils.normalization import (
normalize_environment,
normalize_networks,
normalize_state,
Expand Down
2 changes: 1 addition & 1 deletion eth/tools/fixtures/fillers/vm.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from eth.tools.fixtures.helpers import (
get_test_name,
)
from eth.tools.fixtures.normalization import (
from eth.tools._utils.normalization import (
normalize_bytes,
normalize_call_creates,
normalize_environment,
Expand Down
6 changes: 6 additions & 0 deletions eth/tools/fixtures/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@

from eth import MainnetChain
from eth.db.atomic import AtomicDB
from eth.tools.builder.chain import (
disable_pow_check,
)
from eth.utils.state import (
diff_account_db,
)
Expand Down Expand Up @@ -156,6 +159,9 @@ def new_chain_from_fixture(fixture, chain_cls=MainnetChain):
vm_configuration=vm_config,
)

if 'sealEngine' in fixture and fixture['sealEngine'] == 'NoProof':
ChainFromFixture = disable_pow_check(ChainFromFixture)

return ChainFromFixture.from_genesis(
base_db,
genesis_params=genesis_params_from_fixture(fixture),
Expand Down
3 changes: 3 additions & 0 deletions eth/tools/fixtures/normalization.py
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,9 @@ def normalize_blockchain_fixtures(fixture):
'network': fixture['network'],
}

if 'sealEngine' in fixture:
normalized_fixture['sealEngine'] = fixture['sealEngine']

if 'genesisRLP' in fixture:
normalized_fixture['genesisRLP'] = decode_hex(fixture['genesisRLP'])

Expand Down
2 changes: 1 addition & 1 deletion fixtures
Submodule fixtures updated 14366 files
2 changes: 1 addition & 1 deletion tests/core/fixture-tools/test_normalize_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
ValidationError,
)

from eth.tools.fixtures.normalization import normalize_state
from eth.tools._utils.normalization import normalize_state


ADDRESS_A = b'a' + b'\0' * 19
Expand Down
42 changes: 37 additions & 5 deletions tests/json-fixtures/test_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,13 @@ def fixture_vm_class(fixture_data):
raise ValueError("Unknown Fork Name: {0}".format(fork_name))


PRE_STATE_CLEARING_VMS = (
FrontierVMForTesting,
HomesteadVMForTesting,
TangerineWhistleVMForTesting,
)


def test_state_fixtures(fixture, fixture_vm_class):
header = BlockHeader(
coinbase=fixture['env']['currentCoinbase'],
Expand Down Expand Up @@ -320,19 +327,44 @@ def test_state_fixtures(fixture, fixture_vm_class):
r=r,
s=s,
)
else:
raise Exception("Invariant: No transaction specified")

try:
header, receipt, computation = vm.apply_transaction(vm.block.header, transaction)
transactions = vm.block.transactions + (transaction, )
receipts = vm.block.get_receipts(chaindb) + (receipt, )
block = vm.set_block_transactions(vm.block, header, transactions, receipts)
except ValidationError as err:
block = vm.block
transaction_error = err
logger.warning("Got transaction error", exc_info=True)
transaction_error = err
else:
transaction_error = False

transactions = vm.block.transactions + (transaction, )
receipts = vm.block.get_receipts(chaindb) + (receipt, )
vm.block = vm.set_block_transactions(vm.block, header, transactions, receipts)
finally:
# This is necessary due to the manner in which the state tests are
# generated. State tests are generated from the BlockChainTest tests
# in which these transactions are included in the larger context of a
# block and thus, the mechanisms which would touch/create/clear the
# coinbase account based on the mining reward are present during test
# generation, but not part of the execution, thus we must artificially
# create the account in VMs prior to the state clearing rules,
# as well as conditionally cleaning up the coinbase account when left
# empty in VMs after the state clearing rules came into effect.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ugh, bummer. Thanks for the writeup.

# Related change in geth:
# https://github.com/ethereum/go-ethereum/commit/32f28a9360d26a661d55915915f12fd3c70f012b#diff-f53696be8527ac422b8d4de7c8e945c1R149 # noqa: E501

if isinstance(vm, PRE_STATE_CLEARING_VMS):
state.account_db.touch_account(vm.block.header.coinbase)
state.account_db.persist()
vm.block = vm.block.copy(header=vm.block.header.copy(state_root=state.state_root))
elif state.account_db.account_is_empty(vm.block.header.coinbase):
state.account_db.delete_account(vm.block.header.coinbase)
state.account_db.persist()
vm.block = vm.block.copy(header=vm.block.header.copy(state_root=state.state_root))

block = vm.block

if not transaction_error:
log_entries = computation.get_log_entries()
actual_logs_hash = hash_log_entries(log_entries)
Expand Down