Skip to content
This repository was archived by the owner on May 23, 2023. It is now read-only.

Commit 53245d0

Browse files
vubvub
authored andcommitted
Fixed a bunch of state tests
1 parent 2542c28 commit 53245d0

File tree

8 files changed

+55
-43
lines changed

8 files changed

+55
-43
lines changed

ethereum/new_statetest_utils.py

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@
88
import ethereum.state_transition as state_transition
99
import copy
1010

11-
#from ethereum.slogging import LogRecorder, configure_logging, set_level
12-
#config_string = ':info,eth.vm.log:trace,eth.vm.op:trace,eth.vm.stack:trace,eth.vm.exit:trace,eth.pb.msg:trace,eth.pb.tx:debug'
13-
#configure_logging(config_string=config_string)
11+
from ethereum.slogging import LogRecorder, configure_logging, set_level
12+
config_string = ':info,eth.vm.log:trace,eth.vm.op:trace,eth.vm.stack:trace,eth.vm.exit:trace,eth.pb.msg:trace,eth.pb.tx:debug'
13+
14+
# configure_logging(config_string=config_string)
1415

1516
fake_headers = {}
1617

@@ -30,6 +31,18 @@ def mk_fake_header(blknum):
3031

3132
konfig = copy.copy(default_config)
3233

34+
konfig_homestead = copy.copy(konfig)
35+
konfig_homestead["HOMESTEAD_FORK_BLKNUM"] = 0
36+
konfig_homestead["ANTI_DOS_FORK_BLKNUM"] = 2**99
37+
konfig_homestead["CLEARING_FORK_BLKNUM"] = 2**99
38+
konfig_homestead["METROPOLIS_FORK_BLKNUM"] = 2**99
39+
40+
konfig_tangerine = copy.copy(konfig)
41+
konfig_tangerine["HOMESTEAD_FORK_BLKNUM"] = 0
42+
konfig_tangerine["ANTI_DOS_FORK_BLKNUM"] = 0
43+
konfig_tangerine["CLEARING_FORK_BLKNUM"] = 2**99
44+
konfig_tangerine["METROPOLIS_FORK_BLKNUM"] = 2**99
45+
3346
konfig_spurious = copy.copy(konfig)
3447
konfig_spurious["HOMESTEAD_FORK_BLKNUM"] = 0
3548
konfig_spurious["ANTI_DOS_FORK_BLKNUM"] = 0
@@ -43,6 +56,8 @@ def mk_fake_header(blknum):
4356
konfig_metropolis["METROPOLIS_FORK_BLKNUM"] = 0
4457

4558
configs = {
59+
#"Homestead": konfig_homestead,
60+
"EIP150": konfig_tangerine,
4661
"EIP158": konfig_spurious,
4762
"Metropolis": konfig_metropolis
4863
}
@@ -115,6 +130,6 @@ def verify_state_test(test):
115130
for result in results:
116131
computed = compute_state_test_unit(_state, test["transaction"], result["indexes"], configs[config_name])
117132
if computed["hash"] != result["hash"]:
118-
raise Exception("Hash mismatch: %s computed % supplied" % (computed["hash"], result["hash"]))
133+
raise Exception("Hash mismatch, computed: %s, supplied: %s" % (computed["hash"], result["hash"]))
119134
else:
120135
print("Hash matched!: %s" % computed["hash"])

