forked from DeFiCh/ain
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfeature_token_fork.py
executable file
·127 lines (102 loc) · 4.34 KB
/
feature_token_fork.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#!/usr/bin/env python3
# Copyright (c) 2014-2020 The Bitcoin Core developers
# Copyright (c) DeFi Blockchain Developers
# Distributed under the MIT software license, see the accompanying
# file LICENSE or http://www.opensource.org/licenses/mit-license.php.
"""Test token's RPC.
- verify before fork, not allow create token, after fork can create token
"""
from test_framework.test_framework import DefiTestFramework
from test_framework.authproxy import JSONRPCException
from test_framework.util import assert_equal
class TokensForkTest (DefiTestFramework):
def set_test_params(self):
self.num_nodes = 2
self.setup_clean_chain = True
self.extra_args = [['-txnotokens=0', '-amkheight=120'], ['-txnotokens=0', '-amkheight=120']]
def run_test(self):
assert_equal(len(self.nodes[0].listtokens()), 1) # only one token == DFI
self.nodes[0].generate(100)
self.sync_blocks()
self.nodes[0].generate(2) # for 2 matured utxos
# Try to create token before AMK fork height but will fail:
#========================
collateralGold = self.nodes[0].getnewaddress("", "legacy")
collateralSilver = self.nodes[0].getnewaddress("", "legacy")
try:
self.nodes[0].createtoken({
"symbol": "GOLD",
"name": "shiny gold",
"collateralAddress": collateralGold
}, [])
self.nodes[0].createtoken({
"symbol": "SILVER",
"name": "just silver",
"collateralAddress": collateralSilver
}, [])
except JSONRPCException as e:
errorString = e.error['message']
assert("before AMK height" in errorString)
self.nodes[0].generate(1)
# Before fork, create should fail, so now only have default token
tokens = self.nodes[0].listtokens()
assert_equal(len(tokens), 1)
# Try to mint token before AMK fork height but will fail:
#========================
# Minting can't be checked here on rpc level cause token doesn't exist and it's impossible to create it
# we'll check it at the end with a trick
# try:
# self.nodes[0].minttokens("300@GOLD", [])
# except JSONRPCException as e:
# errorString = e.error['message']
# assert("Token tx before AMK" in errorString)
self.nodes[0].generate(17)
self.sync_blocks()
# Now at AMK height 120
# Now create again, it should pass
self.nodes[0].createtoken({
"symbol": "GOLD",
"name": "shiny gold",
"collateralAddress": collateralGold
}, [])
self.nodes[0].createtoken({
"symbol": "SILVER",
"name": "just silver",
"collateralAddress": collateralSilver
}, [])
self.nodes[0].generate(1)
# After fork, create should pass, so now only have 3 kind of tokens
tokens = self.nodes[0].listtokens()
assert_equal(len(tokens), 3)
list_tokens = self.nodes[0].listtokens()
for idx, token in list_tokens.items():
if (token["symbol"] == "GOLD"):
idGold = idx
if (token["symbol"] == "SILVER"):
idSilver = idx
symbolGold = "GOLD#" + idGold
symbolSilver = "SILVER#" + idSilver
self.sync_blocks()
# MINT:
#========================
# Funding auth addresses
self.nodes[0].sendmany("", { collateralGold : 1, collateralSilver : 1 })
self.nodes[0].generate(1)
self.nodes[0].sendmany("", { collateralGold : 1, collateralSilver : 1 })
self.nodes[0].generate(1)
# print(self.nodes[0].listunspent())
self.nodes[0].minttokens("300@" + symbolGold, [])
self.nodes[0].minttokens("3000@" + symbolSilver, [])
self.nodes[0].generate(1)
self.sync_blocks()
# synthetically check for minting. restart w/o reindex and amk (so, token exists, but minting should fail)
self.stop_node(0)
self.start_node(0, ['-txnotokens=0'])
try:
self.nodes[0].minttokens("300@128", [])
assert(False)
except JSONRPCException as e:
errorString = e.error['message']
assert("before AMK height" in errorString)
if __name__ == '__main__':
TokensForkTest ().main ()