aboutsummaryrefslogtreecommitdiff
path: root/test/functional/test_framework/wallet_util.py
diff options
context:
space:
mode:
Diffstat (limited to 'test/functional/test_framework/wallet_util.py')
-rwxr-xr-xtest/functional/test_framework/wallet_util.py19
1 files changed, 19 insertions, 0 deletions
diff --git a/test/functional/test_framework/wallet_util.py b/test/functional/test_framework/wallet_util.py
index 319f120297..44811918bf 100755
--- a/test/functional/test_framework/wallet_util.py
+++ b/test/functional/test_framework/wallet_util.py
@@ -122,3 +122,22 @@ def generate_keypair(compressed=True, wif=False):
if wif:
privkey = bytes_to_wif(privkey.get_bytes(), compressed)
return privkey, pubkey
+
+class WalletUnlock():
+ """
+ A context manager for unlocking a wallet with a passphrase and automatically locking it afterward.
+ """
+
+ MAXIMUM_TIMEOUT = 999000
+
+ def __init__(self, wallet, passphrase, timeout=MAXIMUM_TIMEOUT):
+ self.wallet = wallet
+ self.passphrase = passphrase
+ self.timeout = timeout
+
+ def __enter__(self):
+ self.wallet.walletpassphrase(self.passphrase, self.timeout)
+
+ def __exit__(self, *args):
+ _ = args
+ self.wallet.walletlock()