12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153 |
- #!/usr/bin/env python3
- #
- # MMGen Wallet, a terminal-based cryptocurrency wallet
- # Copyright (C)2013-2024 The MMGen Project <mmgen@tuta.io>
- #
- # This program is free software: you can redistribute it and/or modify
- # it under the terms of the GNU General Public License as published by
- # the Free Software Foundation, either version 3 of the License, or
- # (at your option) any later version.
- #
- # This program is distributed in the hope that it will be useful,
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- # GNU General Public License for more details.
- #
- # You should have received a copy of the GNU General Public License
- # along with this program. If not, see <http://www.gnu.org/licenses/>.
- """
- test.cmdtest_d.ct_regtest: Regtest tests for the cmdtest.py test suite
- """
- import os, json, time, re
- from decimal import Decimal
- from mmgen.proto.btc.regtest import MMGenRegtest
- from mmgen.proto.bch.cashaddr import b32a
- from mmgen.proto.btc.common import b58a
- from mmgen.color import yellow
- from mmgen.util import msg_r, die, gmsg, capfirst, fmt_list
- from mmgen.protocol import init_proto
- from mmgen.addrlist import AddrList
- from mmgen.wallet import Wallet, get_wallet_cls
- from ..include.common import (
- cfg,
- imsg,
- omsg,
- ok,
- stop_test_daemons,
- joinpath,
- silence,
- end_silence,
- cmp_or_die,
- strip_ansi_escapes,
- gr_uc,
- getrandhex
- )
- from .common import (
- ok_msg,
- get_file_with_ext,
- get_comment,
- tw_comment_lat_cyr_gr,
- tw_comment_zh,
- tx_comment_jp,
- get_env_without_debug_vars
- )
- from .ct_base import CmdTestBase
- from .ct_shared import CmdTestShared
- pat_date = r'\b\d\d-\d\d-\d\d\b'
- pat_date_time = r'\b\d\d\d\d-\d\d-\d\d\s+\d\d:\d\d\b'
- dfl_wcls = get_wallet_cls('mmgen')
- tx_fee = rtFundAmt = rtFee = rtBals = rtBals_gb = rtBobOp3 = rtAmts = {} # pylint
- rt_pw = 'abc-α'
- rt_data = {
- 'tx_fee': {'btc':'0.0001', 'bch':'0.001', 'ltc':'0.01'},
- 'rtFundAmt': {'btc':'500', 'bch':'500', 'ltc':'5500'},
- 'rtFee': {
- 'btc': ('20s', '10s', '60s', '31s', '10s', '20s'),
- 'bch': ('20s', '10s', '60s', '0.0001', '10s', '20s'),
- 'ltc': ('1000s', '500s', '1500s', '0.05', '400s', '1000s')
- },
- 'rtBals': {
- 'btc': ('499.9999488', '399.9998282', '399.9998147', '399.9996877',
- '52.99980410', '946.99933647', '999.99914057', '52.9999',
- '946.99933647', '0.4169328', '6.24987417'),
- 'bch': ('499.9999484', '399.9999194', '399.9998972', '399.9997692',
- '46.78890380', '953.20966920', '999.99857300', '46.789',
- '953.2096692', '0.4169328', '39.58187387'),
- 'ltc': ('5499.99744', '5399.994425', '5399.993885', '5399.987535',
- '52.98520500', '10946.93753500', '10999.92274000', '52.99',
- '10946.937535', '0.41364', '6.24846787'),
- },
- 'rtBals_gb': {
- 'btc': {
- '0conf0': {
- 'mmgen': ('283.22339537', '283.22339537'),
- 'nonmm': ('16.77647763', '116.77629233'),
- 'total': ('299.999873', '399.9996877'),
- },
- '0conf1': {
- 'mmgen': ('283.22339537', '0'),
- 'nonmm': ('16.77647763', '99.9998147'),
- 'total': ('299.999873', '99.9998147'),
- },
- '1conf1': {
- 'mmgen': ('0', '283.22339537'),
- 'nonmm': ('0', '116.77629233'),
- 'total': ('0', '399.9996877'),
- },
- '1conf2': {
- 'mmgen': ('0', '283.22339537', '0'),
- 'nonmm': ('0', '16.77647763', '99.9998147'),
- 'total': ('0', '299.999873', '99.9998147'),
- },
- },
- 'bch': {
- '0conf0': {
- 'mmgen': ('283.22339437', '283.22339437'),
- 'nonmm': ('16.77647763', '116.77637483'),
- 'total': ('299.999872', '399.9997692'),
- },
- '0conf1': {
- 'mmgen': ('283.22339437', '0'),
- 'nonmm': ('16.77647763', '99.9998972'),
- 'total': ('299.999872', '99.9998972'),
- },
- '1conf1': {
- 'mmgen': ('0', '283.22339437'),
- 'nonmm': ('0', '116.77637483'),
- 'total': ('0', '399.9997692'),
- },
- '1conf2': {
- 'mmgen': ('0', '283.22339437', '0'),
- 'nonmm': ('0', '16.77647763', '99.9998972'),
- 'total': ('0', '299.999872', '99.9998972'),
- },
- },
- 'ltc': {
- '0conf0': {
- 'mmgen': ('283.21717237', '283.21717237'),
- 'nonmm': ('16.77647763', '5116.77036263'),
- 'total': ('299.99365', '5399.987535'),
- },
- '0conf1': {
- 'mmgen': ('283.21717237', '0'),
- 'nonmm': ('16.77647763', '5099.993885'),
- 'total': ('299.99365', '5099.993885'),
- },
- '1conf1': {
- 'mmgen': ('0', '283.21717237'),
- 'nonmm': ('0', '5116.77036263'),
- 'total': ('0', '5399.987535'),
- },
- '1conf2': {
- 'mmgen': ('0', '283.21717237', '0'),
- 'nonmm': ('0', '16.77647763', '5099.993885'),
- 'total': ('0', '299.99365', '5099.993885'),
- },
- }
- },
- 'rtBobOp3': {'btc':'S:2', 'bch':'L:3', 'ltc':'S:2'},
- 'rtAmts': {
- 'btc': ('500', '500'),
- 'bch': ('500', '560'),
- 'ltc': ('5500', '5500')
- }
- }
- def make_burn_addr(proto):
- from mmgen.tool.coin import tool_cmd
- return tool_cmd(
- cfg = cfg,
- cmdname = 'pubhash2addr',
- proto = proto,
- mmtype = 'compressed').pubhash2addr('00'*20)
- class CmdTestRegtest(CmdTestBase, CmdTestShared):
- 'transacting and tracking wallet operations via regtest mode'
- networks = ('btc', 'ltc', 'bch')
- passthru_opts = ('coin', 'rpc_backend')
- tmpdir_nums = [17]
- color = True
- deterministic = False
- test_rbf = False
- proto = None # pylint
- bdb_wallet = False
- cmd_group_in = (
- ('setup', 'regtest (Bob and Alice) mode setup'),
- ('subgroup.misc', []),
- ('subgroup.init_bob', []),
- ('subgroup.init_alice', []),
- ('subgroup.fund_users', ['init_bob', 'init_alice']),
- ('subgroup.msg', ['init_bob']),
- ('subgroup.twexport', ['fund_users']),
- ('subgroup.rescan', ['fund_users']),
- ('subgroup.errors', ['fund_users']),
- ('subgroup.main', ['fund_users']),
- ('subgroup.twprune', ['main']),
- ('subgroup.txhist', ['main']),
- ('subgroup.label', ['main']),
- ('subgroup.view', ['label']),
- ('subgroup._auto_chg_deps', ['twexport', 'label']),
- ('subgroup.auto_chg', ['_auto_chg_deps']),
- ('stop', 'stopping regtest daemon'),
- )
- cmd_subgroups = {
- 'misc': (
- 'miscellaneous commands',
- ('daemon_version', 'mmgen-tool daemon_version'),
- ('halving_calculator_bob', 'halving calculator (Bob)'),
- ),
- 'init_bob': (
- 'creating Bob’s MMGen wallet and tracking wallet',
- ('bob_twview_noaddrs', 'viewing Bob’s unspent outputs (error, no addrs)'),
- ('bob_listaddrs_noaddrs', 'viewing Bob’s addresses (error, no addrs)'),
- ('walletgen_bob', 'wallet generation (Bob)'),
- ('addrgen_bob', 'address generation (Bob)'),
- ('addrimport_bob', 'importing Bob’s addresses'),
- ('bob_twview_nobal', 'viewing Bob’s unspent outputs (error, no balance)'),
- ('bob_listaddrs_nobal', 'viewing Bob’s addresses (OK, no balance)'),
- ),
- 'init_alice': (
- 'creating Alice’s MMGen wallet and tracking wallet',
- ('walletgen_alice', 'wallet generation (Alice)'),
- ('addrgen_alice', 'address generation (Alice)'),
- ('addrimport_alice', 'importing Alice’s addresses'),
- ),
- 'fund_users': (
- 'funding Bob and Alice’s wallets',
- ('bob_import_miner_addr', 'importing miner’s coinbase addr into Bob’s wallet'),
- ('fund_bob_deterministic', 'funding Bob’s first MMGen address (deterministic method)'),
- ('fund_alice_deterministic', 'funding Alice’s first MMGen address (deterministic method)'),
- ('bob_recreate_tracking_wallet', 'creation of new tracking wallet (Bob)'),
- ('addrimport_bob2', 'reimporting Bob’s addresses'),
- ('fund_bob', 'funding Bob’s wallet'),
- ('fund_alice', 'funding Alice’s wallet'),
- ('generate', 'mining a block'),
- ('bob_bal1', 'Bob’s balance'),
- ('generate_extra_deterministic', 'generate extra blocks for deterministic run'),
- ),
- 'msg': (
- 'message signing',
- ('bob_msgcreate', 'creating a message file for signing'),
- ('bob_msgsign', 'signing the message file (default wallet)'),
- ('bob_walletconv_words', 'creating an MMGen mnemonic wallet'),
- ('bob_subwalletgen_bip39', 'creating a BIP39 mnemonic subwallet'),
- ('bob_msgsign_userwallet', 'signing the message file (user-specified wallet)'),
- ('bob_msgsign_userwallets', 'signing the message file (user-specified wallets)'),
- ('bob_msgverify', 'verifying the message file (all addresses)'),
- ('bob_msgverify_raw', 'verifying the raw message file (all addresses)'),
- ('bob_msgverify_single', 'verifying the message file (single address)'),
- ('bob_msgexport_single', 'exporting the message file (single address)'),
- ('bob_msgexport', 'exporting the message file (all addresses)'),
- ('bob_msgverify_export', 'verifying the exported JSON data (all addresses)'),
- ('bob_msgverify_export_single', 'verifying the exported JSON data (single address)'),
- ),
- 'twexport': (
- 'exporting and importing tracking wallet to JSON',
- ('bob_twexport', 'exporting a tracking wallet to JSON'),
- ('carol_twimport', 'importing a tracking wallet JSON dump'),
- ('carol_delete_wallet', 'unloading and deleting Carol’s tracking wallet'),
- ('bob_twexport_noamt', 'exporting a tracking wallet to JSON (include_amts=0)'),
- ('carol_twimport_nochksum', 'importing a tracking wallet JSON dump (ignore_checksum=1)'),
- ('carol_delete_wallet', 'unloading and deleting Carol’s tracking wallet'),
- ('carol_twimport_batch', 'importing a tracking wallet JSON dump (batch=1)'),
- ('bob_twexport_pretty', 'exporting a tracking wallet to JSON (pretty=1)'),
- ('bob_edit_json_twdump', 'editing a tracking wallet JSON dump'),
- ('carol_delete_wallet', 'unloading and deleting Carol’s tracking wallet'),
- ('carol_twimport_pretty', 'importing an edited tracking wallet JSON dump (ignore_checksum=1)'),
- ('carol_listaddresses', 'viewing Carol’s tracking wallet'),
- ('carol_delete_wallet', 'unloading and deleting Carol’s tracking wallet'),
- ),
- 'rescan': (
- 'rescanning address and blockchain',
- ('bob_resolve_addr', 'resolving an address in the tracking wallet'),
- ('bob_rescan_addr', 'rescanning an address'),
- ('bob_rescan_blockchain_all', 'rescanning the blockchain (full rescan)'),
- ('bob_rescan_blockchain_gb', 'rescanning the blockchain (Genesis block)'),
- ('bob_rescan_blockchain_one', 'rescanning the blockchain (single block)'),
- ('bob_rescan_blockchain_ss', 'rescanning the blockchain (range of blocks)'),
- ),
- 'errors': (
- 'various error conditions',
- ('bob_bad_locktime1', 'broadcast of transaction with bad locktime (block)'),
- ('bob_bad_locktime2', 'broadcast of transaction with bad locktime (integer size)'),
- ('bob_bad_locktime3', 'broadcast of transaction with bad locktime (time)'),
- ),
- 'main': (
- 'creating, signing, sending and bumping transactions',
- ('bob_add_comment1', 'adding an 80-screen-width label (lat+cyr+gr)'),
- ('bob_twview1', 'viewing Bob’s tracking wallet'),
- ('bob_split1', 'splitting Bob’s funds'),
- ('generate', 'mining a block'),
- ('bob_bal2', 'Bob’s balance'),
- ('bob_rbf_1output_create', 'creating RBF tx with one output'),
- ('bob_rbf_1output_bump', 'bumping RBF tx with one output'),
- ('bob_bal2a', 'Bob’s balance (age_fmt=confs)'),
- ('bob_bal2b', 'Bob’s balance (showempty=1)'),
- ('bob_bal2c', 'Bob’s balance (showempty=1 minconf=2 age_fmt=days)'),
- ('bob_bal2d', 'Bob’s balance (minconf=2)'),
- ('bob_bal2e', 'Bob’s balance (showempty=1 sort=age)'),
- ('bob_bal2f', 'Bob’s balance (showempty=1 sort=age,reverse)'),
- ('bob_send_maybe_rbf', 'sending funds to Alice (RBF, if supported)'),
- ('get_mempool1', 'mempool (before RBF bump)'),
- ('bob_rbf_status1', 'getting status of transaction'),
- ('bob_rbf_bump', 'bumping RBF transaction'),
- ('get_mempool2', 'mempool (after RBF bump)'),
- ('bob_rbf_status2', 'getting status of transaction after replacement'),
- ('bob_rbf_status3', 'getting status of replacement transaction (mempool)'),
- ('generate', 'mining a block'),
- ('bob_rbf_status4', 'getting status of transaction after confirmed (1) replacement'),
- ('bob_rbf_status5', 'getting status of replacement transaction (confirmed)'),
- ('generate', 'mining a block'),
- ('bob_rbf_status6', 'getting status of transaction after confirmed (2) replacement'),
- ('bob_bal3', 'Bob’s balance'),
- ('bob_pre_import', 'sending to non-imported address'),
- ('generate', 'mining a block'),
- ('bob_import_addr', 'importing non-MMGen address'),
- ('bob_bal4', 'Bob’s balance (after import)'),
- ('bob_import_list', 'importing flat address list'),
- ('bob_import_list_rescan', 'importing flat address list with --rescan'),
- ('bob_import_list_rescan_aio', 'importing flat address list with --rescan (aiohttp backend)'),
- ('bob_split2', 'splitting Bob’s funds'),
- ('bob_0conf0_getbalance', 'Bob’s balance (unconfirmed, minconf=0)'),
- ('bob_0conf1_getbalance', 'Bob’s balance (unconfirmed, minconf=1)'),
- ('generate', 'mining a block'),
- ('bob_1conf1_getbalance', 'Bob’s balance (confirmed, minconf=1)'),
- ('bob_1conf2_getbalance', 'Bob’s balance (confirmed, minconf=2)'),
- ('bob_bal5', 'Bob’s balance'),
- ('bob_send_non_mmgen', 'sending funds to Alice (from non-MMGen addrs)'),
- ('generate', 'mining a block'),
- ('alice_send_estimatefee', 'tx creation with no fee on command line'),
- ('generate', 'mining a block'),
- ('bob_bal6', 'Bob’s balance'),
- ('bob_subwallet_addrgen1', 'generating Bob’s addrs from subwallet 29L'),
- ('bob_subwallet_addrgen2', 'generating Bob’s addrs from subwallet 127S'),
- ('bob_subwallet_addrimport1', 'importing Bob’s addrs from subwallet 29L'),
- ('bob_subwallet_addrimport2', 'importing Bob’s addrs from subwallet 127S'),
- ('bob_subwallet_fund', 'funding Bob’s subwallet addrs'),
- ('generate', 'mining a block'),
- ('bob_twview2', 'viewing Bob’s tracking wallet'),
- ('bob_twview3', 'viewing Bob’s tracking wallet'),
- ('bob_subwallet_txcreate', 'creating a transaction with subwallet inputs'),
- ('bob_subwallet_txsign', 'signing a transaction with subwallet inputs'),
- ('bob_subwallet_txdo', 'sending from Bob’s subwallet addrs'),
- ('generate', 'mining a block'),
- ('bob_twview4', 'viewing Bob’s tracking wallet'),
- ('bob_alice_bal', 'Bob and Alice’s balances'),
- ('bob_nochg_burn', 'zero-change transaction to burn address'),
- ('generate', 'mining a block'),
- ),
- 'twprune': (
- 'exporting a pruned tracking wallet to JSON',
- ('bob_twprune_noask', 'pruning a tracking wallet'),
- ('bob_twprune_skip', 'pruning a tracking wallet (skip pruning)'),
- ('bob_twprune_all', 'pruning a tracking wallet (pruning all addrs)'),
- ('bob_twprune_skipamt', 'pruning a tracking wallet (skipping addrs with amt)'),
- ('bob_twprune_skipused', 'pruning a tracking wallet (skipping used addrs)'),
- ('bob_twprune_allamt', 'pruning a tracking wallet (pruning addrs with amt)'),
- ('bob_twprune_allused', 'pruning a tracking wallet (pruning used addrs)'),
- ('bob_twprune1', 'pruning a tracking wallet (selective prune)'),
- ('bob_twprune2', 'pruning a tracking wallet (selective prune)'),
- ('bob_twprune3', 'pruning a tracking wallet (selective prune)'),
- ('bob_twprune4', 'pruning a tracking wallet (selective prune)'),
- ('bob_twprune5', 'pruning a tracking wallet (selective prune)'),
- ('bob_twprune6', 'pruning a tracking wallet (selective prune)'),
- ),
- 'txhist': (
- 'viewing transaction history',
- ('bob_txhist1', 'viewing Bob’s transaction history (sort=age)'),
- ('bob_txhist2', 'viewing Bob’s transaction history (sort=blockheight reverse=1)'),
- ('bob_txhist3', 'viewing Bob’s transaction history (sort=blockheight sinceblock=-7)'),
- ('bob_txhist4', 'viewing Bob’s transaction history (detail=1)'),
- ('bob_txhist5', 'viewing Bob’s transaction history (sinceblock=399 detail=1)'),
- ('bob_txhist_interactive', 'viewing Bob’s transaction history (age_fmt=date_time interactive=true)'),
- ),
- 'label': (
- 'adding, removing and editing labels',
- ('alice_bal2', 'Alice’s balance'),
- ('alice_add_comment1', 'adding a label'),
- ('alice_chk_comment1', 'the label'),
- ('alice_add_comment2', 'adding a label'),
- ('alice_chk_comment2', 'the label'),
- ('alice_edit_comment1', 'editing a label (zh)'),
- ('alice_edit_comment2', 'editing a label (lat+cyr+gr)'),
- ('alice_chk_comment3', 'the label'),
- ('alice_remove_comment1', 'removing a label'),
- ('alice_chk_comment4', 'the label'),
- ('alice_add_comment_coinaddr', 'adding a label using the coin address'),
- ('alice_chk_comment_coinaddr', 'the label'),
- ('alice_add_comment_badaddr1', 'adding a label with invalid address'),
- ('alice_add_comment_badaddr2', 'adding a label with invalid address for this chain'),
- ('alice_add_comment_badaddr3', 'adding a label with wrong MMGen address'),
- ('alice_add_comment_badaddr4', 'adding a label with wrong coin address'),
- ),
- 'view': (
- 'viewing addresses and unspent outputs',
- ('alice_listaddresses_scroll', 'listaddresses (--scroll, interactive=1)'),
- ('alice_listaddresses_cashaddr', 'listaddresses (BCH cashaddr)'),
- ('alice_listaddresses_empty', 'listaddresses (no data)'),
- ('alice_listaddresses_menu', 'listaddresses (menu items)'),
- ('alice_listaddresses1', 'listaddresses'),
- ('alice_listaddresses_days', 'listaddresses (age_fmt=days)'),
- ('alice_listaddresses_date', 'listaddresses (age_fmt=date)'),
- ('alice_listaddresses_date_time', 'listaddresses (age_fmt=date_time)'),
- ('alice_twview1', 'twview'),
- ('alice_twview_days', 'twview (age_fmt=days)'),
- ('alice_twview_date', 'twview (age_fmt=date)'),
- ('alice_twview_date_time', 'twview (age_fmt=date_time)'),
- ('alice_twview_interactive_cashaddr', 'twview (interactive=1, BCH cashaddr)'),
- ('alice_txcreate_info', 'txcreate -i'),
- ('alice_txcreate_info_term', 'txcreate -i (pexpect_spawn)'),
- ('bob_send_to_alice_2addr', 'sending a TX to 2 addresses in Alice’s wallet'),
- ('bob_send_to_alice_reuse', 'sending a TX to a used address in Alice’s wallet'),
- ('generate', 'mining a block'),
- ('alice_twview_grouped', 'twview (testing ‘grouped’ option for TX and address)'),
- ),
- '_auto_chg_deps': (
- 'automatic change address selection dependencies',
- ('bob_auto_chg_split', 'splitting Bob’s funds (auto-chg-addr dependency)'),
- ('bob_auto_chg_generate', 'mining a block (auto-chg-addr dependency)'),
- ),
- 'auto_chg': (
- 'automatic change address selection',
- ('bob_auto_chg1', 'creating an automatic change address transaction (C)'),
- ('bob_auto_chg2', 'creating an automatic change address transaction (B)'),
- ('bob_auto_chg3', 'creating an automatic change address transaction (S)'),
- ('bob_auto_chg4', 'creating an automatic change address transaction (single address)'),
- ('bob_auto_chg_addrtype1', 'creating an automatic change address transaction by addrtype (C)'),
- ('bob_auto_chg_addrtype2', 'creating an automatic change address transaction by addrtype (B)'),
- ('bob_auto_chg_addrtype3', 'creating an automatic change address transaction by addrtype (S)'),
- ('bob_auto_chg_addrtype4', 'creating an automatic change address transaction by addrtype (single address)'),
- ('bob_add_comment_uua1', 'adding a comment for unused address in tracking wallet (C)'),
- ('bob_auto_chg5', 'creating an auto-chg-address TX, skipping unused address with label (C)'),
- ('bob_auto_chg_addrtype5', 'creating an auto-chg-address TX by addrtype, skipping unused address '
- 'with label (C)'),
- ('bob_auto_chg6', 'creating an auto-chg-address TX, using unused address with label (C)'),
- ('bob_auto_chg7', 'creating an automatic change address transaction (exclude cmdline output)'),
- ('bob_auto_chg_addrtype6', 'creating an auto-chg-address TX by addrtype, using unused address with '
- 'label (C)'),
- ('bob_remove_comment_uua1', 'removing a comment for unused address in tracking wallet (C)'),
- ('bob_auto_chg_bad1', 'error handling for auto change address transaction (bad ID FFFFFFFF:C)'),
- ('bob_auto_chg_bad2', 'error handling for auto change address transaction (bad ID 00000000:C)'),
- ('bob_auto_chg_bad3', 'error handling for auto change address transaction (no unused addresses)'),
- ('bob_auto_chg_bad4', 'error handling for auto change address transaction by addrtype '
- '(no unused addresses)'),
- ('bob_auto_chg_bad5', 'error handling (more than one chg address listed)'),
- ('bob_auto_chg_bad6', 'error handling for auto change address transaction '
- '(more than one chg address, mixed)'),
- ('bob_auto_chg_bad7', 'error handling for auto change address transaction '
- '(more than one chg address requested)'),
- ('carol_twimport2', 'recreating Carol’s tracking wallet from JSON dump'),
- ('carol_rescan_blockchain', 'rescanning the blockchain (full rescan)'),
- ('carol_auto_chg1', 'creating an automatic change address transaction (C)'),
- ('carol_auto_chg2', 'creating an automatic change address transaction (B)'),
- ('carol_auto_chg3', 'creating an automatic change address transaction (S)'),
- ('carol_auto_chg_addrtype1', 'creating an automatic change address transaction by addrtype (C)'),
- ('carol_auto_chg_addrtype2', 'creating an automatic change address transaction by addrtype (B)'),
- ('carol_auto_chg_addrtype3', 'creating an automatic change address transaction by addrtype (S)'),
- ('carol_auto_chg_addrtype4', 'creating an automatic change address transaction by addrtype (C) (exclude cmdline output)'),
- ('carol_auto_chg_bad1', 'error handling for auto change address transaction (no unused addresses)'),
- ('carol_auto_chg_bad2', 'error handling for auto change address transaction by addrtype '
- '(no unused addresses)'),
- ('carol_delete_wallet', 'unloading and deleting Carol’s tracking wallet'),
- ),
- }
- def __init__(self, trunner, cfgs, spawn):
- CmdTestBase.__init__(self, trunner, cfgs, spawn)
- if trunner is None:
- return
- if self.proto.testnet:
- die(2, '--testnet and --regtest options incompatible with regtest test suite')
- coin = self.coin
- self.proto = init_proto(cfg, coin, network='regtest', need_amt=True)
- gldict = globals()
- for k in rt_data:
- gldict[k] = rt_data[k][coin] if coin in rt_data[k] else None
- self.use_bdb_wallet = self.bdb_wallet or coin != 'btc'
- self.rt = MMGenRegtest(cfg, coin, bdb_wallet=self.use_bdb_wallet)
- if coin == 'btc':
- self.test_rbf = True # tests are non-coin-dependent, so run just once for BTC
- if cfg.test_suite_deterministic:
- self.deterministic = True
- self.spawn_env['MMGEN_BOGUS_SEND'] = ''
- self.write_to_tmpfile('wallet_password', rt_pw)
- self.dfl_mmtype = 'C' if coin == 'bch' else 'B'
- self.burn_addr = make_burn_addr(self.proto)
- self.user_sids = {}
- def _add_comments_to_addr_file(self, addrfile, outfile, use_comments=False):
- silence()
- gmsg(f'Adding comments to address file {addrfile!r}')
- a = AddrList(cfg, self.proto, addrfile)
- for n, idx in enumerate(a.idxs(), 1):
- if use_comments:
- a.set_comment(idx, get_comment())
- else:
- if n % 2:
- a.set_comment(idx, f'Test address {n}')
- a.file.format(add_comments=True)
- from mmgen.fileutil import write_data_to_file
- write_data_to_file(
- cfg,
- outfile = outfile,
- data = a.file.fmt_data,
- quiet = True,
- ignore_opt_outdir = True)
- end_silence()
- def setup(self):
- stop_test_daemons(self.proto.network_id, force=True, remove_datadir=True)
- from shutil import rmtree
- try:
- rmtree(joinpath(self.tr.data_dir, 'regtest'))
- except:
- pass
- t = self.spawn(
- 'mmgen-regtest',
- (['--bdb-wallet'] if self.use_bdb_wallet else [])
- + ['--setup-no-stop-daemon', 'setup'])
- t.expect('Starting')
- for _ in range(3): t.expect('Creating')
- for _ in range(5): t.expect('Mined')
- t.expect('Setup complete')
- return t
- def daemon_version(self):
- t = self.spawn('mmgen-tool', ['--bob', 'daemon_version'])
- t.expect('version')
- return t
- def halving_calculator_bob(self):
- t = self.spawn('halving-calculator.py', ['--bob'], cmd_dir='examples')
- t.expect('time until halving')
- return t
- def walletgen(self, user):
- t = self.spawn('mmgen-walletgen', ['-q', '-r0', '-p1', f'--{user}'], no_passthru_opts=True)
- t.passphrase_new(f'new {dfl_wcls.desc}', rt_pw)
- t.label()
- t.expect('move it to the data directory? (Y/n): ', 'y')
- t.written_to_file(capfirst(dfl_wcls.desc))
- return t
- def walletgen_bob(self):
- return self.walletgen('bob')
- def walletgen_alice(self):
- return self.walletgen('alice')
- def _user_dir(self, user, coin=None):
- return joinpath(self.tr.data_dir, 'regtest', user)
- def _user_sid(self, user):
- if user in self.user_sids:
- return self.user_sids[user]
- else:
- self.user_sids[user] = os.path.basename(get_file_with_ext(self._user_dir(user), 'mmdat'))[:8]
- return self.user_sids[user]
- def _get_user_subsid(self, user, subseed_idx):
- fn = get_file_with_ext(self._user_dir(user), dfl_wcls.ext)
- silence()
- w = Wallet(cfg, fn=fn, passwd_file=os.path.join(self.tmpdir, 'wallet_password'))
- end_silence()
- return w.seed.subseed(subseed_idx).sid
- def addrgen(
- self,
- user,
- wf = None,
- addr_range = '1-5',
- subseed_idx = None,
- mmtypes = []):
- from mmgen.addr import MMGenAddrType
- for mmtype in mmtypes or self.proto.mmtypes:
- t = self.spawn(
- 'mmgen-addrgen',
- ['--quiet', f'--{user}', f'--type={mmtype}', f'--outdir={self._user_dir(user)}']
- + ([wf] if wf else [])
- + ([f'--subwallet={subseed_idx}'] if subseed_idx else [])
- + [addr_range],
- extra_desc = '({})'.format(MMGenAddrType.mmtypes[mmtype].name))
- t.passphrase(dfl_wcls.desc, rt_pw)
- t.written_to_file('Addresses')
- ok_msg()
- t.skip_ok = True
- return t
- def addrgen_bob(self):
- return self.addrgen('bob')
- def addrgen_alice(self):
- return self.addrgen('alice')
- def addrimport(
- self,
- user,
- sid = None,
- addr_range = '1-5',
- num_addrs = 5,
- mmtypes = [],
- batch = True,
- quiet = True):
- id_strs = {'legacy':'', 'compressed':'-C', 'segwit':'-S', 'bech32':'-B'}
- if not sid:
- sid = self._user_sid(user)
- from mmgen.addr import MMGenAddrType
- for mmtype in mmtypes or self.proto.mmtypes:
- desc = MMGenAddrType.mmtypes[mmtype].name
- addrfile = joinpath(self._user_dir(user),
- '{}{}{}[{}]{x}.regtest.addrs'.format(
- sid, self.altcoin_pfx, id_strs[desc], addr_range,
- x='-α' if cfg.debug_utf8 else ''))
- if mmtype == self.proto.mmtypes[0] and user == 'bob':
- self._add_comments_to_addr_file(addrfile, addrfile, use_comments=True)
- t = self.spawn(
- 'mmgen-addrimport',
- args = (
- (['--quiet'] if quiet else []) +
- ['--'+user] +
- (['--batch'] if batch else []) +
- [addrfile]),
- extra_desc = f'({desc})')
- if cfg.debug:
- t.expect("Type uppercase 'YES' to confirm: ", 'YES\n')
- t.expect('Importing')
- if batch:
- t.expect(f'{num_addrs} addresses imported')
- else:
- t.expect('import completed OK')
- t.ok()
- t.skip_ok = True
- return t
- def addrimport_bob(self):
- return self.addrimport('bob')
- def addrimport_alice(self):
- return self.addrimport('alice', batch=False, quiet=False)
- async def bob_import_miner_addr(self):
- if not self.deterministic:
- return 'skip'
- return self.spawn(
- 'mmgen-addrimport',
- ['--bob', '--rescan', '--quiet', f'--address={await self.rt.miner_addr}'])
- async def fund_wallet_deterministic(self, addr, utxo_nums, skip_passphrase=False):
- """
- the deterministic funding method using specific inputs
- """
- if not self.deterministic:
- return 'skip'
- self.write_to_tmpfile('miner.key', f'{await self.rt.miner_wif}\n')
- keyfile = joinpath(self.tmpdir, 'miner.key')
- return self.user_txdo(
- 'bob', '40s',
- [f'{addr}, {rtFundAmt}', self.burn_addr],
- utxo_nums,
- extra_args = [f'--keys-from-file={keyfile}'],
- skip_passphrase = skip_passphrase)
- def fund_bob_deterministic(self):
- return self.fund_wallet_deterministic(f'{self._user_sid("bob")}:C:1', '1-11')
- def fund_alice_deterministic(self):
- sid = self._user_sid('alice')
- mmtype = ('L', 'S')[self.proto.cap('segwit')]
- addr = self.get_addr_from_addrlist('alice', sid, mmtype, 0, addr_range='1-5')
- return self.fund_wallet_deterministic(addr, '1-11', skip_passphrase=True)
- def generate_extra_deterministic(self):
- if not self.deterministic:
- return 'skip'
- return self.generate(num_blocks=2) # do this so block count matches non-deterministic run
- async def bob_recreate_tracking_wallet(self):
- if not self.deterministic:
- return 'skip'
- self.spawn('', msg_only=True)
- await self.rt.stop()
- from shutil import rmtree
- imsg('Deleting Bob’s old tracking wallet')
- rmtree(os.path.join(self.rt.d.datadir, 'regtest', 'wallets', 'bob'), ignore_errors=True)
- self.rt.init_daemon()
- self.rt.d.start(silent=True)
- imsg('Creating Bob’s new tracking wallet')
- await self.rt.create_wallet('bob')
- await self.rt.stop()
- await self.rt.start()
- return 'ok'
- def addrimport_bob2(self):
- if not self.deterministic:
- return 'skip'
- return self.addrimport('bob')
- def fund_wallet(self, user, mmtype, amt, sid=None, addr_range='1-5'):
- if self.deterministic:
- return 'skip'
- if not sid:
- sid = self._user_sid(user)
- addr = self.get_addr_from_addrlist(user, sid, mmtype, 0, addr_range=addr_range)
- t = self.spawn('mmgen-regtest', ['send', str(addr), str(amt)])
- t.expect(f'Sending {amt} miner {self.proto.coin}')
- t.expect('Mined 1 block')
- return t
- def fund_bob(self):
- return self.fund_wallet('bob', 'C', rtFundAmt)
- def fund_alice(self):
- return self.fund_wallet('alice', ('L', 'S')[self.proto.cap('segwit')], rtFundAmt)
- def user_twview(
- self,
- user,
- chk = None,
- expect = None,
- cmd = 'twview',
- opts = [],
- sort = 'age',
- exit_val = None):
- t = self.spawn('mmgen-tool', [f'--{user}'] + opts + [cmd] + [f'sort={sort}'], exit_val=exit_val)
- if chk:
- t.expect(r'{}\b.*\D{}\b'.format(*chk), regex=True)
- if expect:
- t.expect(expect, regex=True)
- return t
- def bob_twview_noaddrs(self):
- return self.user_twview('bob', expect='No spendable', exit_val=1)
- def bob_listaddrs_noaddrs(self):
- return self.user_twview('bob', cmd='listaddresses', expect='No addresses', exit_val=1)
- def bob_twview_nobal(self):
- return self.user_twview('bob', expect='No spendable', exit_val=1)
- def bob_listaddrs_nobal(self):
- return self.user_twview('bob', cmd='listaddresses', expect='TOTAL:')
- def bob_twview1(self):
- return self.user_twview('bob', chk=('1', rtAmts[0]))
- def user_bal(self, user, bal, opts=[], args=['showempty=1'], skip_check=False):
- t = self.spawn('mmgen-tool', opts + [f'--{user}', 'listaddresses'] + args)
- if not skip_check:
- cmp_or_die(f'{bal} {self.proto.coin}', strip_ansi_escapes(t.expect_getend('TOTAL: ')))
- return t
- def alice_bal1(self):
- return self.user_bal('alice', rtFundAmt)
- def alice_bal2(self):
- return self.user_bal('alice', rtBals[8])
- def bob_bal1(self):
- return self.user_bal('bob', rtFundAmt, self._cashaddr_opt(0))
- def bob_bal2(self):
- return self.user_bal('bob', rtBals[0], self._cashaddr_opt(1))
- def bob_bal2a(self):
- return self.user_bal('bob', rtBals[0], args=['showempty=1', 'age_fmt=confs'])
- def bob_bal2b(self):
- return self.user_bal('bob', rtBals[0], args=['showempty=1'])
- def bob_bal2c(self):
- return self.user_bal('bob', rtBals[0], args=['showempty=1', 'minconf=2', 'age_fmt=days'], skip_check=True)
- def bob_bal2d(self):
- return self.user_bal('bob', rtBals[0], args=['minconf=2'], skip_check=True)
- def bob_bal2e(self):
- return self.user_bal('bob', rtBals[0], args=['showempty=1', 'sort=amt'])
- def bob_bal2f(self):
- return self.user_bal('bob', rtBals[0], args=['showempty=0', 'sort=twmmid', 'reverse=1'])
- def bob_bal3(self):
- return self.user_bal('bob', rtBals[1])
- def bob_bal4(self):
- return self.user_bal('bob', rtBals[2])
- def bob_bal5(self):
- return self.user_bal('bob', rtBals[3])
- def bob_bal6(self):
- return self.user_bal('bob', rtBals[7])
- def bob_subwallet_addrgen1(self):
- return self.addrgen('bob', subseed_idx='29L', mmtypes=['C']) # 29L: 2FA7BBA8
- def bob_subwallet_addrgen2(self):
- return self.addrgen('bob', subseed_idx='127S', mmtypes=['C']) # 127S: '09E8E286'
- def subwallet_addrimport(self, user, subseed_idx):
- sid = self._get_user_subsid(user, subseed_idx)
- return self.addrimport(user, sid=sid, mmtypes=['C'])
- def bob_subwallet_addrimport1(self):
- return self.subwallet_addrimport('bob', '29L')
- def bob_subwallet_addrimport2(self):
- return self.subwallet_addrimport('bob', '127S')
- def bob_subwallet_fund(self):
- sid1 = self._get_user_subsid('bob', '29L')
- sid2 = self._get_user_subsid('bob', '127S')
- chg_addr = self._user_sid('bob') + (':B:1', ':L:1')[self.proto.coin=='BCH']
- return self.user_txdo(
- user = 'bob',
- fee = rtFee[1],
- outputs_cl = [sid1+':C:2,0.29', sid2+':C:3,0.127', chg_addr],
- outputs_list = ('3', '1')[self.proto.coin=='BCH'],
- extra_args = ['--subseeds=127'],
- used_chg_addr_resp = (None, 'y')[self.proto.coin=='BCH'])
- def bob_twview2(self):
- sid1 = self._get_user_subsid('bob', '29L')
- return self.user_twview(
- 'bob',
- opts = self._cashaddr_opt(0),
- chk = (f'{sid1}:C:2', '0.29'),
- sort = 'twmmid',
- expect = rf'[{b58a}]{{8}}' if self.proto.coin == 'BCH' else None)
- def bob_twview3(self):
- sid2 = self._get_user_subsid('bob', '127S')
- return self.user_twview(
- 'bob',
- opts = self._cashaddr_opt(1),
- chk = (f'{sid2}:C:3', '0.127'),
- sort = 'amt',
- expect = rf'[{b32a}]{{8}}' if self.proto.coin == 'BCH' else None)
- def bob_subwallet_txcreate(self):
- sid1 = self._get_user_subsid('bob', '29L')
- sid2 = self._get_user_subsid('bob', '127S')
- outputs_cl = [sid1+':C:5,0.0159', sid2+':C:5']
- t = self.spawn('mmgen-txcreate', ['-d', self.tmpdir, '-B', '--bob'] + outputs_cl)
- return self.txcreate_ui_common(t,
- menu = ['a'],
- inputs = ('1,2', '2,3')[self.proto.coin=='BCH'],
- interactive_fee = '0.00001')
- def bob_subwallet_txsign(self):
- fn = get_file_with_ext(self.tmpdir, 'rawtx')
- t = self.spawn('mmgen-txsign', ['-d', self.tmpdir, '--bob', '--subseeds=127', fn])
- t.view_tx('t')
- t.passphrase(dfl_wcls.desc, rt_pw)
- t.do_comment(None)
- t.expect('(Y/n): ', 'y')
- t.written_to_file('Signed transaction')
- return t
- def bob_subwallet_txdo(self):
- outputs_cl = [self._user_sid('bob')+':L:5']
- inputs = ('1,2', '2,3')[self.proto.coin=='BCH']
- return self.user_txdo(
- 'bob',
- rtFee[5],
- outputs_cl,
- inputs,
- menu = ['a'],
- extra_args = ['--subseeds=127']) # sort: amt
- def bob_twview4(self):
- sid = self._user_sid('bob')
- return self.user_twview('bob', chk=(sid+':L:5', rtBals[9]), sort='twmmid')
- def user_txhist(self, user, args, expect, opts=[], expect2=None):
- t = self.spawn('mmgen-tool', opts + [f'--{user}', 'txhist'] + args)
- text = t.read(strip_color=True)
- for s in (expect, expect2):
- if s:
- m = re.search(s, text, re.DOTALL)
- assert m, f'Expected: {s}'
- return t
- def bob_txhist1(self):
- return self.user_txhist('bob',
- opts = self._cashaddr_opt(1),
- args = ['sort=age'],
- expect = fr'\s1\).*\s{rtFundAmt}\s',
- expect2 = rf'[{b32a}]{{8}}' if self.proto.coin == 'BCH' else None)
- def bob_txhist2(self):
- return self.user_txhist('bob',
- opts = self._cashaddr_opt(0),
- args = ['sort=blockheight', 'reverse=1', 'age_fmt=block'],
- expect = fr'\s1\).*:{self.dfl_mmtype}:1\s',
- expect2 = rf'[{b58a}]{{8}}' if self.proto.coin == 'BCH' else None)
- def bob_txhist3(self):
- return self.user_txhist('bob',
- args = ['sort=blockheight', 'sinceblock=-7', 'age_fmt=block'],
- expect = fr'Displaying transactions since block 399.*\s6\)\s+405\s.*\s{rtBals[9]}\s.*:L:5.*\s7\)'
- )
- def bob_txhist4(self):
- return self.user_txhist('bob',
- args = ['sort=blockheight', 'age_fmt=block', 'detail=1'],
- expect = fr'Block:.*406.*Value:.*{rtBals[10]}'
- )
- def bob_txhist5(self):
- return self.user_txhist('bob',
- args = ['sort=blockheight', 'sinceblock=399', 'age_fmt=block', 'detail=1'],
- expect = fr'Displaying transactions since block 399.*\s7\).*Block:.*406.*Value:.*{rtBals[10]}'
- )
- def bob_txhist_interactive(self):
- self.get_file_with_ext('out', delete_all=True)
- t = self.spawn('mmgen-tool',
- ['--bob', f'--outdir={self.tmpdir}', 'txhist', 'age_fmt=date_time', 'interactive=true'])
- if self.proto.coin == 'BCH':
- for expect, resp in (
- (rf'[{b32a}]{{8}}', 'h'),
- (rf'[{b58a}]{{8}}', 'h')
- ):
- t.expect(expect, regex=True)
- t.expect('draw:\b', resp, regex=True)
- for resp in ('u', 'i', 't', 'a', 'm', 'T', 'A', 'r', 'r', 'D', 'D', 'D', 'D', 'p', 'P', 'n', 'V'):
- t.expect('draw:\b', resp, regex=True)
- if t.pexpect_spawn:
- t.expect(r'Block:.*394', regex=True)
- time.sleep(1)
- t.send('q')
- time.sleep(0.2)
- t.send('n')
- t.expect('draw:\b', 'q', regex=True)
- else:
- txnum, idx = (8, 1) if self.proto.coin == 'BCH' else (9, 3)
- t.expect(rf'\s{txnum}\).*Inputs:.*:L:{idx}.*Outputs \(3\):.*:C:2.*\s10\)', 'q', regex=True)
- return t
- def bob_getbalance(self, bals, confs=1):
- for i in range(len(bals['mmgen'])):
- assert Decimal(bals['mmgen'][i]) + Decimal(bals['nonmm'][i]) == Decimal(bals['total'][i])
- sid = self._user_sid('bob')
- t = self.spawn('mmgen-tool', ['--bob', 'getbalance', f'minconf={confs}'])
- t.expect('Wallet')
- for k, lbl in (
- ('mmgen', f'{sid}:'),
- ('nonmm', 'Non-MMGen:'),
- ('total', f'TOTAL {self.proto.coin}')
- ):
- ret = strip_ansi_escapes(t.expect_getend(lbl + ' '))
- cmp_or_die(
- ' '.join(bals[k]),
- ' '.join(ret.split()),
- desc = k,
- )
- return t
- def bob_0conf0_getbalance(self):
- return self.bob_getbalance(rtBals_gb['0conf0'], confs=0)
- def bob_0conf1_getbalance(self):
- return self.bob_getbalance(rtBals_gb['0conf1'], confs=1)
- def bob_1conf1_getbalance(self):
- return self.bob_getbalance(rtBals_gb['1conf1'], confs=1)
- def bob_1conf2_getbalance(self):
- return self.bob_getbalance(rtBals_gb['1conf2'], confs=2)
- def bob_nochg_burn(self):
- return self.user_txdo('bob',
- fee = '0.00009713',
- outputs_cl = [self.burn_addr],
- outputs_list = '1')
- def bob_alice_bal(self):
- t = self.spawn('mmgen-regtest', ['balances'])
- ret = t.expect_getend("Bob's balance:").strip()
- cmp_or_die(rtBals[4], ret)
- ret = t.expect_getend("Alice's balance:").strip()
- cmp_or_die(rtBals[5], ret)
- ret = t.expect_getend('Total balance:').strip()
- cmp_or_die(rtBals[6], ret)
- return t
- def user_txsend_status(
- self,
- user,
- tx_file,
- exp1 = '',
- exp2 = '',
- extra_args = [],
- exit_val = None):
- t = self.spawn(
- 'mmgen-txsend',
- ['-d', self.tmpdir, '--'+user, '--status'] + extra_args + [tx_file],
- exit_val = exit_val)
- if exp1:
- t.expect(exp1, regex=True)
- if exp2:
- t.expect(exp2, regex=True)
- if self.deterministic:
- imsg(
- 'DETERMINISTIC TESTING NOTE:\n '
- 'output of mmgen-txsend --status cannot be made deterministic, as it uses '
- 'gettransaction’s ‘timereceived’ field')
- return t
- def user_txdo(
- self,
- user,
- fee,
- outputs_cl,
- outputs_list,
- extra_args = [],
- wf = None,
- add_comment = tx_comment_jp,
- return_early = False,
- return_after_send = False,
- menu = ['M'],
- skip_passphrase = False,
- used_chg_addr_resp = None,
- exit_val = None):
- t = self.spawn(
- 'mmgen-txdo',
- ['-d', self.tmpdir, '-B', '--'+user]
- + (['--fee='+fee] if fee else [])
- + extra_args
- + ([], [wf])[bool(wf)]
- + outputs_cl,
- exit_val = exit_val)
- self.txcreate_ui_common(
- t,
- caller = 'txdo',
- menu = menu,
- inputs = outputs_list,
- file_desc = 'Signed transaction',
- interactive_fee = (tx_fee, '')[bool(fee)],
- add_comment = add_comment,
- return_early = return_early,
- view = 't',
- save = True,
- used_chg_addr_resp = used_chg_addr_resp)
- if return_early:
- return t
- if not skip_passphrase:
- t.passphrase(dfl_wcls.desc, rt_pw)
- t.written_to_file('Signed transaction')
- self._do_confirm_send(t)
- if return_after_send:
- return t
- t.expect('Transaction sent')
- return t
- def bob_split1(self):
- sid = self._user_sid('bob')
- outputs_cl = [sid+':C:1,100', sid+':L:2,200', sid+':'+rtBobOp3]
- return self.user_txdo('bob', rtFee[0], outputs_cl, '1', extra_args=['--locktime=500000001'])
- def get_addr_from_addrlist(self, user, sid, mmtype, idx, addr_range='1-5'):
- id_str = {'L':'', 'S':'-S', 'C':'-C', 'B':'-B'}[mmtype]
- ext = '{}{}{}[{}]{x}.regtest.addrs'.format(
- sid, self.altcoin_pfx, id_str, addr_range, x='-α' if cfg.debug_utf8 else '')
- addrfile = get_file_with_ext(self._user_dir(user), ext, no_dot=True)
- silence()
- addr = AddrList(cfg, self.proto, addrfile).data[idx].addr
- end_silence()
- return addr
- def _create_tx_outputs(self, user, data):
- sid = self._user_sid(user)
- return [self.get_addr_from_addrlist(user, sid, mmtype, idx-1)+amt_str for mmtype, idx, amt_str in data]
- def bob_rbf_1output_create(self):
- if not self.test_rbf:
- return 'skip'
- out_addr = self._create_tx_outputs('alice', (('B', 5, ''),))
- t = self.spawn('mmgen-txcreate', ['-d', self.tr.trash_dir, '-B', '--bob'] + out_addr)
- return self.txcreate_ui_common(t, menu=[], inputs='3', interactive_fee='3s') # out amt: 199.99999343
- def bob_rbf_1output_bump(self):
- if not self.test_rbf:
- return 'skip'
- ext = '9343,3]{x}.regtest.rawtx'.format(x='-α' if cfg.debug_utf8 else '')
- txfile = get_file_with_ext(self.tr.trash_dir, ext, delete=False, no_dot=True)
- return self.user_txbump('bob',
- self.tr.trash_dir,
- txfile,
- '8s',
- has_label = False,
- signed_tx = False,
- one_output = True)
- def bob_send_maybe_rbf(self):
- outputs_cl = self._create_tx_outputs('alice', (('L', 1, ', 60'), ('C', 1, ', 40')))
- outputs_cl += [self._user_sid('bob')+':'+rtBobOp3]
- return self.user_txdo(
- user = 'bob',
- fee = rtFee[1],
- outputs_cl = outputs_cl, # alice_sid:L:1,60, alice_sid:C:1,40
- outputs_list = '3',
- extra_args = [] if self.proto.cap('rbf') else ['--no-rbf'],
- used_chg_addr_resp = 'y')
- def bob_send_non_mmgen(self):
- keyfile = joinpath(self.tmpdir, 'non-mmgen.keys')
- atype = 'S' if self.proto.cap('segwit') else 'L'
- outputs_cl = self._create_tx_outputs('alice', ((atype, 2, ', 10'), (atype, 3, '')))
- return self.user_txdo(
- user = 'bob',
- fee = rtFee[3],
- outputs_cl = outputs_cl, # alice_sid:S:2,10, alice_sid:S:3
- outputs_list = '1,4-10',
- extra_args = [f'--keys-from-file={keyfile}', '--vsize-adj=1.02'])
- def alice_send_estimatefee(self):
- outputs_cl = self._create_tx_outputs('bob', (('L', 1, ''),)) # bob_sid:L:1
- return self.user_txdo('alice', None, outputs_cl, '1', extra_args=['--verbose']) # fee=None
- def user_txbump(
- self,
- user,
- outdir,
- txfile,
- fee,
- add_args = [],
- has_label = True,
- signed_tx = True,
- one_output = False):
- if not self.proto.cap('rbf'):
- return 'skip'
- t = self.spawn('mmgen-txbump',
- ['-d', outdir, '--'+user, '--fee='+fee, '--output-to-reduce=c'] + add_args + [txfile])
- if not one_output:
- t.expect('OK? (Y/n): ', 'y') # output OK?
- t.expect('OK? (Y/n): ', 'y') # fee OK?
- t.do_comment(False, has_label=has_label)
- if signed_tx:
- t.passphrase(dfl_wcls.desc, rt_pw)
- t.written_to_file('Signed transaction')
- self.txsend_ui_common(t, caller='txdo', bogus_send=False, file_desc='Signed transaction')
- else:
- t.expect('Save fee-bumped transaction? (y/N): ', 'y')
- t.written_to_file('Fee-bumped transaction')
- return t
- def bob_rbf_bump(self):
- ext = ',{}]{x}.regtest.sigtx'.format(rtFee[1][:-1], x='-α' if cfg.debug_utf8 else '')
- txfile = self.get_file_with_ext(ext, delete=False, no_dot=True)
- return self.user_txbump('bob', self.tmpdir, txfile, rtFee[2], add_args=['--send'])
- def generate(self, num_blocks=1):
- int(num_blocks)
- t = self.spawn('mmgen-regtest', ['generate', str(num_blocks)])
- t.expect(f'Mined {num_blocks} block')
- return t
- def _get_mempool(self):
- ret = self.spawn(
- 'mmgen-regtest',
- ['mempool'],
- env = os.environ if cfg.debug_utf8 else get_env_without_debug_vars(),
- ).read()
- m = re.search(r'(\[\s*"[a-f0-9]{64}"\s*])', ret) # allow for extra output by handler at end
- return json.loads(m.group(1))
- def get_mempool1(self):
- mp = self._get_mempool()
- if len(mp) != 1:
- die(4, 'Mempool has more or less than one TX!')
- self.write_to_tmpfile('rbf_txid', mp[0]+'\n')
- return 'ok'
- def bob_rbf_status(self, fee, exp1, exp2='', exit_val=None):
- if not self.proto.cap('rbf'):
- return 'skip'
- ext = ',{}]{x}.regtest.sigtx'.format(fee[:-1], x='-α' if cfg.debug_utf8 else '')
- txfile = self.get_file_with_ext(ext, delete=False, no_dot=True)
- return self.user_txsend_status('bob', txfile, exp1, exp2, exit_val=exit_val)
- def bob_rbf_status1(self):
- if not self.proto.cap('rbf'):
- return 'skip'
- return self.bob_rbf_status(rtFee[1], 'in mempool, replaceable')
- def get_mempool2(self):
- if not self.proto.cap('rbf'):
- return 'skip'
- mp = self._get_mempool()
- if len(mp) != 1:
- die(4, 'Mempool has more or less than one TX!')
- chk = self.read_from_tmpfile('rbf_txid')
- if chk.strip() == mp[0]:
- die(4, 'TX in mempool has not changed! RBF bump failed')
- self.write_to_tmpfile('rbf_txid2', mp[0]+'\n')
- return 'ok'
- def bob_rbf_status2(self):
- if not self.proto.cap('rbf'):
- return 'skip'
- new_txid = self.read_from_tmpfile('rbf_txid2').strip()
- return self.bob_rbf_status(
- rtFee[1],
- 'Transaction has been replaced',
- f'{new_txid} in mempool',
- exit_val = 0)
- def bob_rbf_status3(self):
- if not self.proto.cap('rbf'):
- return 'skip'
- return self.bob_rbf_status(rtFee[2], 'status: in mempool, replaceable')
- def bob_rbf_status4(self):
- if not self.proto.cap('rbf'):
- return 'skip'
- new_txid = self.read_from_tmpfile('rbf_txid2').strip()
- return self.bob_rbf_status(rtFee[1],
- 'Replacement transaction has 1 confirmation',
- rf'Replacing transactions:\s+{new_txid}')
- def bob_rbf_status5(self):
- if not self.proto.cap('rbf'):
- return 'skip'
- return self.bob_rbf_status(rtFee[2], 'Transaction has 1 confirmation')
- def bob_rbf_status6(self):
- if not self.proto.cap('rbf'):
- return 'skip'
- new_txid = self.read_from_tmpfile('rbf_txid2').strip()
- return self.bob_rbf_status(rtFee[1],
- 'Replacement transaction has 2 confirmations',
- rf'Replacing transactions:\s+{new_txid}')
- def _gen_pairs(self, n):
- from mmgen.tool.api import tool_api
- t = tool_api(cfg)
- t.init_coin(self.proto.coin, self.proto.network)
- def gen_addr(Type):
- t.addrtype = Type
- wif = t.hex2wif(getrandhex(32))
- return (wif, t.wif2addr(wif))
- return [gen_addr('legacy')] + [gen_addr('compressed') for i in range(n-1)]
- def bob_pre_import(self):
- pairs = self._gen_pairs(5)
- self.write_to_tmpfile('non-mmgen.keys', '\n'.join([a[0] for a in pairs])+'\n')
- self.write_to_tmpfile('non-mmgen.addrs', '\n'.join([a[1] for a in pairs])+'\n')
- return self.user_txdo('bob', rtFee[4], [pairs[0][1]], '3')
- def user_import(self, user, args, nAddr):
- t = self.spawn('mmgen-addrimport', ['--'+user] + args)
- if cfg.debug:
- t.expect("Type uppercase 'YES' to confirm: ", 'YES\n')
- t.expect(f'Importing {nAddr} address')
- if '--rescan' in args:
- if not '--quiet' in args:
- t.expect('Continue? (Y/n): ', 'y')
- t.expect('Rescanning block')
- return t
- def bob_import_addr(self):
- addr = self.read_from_tmpfile('non-mmgen.addrs').split()[0]
- return self.user_import('bob', ['--quiet', '--address='+addr], nAddr=1)
- def bob_import_list_rescan_aio(self):
- addrfile = joinpath(self.tmpdir, 'non-mmgen.addrs')
- return self.user_import('bob', ['--rescan', '--rpc-backend=aio', '--addrlist', addrfile], nAddr=5)
- def bob_resolve_addr(self):
- mmaddr = '{}:C:1'.format(self._user_sid('bob'))
- t = self.spawn('mmgen-tool', ['--bob', 'resolve_address', mmaddr])
- coinaddr = re.search(r'[0-9A-Za-z]{30,}', t.read())[0]
- t = self.spawn('mmgen-tool', ['--bob', 'resolve_address', coinaddr], no_msg=True)
- mmaddr_res = re.search(r'[0-9A-F]{8}:C:1', t.read())[0]
- assert mmaddr == mmaddr_res, f'{mmaddr} != {mmaddr_res}'
- return t
- def bob_import_list(self):
- addrfile = joinpath(self.tmpdir, 'non-mmgen.addrs')
- return self.user_import('bob', ['--quiet', '--addrlist', addrfile], nAddr=5)
- def bob_import_list_rescan(self):
- addrfile = joinpath(self.tmpdir, 'non-mmgen.addrs')
- return self.user_import('bob', ['--quiet', '--rescan', '--addrlist', addrfile], nAddr=5)
- def bob_rescan_addr(self):
- sid = self._user_sid('bob')
- t = self.spawn('mmgen-tool', ['--bob', 'rescan_address', f'{sid}:C:1'])
- t.expect('Found 1 unspent output')
- t.expect('updated successfully')
- return t
- def _usr_rescan_blockchain(self, user, add_args, expect=None):
- t = self.spawn('mmgen-tool', [f'--{user}', 'rescan_blockchain'] + add_args)
- if expect:
- t.expect(f'Scanning blocks {expect}')
- t.expect('Done')
- return t
- def bob_rescan_blockchain_all(self):
- return self._usr_rescan_blockchain('bob', [], '300-396')
- def bob_rescan_blockchain_gb(self):
- return self._usr_rescan_blockchain('bob', ['start_block=0', 'stop_block=0'], '0-0')
- def bob_rescan_blockchain_one(self):
- return self._usr_rescan_blockchain('bob', ['start_block=300', 'stop_block=300'], '300-300')
- def bob_rescan_blockchain_ss(self):
- return self._usr_rescan_blockchain('bob', ['start_block=300', 'stop_block=302'], '300-302')
- def bob_twexport(self, add_args=[]):
- t = self.spawn('mmgen-tool', ['--bob', f'--outdir={self.tmpdir}', 'twexport'] + add_args)
- t.written_to_file('JSON data')
- return t
- def bob_twexport_noamt(self):
- return self.bob_twexport(add_args=['include_amts=0'])
- def bob_twexport_pretty(self):
- return self.bob_twexport(add_args=['pretty=1'])
- def _bob_twprune(
- self,
- prune_spec,
- npruned,
- expect_menu = (),
- expect = (),
- expect2 = (),
- warn_used = False,
- non_segwit_ok = False):
- if not (non_segwit_ok or self.proto.cap('segwit')):
- return 'skip'
- t = self.spawn(
- 'mmgen-tool',
- ['--bob', f'--outdir={self.tr.trash_dir}', 'twexport', 'prune=1']
- + (['warn_used=1'] if warn_used else []))
- for s in expect_menu:
- t.expect('prune list:\b', s)
- t.expect('prune list:\b', 'p')
- t.expect('addresses to prune: ', f'{prune_spec}\n')
- for p, s in expect:
- t.expect(p, s, regex=True)
- t.expect('prune list:\b', 'q')
- for p, s in expect2:
- t.expect(p, s, regex=True)
- if npruned:
- t.expect(f'Pruned {npruned} addresses')
- taddr = 35 if self.proto.cap('segwit') else 25
- t.expect(f'Exporting {taddr-npruned} addresses')
- t.written_to_file('JSON data')
- return t
- def bob_twprune_noask(self):
- return self._bob_twprune(
- expect_menu = 'a', # sort by amt to make address order deterministic
- prune_spec = '35,12,18,3-5',
- npruned = 6)
- def bob_twprune_all(self):
- taddr = 35 if self.proto.cap('segwit') else 25
- return self._bob_twprune(
- prune_spec = f'1-{taddr}',
- npruned = taddr,
- expect = [('all with balance: ', 'P')],
- non_segwit_ok = True)
- def bob_twprune_skip(self):
- return self._bob_twprune(
- prune_spec = '',
- npruned = 0,
- non_segwit_ok = True)
- def bob_twprune_skipamt(self):
- return self._bob_twprune(
- prune_spec = '1-35',
- npruned = 32,
- expect = [('all with balance: ', 'S')])
- def bob_twprune_skipused(self):
- return self._bob_twprune(
- prune_spec = '1-35',
- npruned = 18,
- expect = [('all used: ', 'S')],
- warn_used = True)
- def bob_twprune_allamt(self):
- return self._bob_twprune(
- prune_spec = '1-35',
- npruned = 35,
- expect = [('all with balance: ', 'P')],
- expect2 = [('Warning: pruned address .* has a balance', None)])
- def bob_twprune_allused(self):
- return self._bob_twprune(
- prune_spec = '1-35',
- npruned = 32,
- expect = [('all used: ', 'P'), ('all with balance: ', 'S')],
- expect2 = [('Warning: pruned address .* used', None)],
- warn_used = True)
- @property
- def _b_start(self):
- """
- SIDs sort non-deterministically, so we must search for start of main (not subseeds) group, i.e. ':B:1'
- """
- assert self.proto.cap('segwit')
- if not hasattr(self, '_b_start_'):
- t = self.spawn('mmgen-tool', ['--color=0', '--bob', 'listaddresses'], no_msg=True)
- self._b_start_ = int([e for e in t.read().split('\n') if ':B:1' in e][0].split()[0].rstrip(')'))
- t.close()
- return self._b_start_
- def _bob_twprune_selected(self, resp, npruned):
- if not self.proto.cap('segwit'):
- return 'skip'
- B = self._b_start
- a, b, c, d, e, f = resp
- return self._bob_twprune(
- expect_menu = 'a', # sort by amt to make address order deterministic
- prune_spec = f'31-32,{B+14},{B+9},{B}-{B+4}',
- npruned = npruned,
- expect = [
- ('all used: ', a),
- ('all used: ', b),
- ('all with balance: ', c),
- ('all with balance: ', d),
- ('all used: ', e),
- ('all used: ', f),
- ],
- warn_used = True)
- def bob_twprune1(self):
- return self._bob_twprune_selected(resp='sssssS', npruned=3)
- def bob_twprune2(self):
- return self._bob_twprune_selected(resp='sppPsS', npruned=3)
- def bob_twprune3(self):
- return self._bob_twprune_selected(resp='sssPpS', npruned=3)
- def bob_twprune4(self):
- return self._bob_twprune_selected(resp='sssPpP', npruned=9)
- def bob_twprune5(self):
- return self._bob_twprune_selected(resp='pppPpP', npruned=9)
- def bob_twprune6(self):
- return self._bob_twprune_selected(resp='sssSpP', npruned=7)
- def bob_edit_json_twdump(self):
- self.spawn('', msg_only=True)
- from mmgen.tw.json import TwJSON
- fn = TwJSON.Base(cfg, self.proto).dump_fn
- text = json.loads(self.read_from_tmpfile(fn))
- text['data']['entries'][3][3] = f'edited comment [фубар] [{gr_uc}]'
- self.write_to_tmpfile(fn, json.dumps(text, indent=4))
- return 'ok'
- def carol_twimport(
- self,
- rpc_backend = 'http',
- add_parms = [],
- expect_str = None,
- expect_str2 = 'Found 1 unspent output'):
- from mmgen.tw.json import TwJSON
- fn = joinpath(self.tmpdir, TwJSON.Base(cfg, self.proto).dump_fn)
- t = self.spawn(
- 'mmgen-tool',
- ([f'--rpc-backend={rpc_backend}'] if rpc_backend else [])
- + ['--carol', 'twimport', fn]
- + add_parms)
- t.expect('(y/N): ', 'y')
- if expect_str:
- t.expect(expect_str)
- elif 'batch=true' in add_parms:
- t.expect('{} addresses imported'.format(10 if self.proto.coin == 'BCH' else 20))
- else:
- t.expect('import completed OK')
- t.expect(expect_str2)
- return t
- def carol_twimport_nochksum(self):
- return self.carol_twimport(rpc_backend=None, add_parms=['ignore_checksum=true'])
- def carol_twimport_batch(self):
- return self.carol_twimport(add_parms=['batch=true'])
- def carol_twimport_pretty(self):
- return self.carol_twimport(add_parms=['ignore_checksum=true'], expect_str='ignoring incorrect checksum')
- def carol_listaddresses(self):
- return self.spawn('mmgen-tool', ['--carol', 'listaddresses', 'showempty=1'])
- async def carol_delete_wallet(self):
- imsg('Unloading Carol’s tracking wallet')
- if self.proto.coin == 'BCH':
- time.sleep(0.2)
- t = self.spawn('mmgen-regtest', ['cli', 'unloadwallet', 'carol'])
- t.ok()
- wdir = joinpath((await self.rt.rpc).daemon.network_datadir, 'wallets', 'carol')
- from shutil import rmtree
- imsg('Deleting Carol’s tracking wallet')
- rmtree(wdir)
- return 'silent'
- def bob_split2(self):
- addrs = self.read_from_tmpfile('non-mmgen.addrs').split()
- amts = (1.12345678, 2.87654321, 3.33443344, 4.00990099, 5.43214321)
- outputs1 = list(map('{},{}'.format, addrs, amts))
- sid = self._user_sid('bob')
- l1, l2 = (
- (':S', ':B') if 'B' in self.proto.mmtypes else
- (':S', ':S') if self.proto.cap('segwit') else
- (':L', ':L'))
- outputs2 = [sid+':C:2,6.333', sid+':L:3,6.667', sid+l1+':4,0.123', sid+l2+':5']
- return self.user_txdo('bob', rtFee[5], outputs1+outputs2, '1-2')
- def user_add_comment(self, user, addr, comment):
- t = self.spawn('mmgen-tool', ['--'+user, 'add_label', addr, comment])
- t.expect('Added label.*in tracking wallet', regex=True)
- return t
- def user_remove_comment(self, user, addr):
- t = self.spawn('mmgen-tool', ['--'+user, 'remove_label', addr])
- t.expect('Removed label.*in tracking wallet', regex=True)
- return t
- def bob_bad_locktime1(self):
- return self._bob_bad_locktime(123456789, 'non-final', 2) # > current block height
- def bob_bad_locktime2(self):
- return self._bob_bad_locktime(7_000_000_000, 'invalid', 2, return_early=True) # > 4 bytes
- def bob_bad_locktime3(self):
- return self._bob_bad_locktime(0xffffffff, 'non-final', 2, return_early=False) # > cur time
- def _bob_bad_locktime(self, locktime, expect, exit_val, return_early=False):
- sid = self._user_sid('bob')
- t = self.user_txdo(
- user = 'bob',
- fee = '20s',
- outputs_cl = [self.burn_addr+', 0.1', sid+':C:5'],
- outputs_list = '1',
- extra_args = [f'--locktime={locktime}'],
- return_early = return_early,
- add_comment = False,
- return_after_send = True,
- exit_val = exit_val)
- if expect:
- t.expect(expect)
- return t
- def bob_add_comment1(self):
- sid = self._user_sid('bob')
- return self.user_add_comment('bob', sid+':C:1', tw_comment_lat_cyr_gr)
- def alice_add_comment1(self):
- sid = self._user_sid('alice')
- return self.user_add_comment('alice', sid+':C:1', 'Original Label - 月へ')
- def alice_add_comment2(self):
- sid = self._user_sid('alice')
- return self.user_add_comment('alice', sid+':C:1', 'Replacement Label')
- def _user_chk_comment(self, user, addr, comment, extra_args=[]):
- t = self.spawn('mmgen-tool', ['--'+user, 'listaddresses', 'all_labels=1']+extra_args)
- ret = strip_ansi_escapes(t.expect_getend(addr)).strip().split(None, 2)[2]
- cmp_or_die( # squeezed display, double-width chars, so truncate to min field width
- ret[:3].strip(),
- comment[:3].strip())
- return t
- def alice_add_comment_coinaddr(self):
- mmid = self._user_sid('alice') + (':S:1', ':L:1')[self.proto.coin=='BCH']
- t = self.spawn('mmgen-tool', ['--alice', 'listaddress', mmid, 'wide=true'], no_msg=True)
- addr = [i for i in strip_ansi_escapes(t.read()).splitlines() if re.search(rf'\b{mmid}\b', i)][0].split()[3]
- return self.user_add_comment('alice', addr, 'Label added using coin address of MMGen address')
- def alice_chk_comment_coinaddr(self):
- mmid = self._user_sid('alice') + (':S:1', ':L:1')[self.proto.coin=='BCH']
- return self._user_chk_comment('alice', mmid, 'Label added using coin address of MMGen address')
- def alice_add_comment_badaddr(self, addr, reply, exit_val):
- if os.getenv('PYTHONOPTIMIZE'):
- omsg(yellow(f'PYTHONOPTIMIZE set, skipping test {self.test_name!r}'))
- return 'skip'
- t = self.spawn(
- 'mmgen-tool',
- ['--alice', 'add_label', addr, '(none)'],
- exit_val = exit_val)
- t.expect(reply, regex=True)
- return t
- def alice_add_comment_badaddr1(self):
- return self.alice_add_comment_badaddr(rt_pw, 'invalid address', 2)
- def alice_add_comment_badaddr2(self):
- # mainnet zero address:
- addr = init_proto(cfg, self.proto.coin, network='mainnet').pubhash2addr(bytes(20), 'p2pkh')
- return self.alice_add_comment_badaddr(addr, 'invalid address', 2)
- def alice_add_comment_badaddr3(self):
- addr = self._user_sid('alice') + ':C:123'
- return self.alice_add_comment_badaddr(addr, f'MMGen address {addr!r} not found in tracking wallet', 2)
- def alice_add_comment_badaddr4(self):
- addr = self.proto.pubhash2addr(bytes(20), 'p2pkh') # regtest (testnet) zero address
- return self.alice_add_comment_badaddr(addr, f'Coin address {addr!r} not found in tracking wallet', 2)
- def alice_remove_comment1(self):
- sid = self._user_sid('alice')
- mmid = sid + (':S:3', ':L:3')[self.proto.coin=='BCH']
- return self.user_remove_comment('alice', mmid)
- def alice_chk_comment1(self):
- sid = self._user_sid('alice')
- return self._user_chk_comment('alice', sid+':C:1', 'Original Label - 月へ')
- def alice_chk_comment2(self):
- sid = self._user_sid('alice')
- return self._user_chk_comment('alice', sid+':C:1', 'Replacement Label', extra_args=['age_fmt=block'])
- def alice_edit_comment1(self):
- return self.user_edit_comment('alice', '4', tw_comment_lat_cyr_gr)
- def alice_edit_comment2(self):
- return self.user_edit_comment('alice', '3', tw_comment_zh)
- def alice_chk_comment3(self):
- sid = self._user_sid('alice')
- mmid = sid + (':S:3', ':L:3')[self.proto.coin=='BCH']
- return self._user_chk_comment('alice', mmid, tw_comment_lat_cyr_gr, extra_args=['age_fmt=date'])
- def alice_chk_comment4(self):
- sid = self._user_sid('alice')
- mmid = sid + (':S:3', ':L:3')[self.proto.coin=='BCH']
- return self._user_chk_comment('alice', mmid, '-', extra_args=['age_fmt=date_time'])
- def user_edit_comment(self, user, output, comment):
- t = self.spawn('mmgen-txcreate', ['-B', '--'+user, '-i'])
- t.expect(r'add \[l\]abel:.', 'M', regex=True)
- t.expect(r'add \[l\]abel:.', 'l', regex=True)
- t.expect(r'Enter unspent.*return to main menu\):.', output+'\n', regex=True)
- t.expect(r'Enter label text.*:.', comment+'\n', regex=True)
- t.expect(r'\[q\]uit menu, .*?:.', 'q', regex=True)
- return t
- def alice_listaddresses_scroll(self):
- t = self.spawn(
- 'mmgen-tool', [
- '--alice',
- '--scroll',
- f'--outdir={self.tr.trash_dir}',
- 'listaddresses',
- 'interactive=1',
- ]
- )
- prompt = 'abel:\b'
- t.expect(prompt, 'p')
- ret = t.expect([prompt, 'to confirm: '])
- if ret == 1:
- t.send('YES\n')
- t.expect(prompt)
- t.send('l')
- t.expect(
- 'main menu): ',
- '{}\n'.format(2 if self.proto.coin == 'BCH' else 1))
- t.expect('for address.*: ', '\n', regex=True)
- t.expect('unchanged')
- t.expect(prompt, 'q')
- return t
- def _alice_listaddresses_interactive(self, expect=(), expect_menu=()):
- t = self.spawn('mmgen-tool', ['--alice', 'listaddresses', 'interactive=1'])
- prompt = 'abel:\b'
- for e in expect:
- t.expect(*e, regex=True)
- for s in expect_menu:
- t.expect(prompt, s)
- return t
- def alice_listaddresses_cashaddr(self):
- if self.proto.coin != 'BCH':
- return 'skip'
- prompt = 'abel:\b'
- expect = (
- [rf'[{b32a}]{{8}}'],
- [prompt, 'h'],
- [rf'[{b58a}]{{8}}'],
- [prompt, 'q']
- )
- return self._alice_listaddresses_interactive(expect=expect)
- def alice_listaddresses_empty(self):
- return self._alice_listaddresses_interactive(expect_menu='uuEq')
- def alice_listaddresses_menu(self):
- return self._alice_listaddresses_interactive(expect_menu='aAMrDDDDLeq')
- def alice_listaddresses(self, args, expect):
- t = self.spawn('mmgen-tool', ['--alice', 'listaddresses', 'showempty=1'] + args)
- expect_str = r'\D{}\D.*\b{}'.format(*expect)
- t.expect(expect_str, regex=True)
- return t
- def alice_listaddresses1(self):
- return self.alice_listaddresses(
- args = [],
- expect = (rtAmts[1], r'\d+'))
- def alice_listaddresses_days(self):
- return self.alice_listaddresses(
- args = ['age_fmt=days'],
- expect = (rtAmts[1], r'\d+'))
- def alice_listaddresses_date(self):
- return self.alice_listaddresses(
- args = ['age_fmt=date'],
- expect = (rtAmts[1], pat_date))
- def alice_listaddresses_date_time(self):
- return self.alice_listaddresses(
- args = ['age_fmt=date_time'],
- expect = (rtAmts[1], pat_date_time))
- def alice_twview(self, args, expect):
- t = self.spawn('mmgen-tool', ['--alice', 'twview'] + args)
- expect_str = r'\D{}\D.*\b{}'.format(*expect)
- t.expect(expect_str, regex=True)
- return t
- def alice_twview1(self):
- return self.alice_twview(
- args = [],
- expect = (rtAmts[0], r'\d+'))
- def alice_twview_days(self):
- return self.alice_twview(
- args = ['age_fmt=days'],
- expect = (rtAmts[0], r'\d+'))
- def alice_twview_date(self):
- return self.alice_twview(
- args = ['age_fmt=date'],
- expect = (rtAmts[0], pat_date))
- def alice_twview_date_time(self):
- return self.alice_twview(
- args = ['age_fmt=date_time'],
- expect = (rtAmts[0], pat_date_time))
- def alice_twview_interactive_cashaddr(self):
- if self.proto.coin != 'BCH':
- return 'skip'
- t = self.spawn('mmgen-tool', ['--alice', 'twview', 'interactive=true'])
- prompt = 'abel:\b'
- t.expect(rf'[{b32a}]{{8}}', regex=True)
- t.expect(prompt, 'h')
- t.expect(rf'[{b58a}]{{8}}', regex=True)
- t.expect(prompt, 'q')
- return t
- def alice_txcreate_info(self, pexpect_spawn=False):
- t = self.spawn('mmgen-txcreate', ['--alice', '-Bi'], pexpect_spawn=pexpect_spawn)
- pats = (
- (r'\d+', 'w'),
- (r'\d+', 'D'),
- (r'\d+', 'D'),
- (r'\d+', 'D'),
- (pat_date, 'q'))
- for d, s in pats:
- t.expect(
- r'\D{}\D.*\b{}\b'.format(rtAmts[0], d),
- s,
- regex=True)
- if t.pexpect_spawn and s == 'w':
- t.expect(r'Total.*', 'q', regex=True, delay=1 if cfg.exact_output else t.send_delay)
- time.sleep(t.send_delay)
- t.send('e')
- return t
- def alice_txcreate_info_term(self):
- if self.skip_for_win('no pexpect_spawn'):
- return 'skip'
- return self.alice_txcreate_info(pexpect_spawn=True)
- # send one TX to 2 addrs in Alice’s wallet - required for alice_twview_grouped() (group by TxID)
- def bob_send_to_alice_2addr(self):
- outputs_cl = self._create_tx_outputs('alice', [('C', 1, ',0.02'), ('C', 2, ',0.2')])
- outputs_cl += [self._user_sid('bob')+':C:5']
- return self.user_txdo('bob', '25s', outputs_cl, '1')
- # send to a used addr in Alice’s wallet - required for alice_twview_grouped() (group by address)
- def bob_send_to_alice_reuse(self):
- outputs_cl = self._create_tx_outputs('alice', [('C', 1, ',0.0111')])
- outputs_cl += [self._user_sid('bob')+':C:5']
- return self.user_txdo('bob', '25s', outputs_cl, '1')
- def alice_twview_grouped(self):
- t = self.spawn('mmgen-tool', ['--alice', 'twview', 'interactive=1'])
- prompt = 'abel:\b'
- for grouped, send in (
- (False, 'o'), # 'o' = group display
- (False, 'M'), # grouped address
- (True, 't'), # grouped TxID
- (True, 'q')):
- if grouped:
- t.expect('........')
- t.expect(prompt, send)
- return t
- def bob_msgcreate(self):
- sid1 = self._user_sid('bob')
- sid2 = self._get_user_subsid('bob', '29L')
- return self.spawn(
- 'mmgen-msg', [
- '--bob',
- f'--outdir={self.tmpdir}',
- 'create',
- '16/3/2022 Earthquake strikes Fukushima coast',
- f'{sid1}:{self.dfl_mmtype}:1-4',
- f'{sid2}:C:3-7,87,98'
- ])
- def bob_msgsign(self, wallets=[]):
- fn = get_file_with_ext(self.tmpdir, 'rawmsg.json')
- t = self.spawn(
- 'mmgen-msg', [
- '--bob',
- f'--outdir={self.tmpdir}',
- 'sign',
- fn
- ] + wallets)
- if not wallets:
- t.passphrase(dfl_wcls.desc, rt_pw)
- return t
- def bob_walletconv_words(self):
- t = self.spawn(
- 'mmgen-walletconv',
- ['--bob', f'--outdir={self.tmpdir}', '--out-fmt=words'],
- no_passthru_opts = True)
- t.passphrase(dfl_wcls.desc, rt_pw)
- t.written_to_file('data')
- return t
- def bob_subwalletgen_bip39(self):
- t = self.spawn(
- 'mmgen-subwalletgen',
- ['--bob', f'--outdir={self.tmpdir}', '--out-fmt=bip39', '29L'],
- no_passthru_opts = True)
- t.passphrase(dfl_wcls.desc, rt_pw)
- t.written_to_file('data')
- return t
- def bob_msgsign_userwallet(self):
- fn1 = get_file_with_ext(self.tmpdir, 'mmwords')
- return self.bob_msgsign([fn1])
- def bob_msgsign_userwallets(self):
- fn1 = get_file_with_ext(self.tmpdir, 'mmwords')
- fn2 = get_file_with_ext(self.tmpdir, 'bip39')
- return self.bob_msgsign([fn2, fn1])
- def bob_msgverify(
- self,
- addr = None,
- ext = 'sigmsg.json',
- cmd = 'verify',
- msgfile = None,
- exit_val = None):
- return self.spawn(
- 'mmgen-msg', [
- '--bob',
- f'--outdir={self.tmpdir}',
- cmd,
- msgfile or get_file_with_ext(self.tmpdir, ext),
- ]
- + ([addr] if addr else []),
- exit_val = exit_val)
- def bob_msgverify_raw(self):
- t = self.bob_msgverify(ext='rawmsg.json', exit_val=1)
- t.expect('No signatures')
- return t
- def bob_msgverify_single(self):
- sid = self._user_sid('bob')
- return self.bob_msgverify(addr=f'{sid}:{self.dfl_mmtype}:1')
- def bob_msgexport(self, addr=None):
- t = self.bob_msgverify(addr=addr, cmd='export')
- t.written_to_file('data')
- return t
- def bob_msgexport_single(self):
- sid = self._user_sid('bob')
- return self.bob_msgexport(addr=f'{sid}:{self.dfl_mmtype}:1')
- def bob_msgverify_export(self):
- return self.bob_msgverify(
- msgfile = os.path.join(self.tmpdir, 'signatures.json')
- )
- def bob_msgverify_export_single(self):
- sid = self._user_sid('bob')
- mmid = f'{sid}:{self.dfl_mmtype}:1'
- args = ['--bob', '--color=0', 'listaddress', mmid, 'wide=true']
- imsg(f'Running mmgen-tool {fmt_list(args,fmt="bare")}')
- t = self.spawn('mmgen-tool', args, no_msg=True)
- addr = t.expect_getend(mmid).split()[1]
- t.close()
- return self.bob_msgverify(
- addr = addr,
- msgfile = os.path.join(self.tmpdir, 'signatures.json')
- )
- def bob_auto_chg_split(self):
- if not self.proto.cap('segwit'):
- return 'skip'
- sid = self._user_sid('bob')
- return self.user_txdo(
- user = 'bob',
- fee = '23s',
- outputs_cl = [sid+':C:5,0.0135', sid+':L:4'],
- outputs_list = '1')
- def bob_auto_chg_generate(self):
- if not self.proto.cap('segwit'):
- return 'skip'
- return self.generate()
- def _usr_auto_chg(
- self,
- user,
- mmtype,
- idx,
- by_mmtype = False,
- include_dest = True,
- ignore_labels = False,
- add_args = []):
- if mmtype in ('S', 'B') and not self.proto.cap('segwit'):
- return 'skip'
- sid = self._user_sid('bob')
- t = self.spawn(
- 'mmgen-txcreate',
- [f'--outdir={self.tr.trash_dir}', '--no-blank', f'--{user}']
- + (['--autochg-ignore-labels'] if ignore_labels else [])
- + [mmtype if by_mmtype else f'{sid}:{mmtype}']
- + ([self.burn_addr+',0.01'] if include_dest else [])
- + add_args
- )
- return self.txcreate_ui_common(t,
- menu = [],
- inputs = '1',
- interactive_fee = '20s',
- auto_chg_addr = f'{sid}:{mmtype}:{idx}')
- def bob_auto_chg1(self):
- return self._usr_auto_chg('bob', 'C', '3')
- def bob_auto_chg2(self):
- return self._usr_auto_chg('bob', 'B', '2')
- def bob_auto_chg3(self):
- return self._usr_auto_chg('bob', 'S', '1')
- def bob_auto_chg4(self):
- return self._usr_auto_chg('bob', 'C', '3', include_dest=False)
- def bob_auto_chg_addrtype1(self):
- return self._usr_auto_chg('bob', 'C', '3', True)
- def bob_auto_chg_addrtype2(self):
- return self._usr_auto_chg('bob', 'B', '2', True)
- def bob_auto_chg_addrtype3(self):
- return self._usr_auto_chg('bob', 'S', '1', True)
- def bob_auto_chg_addrtype4(self):
- return self._usr_auto_chg('bob', 'C', '3', True, include_dest=False)
- def _bob_add_comment_uua(self, addrspec, comment):
- sid = self._user_sid('bob')
- return self.user_add_comment('bob', sid+addrspec, comment)
- def bob_add_comment_uua1(self):
- return self._bob_add_comment_uua(':C:3', 'comment for unused address')
- def bob_auto_chg5(self):
- return self._usr_auto_chg('bob', 'C', '4')
- def bob_auto_chg_addrtype5(self):
- return self._usr_auto_chg('bob', 'C', '4', True)
- def bob_auto_chg6(self):
- return self._usr_auto_chg('bob', 'C', '3', ignore_labels=True)
- def bob_auto_chg7(self):
- sid = self._user_sid('bob')
- return self._usr_auto_chg('bob', 'S', '3', add_args=[f'{sid}:S:1,0.00345'])
- def bob_auto_chg_addrtype6(self):
- return self._usr_auto_chg('bob', 'C', '3', True, ignore_labels=True)
- def _bob_remove_comment_uua(self, addrspec):
- sid = self._user_sid('bob')
- return self.user_remove_comment('bob', sid+addrspec)
- def bob_remove_comment_uua1(self):
- return self._bob_remove_comment_uua(':C:3')
- def _usr_auto_chg_bad(self, user, al_id, expect, add_args=[]):
- t = self.spawn(
- 'mmgen-txcreate',
- ['-d', self.tr.trash_dir, '-B', f'--{user}']
- + [f'{self.burn_addr},0.01']
- + ([al_id] if al_id else [])
- + add_args,
- exit_val = 2)
- t.expect(expect)
- return t
- def bob_auto_chg_bad1(self):
- return self._usr_auto_chg_bad(
- 'bob',
- 'FFFFFFFF:C',
- 'contains no addresses')
- def bob_auto_chg_bad2(self):
- return self._usr_auto_chg_bad(
- 'bob',
- '00000000:C',
- 'contains no addresses')
- def bob_auto_chg_bad3(self):
- return self._usr_auto_chg_bad(
- 'bob',
- self._user_sid('bob') + ':L',
- 'contains no unused addresses from address list')
- def bob_auto_chg_bad4(self):
- return self._usr_auto_chg_bad(
- 'bob',
- 'L',
- 'contains no unused addresses of address type')
- def bob_auto_chg_bad5(self):
- sid = self._user_sid('bob')
- return self._usr_auto_chg_bad(
- 'bob',
- None,
- 'More than one change address listed',
- add_args = [f'{sid}:C:4', f'{sid}:C:5'])
- def bob_auto_chg_bad6(self):
- sid = self._user_sid('bob')
- return self._usr_auto_chg_bad(
- 'bob',
- 'L',
- 'More than one',
- add_args = [f'{sid}:C:4'])
- def bob_auto_chg_bad7(self):
- return self._usr_auto_chg_bad(
- 'bob',
- 'L',
- 'More than one change address requested',
- add_args = ['B' if self.proto.cap('segwit') else 'C'])
- def carol_twimport2(self):
- u, b = (4, 3) if self.proto.cap('segwit') else (3, 2)
- return self.carol_twimport(
- rpc_backend = None,
- add_parms = ['ignore_checksum=true'],
- expect_str2 = f'Found {u} unspent outputs in {b} blocks')
- def carol_rescan_blockchain(self):
- return self._usr_rescan_blockchain('carol', [])
- def carol_auto_chg1(self):
- return self._usr_auto_chg('carol', 'C', '3')
- def carol_auto_chg2(self):
- return self._usr_auto_chg('carol', 'B', '2')
- def carol_auto_chg3(self):
- return self._usr_auto_chg('carol', 'S', '1')
- def carol_auto_chg_addrtype1(self):
- return self._usr_auto_chg('carol', 'C', '3', True)
- def carol_auto_chg_addrtype2(self):
- return self._usr_auto_chg('carol', 'B', '2', True)
- def carol_auto_chg_addrtype3(self):
- return self._usr_auto_chg('carol', 'S', '1', True)
- def carol_auto_chg_addrtype4(self):
- sid = self._user_sid('bob')
- return self._usr_auto_chg('carol', 'S', '3', True, add_args=[f'{sid}:S:1,0.00345'])
- def carol_auto_chg_bad1(self):
- return self._usr_auto_chg_bad(
- 'carol',
- self._user_sid('bob') + ':L',
- 'contains no unused addresses from address list')
- def carol_auto_chg_bad2(self):
- return self._usr_auto_chg_bad(
- 'carol',
- 'L',
- 'contains no unused addresses of address type')
- def stop(self):
- self.spawn('', msg_only=True)
- if cfg.no_daemon_stop:
- msg_r('(leaving regtest daemon running by user request)')
- imsg('')
- else:
- stop_test_daemons(self.proto.network_id, remove_datadir=True)
- ok()
- return 'ok'
- class CmdTestRegtestBDBWallet(CmdTestRegtest):
- bdb_wallet = True
|