forked from ElementsProject/elements
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathfeature_assetsdir.py
executable file
·70 lines (53 loc) · 2.62 KB
/
feature_assetsdir.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
#!/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 use of assetdir to locally label assets.
# Test listissuances returns a list of all issuances or specific issuances based on asset hex or asset label.
#
from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import assert_equal, assert_greater_than
class AssetdirTests(BitcoinTestFramework):
"""
Test use of assetdir to specify asset labels.
Test listissuances returns a list of all issuances or specific issuances based on asset hex or asset label.
"""
def set_test_params(self):
self.setup_clean_chain = True
self.num_nodes = 1
[["-initialfreecoins=2100000000000000", "-anyonecanspendaremine=1", "-con_connect_coinbase=1", "-con_blocksubsidy=0"]]
def skip_test_if_missing_module(self):
self.skip_if_no_wallet()
def setup_network(self, split=False):
self.setup_nodes()
def run_test(self):
self.nodes[0].generate(101)
#Issue two assets that we will later label using the assetdir parameter
issuance1 = self.nodes[0].issueasset(100, 1, False)
asset1hex = issuance1["asset"]
issuance2 = self.nodes[0].issueasset(100, 1, False)
asset2hex = issuance2["asset"]
#Stop and restart the nodes, providing the assetdir parameter to locally label the assets
self.stop_nodes()
self.start_nodes([["-assetdir=" + asset1hex + ":asset1", "-assetdir=" + asset2hex + ":asset2"]])
#Check that listissuances return all issuances
issuances = self.nodes[0].listissuances()
assert_equal(len(issuances), 2)
#Check all asset labels have been set: 'asset1', 'asset2'
#We can not be sure they will always be returned in the same order so will loop each one
label = ""
for issue in issuances:
label += issue["assetlabel"]
assert_greater_than(label.find("asset1"), -1)
assert_greater_than(label.find("asset2"), -1)
#Check we can get a list of isuances for a given label
issuances = self.nodes[0].listissuances("asset1")
assert_equal(len(issuances), 1)
assert_equal(issuances[0]["assetlabel"], "asset1")
#Check we can get a list of issuances for a given hex
issuances = self.nodes[0].listissuances(asset2hex)
assert_equal(len(issuances), 1)
assert_equal(issuances[0]["assetlabel"], "asset2")
if __name__ == '__main__':
AssetdirTests().main()