5
5
from rlp import DecodingError , DeserializationError
6
6
import sys
7
7
import ethereum .testutils as testutils
8
+ from ethereum .testutils import get_config_overrides
8
9
import copy
9
10
10
11
from ethereum .slogging import get_logger
@@ -69,47 +70,47 @@ def run_block_test(params, config_overrides={}):
69
70
blockmap = {b .hash : b }
70
71
env .db .put (b .hash , rlp .encode (b ))
71
72
old_config = copy .deepcopy (env .config )
72
- for k , v in config_overrides .items ():
73
- env .config [k ] = v
74
- b2 = None
75
- for blk in params ["blocks" ]:
76
- if 'blockHeader' not in blk :
77
- 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 :
78
90
rlpdata = decode_hex (blk ["rlp" ][2 :])
79
- blkparent = rlp .decode (
80
- rlp .encode (rlp .decode (rlpdata )[0 ]), blocks .BlockHeader ).prevhash
91
+ blkparent = rlp .decode (rlp .encode (rlp .decode (rlpdata )[0 ]), blocks .BlockHeader ).prevhash
81
92
b2 = rlp .decode (rlpdata , blocks .Block , parent = blockmap [blkparent ], env = env )
82
- success = b2 .validate_uncles ()
83
- except (ValueError , TypeError , AttributeError , VerificationFailed ,
84
- DecodingError , DeserializationError , InvalidTransaction , KeyError ):
85
- success = False
86
- assert not success
87
- else :
88
- rlpdata = decode_hex (blk ["rlp" ][2 :])
89
- blkparent = rlp .decode (rlp .encode (rlp .decode (rlpdata )[0 ]), blocks .BlockHeader ).prevhash
90
- b2 = rlp .decode (rlpdata , blocks .Block , parent = blockmap [blkparent ], env = env )
91
- assert b2 .validate_uncles ()
92
- blockmap [b2 .hash ] = b2
93
- env .db .put (b2 .hash , rlp .encode (b2 ))
94
- if b2 :
95
- print ('Block %d with state root %s' % (b2 .number , encode_hex (b2 .state .root_hash )))
96
- # blkdict = b.to_dict(False, True, False, True)
97
- # assert blk["blockHeader"] == \
98
- # translate_keys(blkdict["header"], translator_list, lambda y, x: x, [])
99
- # assert blk["transactions"] == \
100
- # [translate_keys(t, translator_list, valueconv, ['hash'])
101
- # for t in blkdict["transactions"]]
102
- # assert blk["uncleHeader"] == \
103
- # [translate_keys(u, translator_list, lambda x: x, [])
104
- # for u in blkdict["uncles"]]
105
- 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
106
109
107
110
108
111
def test_block (filename , testname , testdata ):
109
- run_block_test (testdata , {
110
- 'HOMESTEAD_FORK_BLKNUM' : 0 if 'Homestead' in filename else 5 if 'TestNetwork' in filename else 1000000 ,
111
- 'DAO_FORK_BLKNUM' : 8 if 'bcTheDaoTest' in filename else 1920000
112
- })
112
+ config_overrides = get_config_overrides (filename )
113
+ run_block_test (testdata , config_overrides = config_overrides )
113
114
114
115
115
116
excludes = {
@@ -135,18 +136,15 @@ def main():
135
136
for testname , testdata in list (tests .items ()):
136
137
if testname == sys .argv [2 ]:
137
138
print ("Testing: %s %s" % (filename , testname ))
138
- run_block_test (testdata , {
139
- 'HOMESTEAD_FORK_BLKNUM' : 0 if 'Homestead' in filename else 5 if 'TestNetwork' in filename
140
- else 1000000 ,
141
- 'DAO_FORK_BLKNUM' : 8 if 'bcTheDaoTest' in filename else 1920000 })
139
+ config_overrides = get_config_overrides (filename )
140
+ run_block_test (testdata , config_overrides = config_overrides )
142
141
else :
143
142
for filename , tests in list (fixtures .items ()):
144
143
for testname , testdata in list (tests .items ()):
145
144
if (filename .split ('/' )[- 1 ], testname ) not in excludes :
146
145
print ("Testing: %s %s" % (filename , testname ))
147
- run_block_test (testdata , {
148
- 'HOMESTEAD_FORK_BLKNUM' : 0 if 'Homestead' in filename else 5 if 'TestNetwork' in filename else 1000000 ,
149
- 'DAO_FORK_BLKNUM' : 8 if 'bcTheDaoTest' in filename else 1920000 })
146
+ config_overrides = get_config_overrides (filename )
147
+ run_block_test (testdata , config_overrides = config_overrides )
150
148
151
149
152
150
if __name__ == '__main__' :
0 commit comments