From 310fac8cf9901f065e80dcf6f9087ee8b26c0e84 Mon Sep 17 00:00:00 2001 From: undeath Date: Sat, 27 Oct 2018 19:07:13 +0200 Subject: [PATCH] add test for wallet.mixdepth --- jmclient/test/test_wallet.py | 55 ++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/jmclient/test/test_wallet.py b/jmclient/test/test_wallet.py index 7031101..91e5dd6 100644 --- a/jmclient/test/test_wallet.py +++ b/jmclient/test/test_wallet.py @@ -11,6 +11,7 @@ from commontest import binarize_tx from jmclient import load_program_config, jm_single, get_log,\ SegwitLegacyWallet,BIP32Wallet, BIP49Wallet, LegacyWallet,\ VolatileStorage, get_network, cryptoengine, WalletError +from test_blockchaininterface import sync_test_wallet testdir = os.path.dirname(os.path.realpath(__file__)) log = get_log() @@ -584,6 +585,60 @@ def test_imported_key_removed(setup_wallet): wallet.get_script_path(path) +def test_wallet_mixdepth_simple(setup_wallet): + wallet = get_populated_wallet(num=0) + mixdepth = wallet.mixdepth + assert wallet.max_mixdepth == mixdepth + + wallet.close() + storage_data = wallet._storage.file_data + + new_wallet = type(wallet)(VolatileStorage(data=storage_data)) + assert new_wallet.mixdepth == mixdepth + assert new_wallet.max_mixdepth == mixdepth + + +def test_wallet_mixdepth_increase(setup_wallet): + wallet = get_populated_wallet(num=0) + mixdepth = wallet.mixdepth + + wallet.close() + storage_data = wallet._storage.file_data + + new_mixdepth = mixdepth + 2 + new_wallet = type(wallet)( + VolatileStorage(data=storage_data), mixdepth=new_mixdepth) + assert new_wallet.mixdepth == new_mixdepth + assert new_wallet.max_mixdepth == new_mixdepth + + +def test_wallet_mixdepth_decrease(setup_wallet): + wallet = get_populated_wallet(num=1) + + # setup + max_mixdepth = wallet.max_mixdepth + assert max_mixdepth >= 1, "bad default value for mixdepth for this test" + utxo = fund_wallet_addr(wallet, wallet.get_internal_addr(max_mixdepth), 1) + assert wallet.get_balance_by_mixdepth()[max_mixdepth] == 10**8 + wallet.close() + storage_data = wallet._storage.file_data + + # actual test + new_mixdepth = max_mixdepth - 1 + new_wallet = type(wallet)( + VolatileStorage(data=storage_data), mixdepth=new_mixdepth) + assert new_wallet.max_mixdepth == max_mixdepth + assert new_wallet.mixdepth == new_mixdepth + sync_test_wallet(True, new_wallet) + + assert max_mixdepth not in new_wallet.get_balance_by_mixdepth() + assert max_mixdepth not in new_wallet.get_utxos_by_mixdepth() + + # wallet.select_utxos will still return utxos from higher mixdepths + # because we explicitly ask for a specific mixdepth + assert utxo in new_wallet.select_utxos_(max_mixdepth, 10**7) + + @pytest.fixture(scope='module') def setup_wallet(): load_program_config()