forked from s94130586/mazze-rust-test-toolkits
-
Notifications
You must be signed in to change notification settings - Fork 0
/
hard_fork_test.py
executable file
·53 lines (46 loc) · 1.92 KB
/
hard_fork_test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/env python3
import sys, os
sys.path.insert(1, os.path.dirname(sys.path[0]))
from eth_utils import decode_hex
from rlp.sedes import Binary, BigEndianInt
from mazze import utils
from mazze.rpc import RpcClient
from mazze.utils import encode_hex, bytes_to_int, priv_to_addr, parse_as_int
from test_framework.blocktools import create_block
from test_framework.test_framework import MazzeTestFramework
from test_framework.mininode import *
from test_framework.util import *
FORK_HEIGHT = 20
class HardForkTest(MazzeTestFramework):
def set_test_params(self):
self.num_nodes = 2
self.conf_parameters = {
"tanzanite_transition_height": f"{FORK_HEIGHT}",
}
def setup_network(self):
self.setup_nodes()
self.add_nodes(1)
node_index = len(self.nodes) - 1
initialize_datadir(self.options.tmpdir, node_index, {})
self.start_node(node_index)
start_p2p_connection(self.nodes)
connect_sample_nodes(self.nodes, self.log, sample=2)
def run_test(self):
new_node = RpcClient(self.nodes[0])
new_node2 = RpcClient(self.nodes[1])
old_node = RpcClient(self.nodes[len(self.nodes) - 1])
old_node.generate_empty_blocks(FORK_HEIGHT - 1)
sync_blocks(self.nodes)
old_fork = old_node.generate_empty_blocks(FORK_HEIGHT)
new_fork = new_node.generate_empty_blocks(2 * FORK_HEIGHT)
wait_until(lambda: old_node.get_block_count() == 4 * FORK_HEIGHT)
wait_until(lambda: new_node.get_block_count() == 3 * FORK_HEIGHT)
wait_until(lambda: new_node2.get_block_count() == 3 * FORK_HEIGHT)
for h in new_fork:
b = new_node.block_by_hash(h)
assert_equal(int(b["blame"], 0), 0)
for h in old_fork:
assert_equal(new_node.block_by_hash(h), None)
assert_equal(new_node2.block_by_hash(h), None)
if __name__ == "__main__":
HardForkTest().main()