Skip to content

Commit 7573789

Browse files
committed
test: check for importprunedfunds RPC errors
1 parent 7003b6a commit 7573789

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

test/functional/wallet_importprunedfunds.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,21 @@
55
"""Test the importprunedfunds and removeprunedfunds RPCs."""
66
from decimal import Decimal
77

8-
from test_framework.blocktools import COINBASE_MATURITY
98
from test_framework.address import key_to_p2wpkh
9+
from test_framework.blocktools import COINBASE_MATURITY
1010
from test_framework.key import ECKey
11+
from test_framework.messages import (
12+
CMerkleBlock,
13+
from_hex,
14+
)
1115
from test_framework.test_framework import BitcoinTestFramework
1216
from test_framework.util import (
1317
assert_equal,
1418
assert_raises_rpc_error,
1519
)
1620
from test_framework.wallet_util import bytes_to_wif
1721

22+
1823
class ImportPrunedFundsTest(BitcoinTestFramework):
1924
def set_test_params(self):
2025
self.setup_clean_chain = True
@@ -124,5 +129,18 @@ def run_test(self):
124129
w1.removeprunedfunds(txnid3)
125130
assert not [tx for tx in w1.listtransactions(include_watchonly=True) if tx['txid'] == txnid3]
126131

132+
# Check various RPC parameter validation errors
133+
assert_raises_rpc_error(-22, "TX decode failed", w1.importprunedfunds, b'invalid tx'.hex(), proof1)
134+
assert_raises_rpc_error(-5, "Transaction given doesn't exist in proof", w1.importprunedfunds, rawtxn2, proof1)
135+
136+
mb = from_hex(CMerkleBlock(), proof1)
137+
mb.header.hashMerkleRoot = 0xdeadbeef # cause mismatch between merkle root and merkle block
138+
assert_raises_rpc_error(-5, "Something wrong with merkleblock", w1.importprunedfunds, rawtxn1, mb.serialize().hex())
139+
140+
mb = from_hex(CMerkleBlock(), proof1)
141+
mb.header.nTime += 1 # modify arbitrary block header field to change block hash
142+
assert_raises_rpc_error(-5, "Block not found in chain", w1.importprunedfunds, rawtxn1, mb.serialize().hex())
143+
144+
127145
if __name__ == '__main__':
128146
ImportPrunedFundsTest().main()

0 commit comments

Comments
 (0)