2
2
3
3
import pytest
4
4
5
- from eth_keys import keys
6
- from eth_utils import decode_hex
7
-
8
- from eth import constants
9
- from eth .tools .mining import POWMiningMixin
10
- from eth .vm .forks .frontier import FrontierVM
11
-
12
-
13
5
from trinity .protocol .eth .servers import ETHRequestServer
14
6
from trinity .protocol .les .peer import LESPeer
15
7
from trinity .protocol .les .servers import LightRequestServer
18
10
from trinity .sync .light .chain import LightChainSyncer
19
11
20
12
from tests .trinity .core .integration_test_helpers import (
21
- FakeAsyncChain ,
13
+ ByzantiumTestChain ,
22
14
FakeAsyncChainDB ,
23
15
FakeAsyncHeaderDB ,
24
16
FakeAsyncAtomicDB ,
17
+ load_fixture_db ,
18
+ load_mining_chain ,
19
+ DBFixture ,
25
20
)
26
21
from tests .trinity .core .peer_helpers import (
27
22
get_directly_linked_peers ,
@@ -46,10 +41,10 @@ async def test_fast_syncer(request, event_loop, chaindb_fresh, chaindb_20):
46
41
alice_headerdb = FakeAsyncHeaderDB (chaindb_fresh .db ),
47
42
bob_headerdb = FakeAsyncHeaderDB (chaindb_20 .db ))
48
43
client_peer_pool = MockPeerPoolWithConnectedPeers ([client_peer ])
49
- client = FastChainSyncer (FrontierTestChain (chaindb_fresh .db ), chaindb_fresh , client_peer_pool )
44
+ client = FastChainSyncer (ByzantiumTestChain (chaindb_fresh .db ), chaindb_fresh , client_peer_pool )
50
45
server_peer_pool = MockPeerPoolWithConnectedPeers ([server_peer ])
51
46
server = RegularChainSyncer (
52
- FrontierTestChain (chaindb_20 .db ),
47
+ ByzantiumTestChain (chaindb_20 .db ),
53
48
chaindb_20 ,
54
49
server_peer_pool ,
55
50
)
@@ -86,12 +81,12 @@ async def test_regular_syncer(request, event_loop, chaindb_fresh, chaindb_20):
86
81
alice_headerdb = FakeAsyncHeaderDB (chaindb_fresh .db ),
87
82
bob_headerdb = FakeAsyncHeaderDB (chaindb_20 .db ))
88
83
client = RegularChainSyncer (
89
- FrontierTestChain (chaindb_fresh .db ),
84
+ ByzantiumTestChain (chaindb_fresh .db ),
90
85
chaindb_fresh ,
91
86
MockPeerPoolWithConnectedPeers ([client_peer ]))
92
87
server_peer_pool = MockPeerPoolWithConnectedPeers ([server_peer ])
93
88
server = RegularChainSyncer (
94
- FrontierTestChain (chaindb_20 .db ),
89
+ ByzantiumTestChain (chaindb_20 .db ),
95
90
chaindb_20 ,
96
91
server_peer_pool ,
97
92
)
@@ -126,12 +121,12 @@ async def test_light_syncer(request, event_loop, chaindb_fresh, chaindb_20):
126
121
alice_headerdb = FakeAsyncHeaderDB (chaindb_fresh .db ),
127
122
bob_headerdb = FakeAsyncHeaderDB (chaindb_20 .db ))
128
123
client = LightChainSyncer (
129
- FrontierTestChain (chaindb_fresh .db ),
124
+ ByzantiumTestChain (chaindb_fresh .db ),
130
125
chaindb_fresh ,
131
126
MockPeerPoolWithConnectedPeers ([client_peer ]))
132
127
server_peer_pool = MockPeerPoolWithConnectedPeers ([server_peer ])
133
128
server = LightChainSyncer (
134
- FrontierTestChain (chaindb_20 .db ),
129
+ ByzantiumTestChain (chaindb_20 .db ),
135
130
chaindb_20 ,
136
131
server_peer_pool ,
137
132
)
@@ -157,72 +152,24 @@ def finalizer():
157
152
158
153
159
154
@pytest .fixture
160
- def chaindb_20 ():
161
- chain = PoWMiningChain .from_genesis (FakeAsyncAtomicDB (), GENESIS_PARAMS , GENESIS_STATE )
162
- for i in range (20 ):
163
- tx = chain .create_unsigned_transaction (
164
- nonce = i ,
165
- gas_price = 1234 ,
166
- gas = 1234000 ,
167
- to = RECEIVER .public_key .to_canonical_address (),
168
- value = i ,
169
- data = b'' ,
170
- )
171
- chain .apply_transaction (tx .as_signed_transaction (SENDER ))
172
- chain .mine_block ()
155
+ def leveldb_20 ():
156
+ yield from load_fixture_db (DBFixture .twenty_pow_headers )
157
+
158
+
159
+ @pytest .fixture
160
+ def chaindb_20 (leveldb_20 ):
161
+ chain = load_mining_chain (FakeAsyncAtomicDB (leveldb_20 ))
162
+ assert chain .chaindb .get_canonical_head ().block_number == 20
173
163
return chain .chaindb
174
164
175
165
176
166
@pytest .fixture
177
167
def chaindb_fresh ():
178
- chain = PoWMiningChain . from_genesis (FakeAsyncAtomicDB (), GENESIS_PARAMS , GENESIS_STATE )
168
+ chain = load_mining_chain (FakeAsyncAtomicDB ())
179
169
assert chain .chaindb .get_canonical_head ().block_number == 0
180
170
return chain .chaindb
181
171
182
172
183
- SENDER = keys .PrivateKey (
184
- decode_hex ("49a7b37aa6f6645917e7b807e9d1c00d4fa71f18343b0d4122a4d2df64dd6fee" ))
185
- RECEIVER = keys .PrivateKey (
186
- decode_hex ("b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291" ))
187
- GENESIS_PARAMS = {
188
- 'parent_hash' : constants .GENESIS_PARENT_HASH ,
189
- 'uncles_hash' : constants .EMPTY_UNCLE_HASH ,
190
- 'coinbase' : constants .ZERO_ADDRESS ,
191
- 'transaction_root' : constants .BLANK_ROOT_HASH ,
192
- 'receipt_root' : constants .BLANK_ROOT_HASH ,
193
- 'bloom' : 0 ,
194
- 'difficulty' : 5 ,
195
- 'block_number' : constants .GENESIS_BLOCK_NUMBER ,
196
- 'gas_limit' : 3141592 ,
197
- 'gas_used' : 0 ,
198
- 'timestamp' : 1514764800 ,
199
- 'extra_data' : constants .GENESIS_EXTRA_DATA ,
200
- 'nonce' : constants .GENESIS_NONCE
201
- }
202
- GENESIS_STATE = {
203
- SENDER .public_key .to_canonical_address (): {
204
- "balance" : 100000000000000000 ,
205
- "code" : b"" ,
206
- "nonce" : 0 ,
207
- "storage" : {}
208
- }
209
- }
210
-
211
-
212
- class FrontierTestChain (FakeAsyncChain ):
213
- vm_configuration = ((0 , FrontierVM ),)
214
- chaindb_class = FakeAsyncChainDB
215
- network_id = 999
216
-
217
-
218
- class POWFrontierVM (POWMiningMixin , FrontierVM ):
219
- pass
220
-
221
-
222
- class PoWMiningChain (FrontierTestChain ):
223
- vm_configuration = ((0 , POWFrontierVM ),)
224
-
225
-
226
173
async def wait_for_head (headerdb , header ):
227
174
# A full header sync may involve several round trips, so we must be willing to wait a little
228
175
# bit for them.
0 commit comments