forked from syscoin/syscoin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfeature_asset_reorg.py
executable file
·95 lines (88 loc) · 4.61 KB
/
feature_asset_reorg.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
89
90
91
92
93
94
95
#!/usr/bin/env python3
# Copyright (c) 2019-2020 The Bitcoin Core developers
# Distributed under the MIT software license, see the accompanying
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
from test_framework.test_framework import SyscoinTestFramework
from test_framework.util import assert_equal, assert_raises_rpc_error
class AssetReOrgTest(SyscoinTestFramework):
def set_test_params(self):
self.setup_clean_chain = True
self.num_nodes = 3
self.extra_args = [['-assetindex=1'],['-assetindex=1'],['-assetindex=1']]
def skip_test_if_missing_module(self):
self.skip_if_no_wallet()
def run_test(self):
self.generate(self.nodes[0], 1)
self.sync_blocks()
self.generate(self.nodes[2], 200)
self.sync_blocks()
self.disconnect_nodes(0, 1)
self.disconnect_nodes(0, 2)
self.basic_asset()
# create fork
self.generate(self.nodes[0], 11, sync_fun=self.no_op)
# won't exist on node 0 because it was created on node 2 and we are disconnected
assert_raises_rpc_error(-20, 'Failed to read from asset DB', self.nodes[0].assetinfo, self.asset)
self.generate(self.nodes[2], 10, sync_fun=self.no_op)
assetInfo = self.nodes[2].assetinfo(self.asset)
assert_equal(assetInfo['asset_guid'], self.asset)
# still won't exist on node 0 yet
assert_raises_rpc_error(-20, 'Failed to read from asset DB', self.nodes[0].assetinfo, self.asset)
# connect and sync to longest chain now which does not include the asset
self.connect_nodes(0, 1)
self.connect_nodes(0, 2)
self.sync_blocks()
assert_raises_rpc_error(-20, 'Failed to read from asset DB', self.nodes[0].assetinfo, self.asset)
assert_raises_rpc_error(-20, 'Failed to read from asset DB', self.nodes[1].assetinfo, self.asset)
assert_raises_rpc_error(-20, 'Failed to read from asset DB', self.nodes[2].assetinfo, self.asset)
# node 2 should have the asset in mempool again
self.generate(self.nodes[2], 1)
# asset is there now
assetInfo = self.nodes[0].assetinfo(self.asset)
assert_equal(assetInfo['asset_guid'], self.asset)
assetInfo = self.nodes[1].assetinfo(self.asset)
assert_equal(assetInfo['asset_guid'], self.asset)
assetInfo = self.nodes[2].assetinfo(self.asset)
assert_equal(assetInfo['asset_guid'], self.asset)
# increase total supply
self.generate(self.nodes[2], 1)
self.nodes[2].assetsend(self.asset, self.nodes[1].getnewaddress(), 100)
blockhash = self.nodes[2].getbestblockhash()
self.generate(self.nodes[2], 1)
assetInfo = self.nodes[0].assetinfo(self.asset)
assert_equal(assetInfo['asset_guid'], self.asset)
assert_equal(assetInfo['total_supply'], 100.00000000)
assetInfo = self.nodes[1].assetinfo(self.asset)
assert_equal(assetInfo['total_supply'], 100.00000000)
assert_equal(assetInfo['asset_guid'], self.asset)
assetInfo = self.nodes[2].assetinfo(self.asset)
assert_equal(assetInfo['total_supply'], 100.00000000)
# revert back to before supply was created
self.nodes[0].invalidateblock(blockhash)
self.nodes[1].invalidateblock(blockhash)
self.nodes[2].invalidateblock(blockhash)
assetInfo = self.nodes[0].assetinfo(self.asset)
assert_equal(assetInfo['asset_guid'], self.asset)
assert_equal(assetInfo['total_supply'], 0)
assetInfo = self.nodes[1].assetinfo(self.asset)
assert_equal(assetInfo['total_supply'], 0)
assert_equal(assetInfo['asset_guid'], self.asset)
assetInfo = self.nodes[2].assetinfo(self.asset)
assert_equal(assetInfo['total_supply'], 0)
# back to tip
# revert back to before supply was created
self.nodes[0].reconsiderblock(blockhash)
self.nodes[1].reconsiderblock(blockhash)
self.nodes[2].reconsiderblock(blockhash)
assetInfo = self.nodes[0].assetinfo(self.asset)
assert_equal(assetInfo['asset_guid'], self.asset)
assert_equal(assetInfo['total_supply'], 100.00000000)
assetInfo = self.nodes[1].assetinfo(self.asset)
assert_equal(assetInfo['total_supply'], 100.00000000)
assert_equal(assetInfo['asset_guid'], self.asset)
assetInfo = self.nodes[2].assetinfo(self.asset)
assert_equal(assetInfo['total_supply'], 100.00000000)
def basic_asset(self):
self.asset = self.nodes[2].assetnew('1', 'TST', 'asset description', '0x', 8, 10000, 127, '', {}, {})['asset_guid']
if __name__ == '__main__':
AssetReOrgTest().main()