diff options
author | Brandon Odiwuor <brandon.odiwuor@gmail.com> | 2023-10-09 15:30:40 +0300 |
---|---|---|
committer | Brandon Odiwuor <brandon.odiwuor@gmail.com> | 2023-10-10 18:12:31 +0300 |
commit | 004903ebade38ba47c5ddc17b756d605b963528e (patch) | |
tree | 1dd71fdea15ecce01ccc4be4ff324d9c7243271f /test/functional/test_framework | |
parent | db283a6b6f1419291bcd15d74d51c8598aefe06a (diff) |
test: Add Wallet Unlock Context Manager
Add Context Manager to manage wallet locking/unlocking with passphrase
Diffstat (limited to 'test/functional/test_framework')
-rwxr-xr-x | test/functional/test_framework/wallet_util.py | 19 |
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() |