Skip to content

Commit 7b83c7d

Browse files
author
MarcoFalke
committed
Merge bitcoin/bitcoin#24510: test: check for importprunedfunds RPC errors
7573789 test: check for importprunedfunds RPC errors (Sebastian Falbesoner) Pull request description: This PR adds missing test coverage for the following errors of the `importprunedfunds` RPC: https://github.com/bitcoin/bitcoin/blob/7003b6ab24f6adfffd71d7b7d4182afde52ff859/src/wallet/rpc/backup.cpp#L320-L322 https://github.com/bitcoin/bitcoin/blob/7003b6ab24f6adfffd71d7b7d4182afde52ff859/src/wallet/rpc/backup.cpp#L332-L334 https://github.com/bitcoin/bitcoin/blob/7003b6ab24f6adfffd71d7b7d4182afde52ff859/src/wallet/rpc/backup.cpp#L338-L340 https://github.com/bitcoin/bitcoin/blob/7003b6ab24f6adfffd71d7b7d4182afde52ff859/src/wallet/rpc/backup.cpp#L343-L345 ACKs for top commit: MarcoFalke: review ACK 7573789 Tree-SHA512: b054520d102e5940bdeed2456ca644e91afb187d169b751b1262ce34480e4e9fbe1616ab184a78777c184350dced23508c3d367ed5825cab78bb5ad687fd7dac
2 parents 28bdaa3 + 7573789 commit 7b83c7d

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)