Skip to content

Commit be98b2d

Browse files
committed
[QA] Add scantxoutset test
1 parent eec7cf7 commit be98b2d

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed

test/functional/rpc_scantxoutset.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#!/usr/bin/env python3
2+
# Copyright (c) 2018 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+
"""Test the scantxoutset rpc call."""
6+
from test_framework.test_framework import BitcoinTestFramework
7+
from test_framework.util import *
8+
9+
import shutil
10+
import os
11+
12+
class ScantxoutsetTest(BitcoinTestFramework):
13+
def set_test_params(self):
14+
self.num_nodes = 1
15+
self.setup_clean_chain = True
16+
def run_test(self):
17+
self.log.info("Mining blocks...")
18+
self.nodes[0].generate(110)
19+
20+
addr_P2SH_SEGWIT = self.nodes[0].getnewaddress("", "p2sh-segwit")
21+
pubk1 = self.nodes[0].getaddressinfo(addr_P2SH_SEGWIT)['pubkey']
22+
addr_LEGACY = self.nodes[0].getnewaddress("", "legacy")
23+
pubk2 = self.nodes[0].getaddressinfo(addr_LEGACY)['pubkey']
24+
addr_BECH32 = self.nodes[0].getnewaddress("", "bech32")
25+
pubk3 = self.nodes[0].getaddressinfo(addr_BECH32)['pubkey']
26+
self.nodes[0].sendtoaddress(addr_P2SH_SEGWIT, 1)
27+
self.nodes[0].sendtoaddress(addr_LEGACY, 2)
28+
self.nodes[0].sendtoaddress(addr_BECH32, 3)
29+
self.nodes[0].generate(1)
30+
31+
self.log.info("Stop node, remove wallet, mine again some blocks...")
32+
self.stop_node(0)
33+
shutil.rmtree(os.path.join(self.nodes[0].datadir, "regtest", 'wallets'))
34+
self.start_node(0)
35+
self.nodes[0].generate(110)
36+
37+
self.restart_node(0, ['-nowallet'])
38+
self.log.info("Test if we have found the non HD unspent outputs.")
39+
assert_equal(self.nodes[0].scantxoutset("start", [ {"pubkey": {"pubkey": pubk1}}, {"pubkey": {"pubkey": pubk2}}, {"pubkey": {"pubkey": pubk3}}])['total_amount'], 6)
40+
assert_equal(self.nodes[0].scantxoutset("start", [ {"address": addr_P2SH_SEGWIT}, {"address": addr_LEGACY}, {"address": addr_BECH32}])['total_amount'], 6)
41+
assert_equal(self.nodes[0].scantxoutset("start", [ {"address": addr_P2SH_SEGWIT}, {"address": addr_LEGACY}, {"pubkey": {"pubkey": pubk3}} ])['total_amount'], 6)
42+
43+
self.log.info("Test invalid parameters.")
44+
assert_raises_rpc_error(-8, 'Scanobject "pubkey" must contain an object as value', self.nodes[0].scantxoutset, "start", [ {"pubkey": pubk1}]) #missing pubkey object
45+
assert_raises_rpc_error(-8, 'Scanobject "address" must contain a single string as value', self.nodes[0].scantxoutset, "start", [ {"address": {"address": addr_P2SH_SEGWIT}}]) #invalid object for address object
46+
47+
if __name__ == '__main__':
48+
ScantxoutsetTest().main()

test/functional/test_runner.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@
140140
'feature_uacomment.py',
141141
'p2p_unrequested_blocks.py',
142142
'feature_includeconf.py',
143+
'rpc_scantxoutset.py',
143144
'feature_logging.py',
144145
'p2p_node_network_limited.py',
145146
'feature_blocksdir.py',

0 commit comments

Comments
 (0)