forked from dashpay/dash
-
Notifications
You must be signed in to change notification settings - Fork 714
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge #2725: [test] Rewrite rpc_wallet_encrypted_wallet_sapzkeys unit…
… test as functional test 684c1b5 test: rewrite rpc_wallet_encrypted_wallet_sapzkeys unit test as functional test (furszy) Pull request description: As this test requires a complete real wallet, and not a mocked one, and accesses the node through the RPC server commands in order to perform the sapling keys/addresses checks on an encrypted wallet, it's by definition a functional test. This solves the unneeded headaches that we are having with the unit test. Which is failing sometimes for a missing base chainparams initialization which has nothing to do with the test purpose. ACKs for top commit: random-zebra: ACK 684c1b5 Tree-SHA512: 5aa8a10c82b357b1d28725dd688fb1d12b12525279acde22aad3d7f90a2b10896f633bcc1c89660f181242387534c5c4d0cfb707aa16df4906a24e8fc516676a
- Loading branch information
Showing
3 changed files
with
64 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
#!/usr/bin/env python3 | ||
# Copyright (c) 2021 The PIVX developers | ||
# Distributed under the MIT software license, see the accompanying | ||
# file COPYING or https://www.opensource.org/licenses/mit-license.php . | ||
|
||
from test_framework.test_framework import PivxTestFramework | ||
from test_framework.util import ( | ||
assert_equal, | ||
assert_raises_rpc_error, | ||
assert_true | ||
) | ||
|
||
# Test encrypted wallet behaviour with Sapling addresses | ||
class WalletSaplingTest(PivxTestFramework): | ||
|
||
def set_test_params(self): | ||
self.num_nodes = 1 | ||
self.setup_clean_chain = True | ||
|
||
def run_test(self): | ||
node = self.nodes[0] | ||
node.generate(1) | ||
|
||
# wallet should currently be empty | ||
assert_equal(len(node.listshieldaddresses()), 0) | ||
# create 100 keys | ||
keys_to_generate = 100 | ||
for _ in range (keys_to_generate): | ||
node.getnewshieldaddress() | ||
# Verify we can list the created addresses | ||
addr_list = node.listshieldaddresses() | ||
assert_equal(len(addr_list), keys_to_generate) | ||
|
||
password = "hello" | ||
node.encryptwallet(password) | ||
# assert that the wallet is encrypted | ||
assert_raises_rpc_error(-15, "Error: running with an encrypted wallet, but encryptwallet was called.", node.encryptwallet, 'ff') | ||
|
||
# now verify addresses again | ||
addr_list_post_encryption = node.listshieldaddresses() | ||
assert_equal(len(addr_list_post_encryption), keys_to_generate) | ||
assert_equal(addr_list, addr_list_post_encryption) | ||
|
||
# try to add a new key, but we can't as the wallet is locked | ||
assert_raises_rpc_error(-13, "Error: Please enter the wallet passphrase with walletpassphrase first.", node.getnewshieldaddress) | ||
|
||
# now unlock the wallet and try to generate the key again | ||
node.walletpassphrase(password, 12000) | ||
new_addr = node.getnewshieldaddress() | ||
assert(new_addr is not None) | ||
|
||
# and verify that the key has been added | ||
found = False | ||
addr_list_post_encryption = node.listshieldaddresses() | ||
assert_equal(len(addr_list_post_encryption), keys_to_generate + 1) | ||
for addr in addr_list_post_encryption: | ||
if addr == new_addr: | ||
found = True | ||
assert_true(found, "error: shield address not found in encrypted wallet") | ||
|
||
if __name__ == '__main__': | ||
WalletSaplingTest().main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters