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

Commit 2ffdf64

Browse files
committed
fix: test_chain
1 parent 5a4b09d commit 2ffdf64

File tree

1 file changed

+30
-30
lines changed

1 file changed

+30
-30
lines changed

ethereum/tests/test_chain.py

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,11 @@
1515
logger = get_logger()
1616
# configure_logging('eth.vm:trace,eth.vm.memory:info')
1717

18-
db = EphemDB()
1918

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
2123

2224

2325
@pytest.fixture(scope="module")
@@ -31,10 +33,10 @@ def accounts():
3133

3234
@pytest.fixture(scope="module")
3335
def mkgenesis(initial_alloc={}):
34-
return blocks.genesis(db, initial_alloc, difficulty=1)
36+
return blocks.genesis(mkdb(), initial_alloc, difficulty=1)
3537

3638

37-
def mkquickgenesis(initial_alloc={}, db=db):
39+
def mkquickgenesis(initial_alloc={}, db=mkdb()):
3840
"set INITIAL_DIFFICULTY to a value that is quickly minable"
3941
return blocks.genesis(db, initial_alloc, difficulty=1)
4042

@@ -178,16 +180,6 @@ def test_mine_block():
178180
assert blk2.get_parent() == blk
179181

180182

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-
191183
def test_block_serialization_with_transaction_empty_genesis():
192184
k, v, k2, v2 = accounts()
193185
a_blk = mkquickgenesis({})
@@ -198,6 +190,16 @@ def test_block_serialization_with_transaction_empty_genesis():
198190

199191

200192
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():
201203
k, v, k2, v2 = accounts()
202204
blk = mkquickgenesis({v: {"balance": utils.denoms.ether * 1}})
203205
store_block(blk)
@@ -206,7 +208,7 @@ def test_mine_block_with_transaction():
206208
assert tx in blk2.get_transactions()
207209
store_block(blk2)
208210
assert tx in blk2.get_transactions()
209-
assert blocks.get_block(blk2.hash) == blk2
211+
assert blocks.get_block(blk2.db, blk2.hash) == blk2
210212
assert tx.gasprice == 0
211213
assert blk2.get_balance(
212214
v) == blocks.BLOCK_REWARD + blk.get_balance(v) - tx.value
@@ -216,6 +218,17 @@ def test_mine_block_with_transaction():
216218
assert tx not in blk.get_transactions()
217219

218220

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+
219232
def test_block_serialization_same_db():
220233
k, v, k2, v2 = accounts()
221234
blk = mkquickgenesis({v: {"balance": utils.denoms.ether * 1}})
@@ -284,7 +297,6 @@ def test_block_serialization_with_transaction_other_db():
284297

285298
def test_transaction():
286299
k, v, k2, v2 = accounts()
287-
db = new_db()
288300
blk = mkquickgenesis({v: {"balance": utils.denoms.ether * 1}})
289301
store_block(blk)
290302
blk = mine_next_block(blk)
@@ -304,21 +316,8 @@ def test_transaction_serialization():
304316
assert tx in set([tx])
305317

306318

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-
319319
def test_invalid_transaction():
320320
k, v, k2, v2 = accounts()
321-
db = new_db()
322321
blk = mkquickgenesis({v2: {"balance": utils.denoms.ether * 1}})
323322
store_block(blk)
324323
tx = get_transaction()
@@ -329,7 +328,8 @@ def test_invalid_transaction():
329328

330329

331330
def test_prevhash():
332-
chain = Chain(db, mkquickgenesis({}))
331+
g = mkquickgenesis({})
332+
chain = Chain(g.db, g)
333333
L1 = mine_next_block(chain.head)
334334
L1.get_ancestor_list(2)
335335

0 commit comments

Comments
 (0)