forked from bitcoin/bitcoin
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathblsct_token.py
executable file
·211 lines (146 loc) · 8.47 KB
/
blsct_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
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
#!/usr/bin/env python3
# Copyright (c) 2024 The Navio 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 BitcoinTestFramework
from test_framework.util import (
assert_equal,
)
class NavioBlsctTokenTest(BitcoinTestFramework):
def add_options(self, parser):
self.add_wallet_options(parser, blsct=True)
def set_test_params(self):
# Set up two nodes for the test
self.num_nodes = 2
self.chain = 'blsctregtest'
self.setup_clean_chain = True
def skip_test_if_missing_module(self):
self.skip_if_no_wallet()
def run_test(self):
self.test_legacy()
def test_legacy(self):
self.log.info("Creating wallet1 with BLSCT")
# Create a new wallet
#self.init_wallet(node=0, blsct=True)
self.nodes[0].createwallet(wallet_name="wallet1", blsct=True)
self.nodes[1].createwallet(wallet_name="wallet1", blsct=True)
wallet = self.nodes[0].get_wallet_rpc("wallet1")
wallet_2 = self.nodes[1].get_wallet_rpc("wallet1")
self.log.info("Loading wallet1")
# Ensure wallet is loaded
wallets = self.nodes[0].listwallets()
assert "wallet1" in wallets, "wallet1 was not loaded successfully"
self.log.info("Generating BLSCT address")
# Generate a BLSCT address
blsct_address = wallet.getnewaddress(label="", address_type="blsct")
blsct_address_2 = wallet_2.getnewaddress(label="", address_type="blsct")
self.log.info(f"BLSCT address NODE 1: {blsct_address}")
self.log.info(f"BLSCT address NODE 2: {blsct_address_2}")
# Generate blocks and fund the BLSCT address
self.log.info("Generating 101 blocks to the BLSCT address")
block_hashes = self.generatetoblsctaddress(self.nodes[0], 101, blsct_address)
self.log.info(f"Generated blocks: {len(block_hashes)}")
# Check the balance of the wallet
balance = wallet.getbalance()
self.log.info(f"Balance in wallet1: {balance}")
assert_equal(len(block_hashes), 101)
assert balance > 0, "Balance should be greater than zero after mining"
self.log.info("Creating token and mining 1 block")
token = wallet.createtoken({"name": "Test"}, 1000)
block_hashes = self.generatetoblsctaddress(self.nodes[0], 1, blsct_address)
tokens = self.nodes[0].listtokens()
assert len(tokens) == 1, "length of tokens is not 1"
self.log.info(f"Created token: {token['tokenId']}")
assert tokens[0]['type'] == 'token', "token type is not token"
assert tokens[0]['metadata'] == {'name': 'Test'}, "incorrect metadata"
assert tokens[0]['maxSupply'] == 100000000000, "incorrect max supply"
assert tokens[0]['currentSupply'] == 0, "incorrect current supply"
wallet.minttoken(token['tokenId'], blsct_address, 1)
block_hashes = self.generatetoblsctaddress(self.nodes[0], 1, blsct_address)
tokenInfo = self.nodes[0].gettoken(token['tokenId'])
assert tokenInfo['type'] == 'token', "token type is not token"
assert tokenInfo['metadata'] == {'name': 'Test'}, "incorrect metadata"
assert tokenInfo['maxSupply'] == 100000000000, "incorrect max supply"
assert tokenInfo['currentSupply'] == 100000000, "incorrect current supply"
self.log.info(f"Minted 1 token")
token_balance = wallet.gettokenbalance(token['tokenId'])
token_balance_2 = wallet_2.gettokenbalance(token['tokenId'])
self.log.info(f"Balance in NODE 1: {token_balance}")
self.log.info(f"Balance in NODE 2: {token_balance_2}")
assert token_balance == 1, "incorrect token balance in node 1"
assert token_balance_2 == 0, "incorrect token balance in node 2"
self.log.info(f"Sending 0.5 token to NODE 2")
wallet.sendtokentoblsctaddress(token['tokenId'], blsct_address_2, 0.5)
self.generatetoblsctaddress(self.nodes[0], 2, blsct_address)
token_balance = wallet.gettokenbalance(token['tokenId'])
token_balance_2 = wallet_2.gettokenbalance(token['tokenId'])
self.log.info(f"Balance in NODE 1: {token_balance}")
self.log.info(f"Balance in NODE 2: {token_balance_2}")
assert token_balance == 0.5, "incorrect token balance in node 1"
assert token_balance_2 == 0.5, "incorrect token balance in node 2"
self.log.info(f"Balance in NODE 1: {token_balance}")
self.log.info(f"Balance in NODE 2: {token_balance_2}")
def test_output(self):
self.log.info("Creating wallet1 with BLSCT")
# Create a new wallet
#self.init_wallet(node=0, blsct=True)
self.nodes[0].createwallet(wallet_name="wallet1", blsct=True, storage_output=True)
self.nodes[1].createwallet(wallet_name="wallet1", blsct=True, storage_output=True)
wallet = self.nodes[0].get_wallet_rpc("wallet1")
wallet_2 = self.nodes[1].get_wallet_rpc("wallet1")
self.log.info("Loading wallet1")
# Ensure wallet is loaded
wallets = self.nodes[0].listwallets()
assert "wallet1" in wallets, "wallet1 was not loaded successfully"
self.log.info("Generating BLSCT address")
# Generate a BLSCT address
blsct_address = wallet.getnewaddress(label="", address_type="blsct")
blsct_address_2 = wallet_2.getnewaddress(label="", address_type="blsct")
self.log.info(f"BLSCT address NODE 1: {blsct_address}")
self.log.info(f"BLSCT address NODE 2: {blsct_address_2}")
# Generate blocks and fund the BLSCT address
self.log.info("Generating 101 blocks to the BLSCT address")
block_hashes = self.generatetoblsctaddress(self.nodes[0], 101, blsct_address)
self.log.info(f"Generated blocks: {len(block_hashes)}")
# Check the balance of the wallet
balance = wallet.getbalance()
self.log.info(f"Balance in wallet1: {balance}")
assert_equal(len(block_hashes), 101)
assert balance > 0, "Balance should be greater than zero after mining"
self.log.info("Creating token and mining 1 block")
token = wallet.createtoken({"name": "Test"}, 1000)
block_hashes = self.generatetoblsctaddress(self.nodes[0], 1, blsct_address)
tokens = self.nodes[0].listtokens()
assert len(tokens) == 1, "length of tokens is not 1"
self.log.info(f"Created token: {token['tokenId']}")
assert tokens[0]['type'] == 'token', "token type is not token"
assert tokens[0]['metadata'] == {'name': 'Test'}, "incorrect metadata"
assert tokens[0]['maxSupply'] == 100000000000, "incorrect max supply"
assert tokens[0]['currentSupply'] == 0, "incorrect current supply"
wallet.minttoken(token['tokenId'], blsct_address, 1)
block_hashes = self.generatetoblsctaddress(self.nodes[0], 1, blsct_address)
tokenInfo = self.nodes[0].gettoken(token['tokenId'])
assert tokenInfo['type'] == 'token', "token type is not token"
assert tokenInfo['metadata'] == {'name': 'Test'}, "incorrect metadata"
assert tokenInfo['maxSupply'] == 100000000000, "incorrect max supply"
assert tokenInfo['currentSupply'] == 100000000, "incorrect current supply"
self.log.info(f"Minted 1 token")
token_balance = wallet.gettokenbalance(token['tokenId'])
token_balance_2 = wallet_2.gettokenbalance(token['tokenId'])
self.log.info(f"Balance in NODE 1: {token_balance}")
self.log.info(f"Balance in NODE 2: {token_balance_2}")
assert token_balance == 1, "incorrect token balance in node 1"
assert token_balance_2 == 0, "incorrect token balance in node 2"
self.log.info(f"Sending 0.5 token to NODE 2")
wallet.sendtokentoblsctaddress(token['tokenId'], blsct_address_2, 0.5)
self.generatetoblsctaddress(self.nodes[0], 2, blsct_address)
token_balance = wallet.gettokenbalance(token['tokenId'])
token_balance_2 = wallet_2.gettokenbalance(token['tokenId'])
self.log.info(f"Balance in NODE 1: {token_balance}")
self.log.info(f"Balance in NODE 2: {token_balance_2}")
assert token_balance == 0.5, "incorrect token balance in node 1"
assert token_balance_2 == 0.5, "incorrect token balance in node 2"
self.log.info(f"Balance in NODE 1: {token_balance}")
self.log.info(f"Balance in NODE 2: {token_balance_2}")
if __name__ == '__main__':
NavioBlsctTokenTest().main()