Changeset View
Changeset View
Standalone View
Standalone View
test/functional/rpc_scantxoutset.py
#!/usr/bin/env python3 | #!/usr/bin/env python3 | ||||
# Copyright (c) 2018 The Bitcoin Core developers | # Copyright (c) 2018 The Bitcoin Core developers | ||||
# Distributed under the MIT software license, see the accompanying | # Distributed under the MIT software license, see the accompanying | ||||
# file COPYING or http://www.opensource.org/licenses/mit-license.php. | # file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||||
"""Test the scantxoutset rpc call.""" | """Test the scantxoutset rpc call.""" | ||||
import os | import os | ||||
import shutil | import shutil | ||||
from decimal import Decimal | |||||
from test_framework.test_framework import BitcoinTestFramework | from test_framework.test_framework import BitcoinTestFramework | ||||
from test_framework.util import (assert_equal, assert_raises_rpc_error) | from test_framework.util import assert_equal | ||||
class ScantxoutsetTest(BitcoinTestFramework): | class ScantxoutsetTest(BitcoinTestFramework): | ||||
def set_test_params(self): | def set_test_params(self): | ||||
self.num_nodes = 1 | self.num_nodes = 1 | ||||
self.setup_clean_chain = True | self.setup_clean_chain = True | ||||
def run_test(self): | def run_test(self): | ||||
self.log.info("Mining blocks...") | self.log.info("Mining blocks...") | ||||
self.nodes[0].generate(110) | self.nodes[0].generate(110) | ||||
addr = self.nodes[0].getnewaddress("") | addr = self.nodes[0].getnewaddress("") | ||||
pubkey = self.nodes[0].getaddressinfo(addr)['pubkey'] | pubkey = self.nodes[0].getaddressinfo(addr)['pubkey'] | ||||
self.nodes[0].sendtoaddress(addr, 2) | self.nodes[0].sendtoaddress(addr, 0.002) | ||||
# send to child keys of tprv8ZgxMBicQKsPd7Uf69XL1XwhmjHopUGep8GuEiJDZmbQz6o58LninorQAfcKZWARbtRtfnLcJ5MQ2AtHcQJCCRUcMRvmDUjyEmNUWwx8UbK | |||||
# (m/0'/0'/0') | |||||
self.nodes[0].sendtoaddress( | |||||
"mkHV1C6JLheLoUSSZYk7x3FH5tnx9bu7yc", 0.008) | |||||
# (m/0'/0'/1') | |||||
self.nodes[0].sendtoaddress( | |||||
"mipUSRmJAj2KrjSvsPQtnP8ynUon7FhpCR", 0.016) | |||||
# (m/0'/0'/1500') | |||||
self.nodes[0].sendtoaddress( | |||||
"n37dAGe6Mq1HGM9t4b6rFEEsDGq7Fcgfqg", 0.032) | |||||
# (m/0'/0'/0) | |||||
self.nodes[0].sendtoaddress( | |||||
"mqS9Rpg8nNLAzxFExsgFLCnzHBsoQ3PRM6", 0.064) | |||||
# (m/0'/0'/1) | |||||
self.nodes[0].sendtoaddress( | |||||
"mnTg5gVWr3rbhHaKjJv7EEEc76ZqHgSj4S", 0.128) | |||||
# (m/0'/0'/1500) | |||||
self.nodes[0].sendtoaddress( | |||||
"mketCd6B9U9Uee1iCsppDJJBHfvi6U6ukC", 0.256) | |||||
# (m/1/1/0') | |||||
self.nodes[0].sendtoaddress( | |||||
"mj8zFzrbBcdaWXowCQ1oPZ4qioBVzLzAp7", 0.512) | |||||
# (m/1/1/1') | |||||
self.nodes[0].sendtoaddress( | |||||
"mfnKpKQEftniaoE1iXuMMePQU3PUpcNisA", 1.024) | |||||
# (m/1/1/1500') | |||||
self.nodes[0].sendtoaddress( | |||||
"mou6cB1kaP1nNJM1sryW6YRwnd4shTbXYQ", 2.048) | |||||
# (m/1/1/0) | |||||
self.nodes[0].sendtoaddress( | |||||
"mtfUoUax9L4tzXARpw1oTGxWyoogp52KhJ", 4.096) | |||||
# (m/1/1/1) | |||||
self.nodes[0].sendtoaddress( | |||||
"mxp7w7j8S1Aq6L8StS2PqVvtt4HGxXEvdy", 8.192) | |||||
# (m/1/1/1500) | |||||
self.nodes[0].sendtoaddress( | |||||
"mpQ8rokAhp1TAtJQR6F6TaUmjAWkAWYYBq", 16.384) | |||||
self.nodes[0].generate(1) | self.nodes[0].generate(1) | ||||
self.log.info("Stop node, remove wallet, mine again some blocks...") | self.log.info("Stop node, remove wallet, mine again some blocks...") | ||||
self.stop_node(0) | self.stop_node(0) | ||||
shutil.rmtree(os.path.join( | shutil.rmtree(os.path.join( | ||||
self.nodes[0].datadir, "regtest", 'wallets')) | self.nodes[0].datadir, "regtest", 'wallets')) | ||||
self.start_node(0) | self.start_node(0) | ||||
self.nodes[0].generate(110) | self.nodes[0].generate(110) | ||||
self.restart_node(0, ['-nowallet']) | self.restart_node(0, ['-nowallet']) | ||||
self.log.info("Test if we have found the non HD unspent outputs.") | self.log.info("Test if we have found the non HD unspent outputs.") | ||||
assert_equal(self.nodes[0].scantxoutset( | assert_equal(self.nodes[0].scantxoutset( | ||||
"start", [{"pubkey": {"pubkey": pubkey}}])['total_amount'], 2) | "start", ["pkh(" + pubkey + ")"])['total_amount'], Decimal("0.002")) | ||||
assert_equal(self.nodes[0].scantxoutset( | |||||
"start", ["combo(" + pubkey + ")"])['total_amount'], Decimal("0.002")) | |||||
assert_equal(self.nodes[0].scantxoutset( | |||||
"start", ["addr(" + addr + ")"])['total_amount'], Decimal("0.002")) | |||||
assert_equal(self.nodes[0].scantxoutset( | |||||
"start", ["addr(" + addr + ")"])['total_amount'], Decimal("0.002")) | |||||
self.log.info("Test invalid parameters.") | self.log.info("Test extended key derivation.") | ||||
# missing pubkey object | assert_equal(self.nodes[0].scantxoutset("start", [ | ||||
assert_raises_rpc_error(-8, 'Scanobject "pubkey" must contain an object as value', | "combo(tprv8ZgxMBicQKsPd7Uf69XL1XwhmjHopUGep8GuEiJDZmbQz6o58LninorQAfcKZWARbtRtfnLcJ5MQ2AtHcQJCCRUcMRvmDUjyEmNUWwx8UbK/0'/0h/0h)"])['total_amount'], Decimal("0.008")) | ||||
self.nodes[0].scantxoutset, "start", [{"pubkey": pubkey}]) | assert_equal(self.nodes[0].scantxoutset("start", [ | ||||
# invalid object for address object | "combo(tprv8ZgxMBicQKsPd7Uf69XL1XwhmjHopUGep8GuEiJDZmbQz6o58LninorQAfcKZWARbtRtfnLcJ5MQ2AtHcQJCCRUcMRvmDUjyEmNUWwx8UbK/0'/0'/1h)"])['total_amount'], Decimal("0.016")) | ||||
assert_raises_rpc_error(-8, 'Scanobject "address" must contain a single string as value', self.nodes[0].scantxoutset, "start", [ | assert_equal(self.nodes[0].scantxoutset("start", [ | ||||
{"address": {"address": addr}}]) | "combo(tprv8ZgxMBicQKsPd7Uf69XL1XwhmjHopUGep8GuEiJDZmbQz6o58LninorQAfcKZWARbtRtfnLcJ5MQ2AtHcQJCCRUcMRvmDUjyEmNUWwx8UbK/0h/0'/1500')"])['total_amount'], Decimal("0.032")) | ||||
assert_equal(self.nodes[0].scantxoutset("start", [ | |||||
"combo(tprv8ZgxMBicQKsPd7Uf69XL1XwhmjHopUGep8GuEiJDZmbQz6o58LninorQAfcKZWARbtRtfnLcJ5MQ2AtHcQJCCRUcMRvmDUjyEmNUWwx8UbK/0h/0h/0)"])['total_amount'], Decimal("0.064")) | |||||
assert_equal(self.nodes[0].scantxoutset("start", [ | |||||
"combo(tprv8ZgxMBicQKsPd7Uf69XL1XwhmjHopUGep8GuEiJDZmbQz6o58LninorQAfcKZWARbtRtfnLcJ5MQ2AtHcQJCCRUcMRvmDUjyEmNUWwx8UbK/0'/0h/1)"])['total_amount'], Decimal("0.128")) | |||||
assert_equal(self.nodes[0].scantxoutset("start", [ | |||||
"combo(tprv8ZgxMBicQKsPd7Uf69XL1XwhmjHopUGep8GuEiJDZmbQz6o58LninorQAfcKZWARbtRtfnLcJ5MQ2AtHcQJCCRUcMRvmDUjyEmNUWwx8UbK/0h/0'/1500)"])['total_amount'], Decimal("0.256")) | |||||
assert_equal(self.nodes[0].scantxoutset("start", [ | |||||
{"desc": "combo(tprv8ZgxMBicQKsPd7Uf69XL1XwhmjHopUGep8GuEiJDZmbQz6o58LninorQAfcKZWARbtRtfnLcJ5MQ2AtHcQJCCRUcMRvmDUjyEmNUWwx8UbK/0'/0h/*h)", "range": 1499}])['total_amount'], Decimal("0.024")) | |||||
assert_equal(self.nodes[0].scantxoutset("start", [ | |||||
{"desc": "combo(tprv8ZgxMBicQKsPd7Uf69XL1XwhmjHopUGep8GuEiJDZmbQz6o58LninorQAfcKZWARbtRtfnLcJ5MQ2AtHcQJCCRUcMRvmDUjyEmNUWwx8UbK/0'/0'/*h)", "range": 1500}])['total_amount'], Decimal("0.056")) | |||||
assert_equal(self.nodes[0].scantxoutset("start", [ | |||||
{"desc": "combo(tprv8ZgxMBicQKsPd7Uf69XL1XwhmjHopUGep8GuEiJDZmbQz6o58LninorQAfcKZWARbtRtfnLcJ5MQ2AtHcQJCCRUcMRvmDUjyEmNUWwx8UbK/0h/0'/*)", "range": 1499}])['total_amount'], Decimal("0.192")) | |||||
assert_equal(self.nodes[0].scantxoutset("start", [ | |||||
{"desc": "combo(tprv8ZgxMBicQKsPd7Uf69XL1XwhmjHopUGep8GuEiJDZmbQz6o58LninorQAfcKZWARbtRtfnLcJ5MQ2AtHcQJCCRUcMRvmDUjyEmNUWwx8UbK/0'/0h/*)", "range": 1500}])['total_amount'], Decimal("0.448")) | |||||
assert_equal(self.nodes[0].scantxoutset("start", [ | |||||
"combo(tprv8ZgxMBicQKsPd7Uf69XL1XwhmjHopUGep8GuEiJDZmbQz6o58LninorQAfcKZWARbtRtfnLcJ5MQ2AtHcQJCCRUcMRvmDUjyEmNUWwx8UbK/1/1/0')"])['total_amount'], Decimal("0.512")) | |||||
assert_equal(self.nodes[0].scantxoutset("start", [ | |||||
"combo(tprv8ZgxMBicQKsPd7Uf69XL1XwhmjHopUGep8GuEiJDZmbQz6o58LninorQAfcKZWARbtRtfnLcJ5MQ2AtHcQJCCRUcMRvmDUjyEmNUWwx8UbK/1/1/1')"])['total_amount'], Decimal("1.024")) | |||||
assert_equal(self.nodes[0].scantxoutset("start", [ | |||||
"combo(tprv8ZgxMBicQKsPd7Uf69XL1XwhmjHopUGep8GuEiJDZmbQz6o58LninorQAfcKZWARbtRtfnLcJ5MQ2AtHcQJCCRUcMRvmDUjyEmNUWwx8UbK/1/1/1500h)"])['total_amount'], Decimal("2.048")) | |||||
assert_equal(self.nodes[0].scantxoutset("start", [ | |||||
"combo(tprv8ZgxMBicQKsPd7Uf69XL1XwhmjHopUGep8GuEiJDZmbQz6o58LninorQAfcKZWARbtRtfnLcJ5MQ2AtHcQJCCRUcMRvmDUjyEmNUWwx8UbK/1/1/0)"])['total_amount'], Decimal("4.096")) | |||||
assert_equal(self.nodes[0].scantxoutset("start", [ | |||||
"combo(tprv8ZgxMBicQKsPd7Uf69XL1XwhmjHopUGep8GuEiJDZmbQz6o58LninorQAfcKZWARbtRtfnLcJ5MQ2AtHcQJCCRUcMRvmDUjyEmNUWwx8UbK/1/1/1)"])['total_amount'], Decimal("8.192")) | |||||
assert_equal(self.nodes[0].scantxoutset("start", [ | |||||
"combo(tprv8ZgxMBicQKsPd7Uf69XL1XwhmjHopUGep8GuEiJDZmbQz6o58LninorQAfcKZWARbtRtfnLcJ5MQ2AtHcQJCCRUcMRvmDUjyEmNUWwx8UbK/1/1/1500)"])['total_amount'], Decimal("16.384")) | |||||
assert_equal(self.nodes[0].scantxoutset("start", [ | |||||
"combo(tpubD6NzVbkrYhZ4WaWSyoBvQwbpLkojyoTZPRsgXELWz3Popb3qkjcJyJUGLnL4qHHoQvao8ESaAstxYSnhyswJ76uZPStJRJCTKvosUCJZL5B/1/1/0)"])['total_amount'], Decimal("4.096")) | |||||
assert_equal(self.nodes[0].scantxoutset("start", [ | |||||
"combo(tpubD6NzVbkrYhZ4WaWSyoBvQwbpLkojyoTZPRsgXELWz3Popb3qkjcJyJUGLnL4qHHoQvao8ESaAstxYSnhyswJ76uZPStJRJCTKvosUCJZL5B/1/1/1)"])['total_amount'], Decimal("8.192")) | |||||
assert_equal(self.nodes[0].scantxoutset("start", [ | |||||
"combo(tpubD6NzVbkrYhZ4WaWSyoBvQwbpLkojyoTZPRsgXELWz3Popb3qkjcJyJUGLnL4qHHoQvao8ESaAstxYSnhyswJ76uZPStJRJCTKvosUCJZL5B/1/1/1500)"])['total_amount'], Decimal("16.384")) | |||||
assert_equal(self.nodes[0].scantxoutset("start", [ | |||||
{"desc": "combo(tprv8ZgxMBicQKsPd7Uf69XL1XwhmjHopUGep8GuEiJDZmbQz6o58LninorQAfcKZWARbtRtfnLcJ5MQ2AtHcQJCCRUcMRvmDUjyEmNUWwx8UbK/1/1/*')", "range": 1499}])['total_amount'], Decimal("1.536")) | |||||
assert_equal(self.nodes[0].scantxoutset("start", [ | |||||
{"desc": "combo(tprv8ZgxMBicQKsPd7Uf69XL1XwhmjHopUGep8GuEiJDZmbQz6o58LninorQAfcKZWARbtRtfnLcJ5MQ2AtHcQJCCRUcMRvmDUjyEmNUWwx8UbK/1/1/*')", "range": 1500}])['total_amount'], Decimal("3.584")) | |||||
assert_equal(self.nodes[0].scantxoutset("start", [ | |||||
{"desc": "combo(tprv8ZgxMBicQKsPd7Uf69XL1XwhmjHopUGep8GuEiJDZmbQz6o58LninorQAfcKZWARbtRtfnLcJ5MQ2AtHcQJCCRUcMRvmDUjyEmNUWwx8UbK/1/1/*)", "range": 1499}])['total_amount'], Decimal("12.288")) | |||||
assert_equal(self.nodes[0].scantxoutset("start", [ | |||||
{"desc": "combo(tprv8ZgxMBicQKsPd7Uf69XL1XwhmjHopUGep8GuEiJDZmbQz6o58LninorQAfcKZWARbtRtfnLcJ5MQ2AtHcQJCCRUcMRvmDUjyEmNUWwx8UbK/1/1/*)", "range": 1500}])['total_amount'], Decimal("28.672")) | |||||
assert_equal(self.nodes[0].scantxoutset("start", [ | |||||
{"desc": "combo(tpubD6NzVbkrYhZ4WaWSyoBvQwbpLkojyoTZPRsgXELWz3Popb3qkjcJyJUGLnL4qHHoQvao8ESaAstxYSnhyswJ76uZPStJRJCTKvosUCJZL5B/1/1/*)", "range": 1499}])['total_amount'], Decimal("12.288")) | |||||
assert_equal(self.nodes[0].scantxoutset("start", [ | |||||
{"desc": "combo(tpubD6NzVbkrYhZ4WaWSyoBvQwbpLkojyoTZPRsgXELWz3Popb3qkjcJyJUGLnL4qHHoQvao8ESaAstxYSnhyswJ76uZPStJRJCTKvosUCJZL5B/1/1/*)", "range": 1500}])['total_amount'], Decimal("28.672")) | |||||
if __name__ == '__main__': | if __name__ == '__main__': | ||||
ScantxoutsetTest().main() | ScantxoutsetTest().main() |