Skip to content

Commit e02024e

Browse files
committed
test: add new elements_code_tutorial functional test
1 parent 39be0f0 commit e02024e

File tree

2 files changed

+74
-0
lines changed

2 files changed

+74
-0
lines changed
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
#!/usr/bin/env python3
2+
# Copyright (c) 2017-2020 The Bitcoin Core developers
3+
# Distributed under the MIT software license, see the accompanying
4+
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
5+
"""Tests reissuance functionality from the elements code tutorial
6+
See: https://elementsproject.org/elements-code-tutorial/reissuing-assets
7+
8+
TODO: add functionality from contrib/assets_tutorial/assets_tutorial.py into here
9+
"""
10+
from test_framework.blocktools import COINBASE_MATURITY
11+
from test_framework.test_framework import BitcoinTestFramework
12+
13+
class WalletTest(BitcoinTestFramework):
14+
def set_test_params(self):
15+
self.setup_clean_chain = True
16+
self.num_nodes = 2
17+
self.extra_args = [[
18+
"-blindedaddresses=1",
19+
"-initialfreecoins=2100000000000000",
20+
"-con_blocksubsidy=0",
21+
"-con_connect_genesis_outputs=1",
22+
"-txindex=1",
23+
]] * self.num_nodes
24+
self.extra_args[0].append("-anyonecanspendaremine=1")
25+
26+
def skip_test_if_missing_module(self):
27+
self.skip_if_no_wallet()
28+
29+
def run_test(self):
30+
self.generate(self.nodes[0], COINBASE_MATURITY + 1)
31+
self.sync_all()
32+
33+
assert self.nodes[0].dumpassetlabels() == {'bitcoin': 'b2e15d0d7a0c94e4e2ce0fe6e8691b9e451377f6e46e8045a86f7c4b5d4f0f23'}
34+
35+
issuance = self.nodes[0].issueasset(100, 1)
36+
asset = issuance['asset']
37+
#token = issuance['token']
38+
issuance_txid = issuance['txid']
39+
issuance_vin = issuance['vin']
40+
41+
assert len(self.nodes[0].listissuances()) == 2 # asset & reisuance token
42+
43+
self.nodes[0].generatetoaddress(1, self.nodes[0].getnewaddress(), invalid_call=False) # confirm the tx
44+
45+
issuance_addr = self.nodes[0].gettransaction(issuance_txid)['details'][0]['address']
46+
self.nodes[1].importaddress(issuance_addr)
47+
48+
issuance_key = self.nodes[0].dumpissuanceblindingkey(issuance_txid, issuance_vin)
49+
self.nodes[1].importissuanceblindingkey(issuance_txid, issuance_vin, issuance_key)
50+
issuances = self.nodes[1].listissuances()
51+
assert (issuances[0]['tokenamount'] == 1 and issuances[0]['assetamount'] == 100) \
52+
or (issuances[1]['tokenamount'] == 1 and issuances[1]['assetamount'] == 100)
53+
54+
self.nodes[0].sendtoaddress(self.nodes[0].getnewaddress(), 1)
55+
self.generate(self.nodes[0], 10)
56+
57+
reissuance_tx = self.nodes[0].reissueasset(asset, 99)
58+
reissuance_txid = reissuance_tx['txid']
59+
issuances = self.nodes[0].listissuances(asset)
60+
assert len(issuances) == 2
61+
assert issuances[0]['isreissuance'] or issuances[1]['isreissuance']
62+
63+
self.generate(self.nodes[0], 1)
64+
65+
expected_amt = {
66+
'bitcoin': 0,
67+
'8f1560e209f6bcac318569a935a0b2513c54f326ee4820ccd5b8c1b1b4632373': 0,
68+
'4fa41f2929d4bf6975a55967d9da5b650b6b9bfddeae4d7b54b04394be328f7f': 99
69+
}
70+
assert self.nodes[0].gettransaction(reissuance_txid)['amount'] == expected_amt
71+
72+
if __name__ == '__main__':
73+
WalletTest().main()

test/functional/test_runner.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@
8888
BASE_SCRIPTS = [
8989
# Scripts that are run by default.
9090
# vv First elements tests vv
91+
'example_elements_code_tutorial.py',
9192
'feature_fedpeg.py --legacy-wallet',
9293
'feature_fedpeg.py --pre_transition --legacy-wallet',
9394
'feature_fedpeg.py --post_transition --legacy-wallet',

0 commit comments

Comments
 (0)