1
1
import pytest
2
2
3
- from eth_utils import ValidationError
3
+ from eth_utils import ValidationError , to_wei
4
4
5
5
from eth .chains .base import (
6
6
Chain ,
7
7
MiningChain ,
8
8
)
9
+ from eth .constants import ZERO_ADDRESS
9
10
from eth .tools .builder .chain import (
10
11
at_block_number ,
11
12
build ,
19
20
mine_block ,
20
21
mine_blocks ,
21
22
)
23
+ from eth .tools .factories .transaction import new_transaction
22
24
23
25
24
- MINING_CHAIN_PARAMS = (
25
- MiningChain ,
26
- frontier_at (0 ),
27
- disable_pow_check ,
28
- genesis (),
29
- )
26
+ @pytest .fixture
27
+ def mining_chain_params (funded_address ):
28
+ return (
29
+ MiningChain ,
30
+ frontier_at (0 ),
31
+ disable_pow_check ,
32
+ genesis (
33
+ params = {'gas_limit' : 1000000 },
34
+ state = {funded_address : {'balance' : to_wei (1000 , 'ether' )}}
35
+ ),
36
+ )
30
37
31
38
32
39
@pytest .fixture
33
- def mining_chain ():
34
- return build (* MINING_CHAIN_PARAMS )
40
+ def mining_chain (mining_chain_params ):
41
+ return build (* mining_chain_params )
35
42
36
43
37
44
REGULAR_CHAIN_PARAMS = (
@@ -46,11 +53,6 @@ def regular_chain():
46
53
return build (* REGULAR_CHAIN_PARAMS )
47
54
48
55
49
- @pytest .fixture (params = (MINING_CHAIN_PARAMS , REGULAR_CHAIN_PARAMS ))
50
- def any_chain (request ):
51
- return build (* request .param )
52
-
53
-
54
56
def test_chain_builder_build_single_default_block (mining_chain ):
55
57
chain = build (
56
58
mining_chain ,
@@ -92,6 +94,26 @@ def test_chain_builder_mine_block_with_parameters(mining_chain):
92
94
assert header .extra_data == b'test-setting-extra-data'
93
95
94
96
97
+ def test_chain_builder_mine_block_with_transactions (mining_chain ,
98
+ funded_address ,
99
+ funded_address_private_key ):
100
+ tx = new_transaction (
101
+ mining_chain .get_vm (),
102
+ from_ = funded_address ,
103
+ to = ZERO_ADDRESS ,
104
+ private_key = funded_address_private_key ,
105
+ )
106
+
107
+ chain = build (
108
+ mining_chain ,
109
+ mine_block (transactions = [tx ]),
110
+ )
111
+
112
+ block = chain .get_canonical_block_by_number (1 )
113
+ assert len (block .transactions ) == 1
114
+ assert block .transactions [0 ] == tx
115
+
116
+
95
117
def test_chain_builder_mine_block_only_on_mining_chain (regular_chain ):
96
118
with pytest .raises (ValidationError , match = "MiningChain" ):
97
119
mine_block ()(regular_chain )
0 commit comments