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

Commit a7daa58

Browse files
committed
Ensure env reset after failing test #413
1 parent 9f7960d commit a7daa58

File tree

1 file changed

+34
-32
lines changed

1 file changed

+34
-32
lines changed

ethereum/tests/test_blocks.py

Lines changed: 34 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -70,40 +70,42 @@ def run_block_test(params, config_overrides={}):
7070
blockmap = {b.hash: b}
7171
env.db.put(b.hash, rlp.encode(b))
7272
old_config = copy.deepcopy(env.config)
73-
for k, v in config_overrides.items():
74-
env.config[k] = v
75-
b2 = None
76-
for blk in params["blocks"]:
77-
if 'blockHeader' not in blk:
78-
try:
73+
try:
74+
for k, v in config_overrides.items():
75+
env.config[k] = v
76+
b2 = None
77+
for blk in params["blocks"]:
78+
if 'blockHeader' not in blk:
79+
try:
80+
rlpdata = decode_hex(blk["rlp"][2:])
81+
blkparent = rlp.decode(
82+
rlp.encode(rlp.decode(rlpdata)[0]), blocks.BlockHeader).prevhash
83+
b2 = rlp.decode(rlpdata, blocks.Block, parent=blockmap[blkparent], env=env)
84+
success = b2.validate_uncles()
85+
except (ValueError, TypeError, AttributeError, VerificationFailed,
86+
DecodingError, DeserializationError, InvalidTransaction, KeyError):
87+
success = False
88+
assert not success
89+
else:
7990
rlpdata = decode_hex(blk["rlp"][2:])
80-
blkparent = rlp.decode(
81-
rlp.encode(rlp.decode(rlpdata)[0]), blocks.BlockHeader).prevhash
91+
blkparent = rlp.decode(rlp.encode(rlp.decode(rlpdata)[0]), blocks.BlockHeader).prevhash
8292
b2 = rlp.decode(rlpdata, blocks.Block, parent=blockmap[blkparent], env=env)
83-
success = b2.validate_uncles()
84-
except (ValueError, TypeError, AttributeError, VerificationFailed,
85-
DecodingError, DeserializationError, InvalidTransaction, KeyError):
86-
success = False
87-
assert not success
88-
else:
89-
rlpdata = decode_hex(blk["rlp"][2:])
90-
blkparent = rlp.decode(rlp.encode(rlp.decode(rlpdata)[0]), blocks.BlockHeader).prevhash
91-
b2 = rlp.decode(rlpdata, blocks.Block, parent=blockmap[blkparent], env=env)
92-
assert b2.validate_uncles()
93-
blockmap[b2.hash] = b2
94-
env.db.put(b2.hash, rlp.encode(b2))
95-
if b2:
96-
print('Block %d with state root %s' % (b2.number, encode_hex(b2.state.root_hash)))
97-
# blkdict = b.to_dict(False, True, False, True)
98-
# assert blk["blockHeader"] == \
99-
# translate_keys(blkdict["header"], translator_list, lambda y, x: x, [])
100-
# assert blk["transactions"] == \
101-
# [translate_keys(t, translator_list, valueconv, ['hash'])
102-
# for t in blkdict["transactions"]]
103-
# assert blk["uncleHeader"] == \
104-
# [translate_keys(u, translator_list, lambda x: x, [])
105-
# for u in blkdict["uncles"]]
106-
env.config = old_config
93+
assert b2.validate_uncles()
94+
blockmap[b2.hash] = b2
95+
env.db.put(b2.hash, rlp.encode(b2))
96+
if b2:
97+
print('Block %d with state root %s' % (b2.number, encode_hex(b2.state.root_hash)))
98+
# blkdict = b.to_dict(False, True, False, True)
99+
# assert blk["blockHeader"] == \
100+
# translate_keys(blkdict["header"], translator_list, lambda y, x: x, [])
101+
# assert blk["transactions"] == \
102+
# [translate_keys(t, translator_list, valueconv, ['hash'])
103+
# for t in blkdict["transactions"]]
104+
# assert blk["uncleHeader"] == \
105+
# [translate_keys(u, translator_list, lambda x: x, [])
106+
# for u in blkdict["uncles"]]
107+
finally:
108+
env.config = old_config
107109

108110

109111
def test_block(filename, testname, testdata):

0 commit comments

Comments
 (0)