|
| 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() |
0 commit comments