From 60e2beaa781c1ee9ac483779248abc3ff5f6cd32 Mon Sep 17 00:00:00 2001 From: Kristaps Kaupe Date: Wed, 17 Mar 2021 12:03:26 +0200 Subject: [PATCH] Move wallet_utils tests to test suite --- jmclient/jmclient/wallet_utils.py | 32 +------------ jmclient/test/test_walletutils.py | 76 +++++++++++++++++++++++++++++++ 2 files changed, 77 insertions(+), 31 deletions(-) create mode 100644 jmclient/test/test_walletutils.py diff --git a/jmclient/jmclient/wallet_utils.py b/jmclient/jmclient/wallet_utils.py index 7322b7c..27787db 100644 --- a/jmclient/jmclient/wallet_utils.py +++ b/jmclient/jmclient/wallet_utils.py @@ -146,12 +146,7 @@ def bip32pathparse(path): ret_elements.append(x) return ret_elements -def test_bip32_pathparse(): - assert bip32pathparse("m/2/1/0017") - assert not bip32pathparse("n/1/1/1/1") - assert bip32pathparse("m/0/1'/100'/3'/2/2/21/004/005") - assert not bip32pathparse("m/0/0/00k") - return True + """ WalletView* classes manage wallet representations. """ @@ -1569,28 +1564,3 @@ def wallet_tool_main(wallet_root_path): parser.error("Unknown wallet-tool method: " + method) sys.exit(EXIT_ARGERROR) - -#Testing (can port to test modules, TODO) -if __name__ == "__main__": - if not test_bip32_pathparse(): - sys.exit(EXIT_FAILURE) - rootpath="m/0" - walletbranch = 0 - accounts = range(3) - acctlist = [] - for a in accounts: - branches = [] - for address_type in range(2): - entries = [] - for i in range(4): - entries.append(WalletViewEntry(rootpath, a, address_type, - i, "DUMMYADDRESS"+str(i+a), - [i*10000000, i*10000000])) - branches.append(WalletViewBranch(rootpath, - a, address_type, branchentries=entries, - xpub="xpubDUMMYXPUB"+str(a+address_type))) - acctlist.append(WalletViewAccount(rootpath, a, branches=branches)) - wallet = WalletView(rootpath + "/" + str(walletbranch), - accounts=acctlist) - jmprint(wallet.serialize(), "success") - diff --git a/jmclient/test/test_walletutils.py b/jmclient/test/test_walletutils.py new file mode 100644 index 0000000..0905a27 --- /dev/null +++ b/jmclient/test/test_walletutils.py @@ -0,0 +1,76 @@ +import pytest +from jmclient.wallet_utils import bip32pathparse, WalletView, \ + WalletViewAccount, WalletViewBranch, WalletViewEntry + + +def test_bip32_pathparse(): + assert bip32pathparse("m/2/1/0017") + assert not bip32pathparse("n/1/1/1/1") + assert bip32pathparse("m/0/1'/100'/3'/2/2/21/004/005") + assert not bip32pathparse("m/0/0/00k") + + +def test_walletview(): + rootpath = "m/0" + walletbranch = 0 + accounts = range(3) + acctlist = [] + for a in accounts: + branches = [] + for address_type in range(2): + entries = [] + for i in range(4): + entries.append(WalletViewEntry(rootpath, a, address_type, + i, "DUMMYADDRESS" + str(i+a), [i*10000000, i*10000000])) + branches.append(WalletViewBranch(rootpath, a, address_type, + branchentries=entries, + xpub="xpubDUMMYXPUB" + str(a + address_type))) + acctlist.append(WalletViewAccount(rootpath, a, branches=branches)) + wallet = WalletView(rootpath + "/" + str(walletbranch), + accounts=acctlist) + assert(wallet.serialize() == ( + 'JM wallet\n' + 'mixdepth\t0\n' + 'external addresses\tm/0\txpubDUMMYXPUB0\n' + 'm/0 \tDUMMYADDRESS0\t0.00000000\tnew\n' + 'm/0 \tDUMMYADDRESS1\t0.10000000\tnew\n' + 'm/0 \tDUMMYADDRESS2\t0.20000000\tnew\n' + 'm/0 \tDUMMYADDRESS3\t0.30000000\tnew\n' + 'Balance:\t0.60000000\n' + 'internal addresses\tm/0\txpubDUMMYXPUB1\n' + 'm/0 \tDUMMYADDRESS0\t0.00000000\tnew\n' + 'm/0 \tDUMMYADDRESS1\t0.10000000\tnew\n' + 'm/0 \tDUMMYADDRESS2\t0.20000000\tnew\n' + 'm/0 \tDUMMYADDRESS3\t0.30000000\tnew\n' + 'Balance:\t0.60000000\n' + 'Balance for mixdepth 0:\t1.20000000\n' + 'mixdepth\t1\n' + 'external addresses\tm/0\txpubDUMMYXPUB1\n' + 'm/0 \tDUMMYADDRESS1\t0.00000000\tnew\n' + 'm/0 \tDUMMYADDRESS2\t0.10000000\tnew\n' + 'm/0 \tDUMMYADDRESS3\t0.20000000\tnew\n' + 'm/0 \tDUMMYADDRESS4\t0.30000000\tnew\n' + 'Balance:\t0.60000000\n' + 'internal addresses\tm/0\txpubDUMMYXPUB2\n' + 'm/0 \tDUMMYADDRESS1\t0.00000000\tnew\n' + 'm/0 \tDUMMYADDRESS2\t0.10000000\tnew\n' + 'm/0 \tDUMMYADDRESS3\t0.20000000\tnew\n' + 'm/0 \tDUMMYADDRESS4\t0.30000000\tnew\n' + 'Balance:\t0.60000000\n' + 'Balance for mixdepth 1:\t1.20000000\n' + 'mixdepth\t2\n' + 'external addresses\tm/0\txpubDUMMYXPUB2\n' + 'm/0 \tDUMMYADDRESS2\t0.00000000\tnew\n' + 'm/0 \tDUMMYADDRESS3\t0.10000000\tnew\n' + 'm/0 \tDUMMYADDRESS4\t0.20000000\tnew\n' + 'm/0 \tDUMMYADDRESS5\t0.30000000\tnew\n' + 'Balance:\t0.60000000\n' + 'internal addresses\tm/0\txpubDUMMYXPUB3\n' + 'm/0 \tDUMMYADDRESS2\t0.00000000\tnew\n' + 'm/0 \tDUMMYADDRESS3\t0.10000000\tnew\n' + 'm/0 \tDUMMYADDRESS4\t0.20000000\tnew\n' + 'm/0 \tDUMMYADDRESS5\t0.30000000\tnew\n' + 'Balance:\t0.60000000\n' + 'Balance for mixdepth 2:\t1.20000000\n' + 'Total balance:\t3.60000000')) +