Merge bitcoin/bitcoin#24510: test: check for importprunedfunds RPC errors

7573789925 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:
  7003b6ab24/src/wallet/rpc/backup.cpp (L320-L322)
  7003b6ab24/src/wallet/rpc/backup.cpp (L332-L334)
  7003b6ab24/src/wallet/rpc/backup.cpp (L338-L340)
  7003b6ab24/src/wallet/rpc/backup.cpp (L343-L345)

ACKs for top commit:
  MarcoFalke:
    review ACK 7573789925

Tree-SHA512: b054520d102e5940bdeed2456ca644e91afb187d169b751b1262ce34480e4e9fbe1616ab184a78777c184350dced23508c3d367ed5825cab78bb5ad687fd7dac
This commit is contained in:
MarcoFalke 2022-03-15 16:04:14 +01:00
commit 7b83c7d609
No known key found for this signature in database
GPG key ID: CE2B75697E69A548

View file

@ -5,9 +5,13 @@
"""Test the importprunedfunds and removeprunedfunds RPCs."""
from decimal import Decimal
from test_framework.blocktools import COINBASE_MATURITY
from test_framework.address import key_to_p2wpkh
from test_framework.blocktools import COINBASE_MATURITY
from test_framework.key import ECKey
from test_framework.messages import (
CMerkleBlock,
from_hex,
)
from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import (
assert_equal,
@ -15,6 +19,7 @@ from test_framework.util import (
)
from test_framework.wallet_util import bytes_to_wif
class ImportPrunedFundsTest(BitcoinTestFramework):
def set_test_params(self):
self.setup_clean_chain = True
@ -124,5 +129,18 @@ class ImportPrunedFundsTest(BitcoinTestFramework):
w1.removeprunedfunds(txnid3)
assert not [tx for tx in w1.listtransactions(include_watchonly=True) if tx['txid'] == txnid3]
# Check various RPC parameter validation errors
assert_raises_rpc_error(-22, "TX decode failed", w1.importprunedfunds, b'invalid tx'.hex(), proof1)
assert_raises_rpc_error(-5, "Transaction given doesn't exist in proof", w1.importprunedfunds, rawtxn2, proof1)
mb = from_hex(CMerkleBlock(), proof1)
mb.header.hashMerkleRoot = 0xdeadbeef # cause mismatch between merkle root and merkle block
assert_raises_rpc_error(-5, "Something wrong with merkleblock", w1.importprunedfunds, rawtxn1, mb.serialize().hex())
mb = from_hex(CMerkleBlock(), proof1)
mb.header.nTime += 1 # modify arbitrary block header field to change block hash
assert_raises_rpc_error(-5, "Block not found in chain", w1.importprunedfunds, rawtxn1, mb.serialize().hex())
if __name__ == '__main__':
ImportPrunedFundsTest().main()