11import pytest
22
3- from eth_utils import ValidationError
3+ from eth_utils import ValidationError , to_wei
44
55from eth .chains .base import (
66 Chain ,
77 MiningChain ,
88)
9+ from eth .constants import ZERO_ADDRESS
910from eth .tools .builder .chain import (
1011 at_block_number ,
1112 build ,
1920 mine_block ,
2021 mine_blocks ,
2122)
23+ from eth .tools .factories .transaction import new_transaction
2224
2325
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+ )
3037
3138
3239@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 )
3542
3643
3744REGULAR_CHAIN_PARAMS = (
@@ -46,11 +53,6 @@ def regular_chain():
4653 return build (* REGULAR_CHAIN_PARAMS )
4754
4855
49- @pytest .fixture (params = (MINING_CHAIN_PARAMS , REGULAR_CHAIN_PARAMS ))
50- def any_chain (request ):
51- return build (* request .param )
52-
53-
5456def test_chain_builder_build_single_default_block (mining_chain ):
5557 chain = build (
5658 mining_chain ,
@@ -92,6 +94,26 @@ def test_chain_builder_mine_block_with_parameters(mining_chain):
9294 assert header .extra_data == b'test-setting-extra-data'
9395
9496
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+
95117def test_chain_builder_mine_block_only_on_mining_chain (regular_chain ):
96118 with pytest .raises (ValidationError , match = "MiningChain" ):
97119 mine_block ()(regular_chain )
0 commit comments