forked from dingocoin/dingocoin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathauxpow.py
executable file
·88 lines (71 loc) · 3.09 KB
/
auxpow.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#!/usr/bin/env python3
# Copyright (c) 2015-2018 The Dingocoin Core developers
# Distributed under the MIT software license, see the accompanying
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
#
# Test AuxPOW RPC interface and constraints
#
from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import *
from test_framework import scrypt_auxpow
class AuxPOWTest (BitcoinTestFramework):
REWARD = 500000 # reward per block
CHAIN_ID = "62"
DIGISHIELD_START = 10 # nHeight when digishield starts
AUXPOW_START = 20 # nHeight when auxpow starts
MATURITY_HEIGHT = 60 # number of blocks for mined transactions to mature
def setup_chain(self):
print("Initializing test directory " + self.options.tmpdir)
initialize_chain_clean(self.options.tmpdir, 2)
def setup_network(self, split=False):
self.nodes = start_nodes(2, self.options.tmpdir)
connect_nodes_bi(self.nodes,0,1)
self.is_network_split=False
self.sync_all()
def run_test(self):
print("Mining blocks...")
# 1. mine an auxpow block before auxpow is allowed, expect: fail
try:
scrypt_auxpow.mineScryptAux(self.nodes[0], "00", True)
except JSONRPCException as ex:
if ex.error['message'] == "getauxblock method is not yet available":
pass
else:
raise ex
self.sync_all()
# 2. mine a non-auxpow block, just to ensure that this node
# can mine at all, expect: success
self.nodes[0].generate(1)
self.sync_all()
# 3. mine blocks until we're in digishield era
self.nodes[1].generate(self.DIGISHIELD_START - 1 - 1)
self.sync_all()
# 4. mine an auxpow block before auxpow is allowed, attempt 2
# expect: fail
try:
scrypt_auxpow.mineScryptAux(self.nodes[0], "00", True)
except JSONRPCException as ex:
if ex.error['message'] == "getauxblock method is not yet available":
pass
else:
raise ex
self.sync_all()
# 5. mine blocks until we're in in auxpow era
self.nodes[1].generate(self.AUXPOW_START - self.DIGISHIELD_START)
self.sync_all()
# 6. mine a valid auxpow block, expect: success
assert scrypt_auxpow.mineScryptAux(self.nodes[0], "00", True) is True
# 7. mine an auxpow block with high pow, expect: fail
assert scrypt_auxpow.mineScryptAux(self.nodes[0], "00", False) is False
# 8. mine a valid auxpow block with the parent chain being us
# expect: fail
assert scrypt_auxpow.mineScryptAux(self.nodes[0], self.CHAIN_ID, True) is False
self.sync_all()
# 9. mine enough blocks to mature all node 0 rewards
self.nodes[1].generate(self.MATURITY_HEIGHT)
self.sync_all()
# node 0 should have block rewards for 2 blocks,
# One from step 2 and one from step 6.
assert_equal(self.nodes[0].getbalance(), self.REWARD * 2)
if __name__ == '__main__':
AuxPOWTest ().main ()