ethereum/processblock.py

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ def _apply_msg(ext, msg, code):
7272
if trace_msg:
7373
log_msg.debug("MSG APPLY", sender=encode_hex(msg.sender), to=encode_hex(msg.to),
7474
gas=msg.gas, value=msg.value,
75-
data=encode_hex(msg.data.extract_all()))
75+
data=encode_hex(msg.data.extract_all()) if msg.data.size < 2500 else ("data<%d>" % msg.data.size))
7676
if log_state.is_active('trace'):
7777
log_state.trace('MSG PRE STATE SENDER', account=encode_hex(msg.sender),
7878
bal=ext.get_balance(msg.sender),
@@ -97,7 +97,7 @@ def _apply_msg(ext, msg, code):
9797
# assert utils.is_numeric(gas)
9898
if trace_msg:
9999
log_msg.debug('MSG APPLIED', gas_remained=gas,
100-
sender=encode_hex(msg.sender), to=encode_hex(msg.to), data=dat)
100+
sender=encode_hex(msg.sender), to=encode_hex(msg.to), data=dat if len(dat) < 2500 else ("data<%d>" % len(dat)))
101101
if log_state.is_active('trace'):
102102
log_state.trace('MSG POST STATE SENDER', account=encode_hex(msg.sender),
103103
bal=ext.get_balance(msg.sender),
@@ -118,40 +118,30 @@ def create_contract(ext, msg):
118118
#print('CREATING WITH GAS', msg.gas)
119119
sender = decode_hex(msg.sender) if len(msg.sender) == 40 else msg.sender
120120
code = msg.data.extract_all()
121-
if ext.post_metropolis_hardfork():
122-
msg.to = mk_metropolis_contract_address(msg.sender, code)
123-
if ext.get_code(msg.to):
124-
if ext.get_nonce(msg.to) >= 2**40:
125-
ext.set_nonce(msg.to, (ext.get_nonce(msg.to) + 1) % 2**160)
126-
msg.to = normalize_address((ext.get_nonce(msg.to) - 1) % 2**160)
127-
else:
128-
ext.set_nonce(msg.to, (big_endian_to_int(msg.to) + 2) % 2**160)
129-
msg.to = normalize_address((ext.get_nonce(msg.to) - 1) % 2**160)
130-
else:
131-
if ext.tx_origin != msg.sender:
132-
ext.increment_nonce(msg.sender)
133-
nonce = utils.encode_int(ext.get_nonce(msg.sender) - 1)
134-
msg.to = mk_contract_address(sender, nonce)
121+
if ext.tx_origin != msg.sender:
122+
ext.increment_nonce(msg.sender)
123+
nonce = utils.encode_int(ext.get_nonce(msg.sender) - 1)
124+
msg.to = mk_contract_address(sender, nonce)
135125
b = ext.get_balance(msg.to)
136126
if b > 0:
137127
ext.set_balance(msg.to, b)
138128
ext.set_nonce(msg.to, 0)
139129
ext.set_code(msg.to, b'')
140-
ext.reset_storage(msg.to)
130+
# ext.reset_storage(msg.to)
141131
msg.is_create = True
142132
# assert not ext.get_code(msg.to)
143133
msg.data = vm.CallData([], 0, 0)
144134
snapshot = ext.snapshot()
145135
ext.set_nonce(msg.to, 1 if ext.post_clearing_hardfork() else 0)
146136
res, gas, dat = _apply_msg(ext, msg, code)
147137
assert utils.is_numeric(gas)
148-
log_msg.debug('CONTRACT CREATION FINISHED', res=res, gas=gas, dat=dat)
138+
log_msg.debug('CONTRACT CREATION FINISHED', res=res, gas=gas, dat=dat if len(dat) < 2500 else ("data<%d>" % len(dat)))
149139

150140
if res:
151141
if not len(dat):
152142
return 1, gas, msg.to
153143
gcost = len(dat) * opcodes.GCONTRACTBYTE
154-
if gas >= gcost and len(dat) < 24000:
144+
if gas >= gcost and (len(dat) <= 24576 or not ext.post_anti_dos_hardfork()):
155145
gas -= gcost
156146
else:
157147
dat = []

ethereum/state.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from ethereum.config import default_config, Env
1212
from ethereum.block import FakeHeader
1313
from ethereum.db import BaseDB, EphemDB, OverlayDB
14+
from ethereum.specials import specials as default_specials
1415
import copy
1516
import sys
1617
if sys.version_info.major == 2:
@@ -252,7 +253,7 @@ def commit(self, allow_empties=False):
252253
if not acct.deleted:
253254
acct._cached_rlp = None
254255
# print 'moose', addr.encode('hex'), self.is_CLEARING(), acct.is_blank(), acct.nonce, acct.balance, repr(acct.code)
255-
if self.is_CLEARING() and acct.is_blank() and not allow_empties:
256+
if self.is_CLEARING() and acct.is_blank() and not allow_empties and addr not in default_specials:
256257
self.trie.delete(addr)
257258
else:
258259
self.trie.update(addr, rlp.encode(acct))
@@ -292,11 +293,11 @@ def add_log(self, log):
292293
# Returns a value x, where State.revert(x) at any later point will return
293294
# you to the point at which the snapshot was made (unless journal_reset was called).
294295
def snapshot(self):
295-
return (self.trie.root_hash, len(self.journal))
296+
return (self.trie.root_hash, len(self.journal), {k: copy.copy(getattr(self, k)) for k in STATE_DEFAULTS})
296297

297298
# Reverts to the provided snapshot
298299
def revert(self, snapshot):
299-
root, journal_length = snapshot
300+
root, journal_length, auxvars = snapshot
300301
if root != self.trie.root_hash and journal_length != 0:
301302
raise Exception("Cannot return to this snapshot")
302303
if root != self.trie.root_hash:
@@ -314,6 +315,8 @@ def revert(self, snapshot):
314315
self.cache[addr][key] = preval
315316
if not premod:
316317
del self.modified[addr]
318+
for k in STATE_DEFAULTS:
319+
setattr(self, k, copy.copy(auxvars[k]))
317320

318321
# Prints the state for a single account
319322
def account_to_dict(self, address):

ethereum/state_transition.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ def rp(what, actual, target):
236236
if tx.startgas < intrinsic_gas:
237237
raise InsufficientStartGas(rp('startgas', tx.startgas, intrinsic_gas))
238238

239-
log_tx.debug('TX NEW', tx_dict=tx.log_dict())
239+
log_tx.debug('TX NEW', tx_dict=tx.log_dict(abbrev=True))
240240
# start transacting #################
241241
state.increment_nonce(tx.sender)
242242

ethereum/tests/test_state.py

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,26 +11,31 @@
1111
configure_logging(':trace')
1212
sys.argv.remove('--trace')
1313

14-
if '--new' in sys.argv: # not default
15-
checker = new_statetest_utils.verify_state_test
16-
sys.argv.remove('--new')
14+
if '--old' in sys.argv: # not default
15+
checker = lambda x: testutils.check_state_test(testutils.fixture_to_bytes(x))
16+
place_to_check = 'StateTests'
17+
sys.argv.remove('--old')
1718
else:
18-
checker = testutils.check_state_test
19+
checker = new_statetest_utils.verify_state_test
20+
place_to_check = 'GeneralStateTests'
1921

2022

2123
def test_state(filename, testname, testdata):
2224
logger.debug('running test:%r in %r' % (testname, filename))
23-
checker(testutils.fixture_to_bytes(testdata))
25+
checker(testdata)
2426

2527

2628
def pytest_generate_tests(metafunc):
2729
testutils.generate_test_params(
28-
'StateTests',
30+
place_to_check,
2931
metafunc,
30-
lambda filename, _, __: (
31-
'stQuadraticComplexityTest.json' in filename or
32-
'stMemoryStressTest.json' in filename or
33-
'stPreCompiledContractsTransaction.json' in filename
32+
exclude_func=lambda filename, _, __: (
33+
'stQuadraticComplexityTest' in filename or
34+
'stMemoryStressTest' in filename or
35+
'stMemoryTest' in filename or
36+
'CALLCODE_Bounds3.json' in filename or
37+
'stPreCompiledContractsTransaction.json' in filename or
38+
'MLOAD_Bounds.json' in filename
3439
)
3540
)
3641

ethereum/transactions.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,11 +149,11 @@ def to_dict(self):
149149
d['hash'] = encode_hex(self.hash)
150150
return d
151151

152-
def log_dict(self):
152+
def log_dict(self, abbrev=False):
153153
d = self.to_dict()
154154
d['sender'] = encode_hex(d['sender'] or '')
155155
d['to'] = encode_hex(d['to'])
156-
d['data'] = encode_hex(d['data'])
156+
d['data'] = encode_hex(d['data']) if len(d['data']) < 2500 or not abbrev else "data<%d>" % len(d['data'])
157157
return d
158158

159159
@property

ethereum/vm.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -245,11 +245,10 @@ def vm_execute(ext, msg, code):
245245
if steps == 0:
246246
trace_data['depth'] = msg.depth
247247
trace_data['address'] = msg.to
248-
trace_data['op'] = op
249248
trace_data['steps'] = steps
250249
if op[:4] == 'PUSH':
251250
trace_data['pushvalue'] = pushval
252-
log_vm_op.trace('vm', **trace_data)
251+
log_vm_op.trace('vm', op=op, **trace_data)
253252
steps += 1
254253
_prevop = op
255254

@@ -702,7 +701,7 @@ def vm_execute(ext, msg, code):
702701
ext.set_balance(to, ext.get_balance(to) + xfer)
703702
ext.set_balance(msg.to, 0)
704703
ext.add_suicide(msg.to)
705-
# print('suiciding %s %s %d' % (msg.to, to, xfer))
704+
print('suiciding %s %s %d' % (msg.to, to, xfer))
706705
return 1, compustate.gas, []
707706

708707
# assert utils.is_numeric(compustate.gas)

fixtures

Submodule fixtures updated 26 files

0 commit comments

Comments
 (0)