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 decimal import Decimal | ||||
from test_framework.test_framework import BitcoinTestFramework | from test_framework.test_framework import BitcoinTestFramework | ||||
from test_framework.util import assert_equal | from test_framework.util import assert_equal, assert_raises_rpc_error | ||||
def descriptors(out): | def descriptors(out): | ||||
return sorted(u['desc'] for u in out['unspents']) | return sorted(u['desc'] for u in out['unspents']) | ||||
class ScantxoutsetTest(BitcoinTestFramework): | class ScantxoutsetTest(BitcoinTestFramework): | ||||
def set_test_params(self): | def set_test_params(self): | ||||
▲ Show 20 Lines • Show All 64 Lines • ▼ Show 20 Lines | def run_test(self): | ||||
"start", ["pkh(" + pubkey + ")"])['total_amount'], Decimal("0.002")) | "start", ["pkh(" + pubkey + ")"])['total_amount'], Decimal("0.002")) | ||||
assert_equal(self.nodes[0].scantxoutset( | assert_equal(self.nodes[0].scantxoutset( | ||||
"start", ["combo(" + pubkey + ")"])['total_amount'], Decimal("0.002")) | "start", ["combo(" + pubkey + ")"])['total_amount'], Decimal("0.002")) | ||||
assert_equal(self.nodes[0].scantxoutset( | assert_equal(self.nodes[0].scantxoutset( | ||||
"start", ["addr(" + addr + ")"])['total_amount'], Decimal("0.002")) | "start", ["addr(" + addr + ")"])['total_amount'], Decimal("0.002")) | ||||
assert_equal(self.nodes[0].scantxoutset( | assert_equal(self.nodes[0].scantxoutset( | ||||
"start", ["addr(" + addr + ")"])['total_amount'], Decimal("0.002")) | "start", ["addr(" + addr + ")"])['total_amount'], Decimal("0.002")) | ||||
self.log.info("Test range validation.") | |||||
assert_raises_rpc_error(-8, | |||||
"End of range is too high", | |||||
self.nodes[0].scantxoutset, | |||||
"start", | |||||
[{"desc": "desc", | |||||
"range": -1}]) | |||||
assert_raises_rpc_error(-8, | |||||
"Range should be greater or equal than 0", | |||||
self.nodes[0].scantxoutset, | |||||
"start", | |||||
[{"desc": "desc", | |||||
"range": [-1, | |||||
10]}]) | |||||
assert_raises_rpc_error(-8, | |||||
"End of range is too high", | |||||
self.nodes[0].scantxoutset, | |||||
"start", | |||||
[{"desc": "desc", | |||||
"range": [(2 << 31 + 1) - 1000000, | |||||
(2 << 31 + 1)]}]) | |||||
assert_raises_rpc_error(-8, | |||||
"Range specified as [begin,end] must not have begin after end", | |||||
self.nodes[0].scantxoutset, | |||||
"start", | |||||
[{"desc": "desc", | |||||
"range": [2, | |||||
1]}]) | |||||
assert_raises_rpc_error(-8, | |||||
"Range is too large", | |||||
self.nodes[0].scantxoutset, | |||||
"start", | |||||
[{"desc": "desc", | |||||
"range": [0, | |||||
1000001]}]) | |||||
self.log.info("Test extended key derivation.") | self.log.info("Test extended key derivation.") | ||||
# Run various scans, and verify that the sum of the amounts of the matches corresponds to the expected subset. | # Run various scans, and verify that the sum of the amounts of the matches corresponds to the expected subset. | ||||
# Note that all amounts in the UTXO set are powers of 2 multiplied by | # Note that all amounts in the UTXO set are powers of 2 multiplied by | ||||
# 0.001 BTC, so each amounts uniquely identifies a subset. | # 0.001 BTC, so each amounts uniquely identifies a subset. | ||||
assert_equal(self.nodes[0].scantxoutset("start", [ | assert_equal(self.nodes[0].scantxoutset("start", [ | ||||
"combo(tprv8ZgxMBicQKsPd7Uf69XL1XwhmjHopUGep8GuEiJDZmbQz6o58LninorQAfcKZWARbtRtfnLcJ5MQ2AtHcQJCCRUcMRvmDUjyEmNUWwx8UbK/0'/0h/0h)"])['total_amount'], Decimal("0.008")) | "combo(tprv8ZgxMBicQKsPd7Uf69XL1XwhmjHopUGep8GuEiJDZmbQz6o58LninorQAfcKZWARbtRtfnLcJ5MQ2AtHcQJCCRUcMRvmDUjyEmNUWwx8UbK/0'/0h/0h)"])['total_amount'], Decimal("0.008")) | ||||
assert_equal(self.nodes[0].scantxoutset("start", [ | assert_equal(self.nodes[0].scantxoutset("start", [ | ||||
"combo(tprv8ZgxMBicQKsPd7Uf69XL1XwhmjHopUGep8GuEiJDZmbQz6o58LninorQAfcKZWARbtRtfnLcJ5MQ2AtHcQJCCRUcMRvmDUjyEmNUWwx8UbK/0'/0'/1h)"])['total_amount'], Decimal("0.016")) | "combo(tprv8ZgxMBicQKsPd7Uf69XL1XwhmjHopUGep8GuEiJDZmbQz6o58LninorQAfcKZWARbtRtfnLcJ5MQ2AtHcQJCCRUcMRvmDUjyEmNUWwx8UbK/0'/0'/1h)"])['total_amount'], Decimal("0.016")) | ||||
▲ Show 20 Lines • Show All 79 Lines • Show Last 20 Lines |