-
Notifications
You must be signed in to change notification settings - Fork 388
/
Copy pathfeature_initial_reissuance_token.py
executable file
·86 lines (66 loc) · 3.25 KB
/
feature_initial_reissuance_token.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
#!/usr/bin/env python3
# Copyright (c) 2014-2016 The Bitcoin Core developers
# Distributed under the MIT software license, see the accompanying
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
#
# Test chain initialisation when specifying number of reissuance tokens to issue.
#
from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import assert_equal
class InitialReissuanceTokenTest(BitcoinTestFramework):
"""
Test creation of initial reissuance token for default asset on chain set up
"""
def set_test_params(self):
self.setup_clean_chain = True
self.num_nodes = 2
#Set number of initial reissuance tokens and also set initial free coins less than max so we can reissue more later
self.extra_args = [["-initialreissuancetokens=200000000", "-initialfreecoins=2000000000000000", "-anyonecanspendaremine=1", "-con_connect_genesis_outputs=1", "-con_blocksubsidy=0", "-blindedaddresses=1"]]*2
def skip_test_if_missing_module(self):
self.skip_if_no_wallet()
def setup_network(self, split=False):
self.setup_nodes()
self.connect_nodes(0, 1)
self.sync_all()
def run_test(self):
self.generate(self.nodes[0], 101)
self.sync_all()
walletinfo = self.nodes[0].getwalletinfo()
balance = walletinfo['balance']
token = ""
#Get the hex of the reissuance token
for i in balance:
token = i
if token != "bitcoin":
break
# Claim all anyone-can-spend reissuance tokens, which also blinds the token output
# which is required for re-issuance: https://github.com/ElementsProject/elements/issues/259
self.nodes[0].sendtoaddress(self.nodes[0].getnewaddress(), 2, "", "", False, False, 6, "UNSET", False, token)
self.generate(self.nodes[0], 101)
self.sync_all()
#Check balances
walletinfo1 = self.nodes[0].getwalletinfo()
assert_equal(walletinfo1["balance"]["bitcoin"], 20000000)
assert_equal(walletinfo1["balance"][token], 2)
#Reissue some of the default asset
self.nodes[0].reissueasset("bitcoin", 1234)
self.generate(self.nodes[0], 101)
self.sync_all()
#Check the reissuance worked
walletinfo1 = self.nodes[0].getwalletinfo()
assert_equal(walletinfo1["balance"]["bitcoin"], 20001234)
#Send some 'bitcoin' to node 2 so they can fund a reissuance transaction
self.nodes[0].sendtoaddress(self.nodes[1].getnewaddress(), 1, "", "", False)
#Send a reissuance token to node 2 so they can reissue the default asset
self.nodes[0].sendtoaddress(self.nodes[1].getnewaddress(), 1, "", "", False, False, 6, "UNSET", False, token)
self.generate(self.nodes[0], 101)
self.sync_all()
#Reissue some of the default asset
self.nodes[1].reissueasset("bitcoin", 1000)
self.generate(self.nodes[1], 101)
self.sync_all()
#Check balance is the 1 'bitcoin' sent from node 1 plus the 1000 'bitcoin' reissued by node 2
walletinfo2 = self.nodes[1].getwalletinfo()
assert_equal(walletinfo2["balance"]["bitcoin"], 1001)
if __name__ == '__main__':
InitialReissuanceTokenTest().main()