15
15
logger = get_logger ()
16
16
# configure_logging('eth.vm:trace,eth.vm.memory:info')
17
17
18
- db = EphemDB ()
19
18
20
- blocks .peck_cache (db , b'\x00 ' * 32 , ethash_utils .get_cache_size (0 ))
19
+ def mkdb ():
20
+ db = EphemDB ()
21
+ blocks .peck_cache (db , b'\x00 ' * 32 , ethash_utils .get_cache_size (0 ))
22
+ return db
21
23
22
24
23
25
@pytest .fixture (scope = "module" )
@@ -31,10 +33,10 @@ def accounts():
31
33
32
34
@pytest .fixture (scope = "module" )
33
35
def mkgenesis (initial_alloc = {}):
34
- return blocks .genesis (db , initial_alloc , difficulty = 1 )
36
+ return blocks .genesis (mkdb () , initial_alloc , difficulty = 1 )
35
37
36
38
37
- def mkquickgenesis (initial_alloc = {}, db = db ):
39
+ def mkquickgenesis (initial_alloc = {}, db = mkdb () ):
38
40
"set INITIAL_DIFFICULTY to a value that is quickly minable"
39
41
return blocks .genesis (db , initial_alloc , difficulty = 1 )
40
42
@@ -178,16 +180,6 @@ def test_mine_block():
178
180
assert blk2 .get_parent () == blk
179
181
180
182
181
- def test_mine_block_with_transaction ():
182
- k , v , k2 , v2 = accounts ()
183
- # mine two blocks
184
- a_blk = mkquickgenesis ({v : {"balance" : utils .denoms .ether * 1 }})
185
- store_block (a_blk )
186
- tx = get_transaction ()
187
- a_blk2 = mine_next_block (a_blk , transactions = [tx ])
188
- assert tx in a_blk2 .get_transactions ()
189
-
190
-
191
183
def test_block_serialization_with_transaction_empty_genesis ():
192
184
k , v , k2 , v2 = accounts ()
193
185
a_blk = mkquickgenesis ({})
@@ -198,6 +190,16 @@ def test_block_serialization_with_transaction_empty_genesis():
198
190
199
191
200
192
def test_mine_block_with_transaction ():
193
+ k , v , k2 , v2 = accounts ()
194
+ # mine two blocks
195
+ a_blk = mkquickgenesis ({v : {"balance" : utils .denoms .ether * 1 }})
196
+ store_block (a_blk )
197
+ tx = get_transaction ()
198
+ a_blk2 = mine_next_block (a_blk , transactions = [tx ])
199
+ assert tx in a_blk2 .get_transactions ()
200
+
201
+
202
+ def test_mine_block_with_transaction2 ():
201
203
k , v , k2 , v2 = accounts ()
202
204
blk = mkquickgenesis ({v : {"balance" : utils .denoms .ether * 1 }})
203
205
store_block (blk )
@@ -206,7 +208,7 @@ def test_mine_block_with_transaction():
206
208
assert tx in blk2 .get_transactions ()
207
209
store_block (blk2 )
208
210
assert tx in blk2 .get_transactions ()
209
- assert blocks .get_block (blk2 .hash ) == blk2
211
+ assert blocks .get_block (blk2 .db , blk2 . hash ) == blk2
210
212
assert tx .gasprice == 0
211
213
assert blk2 .get_balance (
212
214
v ) == blocks .BLOCK_REWARD + blk .get_balance (v ) - tx .value
@@ -216,6 +218,17 @@ def test_mine_block_with_transaction():
216
218
assert tx not in blk .get_transactions ()
217
219
218
220
221
+ def test_mine_block_with_transaction3 ():
222
+ k , v , k2 , v2 = accounts ()
223
+ blk = mkquickgenesis ({v : {"balance" : utils .denoms .ether * 1 }})
224
+ store_block (blk )
225
+ tx = get_transaction ()
226
+ blk = mine_next_block (blk , transactions = [tx ])
227
+ assert tx in blk .get_transactions ()
228
+ assert blk .get_balance (v ) == utils .denoms .finney * 990
229
+ assert blk .get_balance (v2 ) == utils .denoms .finney * 10
230
+
231
+
219
232
def test_block_serialization_same_db ():
220
233
k , v , k2 , v2 = accounts ()
221
234
blk = mkquickgenesis ({v : {"balance" : utils .denoms .ether * 1 }})
@@ -284,7 +297,6 @@ def test_block_serialization_with_transaction_other_db():
284
297
285
298
def test_transaction ():
286
299
k , v , k2 , v2 = accounts ()
287
- db = new_db ()
288
300
blk = mkquickgenesis ({v : {"balance" : utils .denoms .ether * 1 }})
289
301
store_block (blk )
290
302
blk = mine_next_block (blk )
@@ -304,21 +316,8 @@ def test_transaction_serialization():
304
316
assert tx in set ([tx ])
305
317
306
318
307
- def test_mine_block_with_transaction ():
308
- k , v , k2 , v2 = accounts ()
309
- db = new_db ()
310
- blk = mkquickgenesis ({v : {"balance" : utils .denoms .ether * 1 }})
311
- store_block (blk )
312
- tx = get_transaction ()
313
- blk = mine_next_block (blk , transactions = [tx ])
314
- assert tx in blk .get_transactions ()
315
- assert blk .get_balance (v ) == utils .denoms .finney * 990
316
- assert blk .get_balance (v2 ) == utils .denoms .finney * 10
317
-
318
-
319
319
def test_invalid_transaction ():
320
320
k , v , k2 , v2 = accounts ()
321
- db = new_db ()
322
321
blk = mkquickgenesis ({v2 : {"balance" : utils .denoms .ether * 1 }})
323
322
store_block (blk )
324
323
tx = get_transaction ()
@@ -329,7 +328,8 @@ def test_invalid_transaction():
329
328
330
329
331
330
def test_prevhash ():
332
- chain = Chain (db , mkquickgenesis ({}))
331
+ g = mkquickgenesis ({})
332
+ chain = Chain (g .db , g )
333
333
L1 = mine_next_block (chain .head )
334
334
L1 .get_ancestor_list (2 )
335
335
0 commit comments