diff options
author | fanquake <fanquake@gmail.com> | 2023-10-19 10:07:55 +0100 |
---|---|---|
committer | fanquake <fanquake@gmail.com> | 2023-10-19 10:23:44 +0100 |
commit | 091d29c49590d31dacdace24a8ae0fb781665ed6 (patch) | |
tree | 659ff858a767d0f2635f0724cc882a87cc789300 /test/functional/wallet_fundrawtransaction.py | |
parent | 5eb82d5706ea1b3b9eee2daaf6e47d1405549d4f (diff) | |
parent | 004903ebade38ba47c5ddc17b756d605b963528e (diff) | |
download | bitcoin-091d29c49590d31dacdace24a8ae0fb781665ed6.tar.xz |
Merge bitcoin/bitcoin#28617: test: Add Wallet Unlock Context Manager
004903ebade38ba47c5ddc17b756d605b963528e test: Add Wallet Unlock Context Manager (Brandon Odiwuor)
Pull request description:
Fixes #28601, see https://github.com/bitcoin/bitcoin/pull/28403#discussion_r1325426430
Add Context Manager to manage the locking and unlocking of locked wallets with a passphrase during testing.
ACKs for top commit:
kevkevinpal:
lgtm ACK [004903e](https://github.com/bitcoin/bitcoin/pull/28617/commits/004903ebade38ba47c5ddc17b756d605b963528e)
maflcko:
lgtm ACK 004903ebade38ba47c5ddc17b756d605b963528e
Tree-SHA512: ab234c167e71531df0d974ff9a31d444f7ce2a1d05aba5ea868cc9452f139845eeb24ca058d88f058bc02482b762adf2d99e63a6640b872cc71a57a0068abfe8
Diffstat (limited to 'test/functional/wallet_fundrawtransaction.py')
-rwxr-xr-x | test/functional/wallet_fundrawtransaction.py | 48 |
1 files changed, 23 insertions, 25 deletions
diff --git a/test/functional/wallet_fundrawtransaction.py b/test/functional/wallet_fundrawtransaction.py index 9b125d998b..77611649ac 100755 --- a/test/functional/wallet_fundrawtransaction.py +++ b/test/functional/wallet_fundrawtransaction.py @@ -25,7 +25,7 @@ from test_framework.util import ( find_vout_for_address, get_fee, ) -from test_framework.wallet_util import generate_keypair +from test_framework.wallet_util import generate_keypair, WalletUnlock ERR_NOT_ENOUGH_PRESET_INPUTS = "The preselected coins total amount does not cover the transaction target. " \ "Please allow other inputs to be automatically selected or include more coins manually" @@ -581,19 +581,18 @@ class RawTransactionsTest(BitcoinTestFramework): wallet.encryptwallet("test") if self.options.descriptors: - wallet.walletpassphrase("test", 999000) - wallet.importdescriptors([{ - 'desc': descsum_create('wpkh(tprv8ZgxMBicQKsPdYeeZbPSKd2KYLmeVKtcFA7kqCxDvDR13MQ6us8HopUR2wLcS2ZKPhLyKsqpDL2FtL73LMHcgoCL7DXsciA8eX8nbjCR2eG/0h/*h)'), - 'timestamp': 'now', - 'active': True - }, - { - 'desc': descsum_create('wpkh(tprv8ZgxMBicQKsPdYeeZbPSKd2KYLmeVKtcFA7kqCxDvDR13MQ6us8HopUR2wLcS2ZKPhLyKsqpDL2FtL73LMHcgoCL7DXsciA8eX8nbjCR2eG/1h/*h)'), - 'timestamp': 'now', - 'active': True, - 'internal': True - }]) - wallet.walletlock() + with WalletUnlock(wallet, "test"): + wallet.importdescriptors([{ + 'desc': descsum_create('wpkh(tprv8ZgxMBicQKsPdYeeZbPSKd2KYLmeVKtcFA7kqCxDvDR13MQ6us8HopUR2wLcS2ZKPhLyKsqpDL2FtL73LMHcgoCL7DXsciA8eX8nbjCR2eG/0h/*h)'), + 'timestamp': 'now', + 'active': True + }, + { + 'desc': descsum_create('wpkh(tprv8ZgxMBicQKsPdYeeZbPSKd2KYLmeVKtcFA7kqCxDvDR13MQ6us8HopUR2wLcS2ZKPhLyKsqpDL2FtL73LMHcgoCL7DXsciA8eX8nbjCR2eG/1h/*h)'), + 'timestamp': 'now', + 'active': True, + 'internal': True + }]) # Drain the keypool. wallet.getnewaddress() @@ -619,9 +618,8 @@ class RawTransactionsTest(BitcoinTestFramework): assert_raises_rpc_error(-4, "Transaction needs a change address, but we can't generate it.", wallet.fundrawtransaction, rawtx) # Refill the keypool. - wallet.walletpassphrase("test", 999000) - wallet.keypoolrefill(8) #need to refill the keypool to get an internal change address - wallet.walletlock() + with WalletUnlock(wallet, "test"): + wallet.keypoolrefill(8) #need to refill the keypool to get an internal change address assert_raises_rpc_error(-13, "walletpassphrase", wallet.sendtoaddress, self.nodes[0].getnewaddress(), 1.2) @@ -634,16 +632,16 @@ class RawTransactionsTest(BitcoinTestFramework): assert fundedTx["changepos"] != -1 # Now we need to unlock. - wallet.walletpassphrase("test", 999000) - signedTx = wallet.signrawtransactionwithwallet(fundedTx['hex']) - wallet.sendrawtransaction(signedTx['hex']) - self.generate(self.nodes[1], 1) + with WalletUnlock(wallet, "test"): + signedTx = wallet.signrawtransactionwithwallet(fundedTx['hex']) + wallet.sendrawtransaction(signedTx['hex']) + self.generate(self.nodes[1], 1) - # Make sure funds are received at node1. - assert_equal(oldBalance+Decimal('51.10000000'), self.nodes[0].getbalance()) + # Make sure funds are received at node1. + assert_equal(oldBalance+Decimal('51.10000000'), self.nodes[0].getbalance()) - # Restore pre-test wallet state - wallet.sendall(recipients=[df_wallet.getnewaddress(), df_wallet.getnewaddress(), df_wallet.getnewaddress()]) + # Restore pre-test wallet state + wallet.sendall(recipients=[df_wallet.getnewaddress(), df_wallet.getnewaddress(), df_wallet.getnewaddress()]) wallet.unloadwallet() self.generate(self.nodes[1], 1) |