ct_regtest.py 72 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077
  1. #!/usr/bin/env python3
  2. #
  3. # mmgen = Multi-Mode GENerator, command-line Bitcoin cold storage solution
  4. # Copyright (C)2013-2024 The MMGen Project <mmgen@tuta.io>
  5. #
  6. # This program is free software: you can redistribute it and/or modify
  7. # it under the terms of the GNU General Public License as published by
  8. # the Free Software Foundation, either version 3 of the License, or
  9. # (at your option) any later version.
  10. #
  11. # This program is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU General Public License
  17. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. """
  19. test.cmdtest_py_d.ct_regtest: Regtest tests for the cmdtest.py test suite
  20. """
  21. import sys,os,json,time,re
  22. from decimal import Decimal
  23. from mmgen.proto.btc.regtest import MMGenRegtest
  24. from mmgen.color import yellow
  25. from mmgen.util import msg_r,die,gmsg,capfirst,fmt_list
  26. from mmgen.protocol import init_proto
  27. from mmgen.addrlist import AddrList
  28. from mmgen.wallet import Wallet,get_wallet_cls
  29. from ..include.common import (
  30. cfg,
  31. imsg,
  32. omsg,
  33. stop_test_daemons,
  34. joinpath,
  35. silence,
  36. end_silence,
  37. cmp_or_die,
  38. strip_ansi_escapes,
  39. gr_uc,
  40. getrandhex
  41. )
  42. from .common import (
  43. ok_msg,
  44. get_file_with_ext,
  45. get_comment,
  46. tw_comment_lat_cyr_gr,
  47. tw_comment_zh,
  48. tx_comment_jp,
  49. get_env_without_debug_vars
  50. )
  51. from .ct_base import CmdTestBase
  52. from .ct_shared import CmdTestShared
  53. pat_date = r'\b\d\d-\d\d-\d\d\b'
  54. pat_date_time = r'\b\d\d\d\d-\d\d-\d\d\s+\d\d:\d\d\b'
  55. dfl_wcls = get_wallet_cls('mmgen')
  56. tx_fee = rtFundAmt = rtFee = rtBals = rtBals_gb = rtBobOp3 = rtAmts = {} # pylint
  57. rt_pw = 'abc-α'
  58. rt_data = {
  59. 'tx_fee': {'btc':'0.0001','bch':'0.001','ltc':'0.01'},
  60. 'rtFundAmt': {'btc':'500','bch':'500','ltc':'5500'},
  61. 'rtFee': {
  62. 'btc': ('20s','10s','60s','31s','10s','20s'),
  63. 'bch': ('20s','10s','60s','0.0001','10s','20s'),
  64. 'ltc': ('1000s','500s','1500s','0.05','400s','1000s')
  65. },
  66. 'rtBals': {
  67. 'btc': ('499.9999488','399.9998282','399.9998147','399.9996877',
  68. '52.99980410','946.99933647','999.99914057','52.9999',
  69. '946.99933647','0.4169328','6.24987417'),
  70. 'bch': ('499.9999484','399.9999194','399.9998972','399.9997692',
  71. '46.78890380','953.20966920','999.99857300','46.789',
  72. '953.2096692','0.4169328','39.58187387'),
  73. 'ltc': ('5499.99744','5399.994425','5399.993885','5399.987535',
  74. '52.98520500','10946.93753500','10999.92274000','52.99',
  75. '10946.937535','0.41364','6.24846787'),
  76. },
  77. 'rtBals_gb': {
  78. 'btc': {
  79. '0conf0': {
  80. 'mmgen': ('283.22339537','283.22339537'),
  81. 'nonmm': ('16.77647763','116.77629233'),
  82. 'total': ('299.999873','399.9996877'),
  83. },
  84. '0conf1': {
  85. 'mmgen': ('283.22339537','0'),
  86. 'nonmm': ('16.77647763','99.9998147'),
  87. 'total': ('299.999873','99.9998147'),
  88. },
  89. '1conf1': {
  90. 'mmgen': ('0','283.22339537'),
  91. 'nonmm': ('0','116.77629233'),
  92. 'total': ('0','399.9996877'),
  93. },
  94. '1conf2': {
  95. 'mmgen': ('0','283.22339537','0'),
  96. 'nonmm': ('0','16.77647763','99.9998147'),
  97. 'total': ('0','299.999873','99.9998147'),
  98. },
  99. },
  100. 'bch': {
  101. '0conf0': {
  102. 'mmgen': ('283.22339437','283.22339437'),
  103. 'nonmm': ('16.77647763','116.77637483'),
  104. 'total': ('299.999872','399.9997692'),
  105. },
  106. '0conf1': {
  107. 'mmgen': ('283.22339437','0'),
  108. 'nonmm': ('16.77647763','99.9998972'),
  109. 'total': ('299.999872','99.9998972'),
  110. },
  111. '1conf1': {
  112. 'mmgen': ('0','283.22339437'),
  113. 'nonmm': ('0','116.77637483'),
  114. 'total': ('0','399.9997692'),
  115. },
  116. '1conf2': {
  117. 'mmgen': ('0','283.22339437','0'),
  118. 'nonmm': ('0','16.77647763','99.9998972'),
  119. 'total': ('0','299.999872','99.9998972'),
  120. },
  121. },
  122. 'ltc': {
  123. '0conf0': {
  124. 'mmgen': ('283.21717237','283.21717237'),
  125. 'nonmm': ('16.77647763','5116.77036263'),
  126. 'total': ('299.99365','5399.987535'),
  127. },
  128. '0conf1': {
  129. 'mmgen': ('283.21717237','0'),
  130. 'nonmm': ('16.77647763','5099.993885'),
  131. 'total': ('299.99365','5099.993885'),
  132. },
  133. '1conf1': {
  134. 'mmgen': ('0','283.21717237'),
  135. 'nonmm': ('0','5116.77036263'),
  136. 'total': ('0','5399.987535'),
  137. },
  138. '1conf2': {
  139. 'mmgen': ('0','283.21717237','0'),
  140. 'nonmm': ('0','16.77647763','5099.993885'),
  141. 'total': ('0','299.99365','5099.993885'),
  142. },
  143. }
  144. },
  145. 'rtBobOp3': {'btc':'S:2','bch':'L:3','ltc':'S:2'},
  146. 'rtAmts': {
  147. 'btc': ('500','500'),
  148. 'bch': ('500','560'),
  149. 'ltc': ('5500','5500')
  150. }
  151. }
  152. def make_burn_addr(proto):
  153. from mmgen.tool.coin import tool_cmd
  154. return tool_cmd(
  155. cfg = cfg,
  156. cmdname = 'pubhash2addr',
  157. proto = proto,
  158. mmtype = 'compressed' ).pubhash2addr('00'*20)
  159. class CmdTestRegtest(CmdTestBase,CmdTestShared):
  160. 'transacting and tracking wallet operations via regtest mode'
  161. networks = ('btc','ltc','bch')
  162. passthru_opts = ('coin','rpc_backend')
  163. extra_spawn_args = ['--regtest=1']
  164. tmpdir_nums = [17]
  165. color = True
  166. deterministic = False
  167. test_rbf = False
  168. proto = None # pylint
  169. bdb_wallet = False
  170. cmd_group_in = (
  171. ('setup', 'regtest (Bob and Alice) mode setup'),
  172. ('subgroup.misc', []),
  173. ('subgroup.init_bob', []),
  174. ('subgroup.init_alice', []),
  175. ('subgroup.fund_users', ['init_bob','init_alice']),
  176. ('subgroup.msg', ['init_bob']),
  177. ('subgroup.twexport', ['fund_users']),
  178. ('subgroup.rescan', ['fund_users']),
  179. ('subgroup.errors', ['fund_users']),
  180. ('subgroup.main', ['fund_users']),
  181. ('subgroup.twprune', ['main']),
  182. ('subgroup.txhist', ['main']),
  183. ('subgroup.label', ['main']),
  184. ('subgroup.view', ['label']),
  185. ('subgroup._auto_chg_deps', ['twexport','label']),
  186. ('subgroup.auto_chg', ['_auto_chg_deps']),
  187. ('stop', 'stopping regtest daemon'),
  188. )
  189. cmd_subgroups = {
  190. 'misc': (
  191. 'miscellaneous commands',
  192. ('daemon_version', 'mmgen-tool daemon_version'),
  193. ('halving_calculator_bob', 'halving calculator (Bob)'),
  194. ),
  195. 'init_bob': (
  196. 'creating Bob’s MMGen wallet and tracking wallet',
  197. ('bob_twview_noaddrs', 'viewing Bob’s unspent outputs (error, no addrs)'),
  198. ('bob_listaddrs_noaddrs', 'viewing Bob’s addresses (error, no addrs)'),
  199. ('walletgen_bob', 'wallet generation (Bob)'),
  200. ('addrgen_bob', 'address generation (Bob)'),
  201. ('addrimport_bob', "importing Bob's addresses"),
  202. ('bob_twview_nobal', 'viewing Bob’s unspent outputs (error, no balance)'),
  203. ('bob_listaddrs_nobal', 'viewing Bob’s addresses (OK, no balance)'),
  204. ),
  205. 'init_alice': (
  206. 'creating Alice’s MMGen wallet and tracking wallet',
  207. ('walletgen_alice', 'wallet generation (Alice)'),
  208. ('addrgen_alice', 'address generation (Alice)'),
  209. ('addrimport_alice', "importing Alice's addresses"),
  210. ),
  211. 'fund_users': (
  212. 'funding Bob and Alice’s wallets',
  213. ('bob_import_miner_addr', "importing miner’s coinbase addr into Bob’s wallet"),
  214. ('fund_bob_deterministic', "funding Bob’s first MMGen address (deterministic method)"),
  215. ('fund_alice_deterministic', "funding Alice’s first MMGen address (deterministic method)"),
  216. ('bob_recreate_tracking_wallet', 'creation of new tracking wallet (Bob)'),
  217. ('addrimport_bob2', "reimporting Bob's addresses"),
  218. ('fund_bob', "funding Bob's wallet"),
  219. ('fund_alice', "funding Alice's wallet"),
  220. ('generate', 'mining a block'),
  221. ('bob_bal1', "Bob's balance"),
  222. ('generate_extra_deterministic', "generate extra blocks for deterministic run"),
  223. ),
  224. 'msg': (
  225. 'message signing',
  226. ('bob_msgcreate', 'creating a message file for signing'),
  227. ('bob_msgsign', 'signing the message file (default wallet)'),
  228. ('bob_walletconv_words', 'creating an MMGen mnemonic wallet'),
  229. ('bob_subwalletgen_bip39', 'creating a BIP39 mnemonic subwallet'),
  230. ('bob_msgsign_userwallet', 'signing the message file (user-specified wallet)'),
  231. ('bob_msgsign_userwallets', 'signing the message file (user-specified wallets)'),
  232. ('bob_msgverify', 'verifying the message file (all addresses)'),
  233. ('bob_msgverify_raw', 'verifying the raw message file (all addresses)'),
  234. ('bob_msgverify_single', 'verifying the message file (single address)'),
  235. ('bob_msgexport_single', 'exporting the message file (single address)'),
  236. ('bob_msgexport', 'exporting the message file (all addresses)'),
  237. ('bob_msgverify_export', 'verifying the exported JSON data (all addresses)'),
  238. ('bob_msgverify_export_single', 'verifying the exported JSON data (single address)'),
  239. ),
  240. 'twexport': (
  241. 'exporting and importing tracking wallet to JSON',
  242. ('bob_twexport', 'exporting a tracking wallet to JSON'),
  243. ('carol_twimport', 'importing a tracking wallet JSON dump'),
  244. ('carol_delete_wallet', 'unloading and deleting Carol’s tracking wallet'),
  245. ('bob_twexport_noamt', 'exporting a tracking wallet to JSON (include_amts=0)'),
  246. ('carol_twimport_nochksum', 'importing a tracking wallet JSON dump (ignore_checksum=1)'),
  247. ('carol_delete_wallet', 'unloading and deleting Carol’s tracking wallet'),
  248. ('carol_twimport_batch', 'importing a tracking wallet JSON dump (batch=1)'),
  249. ('bob_twexport_pretty', 'exporting a tracking wallet to JSON (pretty=1)'),
  250. ('bob_edit_json_twdump', 'editing a tracking wallet JSON dump'),
  251. ('carol_delete_wallet', 'unloading and deleting Carol’s tracking wallet'),
  252. ('carol_twimport_pretty', 'importing an edited tracking wallet JSON dump (ignore_checksum=1)'),
  253. ('carol_listaddresses', 'viewing Carol’s tracking wallet'),
  254. ('carol_delete_wallet', 'unloading and deleting Carol’s tracking wallet'),
  255. ),
  256. 'rescan': (
  257. 'rescanning address and blockchain',
  258. ('bob_resolve_addr', 'resolving an address in the tracking wallet'),
  259. ('bob_rescan_addr', 'rescanning an address'),
  260. ('bob_rescan_blockchain_all', 'rescanning the blockchain (full rescan)'),
  261. ('bob_rescan_blockchain_gb', 'rescanning the blockchain (Genesis block)'),
  262. ('bob_rescan_blockchain_one', 'rescanning the blockchain (single block)'),
  263. ('bob_rescan_blockchain_ss', 'rescanning the blockchain (range of blocks)'),
  264. ),
  265. 'errors': (
  266. 'various error conditions',
  267. ('bob_bad_locktime1', 'broadcast of transaction with bad locktime (block)'),
  268. ('bob_bad_locktime2', 'broadcast of transaction with bad locktime (integer size)'),
  269. ('bob_bad_locktime3', 'broadcast of transaction with bad locktime (time)'),
  270. ),
  271. 'main': (
  272. 'creating, signing, sending and bumping transactions',
  273. ('bob_add_comment1', "adding an 80-screen-width label (lat+cyr+gr)"),
  274. ('bob_twview1', "viewing Bob's tracking wallet"),
  275. ('bob_split1', "splitting Bob's funds"),
  276. ('generate', 'mining a block'),
  277. ('bob_bal2', "Bob's balance"),
  278. ('bob_rbf_1output_create', 'creating RBF tx with one output'),
  279. ('bob_rbf_1output_bump', 'bumping RBF tx with one output'),
  280. ('bob_bal2a', "Bob's balance (age_fmt=confs)"),
  281. ('bob_bal2b', "Bob's balance (showempty=1)"),
  282. ('bob_bal2c', "Bob's balance (showempty=1 minconf=2 age_fmt=days)"),
  283. ('bob_bal2d', "Bob's balance (minconf=2)"),
  284. ('bob_bal2e', "Bob's balance (showempty=1 sort=age)"),
  285. ('bob_bal2f', "Bob's balance (showempty=1 sort=age,reverse)"),
  286. ('bob_send_maybe_rbf', 'sending funds to Alice (RBF, if supported)'),
  287. ('get_mempool1', 'mempool (before RBF bump)'),
  288. ('bob_rbf_status1', 'getting status of transaction'),
  289. ('bob_rbf_bump', 'bumping RBF transaction'),
  290. ('get_mempool2', 'mempool (after RBF bump)'),
  291. ('bob_rbf_status2', 'getting status of transaction after replacement'),
  292. ('bob_rbf_status3', 'getting status of replacement transaction (mempool)'),
  293. ('generate', 'mining a block'),
  294. ('bob_rbf_status4', 'getting status of transaction after confirmed (1) replacement'),
  295. ('bob_rbf_status5', 'getting status of replacement transaction (confirmed)'),
  296. ('generate', 'mining a block'),
  297. ('bob_rbf_status6', 'getting status of transaction after confirmed (2) replacement'),
  298. ('bob_bal3', "Bob's balance"),
  299. ('bob_pre_import', 'sending to non-imported address'),
  300. ('generate', 'mining a block'),
  301. ('bob_import_addr', 'importing non-MMGen address'),
  302. ('bob_bal4', "Bob's balance (after import)"),
  303. ('bob_import_list', 'importing flat address list'),
  304. ('bob_import_list_rescan', 'importing flat address list with --rescan'),
  305. ('bob_import_list_rescan_aio', 'importing flat address list with --rescan (aiohttp backend)'),
  306. ('bob_split2', "splitting Bob's funds"),
  307. ('bob_0conf0_getbalance', "Bob's balance (unconfirmed, minconf=0)"),
  308. ('bob_0conf1_getbalance', "Bob's balance (unconfirmed, minconf=1)"),
  309. ('generate', 'mining a block'),
  310. ('bob_1conf1_getbalance', "Bob's balance (confirmed, minconf=1)"),
  311. ('bob_1conf2_getbalance', "Bob's balance (confirmed, minconf=2)"),
  312. ('bob_bal5', "Bob's balance"),
  313. ('bob_send_non_mmgen', 'sending funds to Alice (from non-MMGen addrs)'),
  314. ('generate', 'mining a block'),
  315. ('alice_send_estimatefee', 'tx creation with no fee on command line'),
  316. ('generate', 'mining a block'),
  317. ('bob_bal6', "Bob's balance"),
  318. ('bob_subwallet_addrgen1', "generating Bob's addrs from subwallet 29L"),
  319. ('bob_subwallet_addrgen2', "generating Bob's addrs from subwallet 127S"),
  320. ('bob_subwallet_addrimport1', "importing Bob's addrs from subwallet 29L"),
  321. ('bob_subwallet_addrimport2', "importing Bob's addrs from subwallet 127S"),
  322. ('bob_subwallet_fund', "funding Bob's subwallet addrs"),
  323. ('generate', 'mining a block'),
  324. ('bob_twview2', "viewing Bob's tracking wallet"),
  325. ('bob_twview3', "viewing Bob's tracking wallet"),
  326. ('bob_subwallet_txcreate', 'creating a transaction with subwallet inputs'),
  327. ('bob_subwallet_txsign', 'signing a transaction with subwallet inputs'),
  328. ('bob_subwallet_txdo', "sending from Bob's subwallet addrs"),
  329. ('generate', 'mining a block'),
  330. ('bob_twview4', "viewing Bob's tracking wallet"),
  331. ('bob_alice_bal', "Bob and Alice's balances"),
  332. ('bob_nochg_burn', 'zero-change transaction to burn address'),
  333. ('generate', 'mining a block'),
  334. ),
  335. 'twprune': (
  336. 'exporting a pruned tracking wallet to JSON',
  337. ('bob_twprune_noask', 'pruning a tracking wallet'),
  338. ('bob_twprune_skip', 'pruning a tracking wallet (skip pruning)'),
  339. ('bob_twprune_all', 'pruning a tracking wallet (pruning all addrs)'),
  340. ('bob_twprune_skipamt', 'pruning a tracking wallet (skipping addrs with amt)'),
  341. ('bob_twprune_skipused', 'pruning a tracking wallet (skipping used addrs)'),
  342. ('bob_twprune_allamt', 'pruning a tracking wallet (pruning addrs with amt)'),
  343. ('bob_twprune_allused', 'pruning a tracking wallet (pruning used addrs)'),
  344. ('bob_twprune1', 'pruning a tracking wallet (selective prune)'),
  345. ('bob_twprune2', 'pruning a tracking wallet (selective prune)'),
  346. ('bob_twprune3', 'pruning a tracking wallet (selective prune)'),
  347. ('bob_twprune4', 'pruning a tracking wallet (selective prune)'),
  348. ('bob_twprune5', 'pruning a tracking wallet (selective prune)'),
  349. ('bob_twprune6', 'pruning a tracking wallet (selective prune)'),
  350. ),
  351. 'txhist': (
  352. 'viewing transaction history',
  353. ('bob_txhist1', "viewing Bob's transaction history (sort=age)"),
  354. ('bob_txhist2', "viewing Bob's transaction history (sort=blockheight reverse=1)"),
  355. ('bob_txhist3', "viewing Bob's transaction history (sort=blockheight sinceblock=-7)"),
  356. ('bob_txhist4', "viewing Bob's transaction history (detail=1)"),
  357. ('bob_txhist5', "viewing Bob's transaction history (sinceblock=399 detail=1)"),
  358. ('bob_txhist_interactive', "viewing Bob's transaction history (age_fmt=date_time interactive=true)"),
  359. ),
  360. 'label': (
  361. 'adding, removing and editing labels',
  362. ('alice_bal2', "Alice's balance"),
  363. ('alice_add_comment1', 'adding a label'),
  364. ('alice_chk_comment1', 'the label'),
  365. ('alice_add_comment2', 'adding a label'),
  366. ('alice_chk_comment2', 'the label'),
  367. ('alice_edit_comment1', 'editing a label (zh)'),
  368. ('alice_edit_comment2', 'editing a label (lat+cyr+gr)'),
  369. ('alice_chk_comment3', 'the label'),
  370. ('alice_remove_comment1', 'removing a label'),
  371. ('alice_chk_comment4', 'the label'),
  372. ('alice_add_comment_coinaddr', 'adding a label using the coin address'),
  373. ('alice_chk_comment_coinaddr', 'the label'),
  374. ('alice_add_comment_badaddr1', 'adding a label with invalid address'),
  375. ('alice_add_comment_badaddr2', 'adding a label with invalid address for this chain'),
  376. ('alice_add_comment_badaddr3', 'adding a label with wrong MMGen address'),
  377. ('alice_add_comment_badaddr4', 'adding a label with wrong coin address'),
  378. ),
  379. 'view': (
  380. 'viewing addresses and unspent outputs',
  381. ('alice_listaddresses_scroll', 'listaddresses (--scroll, interactive=1)'),
  382. ('alice_listaddresses_empty', 'listaddresses (no data)'),
  383. ('alice_listaddresses_menu', 'listaddresses (menu items)'),
  384. ('alice_listaddresses1', 'listaddresses'),
  385. ('alice_listaddresses_days', 'listaddresses (age_fmt=days)'),
  386. ('alice_listaddresses_date', 'listaddresses (age_fmt=date)'),
  387. ('alice_listaddresses_date_time', 'listaddresses (age_fmt=date_time)'),
  388. ('alice_twview1', 'twview'),
  389. ('alice_twview_days', 'twview (age_fmt=days)'),
  390. ('alice_twview_date', 'twview (age_fmt=date)'),
  391. ('alice_twview_date_time', 'twview (age_fmt=date_time)'),
  392. ('alice_txcreate_info', 'txcreate -i'),
  393. ('alice_txcreate_info_term', 'txcreate -i (pexpect_spawn)'),
  394. ('bob_send_to_alice_2addr', 'sending a TX to 2 addresses in Alice’s wallet'),
  395. ('bob_send_to_alice_reuse', 'sending a TX to a used address in Alice’s wallet'),
  396. ('generate', 'mining a block'),
  397. ('alice_twview_grouped', 'twview (testing ‘grouped’ option for TX and address)'),
  398. ),
  399. '_auto_chg_deps': (
  400. 'automatic change address selection dependencies',
  401. ('bob_auto_chg_split', 'splitting Bob’s funds (auto-chg-addr dependency)'),
  402. ('bob_auto_chg_generate', 'mining a block (auto-chg-addr dependency)'),
  403. ),
  404. 'auto_chg': (
  405. 'automatic change address selection',
  406. ('bob_auto_chg1', 'creating an automatic change address transaction (C)'),
  407. ('bob_auto_chg2', 'creating an automatic change address transaction (B)'),
  408. ('bob_auto_chg3', 'creating an automatic change address transaction (S)'),
  409. ('bob_auto_chg4', 'creating an automatic change address transaction (single address)'),
  410. ('bob_auto_chg_addrtype1', 'creating an automatic change address transaction by addrtype (C)'),
  411. ('bob_auto_chg_addrtype2', 'creating an automatic change address transaction by addrtype (B)'),
  412. ('bob_auto_chg_addrtype3', 'creating an automatic change address transaction by addrtype (S)'),
  413. ('bob_auto_chg_addrtype4', 'creating an automatic change address transaction by addrtype (single address)'),
  414. ('bob_add_comment_uua1', 'adding a comment for unused address in tracking wallet (C)'),
  415. ('bob_auto_chg5', 'creating an auto-chg-address TX, skipping unused address with label (C)'),
  416. ('bob_auto_chg_addrtype5', 'creating an auto-chg-address TX by addrtype, skipping unused address '
  417. 'with label (C)'),
  418. ('bob_auto_chg6', 'creating an auto-chg-address TX, using unused address with label (C)'),
  419. ('bob_auto_chg7', 'creating an automatic change address transaction (exclude cmdline output)'),
  420. ('bob_auto_chg_addrtype6', 'creating an auto-chg-address TX by addrtype, using unused address with '
  421. 'label (C)'),
  422. ('bob_remove_comment_uua1', 'removing a comment for unused address in tracking wallet (C)'),
  423. ('bob_auto_chg_bad1', 'error handling for auto change address transaction (bad ID FFFFFFFF:C)'),
  424. ('bob_auto_chg_bad2', 'error handling for auto change address transaction (bad ID 00000000:C)'),
  425. ('bob_auto_chg_bad3', 'error handling for auto change address transaction (no unused addresses)'),
  426. ('bob_auto_chg_bad4', 'error handling for auto change address transaction by addrtype '
  427. '(no unused addresses)'),
  428. ('bob_auto_chg_bad5', 'error handling (more than one chg address listed)'),
  429. ('bob_auto_chg_bad6', 'error handling for auto change address transaction '
  430. '(more than one chg address, mixed)'),
  431. ('bob_auto_chg_bad7', 'error handling for auto change address transaction '
  432. '(more than one chg address requested)'),
  433. ('carol_twimport2', 'recreating Carol’s tracking wallet from JSON dump'),
  434. ('carol_rescan_blockchain', 'rescanning the blockchain (full rescan)'),
  435. ('carol_auto_chg1', 'creating an automatic change address transaction (C)'),
  436. ('carol_auto_chg2', 'creating an automatic change address transaction (B)'),
  437. ('carol_auto_chg3', 'creating an automatic change address transaction (S)'),
  438. ('carol_auto_chg_addrtype1', 'creating an automatic change address transaction by addrtype (C)'),
  439. ('carol_auto_chg_addrtype2', 'creating an automatic change address transaction by addrtype (B)'),
  440. ('carol_auto_chg_addrtype3', 'creating an automatic change address transaction by addrtype (S)'),
  441. ('carol_auto_chg_addrtype4', 'creating an automatic change address transaction by addrtype (C) (exclude cmdline output)'),
  442. ('carol_auto_chg_bad1', 'error handling for auto change address transaction (no unused addresses)'),
  443. ('carol_auto_chg_bad2', 'error handling for auto change address transaction by addrtype '
  444. '(no unused addresses)'),
  445. ('carol_delete_wallet', 'unloading and deleting Carol’s tracking wallet'),
  446. ),
  447. }
  448. def __init__(self,trunner,cfgs,spawn):
  449. CmdTestBase.__init__(self,trunner,cfgs,spawn)
  450. if trunner == None:
  451. return
  452. if self.proto.testnet:
  453. die(2,'--testnet and --regtest options incompatible with regtest test suite')
  454. self.proto = init_proto( cfg, self.proto.coin, network='regtest', need_amt=True )
  455. coin = self.proto.coin.lower()
  456. gldict = globals()
  457. for k in rt_data:
  458. gldict[k] = rt_data[k][coin] if coin in rt_data[k] else None
  459. self.use_bdb_wallet = self.bdb_wallet or self.proto.coin != 'BTC'
  460. self.rt = MMGenRegtest(cfg, self.proto.coin, bdb_wallet=self.use_bdb_wallet)
  461. if self.proto.coin == 'BTC':
  462. self.test_rbf = True # tests are non-coin-dependent, so run just once for BTC
  463. if cfg.test_suite_deterministic:
  464. self.deterministic = True
  465. self.spawn_env['MMGEN_BOGUS_SEND'] = ''
  466. self.write_to_tmpfile('wallet_password',rt_pw)
  467. self.dfl_mmtype = 'C' if self.proto.coin == 'BCH' else 'B'
  468. self.burn_addr = make_burn_addr(self.proto)
  469. self.user_sids = {}
  470. def _add_comments_to_addr_file(self,addrfile,outfile,use_comments=False):
  471. silence()
  472. gmsg(f'Adding comments to address file {addrfile!r}')
  473. a = AddrList( cfg, self.proto, addrfile )
  474. for n,idx in enumerate(a.idxs(),1):
  475. if use_comments:
  476. a.set_comment(idx,get_comment())
  477. else:
  478. if n % 2:
  479. a.set_comment(idx,f'Test address {n}')
  480. a.file.format(add_comments=True)
  481. from mmgen.fileutil import write_data_to_file
  482. write_data_to_file(
  483. cfg,
  484. outfile = outfile,
  485. data = a.file.fmt_data,
  486. quiet = True,
  487. ignore_opt_outdir = True )
  488. end_silence()
  489. def setup(self):
  490. stop_test_daemons(self.proto.network_id,force=True,remove_datadir=True)
  491. from shutil import rmtree
  492. try:
  493. rmtree(joinpath(self.tr.data_dir,'regtest'))
  494. except:
  495. pass
  496. t = self.spawn(
  497. 'mmgen-regtest',
  498. (['--bdb-wallet'] if self.use_bdb_wallet else [])
  499. + ['--setup-no-stop-daemon', 'setup'])
  500. for s in ('Starting','Creating','Creating','Creating','Mined','Setup complete'):
  501. t.expect(s)
  502. return t
  503. def daemon_version(self):
  504. t = self.spawn('mmgen-tool', ['--bob','daemon_version'])
  505. t.expect('version')
  506. return t
  507. def halving_calculator_bob(self):
  508. t = self.spawn('halving-calculator.py',['--bob'],cmd_dir='examples')
  509. t.expect('time until halving')
  510. return t
  511. def walletgen(self,user):
  512. t = self.spawn('mmgen-walletgen',['-q','-r0','-p1','--'+user])
  513. t.passphrase_new('new '+dfl_wcls.desc,rt_pw)
  514. t.label()
  515. t.expect('move it to the data directory? (Y/n): ','y')
  516. t.written_to_file(capfirst(dfl_wcls.desc))
  517. return t
  518. def walletgen_bob(self):
  519. return self.walletgen('bob')
  520. def walletgen_alice(self):
  521. return self.walletgen('alice')
  522. def _user_dir(self,user,coin=None):
  523. return joinpath(self.tr.data_dir,'regtest',coin or self.proto.coin.lower(),user)
  524. def _user_sid(self,user):
  525. if user in self.user_sids:
  526. return self.user_sids[user]
  527. else:
  528. self.user_sids[user] = os.path.basename(get_file_with_ext(self._user_dir(user),'mmdat'))[:8]
  529. return self.user_sids[user]
  530. def _get_user_subsid(self,user,subseed_idx):
  531. fn = get_file_with_ext(self._user_dir(user),dfl_wcls.ext)
  532. silence()
  533. w = Wallet( cfg, fn=fn, passwd_file=os.path.join(self.tmpdir,'wallet_password') )
  534. end_silence()
  535. return w.seed.subseed(subseed_idx).sid
  536. def addrgen(
  537. self,
  538. user,
  539. wf = None,
  540. addr_range = '1-5',
  541. subseed_idx = None,
  542. mmtypes = []):
  543. from mmgen.addr import MMGenAddrType
  544. for mmtype in mmtypes or self.proto.mmtypes:
  545. t = self.spawn(
  546. 'mmgen-addrgen',
  547. ['--quiet','--'+user,'--type='+mmtype,f'--outdir={self._user_dir(user)}'] +
  548. ([wf] if wf else []) +
  549. (['--subwallet='+subseed_idx] if subseed_idx else []) +
  550. [addr_range],
  551. extra_desc = '({})'.format( MMGenAddrType.mmtypes[mmtype].name ))
  552. t.passphrase(dfl_wcls.desc,rt_pw)
  553. t.written_to_file('Addresses')
  554. ok_msg()
  555. t.skip_ok = True
  556. return t
  557. def addrgen_bob(self):
  558. return self.addrgen('bob')
  559. def addrgen_alice(self):
  560. return self.addrgen('alice')
  561. def addrimport(
  562. self,
  563. user,
  564. sid = None,
  565. addr_range = '1-5',
  566. num_addrs = 5,
  567. mmtypes = [],
  568. batch = True,
  569. quiet = True):
  570. id_strs = { 'legacy':'', 'compressed':'-C', 'segwit':'-S', 'bech32':'-B' }
  571. if not sid:
  572. sid = self._user_sid(user)
  573. from mmgen.addr import MMGenAddrType
  574. for mmtype in mmtypes or self.proto.mmtypes:
  575. desc = MMGenAddrType.mmtypes[mmtype].name
  576. addrfile = joinpath(self._user_dir(user),
  577. '{}{}{}[{}]{x}.regtest.addrs'.format(
  578. sid,self.altcoin_pfx,id_strs[desc],addr_range,
  579. x='-α' if cfg.debug_utf8 else ''))
  580. if mmtype == self.proto.mmtypes[0] and user == 'bob':
  581. self._add_comments_to_addr_file(addrfile,addrfile,use_comments=True)
  582. t = self.spawn(
  583. 'mmgen-addrimport',
  584. args = (
  585. (['--quiet'] if quiet else []) +
  586. ['--'+user] +
  587. (['--batch'] if batch else []) +
  588. [addrfile] ),
  589. extra_desc = f'({desc})' )
  590. if cfg.debug:
  591. t.expect("Type uppercase 'YES' to confirm: ",'YES\n')
  592. t.expect('Importing')
  593. if batch:
  594. t.expect(f'{num_addrs} addresses imported')
  595. else:
  596. t.expect('import completed OK')
  597. t.ok()
  598. t.skip_ok = True
  599. return t
  600. def addrimport_bob(self):
  601. return self.addrimport('bob')
  602. def addrimport_alice(self):
  603. return self.addrimport('alice',batch=False,quiet=False)
  604. async def bob_import_miner_addr(self):
  605. if not self.deterministic:
  606. return 'skip'
  607. return self.spawn(
  608. 'mmgen-addrimport',
  609. [ '--bob', '--rescan', '--quiet', f'--address={await self.rt.miner_addr}' ] )
  610. async def fund_wallet_deterministic(self, addr, utxo_nums, skip_passphrase=False):
  611. """
  612. the deterministic funding method using specific inputs
  613. """
  614. if not self.deterministic:
  615. return 'skip'
  616. self.write_to_tmpfile('miner.key',f'{await self.rt.miner_wif}\n')
  617. keyfile = joinpath(self.tmpdir,'miner.key')
  618. return self.user_txdo(
  619. 'bob', '40s',
  620. [ f'{addr},{rtFundAmt}', self.burn_addr ],
  621. utxo_nums,
  622. extra_args = [f'--keys-from-file={keyfile}'],
  623. skip_passphrase = skip_passphrase )
  624. def fund_bob_deterministic(self):
  625. return self.fund_wallet_deterministic( f'{self._user_sid("bob")}:C:1', '1-11' )
  626. def fund_alice_deterministic(self):
  627. sid = self._user_sid('alice')
  628. mmtype = ('L','S')[self.proto.cap('segwit')]
  629. addr = self.get_addr_from_addrlist('alice',sid,mmtype,0,addr_range='1-5')
  630. return self.fund_wallet_deterministic( addr, '1-11', skip_passphrase=True )
  631. def generate_extra_deterministic(self):
  632. if not self.deterministic:
  633. return 'skip'
  634. return self.generate(num_blocks=2) # do this so block count matches non-deterministic run
  635. async def bob_recreate_tracking_wallet(self):
  636. if not self.deterministic:
  637. return 'skip'
  638. self.spawn('',msg_only=True)
  639. await self.rt.stop()
  640. from shutil import rmtree
  641. imsg('Deleting Bob’s old tracking wallet')
  642. rmtree(os.path.join(self.rt.d.datadir, 'regtest', 'wallets', 'bob'), ignore_errors=True)
  643. self.rt.init_daemon()
  644. self.rt.d.start(silent=True)
  645. imsg('Creating Bob’s new tracking wallet')
  646. await self.rt.create_wallet('bob')
  647. await self.rt.stop()
  648. await self.rt.start()
  649. return 'ok'
  650. def addrimport_bob2(self):
  651. if not self.deterministic:
  652. return 'skip'
  653. return self.addrimport('bob')
  654. def fund_wallet(self,user,mmtype,amt,sid=None,addr_range='1-5'):
  655. if self.deterministic:
  656. return 'skip'
  657. if not sid:
  658. sid = self._user_sid(user)
  659. addr = self.get_addr_from_addrlist(user,sid,mmtype,0,addr_range=addr_range)
  660. t = self.spawn('mmgen-regtest', ['send',str(addr),str(amt)])
  661. t.expect(f'Sending {amt} miner {self.proto.coin}')
  662. t.expect('Mined 1 block')
  663. return t
  664. def fund_bob(self):
  665. return self.fund_wallet('bob','C',rtFundAmt)
  666. def fund_alice(self):
  667. return self.fund_wallet('alice',('L','S')[self.proto.cap('segwit')],rtFundAmt)
  668. def user_twview(self, user, chk=None, expect=None, cmdline=['twview'], sort='age', exit_val=None):
  669. t = self.spawn('mmgen-tool',[f'--{user}'] + cmdline + ['sort='+sort], exit_val=exit_val)
  670. if chk:
  671. t.expect(r'{}\b.*\D{}\b'.format(*chk),regex=True)
  672. if expect:
  673. t.expect(expect)
  674. return t
  675. def bob_twview_noaddrs(self):
  676. return self.user_twview('bob', expect='No spendable', exit_val=1)
  677. def bob_listaddrs_noaddrs(self):
  678. return self.user_twview('bob', cmdline=['listaddresses'], expect='No addresses', exit_val=1)
  679. def bob_twview_nobal(self):
  680. return self.user_twview('bob', expect='No spendable', exit_val=1)
  681. def bob_listaddrs_nobal(self):
  682. return self.user_twview('bob', cmdline=['listaddresses'], expect='TOTAL:')
  683. def bob_twview1(self):
  684. return self.user_twview('bob', chk = ('1',rtAmts[0]) )
  685. def user_bal(self,user,bal,args=['showempty=1'],skip_check=False):
  686. t = self.spawn('mmgen-tool',['--'+user,'listaddresses'] + args)
  687. if not skip_check:
  688. cmp_or_die(f'{bal} {self.proto.coin}',strip_ansi_escapes(t.expect_getend('TOTAL: ')))
  689. return t
  690. def alice_bal1(self):
  691. return self.user_bal('alice',rtFundAmt)
  692. def alice_bal2(self):
  693. return self.user_bal('alice',rtBals[8])
  694. def bob_bal1(self):
  695. return self.user_bal('bob',rtFundAmt)
  696. def bob_bal2(self):
  697. return self.user_bal('bob',rtBals[0])
  698. def bob_bal2a(self):
  699. return self.user_bal('bob',rtBals[0],args=['showempty=1','age_fmt=confs'])
  700. def bob_bal2b(self):
  701. return self.user_bal('bob',rtBals[0],args=['showempty=1'])
  702. def bob_bal2c(self):
  703. return self.user_bal('bob',rtBals[0],args=['showempty=1','minconf=2','age_fmt=days'],skip_check=True)
  704. def bob_bal2d(self):
  705. return self.user_bal('bob',rtBals[0],args=['minconf=2'],skip_check=True)
  706. def bob_bal2e(self):
  707. return self.user_bal('bob',rtBals[0],args=['showempty=1','sort=amt'])
  708. def bob_bal2f(self):
  709. return self.user_bal('bob',rtBals[0],args=['showempty=0','sort=twmmid','reverse=1'])
  710. def bob_bal3(self):
  711. return self.user_bal('bob',rtBals[1])
  712. def bob_bal4(self):
  713. return self.user_bal('bob',rtBals[2])
  714. def bob_bal5(self):
  715. return self.user_bal('bob',rtBals[3])
  716. def bob_bal6(self):
  717. return self.user_bal('bob',rtBals[7])
  718. def bob_subwallet_addrgen1(self):
  719. return self.addrgen('bob',subseed_idx='29L',mmtypes=['C']) # 29L: 2FA7BBA8
  720. def bob_subwallet_addrgen2(self):
  721. return self.addrgen('bob',subseed_idx='127S',mmtypes=['C']) # 127S: '09E8E286'
  722. def subwallet_addrimport(self,user,subseed_idx):
  723. sid = self._get_user_subsid(user,subseed_idx)
  724. return self.addrimport(user,sid=sid,mmtypes=['C'])
  725. def bob_subwallet_addrimport1(self):
  726. return self.subwallet_addrimport('bob','29L')
  727. def bob_subwallet_addrimport2(self):
  728. return self.subwallet_addrimport('bob','127S')
  729. def bob_subwallet_fund(self):
  730. sid1 = self._get_user_subsid('bob','29L')
  731. sid2 = self._get_user_subsid('bob','127S')
  732. chg_addr = self._user_sid('bob') + (':B:1',':L:1')[self.proto.coin=='BCH']
  733. return self.user_txdo(
  734. user = 'bob',
  735. fee = rtFee[1],
  736. outputs_cl = [sid1+':C:2,0.29',sid2+':C:3,0.127',chg_addr],
  737. outputs_list = ('3','1')[self.proto.coin=='BCH'],
  738. extra_args = ['--subseeds=127'],
  739. used_chg_addr_resp = (None,'y')[self.proto.coin=='BCH'] )
  740. def bob_twview2(self):
  741. sid1 = self._get_user_subsid('bob','29L')
  742. return self.user_twview('bob',chk=(sid1+':C:2','0.29'),sort='twmmid')
  743. def bob_twview3(self):
  744. sid2 = self._get_user_subsid('bob','127S')
  745. return self.user_twview('bob',chk=(sid2+':C:3','0.127'),sort='amt')
  746. def bob_subwallet_txcreate(self):
  747. sid1 = self._get_user_subsid('bob','29L')
  748. sid2 = self._get_user_subsid('bob','127S')
  749. outputs_cl = [sid1+':C:5,0.0159',sid2+':C:5']
  750. t = self.spawn('mmgen-txcreate',['-d',self.tmpdir,'-B','--bob'] + outputs_cl)
  751. return self.txcreate_ui_common(t,
  752. menu = ['a'],
  753. inputs = ('1,2','2,3')[self.proto.coin=='BCH'],
  754. interactive_fee = '0.00001')
  755. def bob_subwallet_txsign(self):
  756. fn = get_file_with_ext(self.tmpdir,'rawtx')
  757. t = self.spawn('mmgen-txsign',['-d',self.tmpdir,'--bob','--subseeds=127',fn])
  758. t.view_tx('t')
  759. t.passphrase(dfl_wcls.desc,rt_pw)
  760. t.do_comment(None)
  761. t.expect('(Y/n): ','y')
  762. t.written_to_file('Signed transaction')
  763. return t
  764. def bob_subwallet_txdo(self):
  765. outputs_cl = [self._user_sid('bob')+':L:5']
  766. inputs = ('1,2','2,3')[self.proto.coin=='BCH']
  767. return self.user_txdo('bob',rtFee[5],outputs_cl,inputs,menu=['a'],extra_args=['--subseeds=127']) # sort: amt
  768. def bob_twview4(self):
  769. sid = self._user_sid('bob')
  770. return self.user_twview('bob',chk=(sid+':L:5',rtBals[9]),sort='twmmid')
  771. def user_txhist(self,user,args,expect):
  772. t = self.spawn('mmgen-tool',['--'+user,'txhist'] + args)
  773. m = re.search( expect, t.read(strip_color=True), re.DOTALL )
  774. assert m, f'Expected: {expect}'
  775. return t
  776. def bob_txhist1(self):
  777. return self.user_txhist('bob',
  778. args = ['sort=age'],
  779. expect = fr'\s1\).*\s{rtFundAmt}\s' )
  780. def bob_txhist2(self):
  781. return self.user_txhist('bob',
  782. args = ['sort=blockheight','reverse=1','age_fmt=block'],
  783. expect = fr'\s1\).*:{self.dfl_mmtype}:1\s' )
  784. def bob_txhist3(self):
  785. return self.user_txhist('bob',
  786. args = ['sort=blockheight','sinceblock=-7','age_fmt=block'],
  787. expect = fr'Displaying transactions since block 399.*\s6\)\s+405\s.*\s{rtBals[9]}\s.*:L:5.*\s7\)'
  788. )
  789. def bob_txhist4(self):
  790. return self.user_txhist('bob',
  791. args = ['sort=blockheight','age_fmt=block','detail=1'],
  792. expect = fr'Block:.*406.*Value:.*{rtBals[10]}'
  793. )
  794. def bob_txhist5(self):
  795. return self.user_txhist('bob',
  796. args = ['sort=blockheight','sinceblock=399','age_fmt=block','detail=1'],
  797. expect = fr'Displaying transactions since block 399.*\s7\).*Block:.*406.*Value:.*{rtBals[10]}'
  798. )
  799. def bob_txhist_interactive(self):
  800. self.get_file_with_ext('out',delete_all=True)
  801. t = self.spawn('mmgen-tool',
  802. ['--bob',f'--outdir={self.tmpdir}','txhist','age_fmt=date_time','interactive=true'] )
  803. for resp in ('u','i','t','a','m','T','A','r','r','D','D','D','D','p','P','n','V'):
  804. t.expect('draw:\b',resp,regex=True)
  805. if t.pexpect_spawn:
  806. t.expect(r'Block:.*394',regex=True)
  807. time.sleep(1)
  808. t.send('q')
  809. time.sleep(0.2)
  810. t.send('n')
  811. t.expect('draw:\b','q',regex=True)
  812. else:
  813. txnum,idx = (8,1) if self.proto.coin == 'BCH' else (9,3)
  814. t.expect(rf'\s{txnum}\).*Inputs:.*:L:{idx}.*Outputs \(3\):.*:C:2.*\s10\)','q',regex=True)
  815. return t
  816. def bob_getbalance(self,bals,confs=1):
  817. for i in range(len(bals['mmgen'])):
  818. assert Decimal(bals['mmgen'][i]) + Decimal(bals['nonmm'][i]) == Decimal(bals['total'][i])
  819. sid = self._user_sid('bob')
  820. t = self.spawn('mmgen-tool',['--bob','getbalance',f'minconf={confs}'])
  821. t.expect('Wallet')
  822. for k,lbl in (
  823. ('mmgen',f'{sid}:'),
  824. ('nonmm','Non-MMGen:'),
  825. ('total',f'TOTAL {self.proto.coin}')
  826. ):
  827. ret = strip_ansi_escapes(t.expect_getend(lbl + ' '))
  828. cmp_or_die(
  829. ' '.join(bals[k]),
  830. ' '.join(ret.split()),
  831. desc = k,
  832. )
  833. return t
  834. def bob_0conf0_getbalance(self):
  835. return self.bob_getbalance(rtBals_gb['0conf0'],confs=0)
  836. def bob_0conf1_getbalance(self):
  837. return self.bob_getbalance(rtBals_gb['0conf1'],confs=1)
  838. def bob_1conf1_getbalance(self):
  839. return self.bob_getbalance(rtBals_gb['1conf1'],confs=1)
  840. def bob_1conf2_getbalance(self):
  841. return self.bob_getbalance(rtBals_gb['1conf2'],confs=2)
  842. def bob_nochg_burn(self):
  843. return self.user_txdo('bob',
  844. fee = '0.00009713',
  845. outputs_cl = [self.burn_addr],
  846. outputs_list = '1' )
  847. def bob_alice_bal(self):
  848. t = self.spawn('mmgen-regtest',['balances'])
  849. ret = t.expect_getend("Bob's balance:").strip()
  850. cmp_or_die(rtBals[4],ret)
  851. ret = t.expect_getend("Alice's balance:").strip()
  852. cmp_or_die(rtBals[5],ret)
  853. ret = t.expect_getend("Total balance:").strip()
  854. cmp_or_die(rtBals[6],ret)
  855. return t
  856. def user_txsend_status(
  857. self,
  858. user,
  859. tx_file,
  860. exp1 = '',
  861. exp2 = '',
  862. extra_args = [],
  863. exit_val = None):
  864. t = self.spawn(
  865. 'mmgen-txsend',
  866. ['-d', self.tmpdir, '--'+user, '--status'] + extra_args + [tx_file],
  867. exit_val = exit_val)
  868. if exp1:
  869. t.expect(exp1,regex=True)
  870. if exp2:
  871. t.expect(exp2,regex=True)
  872. if self.deterministic:
  873. imsg(
  874. 'DETERMINISTIC TESTING NOTE:\n '
  875. 'output of mmgen-txsend --status cannot be made deterministic, as it uses '
  876. 'gettransaction’s ‘timereceived’ field')
  877. return t
  878. def user_txdo(
  879. self,
  880. user,
  881. fee,
  882. outputs_cl,
  883. outputs_list,
  884. extra_args = [],
  885. wf = None,
  886. add_comment = tx_comment_jp,
  887. return_early = False,
  888. return_after_send = False,
  889. menu = ['M'],
  890. skip_passphrase = False,
  891. used_chg_addr_resp = None,
  892. exit_val = None):
  893. t = self.spawn(
  894. 'mmgen-txdo',
  895. ['-d',self.tmpdir,'-B','--'+user]
  896. + (['--fee='+fee] if fee else [])
  897. + extra_args
  898. + ([],[wf])[bool(wf)]
  899. + outputs_cl,
  900. exit_val = exit_val)
  901. self.txcreate_ui_common(
  902. t,
  903. caller = 'txdo',
  904. menu = menu,
  905. inputs = outputs_list,
  906. file_desc = 'Signed transaction',
  907. interactive_fee = (tx_fee,'')[bool(fee)],
  908. add_comment = add_comment,
  909. return_early = return_early,
  910. view = 't',
  911. save = True,
  912. used_chg_addr_resp = used_chg_addr_resp)
  913. if return_early:
  914. return t
  915. if not skip_passphrase:
  916. t.passphrase(dfl_wcls.desc,rt_pw)
  917. t.written_to_file('Signed transaction')
  918. self._do_confirm_send(t)
  919. if return_after_send:
  920. return t
  921. t.expect('Transaction sent')
  922. return t
  923. def bob_split1(self):
  924. sid = self._user_sid('bob')
  925. outputs_cl = [sid+':C:1,100', sid+':L:2,200',sid+':'+rtBobOp3]
  926. return self.user_txdo('bob',rtFee[0],outputs_cl,'1',extra_args=['--locktime=500000001'])
  927. def get_addr_from_addrlist(self,user,sid,mmtype,idx,addr_range='1-5'):
  928. id_str = { 'L':'', 'S':'-S', 'C':'-C', 'B':'-B' }[mmtype]
  929. ext = '{}{}{}[{}]{x}.regtest.addrs'.format(
  930. sid,self.altcoin_pfx,id_str,addr_range,x='-α' if cfg.debug_utf8 else '')
  931. addrfile = get_file_with_ext(self._user_dir(user),ext,no_dot=True)
  932. silence()
  933. addr = AddrList( cfg, self.proto, addrfile ).data[idx].addr
  934. end_silence()
  935. return addr
  936. def _create_tx_outputs(self,user,data):
  937. sid = self._user_sid(user)
  938. return [self.get_addr_from_addrlist(user,sid,mmtype,idx-1)+amt_str for mmtype,idx,amt_str in data]
  939. def bob_rbf_1output_create(self):
  940. if not self.test_rbf:
  941. return 'skip'
  942. out_addr = self._create_tx_outputs('alice',(('B',5,''),))
  943. t = self.spawn('mmgen-txcreate',['-d',self.tr.trash_dir,'-B','--bob'] + out_addr)
  944. return self.txcreate_ui_common(t,menu=[],inputs='3',interactive_fee='3s') # out amt: 199.99999343
  945. def bob_rbf_1output_bump(self):
  946. if not self.test_rbf:
  947. return 'skip'
  948. ext = '9343,3]{x}.regtest.rawtx'.format(x='-α' if cfg.debug_utf8 else '')
  949. txfile = get_file_with_ext(self.tr.trash_dir,ext,delete=False,no_dot=True)
  950. return self.user_txbump('bob',
  951. self.tr.trash_dir,
  952. txfile,
  953. '8s',
  954. has_label = False,
  955. signed_tx = False,
  956. one_output = True )
  957. def bob_send_maybe_rbf(self):
  958. outputs_cl = self._create_tx_outputs('alice',(('L',1,',60'),('C',1,',40')))
  959. outputs_cl += [self._user_sid('bob')+':'+rtBobOp3]
  960. return self.user_txdo(
  961. user = 'bob',
  962. fee = rtFee[1],
  963. outputs_cl = outputs_cl, # alice_sid:L:1,60, alice_sid:C:1,40
  964. outputs_list = '3',
  965. extra_args = [] if self.proto.cap('rbf') else ['--no-rbf'],
  966. used_chg_addr_resp = 'y')
  967. def bob_send_non_mmgen(self):
  968. keyfile = joinpath(self.tmpdir,'non-mmgen.keys')
  969. atype = 'S' if self.proto.cap('segwit') else 'L'
  970. outputs_cl = self._create_tx_outputs('alice',((atype, 2, ', 10'), (atype, 3, '')))
  971. return self.user_txdo(
  972. user = 'bob',
  973. fee = rtFee[3],
  974. outputs_cl = outputs_cl, # alice_sid:S:2,10, alice_sid:S:3
  975. outputs_list = '1,4-10',
  976. extra_args = [f'--keys-from-file={keyfile}', '--vsize-adj=1.02'])
  977. def alice_send_estimatefee(self):
  978. outputs_cl = self._create_tx_outputs('bob',(('L',1,''),)) # bob_sid:L:1
  979. return self.user_txdo('alice',None,outputs_cl,'1') # fee=None
  980. def user_txbump(
  981. self,
  982. user,
  983. outdir,
  984. txfile,
  985. fee,
  986. add_args = [],
  987. has_label = True,
  988. signed_tx = True,
  989. one_output = False):
  990. if not self.proto.cap('rbf'):
  991. return 'skip'
  992. t = self.spawn('mmgen-txbump',
  993. ['-d',outdir,'--'+user,'--fee='+fee,'--output-to-reduce=c'] + add_args + [txfile])
  994. if not one_output:
  995. t.expect('OK? (Y/n): ','y') # output OK?
  996. t.expect('OK? (Y/n): ','y') # fee OK?
  997. t.do_comment(False,has_label=has_label)
  998. if signed_tx:
  999. t.passphrase(dfl_wcls.desc,rt_pw)
  1000. t.written_to_file('Signed transaction')
  1001. self.txsend_ui_common(t,caller='txdo',bogus_send=False,file_desc='Signed transaction')
  1002. else:
  1003. t.expect('Save fee-bumped transaction? (y/N): ','y')
  1004. t.written_to_file('Fee-bumped transaction')
  1005. return t
  1006. def bob_rbf_bump(self):
  1007. ext = ',{}]{x}.regtest.sigtx'.format(rtFee[1][:-1],x='-α' if cfg.debug_utf8 else '')
  1008. txfile = self.get_file_with_ext(ext,delete=False,no_dot=True)
  1009. return self.user_txbump('bob',self.tmpdir,txfile,rtFee[2],add_args=['--send'])
  1010. def generate(self,num_blocks=1):
  1011. int(num_blocks)
  1012. t = self.spawn('mmgen-regtest',['generate',str(num_blocks)])
  1013. t.expect(f'Mined {num_blocks} block')
  1014. return t
  1015. def _get_mempool(self):
  1016. ret = self.spawn(
  1017. 'mmgen-regtest',
  1018. ['mempool'],
  1019. env = os.environ if cfg.debug_utf8 else get_env_without_debug_vars(),
  1020. ).read()
  1021. m = re.search(r'(\[\s*"[a-f0-9]{64}"\s*])',ret) # allow for extra output by handler at end
  1022. return json.loads(m.group(1))
  1023. def get_mempool1(self):
  1024. mp = self._get_mempool()
  1025. if len(mp) != 1:
  1026. die(4,'Mempool has more or less than one TX!')
  1027. self.write_to_tmpfile('rbf_txid',mp[0]+'\n')
  1028. return 'ok'
  1029. def bob_rbf_status(self, fee, exp1, exp2='', exit_val=None):
  1030. if not self.proto.cap('rbf'):
  1031. return 'skip'
  1032. ext = ',{}]{x}.regtest.sigtx'.format(fee[:-1],x='-α' if cfg.debug_utf8 else '')
  1033. txfile = self.get_file_with_ext(ext,delete=False,no_dot=True)
  1034. return self.user_txsend_status('bob', txfile, exp1, exp2, exit_val=exit_val)
  1035. def bob_rbf_status1(self):
  1036. if not self.proto.cap('rbf'):
  1037. return 'skip'
  1038. return self.bob_rbf_status(rtFee[1],'in mempool, replaceable')
  1039. def get_mempool2(self):
  1040. if not self.proto.cap('rbf'):
  1041. return 'skip'
  1042. mp = self._get_mempool()
  1043. if len(mp) != 1:
  1044. die(4,'Mempool has more or less than one TX!')
  1045. chk = self.read_from_tmpfile('rbf_txid')
  1046. if chk.strip() == mp[0]:
  1047. die(4,'TX in mempool has not changed! RBF bump failed')
  1048. self.write_to_tmpfile('rbf_txid2',mp[0]+'\n')
  1049. return 'ok'
  1050. def bob_rbf_status2(self):
  1051. if not self.proto.cap('rbf'):
  1052. return 'skip'
  1053. new_txid = self.read_from_tmpfile('rbf_txid2').strip()
  1054. return self.bob_rbf_status(
  1055. rtFee[1],
  1056. 'Transaction has been replaced',
  1057. f'{new_txid} in mempool',
  1058. exit_val = 0)
  1059. def bob_rbf_status3(self):
  1060. if not self.proto.cap('rbf'):
  1061. return 'skip'
  1062. return self.bob_rbf_status(rtFee[2],'status: in mempool, replaceable')
  1063. def bob_rbf_status4(self):
  1064. if not self.proto.cap('rbf'):
  1065. return 'skip'
  1066. new_txid = self.read_from_tmpfile('rbf_txid2').strip()
  1067. return self.bob_rbf_status(rtFee[1],
  1068. 'Replacement transaction has 1 confirmation',
  1069. rf'Replacing transactions:\s+{new_txid}' )
  1070. def bob_rbf_status5(self):
  1071. if not self.proto.cap('rbf'):
  1072. return 'skip'
  1073. return self.bob_rbf_status(rtFee[2],'Transaction has 1 confirmation')
  1074. def bob_rbf_status6(self):
  1075. if not self.proto.cap('rbf'):
  1076. return 'skip'
  1077. new_txid = self.read_from_tmpfile('rbf_txid2').strip()
  1078. return self.bob_rbf_status(rtFee[1],
  1079. 'Replacement transaction has 2 confirmations',
  1080. rf'Replacing transactions:\s+{new_txid}' )
  1081. def _gen_pairs(self,n):
  1082. from mmgen.tool.api import tool_api
  1083. t = tool_api(cfg)
  1084. t.init_coin(self.proto.coin,self.proto.network)
  1085. def gen_addr(Type):
  1086. t.addrtype = Type
  1087. wif = t.hex2wif(getrandhex(32))
  1088. return ( wif, t.wif2addr(wif) )
  1089. return [gen_addr('legacy')] + [gen_addr('compressed') for i in range(n-1)]
  1090. def bob_pre_import(self):
  1091. pairs = self._gen_pairs(5)
  1092. self.write_to_tmpfile('non-mmgen.keys','\n'.join([a[0] for a in pairs])+'\n')
  1093. self.write_to_tmpfile('non-mmgen.addrs','\n'.join([a[1] for a in pairs])+'\n')
  1094. return self.user_txdo('bob',rtFee[4],[pairs[0][1]],'3')
  1095. def user_import(self,user,args,nAddr):
  1096. t = self.spawn('mmgen-addrimport',['--'+user]+args)
  1097. if cfg.debug:
  1098. t.expect("Type uppercase 'YES' to confirm: ",'YES\n')
  1099. t.expect(f'Importing {nAddr} address')
  1100. if '--rescan' in args:
  1101. if not '--quiet' in args:
  1102. t.expect('Continue? (Y/n): ','y')
  1103. t.expect('Rescanning block')
  1104. return t
  1105. def bob_import_addr(self):
  1106. addr = self.read_from_tmpfile('non-mmgen.addrs').split()[0]
  1107. return self.user_import('bob',['--quiet','--address='+addr],nAddr=1)
  1108. def bob_import_list_rescan_aio(self):
  1109. addrfile = joinpath(self.tmpdir,'non-mmgen.addrs')
  1110. return self.user_import('bob',['--rescan','--rpc-backend=aio','--addrlist',addrfile],nAddr=5)
  1111. def bob_resolve_addr(self):
  1112. mmaddr = '{}:C:1'.format(self._user_sid('bob'))
  1113. t = self.spawn('mmgen-tool',['--bob','resolve_address',mmaddr])
  1114. coinaddr = re.search(r'[0-9A-Za-z]{30,}', t.read())[0]
  1115. t = self.spawn('mmgen-tool',['--bob','resolve_address',coinaddr],no_msg=True)
  1116. mmaddr_res = re.search(r'[0-9A-F]{8}:C:1', t.read())[0]
  1117. assert mmaddr == mmaddr_res, f'{mmaddr} != {mmaddr_res}'
  1118. return t
  1119. def bob_import_list(self):
  1120. addrfile = joinpath(self.tmpdir,'non-mmgen.addrs')
  1121. return self.user_import('bob',['--quiet','--addrlist',addrfile],nAddr=5)
  1122. def bob_import_list_rescan(self):
  1123. addrfile = joinpath(self.tmpdir,'non-mmgen.addrs')
  1124. return self.user_import('bob',['--quiet','--rescan','--addrlist',addrfile],nAddr=5)
  1125. def bob_rescan_addr(self):
  1126. sid = self._user_sid('bob')
  1127. t = self.spawn('mmgen-tool',['--bob','rescan_address',f'{sid}:C:1'])
  1128. t.expect('Found 1 unspent output')
  1129. t.expect('updated successfully')
  1130. return t
  1131. def _usr_rescan_blockchain(self,user,add_args,expect=None):
  1132. t = self.spawn('mmgen-tool',[f'--{user}','rescan_blockchain'] + add_args)
  1133. if expect:
  1134. t.expect(f'Scanning blocks {expect}')
  1135. t.expect('Done')
  1136. return t
  1137. def bob_rescan_blockchain_all(self):
  1138. return self._usr_rescan_blockchain('bob',[],'300-396')
  1139. def bob_rescan_blockchain_gb(self):
  1140. return self._usr_rescan_blockchain('bob',['start_block=0','stop_block=0'],'0-0')
  1141. def bob_rescan_blockchain_one(self):
  1142. return self._usr_rescan_blockchain('bob',['start_block=300','stop_block=300'],'300-300')
  1143. def bob_rescan_blockchain_ss(self):
  1144. return self._usr_rescan_blockchain('bob',['start_block=300','stop_block=302'],'300-302')
  1145. def bob_twexport(self,add_args=[]):
  1146. t = self.spawn('mmgen-tool',['--bob',f'--outdir={self.tmpdir}','twexport'] + add_args)
  1147. t.written_to_file('JSON data')
  1148. return t
  1149. def bob_twexport_noamt(self):
  1150. return self.bob_twexport(add_args=['include_amts=0'])
  1151. def bob_twexport_pretty(self):
  1152. return self.bob_twexport(add_args=['pretty=1'])
  1153. def _bob_twprune(
  1154. self,
  1155. prune_spec,
  1156. npruned,
  1157. expect_menu = (),
  1158. expect = (),
  1159. expect2 = (),
  1160. warn_used = False,
  1161. non_segwit_ok = False):
  1162. if not (non_segwit_ok or self.proto.cap('segwit')):
  1163. return 'skip'
  1164. t = self.spawn(
  1165. 'mmgen-tool',
  1166. ['--bob',f'--outdir={self.tr.trash_dir}','twexport','prune=1']
  1167. + (['warn_used=1'] if warn_used else []) )
  1168. for s in expect_menu:
  1169. t.expect('prune list:\b',s)
  1170. t.expect('prune list:\b','p')
  1171. t.expect('addresses to prune: ',f'{prune_spec}\n')
  1172. for p,s in expect:
  1173. t.expect(p,s,regex=True)
  1174. t.expect('prune list:\b','q')
  1175. for p,s in expect2:
  1176. t.expect(p,s,regex=True)
  1177. if npruned:
  1178. t.expect(f'Pruned {npruned} addresses')
  1179. taddr = 35 if self.proto.cap('segwit') else 25
  1180. t.expect(f'Exporting {taddr-npruned} addresses')
  1181. t.written_to_file('JSON data')
  1182. return t
  1183. def bob_twprune_noask(self):
  1184. return self._bob_twprune(
  1185. expect_menu = 'a', # sort by amt to make address order deterministic
  1186. prune_spec = '35,12,18,3-5',
  1187. npruned = 6 )
  1188. def bob_twprune_all(self):
  1189. taddr = 35 if self.proto.cap('segwit') else 25
  1190. return self._bob_twprune(
  1191. prune_spec = f'1-{taddr}',
  1192. npruned = taddr,
  1193. expect = [('all with balance: ','P')],
  1194. non_segwit_ok = True )
  1195. def bob_twprune_skip(self):
  1196. return self._bob_twprune(
  1197. prune_spec = '',
  1198. npruned = 0,
  1199. non_segwit_ok = True )
  1200. def bob_twprune_skipamt(self):
  1201. return self._bob_twprune(
  1202. prune_spec = '1-35',
  1203. npruned = 32,
  1204. expect = [('all with balance: ','S')] )
  1205. def bob_twprune_skipused(self):
  1206. return self._bob_twprune(
  1207. prune_spec = '1-35',
  1208. npruned = 18,
  1209. expect = [('all used: ','S')],
  1210. warn_used = True )
  1211. def bob_twprune_allamt(self):
  1212. return self._bob_twprune(
  1213. prune_spec = '1-35',
  1214. npruned = 35,
  1215. expect = [('all with balance: ','P')],
  1216. expect2 = [('Warning: pruned address .* has a balance',None)] )
  1217. def bob_twprune_allused(self):
  1218. return self._bob_twprune(
  1219. prune_spec = '1-35',
  1220. npruned = 32,
  1221. expect = [('all used: ','P'),('all with balance: ','S')],
  1222. expect2 = [('Warning: pruned address .* used',None)],
  1223. warn_used = True )
  1224. @property
  1225. def _b_start(self):
  1226. """
  1227. SIDs sort non-deterministically, so we must search for start of main (not subseeds) group, i.e. ':B:1'
  1228. """
  1229. assert self.proto.cap('segwit')
  1230. if not hasattr(self,'_b_start_'):
  1231. t = self.spawn( 'mmgen-tool', ['--color=0','--bob','listaddresses'], no_msg=True )
  1232. self._b_start_ = int([e for e in t.read().split('\n') if ':B:1' in e][0].split()[0].rstrip(')'))
  1233. t.close()
  1234. return self._b_start_
  1235. def _bob_twprune_selected(self,resp,npruned):
  1236. if not self.proto.cap('segwit'):
  1237. return 'skip'
  1238. B = self._b_start
  1239. a,b,c,d,e,f = resp
  1240. return self._bob_twprune(
  1241. expect_menu = 'a', # sort by amt to make address order deterministic
  1242. prune_spec = f'31-32,{B+14},{B+9},{B}-{B+4}',
  1243. npruned = npruned,
  1244. expect = [
  1245. ('all used: ', a),
  1246. ('all used: ', b),
  1247. ('all with balance: ', c),
  1248. ('all with balance: ', d),
  1249. ('all used: ', e),
  1250. ('all used: ', f),
  1251. ],
  1252. warn_used = True )
  1253. def bob_twprune1(self):
  1254. return self._bob_twprune_selected(resp='sssssS',npruned=3)
  1255. def bob_twprune2(self):
  1256. return self._bob_twprune_selected(resp='sppPsS',npruned=3)
  1257. def bob_twprune3(self):
  1258. return self._bob_twprune_selected(resp='sssPpS',npruned=3)
  1259. def bob_twprune4(self):
  1260. return self._bob_twprune_selected(resp='sssPpP',npruned=9)
  1261. def bob_twprune5(self):
  1262. return self._bob_twprune_selected(resp='pppPpP',npruned=9)
  1263. def bob_twprune6(self):
  1264. return self._bob_twprune_selected(resp='sssSpP',npruned=7)
  1265. def bob_edit_json_twdump(self):
  1266. self.spawn('',msg_only=True)
  1267. from mmgen.tw.json import TwJSON
  1268. fn = TwJSON.Base(cfg,self.proto).dump_fn
  1269. text = json.loads(self.read_from_tmpfile(fn))
  1270. text['data']['entries'][3][3] = f'edited comment [фубар] [{gr_uc}]'
  1271. self.write_to_tmpfile( fn, json.dumps(text,indent=4) )
  1272. return 'ok'
  1273. def carol_twimport(
  1274. self,
  1275. rpc_backend = 'http',
  1276. add_parms = [],
  1277. expect_str = None,
  1278. expect_str2 = 'Found 1 unspent output'):
  1279. from mmgen.tw.json import TwJSON
  1280. fn = joinpath( self.tmpdir, TwJSON.Base(cfg,self.proto).dump_fn )
  1281. t = self.spawn(
  1282. 'mmgen-tool',
  1283. ([f'--rpc-backend={rpc_backend}'] if rpc_backend else [])
  1284. + ['--carol','twimport',fn]
  1285. + add_parms )
  1286. t.expect('(y/N): ','y')
  1287. if expect_str:
  1288. t.expect(expect_str)
  1289. elif 'batch=true' in add_parms:
  1290. t.expect('{} addresses imported'.format(10 if self.proto.coin == 'BCH' else 20))
  1291. else:
  1292. t.expect('import completed OK')
  1293. t.expect(expect_str2)
  1294. return t
  1295. def carol_twimport_nochksum(self):
  1296. return self.carol_twimport(rpc_backend=None,add_parms=['ignore_checksum=true'])
  1297. def carol_twimport_batch(self):
  1298. return self.carol_twimport(add_parms=['batch=true'])
  1299. def carol_twimport_pretty(self):
  1300. return self.carol_twimport(add_parms=['ignore_checksum=true'],expect_str='ignoring incorrect checksum')
  1301. def carol_listaddresses(self):
  1302. return self.spawn('mmgen-tool',['--carol','listaddresses','showempty=1'])
  1303. async def carol_delete_wallet(self):
  1304. imsg('Unloading Carol’s tracking wallet')
  1305. t = self.spawn('mmgen-regtest',['cli','unloadwallet','carol'])
  1306. t.ok()
  1307. wdir = joinpath((await self.rt.rpc).daemon.network_datadir, 'wallets', 'carol')
  1308. from shutil import rmtree
  1309. imsg('Deleting Carol’s tracking wallet')
  1310. rmtree(wdir)
  1311. return 'silent'
  1312. def bob_split2(self):
  1313. addrs = self.read_from_tmpfile('non-mmgen.addrs').split()
  1314. amts = (1.12345678,2.87654321,3.33443344,4.00990099,5.43214321)
  1315. outputs1 = list(map('{},{}'.format,addrs,amts))
  1316. sid = self._user_sid('bob')
  1317. l1,l2 = (
  1318. (':S',':B') if 'B' in self.proto.mmtypes else
  1319. (':S',':S') if self.proto.cap('segwit') else
  1320. (':L',':L') )
  1321. outputs2 = [sid+':C:2,6.333', sid+':L:3,6.667',sid+l1+':4,0.123',sid+l2+':5']
  1322. return self.user_txdo('bob',rtFee[5],outputs1+outputs2,'1-2')
  1323. def user_add_comment(self,user,addr,comment):
  1324. t = self.spawn('mmgen-tool',['--'+user,'add_label',addr,comment])
  1325. t.expect('Added label.*in tracking wallet',regex=True)
  1326. return t
  1327. def user_remove_comment(self,user,addr):
  1328. t = self.spawn('mmgen-tool',['--'+user,'remove_label',addr])
  1329. t.expect('Removed label.*in tracking wallet',regex=True)
  1330. return t
  1331. def bob_bad_locktime1(self):
  1332. return self._bob_bad_locktime(123456789, 'non-final', 2) # > current block height
  1333. def bob_bad_locktime2(self):
  1334. return self._bob_bad_locktime(7_000_000_000, 'invalid', 2, return_early=True) # > 4 bytes
  1335. def bob_bad_locktime3(self):
  1336. return self._bob_bad_locktime(0xffffffff, 'non-final', 2, return_early=False) # > cur time
  1337. def _bob_bad_locktime(self,locktime,expect,exit_val,return_early=False):
  1338. sid = self._user_sid('bob')
  1339. t = self.user_txdo(
  1340. user = 'bob',
  1341. fee = '20s',
  1342. outputs_cl = [self.burn_addr+',0.1', sid+':C:5'],
  1343. outputs_list = '1',
  1344. extra_args = [f'--locktime={locktime}'],
  1345. return_early = return_early,
  1346. add_comment = False,
  1347. return_after_send = True,
  1348. exit_val = exit_val)
  1349. if expect:
  1350. t.expect(expect)
  1351. return t
  1352. def bob_add_comment1(self):
  1353. sid = self._user_sid('bob')
  1354. return self.user_add_comment('bob',sid+':C:1',tw_comment_lat_cyr_gr)
  1355. def alice_add_comment1(self):
  1356. sid = self._user_sid('alice')
  1357. return self.user_add_comment('alice',sid+':C:1','Original Label - 月へ')
  1358. def alice_add_comment2(self):
  1359. sid = self._user_sid('alice')
  1360. return self.user_add_comment('alice',sid+':C:1','Replacement Label')
  1361. def _user_chk_comment(self,user,addr,comment,extra_args=[]):
  1362. t = self.spawn('mmgen-tool',['--'+user,'listaddresses','all_labels=1']+extra_args)
  1363. ret = strip_ansi_escapes(t.expect_getend(addr)).strip().split(None,2)[2]
  1364. cmp_or_die( # squeezed display, double-width chars, so truncate to min field width
  1365. ret[:3].strip(),
  1366. comment[:3].strip())
  1367. return t
  1368. def alice_add_comment_coinaddr(self):
  1369. mmid = self._user_sid('alice') + (':S:1',':L:1')[self.proto.coin=='BCH']
  1370. t = self.spawn('mmgen-tool',['--alice','listaddress',mmid,'wide=true'],no_msg=True)
  1371. addr = [i for i in strip_ansi_escapes(t.read()).splitlines() if re.search(rf'\b{mmid}\b',i)][0].split()[3]
  1372. return self.user_add_comment('alice',addr,'Label added using coin address of MMGen address')
  1373. def alice_chk_comment_coinaddr(self):
  1374. mmid = self._user_sid('alice') + (':S:1',':L:1')[self.proto.coin=='BCH']
  1375. return self._user_chk_comment('alice',mmid,'Label added using coin address of MMGen address')
  1376. def alice_add_comment_badaddr(self,addr,reply,exit_val):
  1377. if os.getenv('PYTHONOPTIMIZE'):
  1378. omsg(yellow(f'PYTHONOPTIMIZE set, skipping test {self.test_name!r}'))
  1379. return 'skip'
  1380. t = self.spawn(
  1381. 'mmgen-tool',
  1382. ['--alice','add_label',addr,'(none)'],
  1383. exit_val = exit_val)
  1384. t.expect(reply,regex=True)
  1385. return t
  1386. def alice_add_comment_badaddr1(self):
  1387. return self.alice_add_comment_badaddr( rt_pw, 'invalid address', 2 )
  1388. def alice_add_comment_badaddr2(self):
  1389. # mainnet zero address:
  1390. addr = init_proto( cfg, self.proto.coin, network='mainnet' ).pubhash2addr(bytes(20),False)
  1391. return self.alice_add_comment_badaddr( addr, 'invalid address', 2 )
  1392. def alice_add_comment_badaddr3(self):
  1393. addr = self._user_sid('alice') + ':C:123'
  1394. return self.alice_add_comment_badaddr( addr, f'MMGen address {addr!r} not found in tracking wallet', 2 )
  1395. def alice_add_comment_badaddr4(self):
  1396. addr = self.proto.pubhash2addr(bytes(20),False) # regtest (testnet) zero address
  1397. return self.alice_add_comment_badaddr( addr, f'Coin address {addr!r} not found in tracking wallet', 2 )
  1398. def alice_remove_comment1(self):
  1399. sid = self._user_sid('alice')
  1400. mmid = sid + (':S:3',':L:3')[self.proto.coin=='BCH']
  1401. return self.user_remove_comment('alice',mmid)
  1402. def alice_chk_comment1(self):
  1403. sid = self._user_sid('alice')
  1404. return self._user_chk_comment('alice',sid+':C:1','Original Label - 月へ')
  1405. def alice_chk_comment2(self):
  1406. sid = self._user_sid('alice')
  1407. return self._user_chk_comment('alice',sid+':C:1','Replacement Label',extra_args=['age_fmt=block'])
  1408. def alice_edit_comment1(self):
  1409. return self.user_edit_comment('alice','4',tw_comment_lat_cyr_gr)
  1410. def alice_edit_comment2(self):
  1411. return self.user_edit_comment('alice','3',tw_comment_zh)
  1412. def alice_chk_comment3(self):
  1413. sid = self._user_sid('alice')
  1414. mmid = sid + (':S:3',':L:3')[self.proto.coin=='BCH']
  1415. return self._user_chk_comment('alice',mmid,tw_comment_lat_cyr_gr,extra_args=['age_fmt=date'])
  1416. def alice_chk_comment4(self):
  1417. sid = self._user_sid('alice')
  1418. mmid = sid + (':S:3',':L:3')[self.proto.coin=='BCH']
  1419. return self._user_chk_comment('alice',mmid,'-',extra_args=['age_fmt=date_time'])
  1420. def user_edit_comment(self,user,output,comment):
  1421. t = self.spawn('mmgen-txcreate',['-B','--'+user,'-i'])
  1422. t.expect(r'add \[l\]abel:.','M',regex=True)
  1423. t.expect(r'add \[l\]abel:.','l',regex=True)
  1424. t.expect(r"Enter unspent.*return to main menu\):.",output+'\n',regex=True)
  1425. t.expect(r"Enter label text.*:.",comment+'\n',regex=True)
  1426. t.expect(r'\[q\]uit menu, .*?:.','q',regex=True)
  1427. return t
  1428. def alice_listaddresses_scroll(self):
  1429. t = self.spawn(
  1430. 'mmgen-tool', [
  1431. '--alice',
  1432. '--scroll',
  1433. f'--outdir={self.tr.trash_dir}',
  1434. 'listaddresses',
  1435. 'interactive=1',
  1436. ]
  1437. )
  1438. t.expect('abel:\b','p')
  1439. ret = t.expect([ 'abel:\b', 'to confirm: ' ])
  1440. if ret == 1:
  1441. t.send('YES\n')
  1442. t.expect('abel:\b')
  1443. t.send('l')
  1444. t.expect(
  1445. 'main menu): ',
  1446. '{}\n'.format(2 if self.proto.coin == 'BCH' else 1) )
  1447. t.expect('for address.*: ','\n',regex=True)
  1448. t.expect('unchanged')
  1449. t.expect('abel:\b','q')
  1450. return t
  1451. def _alice_listaddresses_interactive(self,expect=(),expect_menu=()):
  1452. t = self.spawn('mmgen-tool',['--alice','listaddresses','interactive=1'])
  1453. for s in expect_menu:
  1454. t.expect('abel:\b',s)
  1455. for p,s in expect:
  1456. t.expect(p,s)
  1457. return t
  1458. def alice_listaddresses_empty(self):
  1459. return self._alice_listaddresses_interactive(expect_menu='uuEq')
  1460. def alice_listaddresses_menu(self):
  1461. return self._alice_listaddresses_interactive(expect_menu='aAMrDDDDLeq')
  1462. def alice_listaddresses(self,args,expect):
  1463. t = self.spawn('mmgen-tool',['--alice','listaddresses','showempty=1'] + args)
  1464. expect_str = r'\D{}\D.*\b{}'.format(*expect)
  1465. t.expect(expect_str,regex=True)
  1466. return t
  1467. def alice_listaddresses1(self):
  1468. return self.alice_listaddresses(
  1469. args = [],
  1470. expect = (rtAmts[1],r'\d+') )
  1471. def alice_listaddresses_days(self):
  1472. return self.alice_listaddresses(
  1473. args = ['age_fmt=days'],
  1474. expect = (rtAmts[1],r'\d+') )
  1475. def alice_listaddresses_date(self):
  1476. return self.alice_listaddresses(
  1477. args = ['age_fmt=date'],
  1478. expect = (rtAmts[1],pat_date) )
  1479. def alice_listaddresses_date_time(self):
  1480. return self.alice_listaddresses(
  1481. args = ['age_fmt=date_time'],
  1482. expect = (rtAmts[1],pat_date_time) )
  1483. def alice_twview(self,args,expect):
  1484. t = self.spawn('mmgen-tool',['--alice','twview'] + args)
  1485. expect_str = r'\D{}\D.*\b{}'.format(*expect)
  1486. t.expect(expect_str,regex=True)
  1487. return t
  1488. def alice_twview1(self):
  1489. return self.alice_twview(
  1490. args = [],
  1491. expect = (rtAmts[0],r'\d+') )
  1492. def alice_twview_days(self):
  1493. return self.alice_twview(
  1494. args = ['age_fmt=days'],
  1495. expect = (rtAmts[0],r'\d+') )
  1496. def alice_twview_date(self):
  1497. return self.alice_twview(
  1498. args = ['age_fmt=date'],
  1499. expect = (rtAmts[0],pat_date) )
  1500. def alice_twview_date_time(self):
  1501. return self.alice_twview(
  1502. args = ['age_fmt=date_time'],
  1503. expect = (rtAmts[0],pat_date_time) )
  1504. def alice_txcreate_info(self,pexpect_spawn=False):
  1505. t = self.spawn('mmgen-txcreate',['--alice','-Bi'],pexpect_spawn=pexpect_spawn)
  1506. pats = (
  1507. ( r'\d+', 'w'),
  1508. ( r'\d+', 'D'),
  1509. ( r'\d+', 'D'),
  1510. ( r'\d+', 'D'),
  1511. ( pat_date, 'q'),
  1512. )
  1513. for d,s in pats:
  1514. t.expect(
  1515. r'\D{}\D.*\b{}\b'.format( rtAmts[0], d ),
  1516. s,
  1517. regex=True )
  1518. if t.pexpect_spawn and s == 'w':
  1519. t.expect(r'Total.*','q',regex=True,delay=1 if cfg.exact_output else t.send_delay)
  1520. time.sleep(t.send_delay)
  1521. t.send('e')
  1522. return t
  1523. def alice_txcreate_info_term(self):
  1524. if self.skip_for_win():
  1525. return 'skip'
  1526. return self.alice_txcreate_info(pexpect_spawn=True)
  1527. # send one TX to 2 addrs in Alice’s wallet - required for alice_twview_grouped() (group by TxID)
  1528. def bob_send_to_alice_2addr(self):
  1529. outputs_cl = self._create_tx_outputs('alice',[('C',1,',0.02'),('C',2,',0.2')])
  1530. outputs_cl += [self._user_sid('bob')+':C:5']
  1531. return self.user_txdo('bob','25s',outputs_cl,'1')
  1532. # send to a used addr in Alice’s wallet - required for alice_twview_grouped() (group by address)
  1533. def bob_send_to_alice_reuse(self):
  1534. outputs_cl = self._create_tx_outputs('alice',[('C',1,',0.0111')])
  1535. outputs_cl += [self._user_sid('bob')+':C:5']
  1536. return self.user_txdo('bob','25s',outputs_cl,'1')
  1537. def alice_twview_grouped(self):
  1538. t = self.spawn('mmgen-tool',['--alice','twview','interactive=1'])
  1539. prompt = 'abel:\b'
  1540. for grouped, send in (
  1541. (False, 'o'), # 'o' = group display
  1542. (False, 'M'), # grouped address
  1543. (True, 't'), # grouped TxID
  1544. (True, 'q'),
  1545. ):
  1546. if grouped:
  1547. t.expect('........')
  1548. t.expect(prompt, send)
  1549. return t
  1550. def bob_msgcreate(self):
  1551. sid1 = self._user_sid('bob')
  1552. sid2 = self._get_user_subsid('bob','29L')
  1553. return self.spawn(
  1554. 'mmgen-msg', [
  1555. '--bob',
  1556. f'--outdir={self.tmpdir}',
  1557. 'create',
  1558. '16/3/2022 Earthquake strikes Fukushima coast',
  1559. f'{sid1}:{self.dfl_mmtype}:1-4',
  1560. f'{sid2}:C:3-7,87,98'
  1561. ])
  1562. def bob_msgsign(self,wallets=[]):
  1563. fn = get_file_with_ext(self.tmpdir,'rawmsg.json')
  1564. t = self.spawn(
  1565. 'mmgen-msg', [
  1566. '--bob',
  1567. f'--outdir={self.tmpdir}',
  1568. 'sign',
  1569. fn
  1570. ] + wallets )
  1571. if not wallets:
  1572. t.passphrase(dfl_wcls.desc,rt_pw)
  1573. return t
  1574. def bob_walletconv_words(self):
  1575. t = self.spawn(
  1576. 'mmgen-walletconv', [ '--bob', f'--outdir={self.tmpdir}', '--out-fmt=words' ] )
  1577. t.passphrase(dfl_wcls.desc,rt_pw)
  1578. t.written_to_file('data')
  1579. return t
  1580. def bob_subwalletgen_bip39(self):
  1581. t = self.spawn(
  1582. 'mmgen-subwalletgen', [ '--bob', f'--outdir={self.tmpdir}', '--out-fmt=bip39', '29L' ] )
  1583. t.passphrase(dfl_wcls.desc,rt_pw)
  1584. t.written_to_file('data')
  1585. return t
  1586. def bob_msgsign_userwallet(self):
  1587. fn1 = get_file_with_ext(self.tmpdir,'mmwords')
  1588. return self.bob_msgsign([fn1])
  1589. def bob_msgsign_userwallets(self):
  1590. fn1 = get_file_with_ext(self.tmpdir,'mmwords')
  1591. fn2 = get_file_with_ext(self.tmpdir,'bip39')
  1592. return self.bob_msgsign([fn2,fn1])
  1593. def bob_msgverify(
  1594. self,
  1595. addr = None,
  1596. ext = 'sigmsg.json',
  1597. cmd = 'verify',
  1598. msgfile = None,
  1599. exit_val = None):
  1600. return self.spawn(
  1601. 'mmgen-msg', [
  1602. '--bob',
  1603. f'--outdir={self.tmpdir}',
  1604. cmd,
  1605. msgfile or get_file_with_ext(self.tmpdir,ext),
  1606. ]
  1607. + ([addr] if addr else []),
  1608. exit_val = exit_val)
  1609. def bob_msgverify_raw(self):
  1610. t = self.bob_msgverify(ext='rawmsg.json', exit_val=1)
  1611. t.expect('No signatures')
  1612. return t
  1613. def bob_msgverify_single(self):
  1614. sid = self._user_sid('bob')
  1615. return self.bob_msgverify(addr=f'{sid}:{self.dfl_mmtype}:1')
  1616. def bob_msgexport(self,addr=None):
  1617. t = self.bob_msgverify( addr=addr, cmd='export' )
  1618. t.written_to_file('data')
  1619. return t
  1620. def bob_msgexport_single(self):
  1621. sid = self._user_sid('bob')
  1622. return self.bob_msgexport(addr=f'{sid}:{self.dfl_mmtype}:1')
  1623. def bob_msgverify_export(self):
  1624. return self.bob_msgverify(
  1625. msgfile = os.path.join(self.tmpdir,'signatures.json')
  1626. )
  1627. def bob_msgverify_export_single(self):
  1628. sid = self._user_sid('bob')
  1629. mmid = f'{sid}:{self.dfl_mmtype}:1'
  1630. args = [ '--bob', '--color=0', 'listaddress', mmid, 'wide=true' ]
  1631. imsg(f'Running mmgen-tool {fmt_list(args,fmt="bare")}')
  1632. t = self.spawn('mmgen-tool', args, no_msg=True)
  1633. addr = t.expect_getend(mmid).split()[1]
  1634. t.close()
  1635. return self.bob_msgverify(
  1636. addr = addr,
  1637. msgfile = os.path.join(self.tmpdir,'signatures.json')
  1638. )
  1639. def bob_auto_chg_split(self):
  1640. if not self.proto.cap('segwit'):
  1641. return 'skip'
  1642. sid = self._user_sid('bob')
  1643. return self.user_txdo(
  1644. user = 'bob',
  1645. fee = '23s',
  1646. outputs_cl = [sid+':C:5,0.0135', sid+':L:4'],
  1647. outputs_list = '1' )
  1648. def bob_auto_chg_generate(self):
  1649. if not self.proto.cap('segwit'):
  1650. return 'skip'
  1651. return self.generate()
  1652. def _usr_auto_chg(
  1653. self,
  1654. user,
  1655. mmtype,
  1656. idx,
  1657. by_mmtype = False,
  1658. include_dest = True,
  1659. ignore_labels = False,
  1660. add_args = []):
  1661. if mmtype in ('S','B') and not self.proto.cap('segwit'):
  1662. return 'skip'
  1663. sid = self._user_sid('bob')
  1664. t = self.spawn(
  1665. 'mmgen-txcreate',
  1666. [f'--outdir={self.tr.trash_dir}', '--no-blank', f'--{user}']
  1667. + (['--autochg-ignore-labels'] if ignore_labels else [])
  1668. + [mmtype if by_mmtype else f'{sid}:{mmtype}']
  1669. + ([self.burn_addr+',0.01'] if include_dest else [])
  1670. + add_args
  1671. )
  1672. return self.txcreate_ui_common(t,
  1673. menu = [],
  1674. inputs = '1',
  1675. interactive_fee = '20s',
  1676. auto_chg_addr = f'{sid}:{mmtype}:{idx}')
  1677. def bob_auto_chg1(self):
  1678. return self._usr_auto_chg( 'bob', 'C', '3' )
  1679. def bob_auto_chg2(self):
  1680. return self._usr_auto_chg( 'bob', 'B', '2' )
  1681. def bob_auto_chg3(self):
  1682. return self._usr_auto_chg( 'bob', 'S', '1' )
  1683. def bob_auto_chg4(self):
  1684. return self._usr_auto_chg( 'bob', 'C', '3', include_dest=False )
  1685. def bob_auto_chg_addrtype1(self):
  1686. return self._usr_auto_chg( 'bob', 'C', '3', True )
  1687. def bob_auto_chg_addrtype2(self):
  1688. return self._usr_auto_chg( 'bob', 'B', '2', True )
  1689. def bob_auto_chg_addrtype3(self):
  1690. return self._usr_auto_chg( 'bob', 'S', '1', True )
  1691. def bob_auto_chg_addrtype4(self):
  1692. return self._usr_auto_chg( 'bob', 'C', '3', True, include_dest=False )
  1693. def _bob_add_comment_uua(self,addrspec,comment):
  1694. sid = self._user_sid('bob')
  1695. return self.user_add_comment('bob',sid+addrspec,comment)
  1696. def bob_add_comment_uua1(self):
  1697. return self._bob_add_comment_uua(':C:3','comment for unused address')
  1698. def bob_auto_chg5(self):
  1699. return self._usr_auto_chg( 'bob', 'C', '4' )
  1700. def bob_auto_chg_addrtype5(self):
  1701. return self._usr_auto_chg( 'bob', 'C', '4', True )
  1702. def bob_auto_chg6(self):
  1703. return self._usr_auto_chg( 'bob', 'C', '3', ignore_labels=True )
  1704. def bob_auto_chg7(self):
  1705. sid = self._user_sid('bob')
  1706. return self._usr_auto_chg( 'bob', 'S', '3', add_args=[f'{sid}:S:1,0.00345'] )
  1707. def bob_auto_chg_addrtype6(self):
  1708. return self._usr_auto_chg( 'bob', 'C', '3', True, ignore_labels=True )
  1709. def _bob_remove_comment_uua(self,addrspec):
  1710. sid = self._user_sid('bob')
  1711. return self.user_remove_comment('bob',sid+addrspec)
  1712. def bob_remove_comment_uua1(self):
  1713. return self._bob_remove_comment_uua(':C:3')
  1714. def _usr_auto_chg_bad(self, user, al_id, expect, add_args=[]):
  1715. t = self.spawn(
  1716. 'mmgen-txcreate',
  1717. ['-d', self.tr.trash_dir, '-B', f'--{user}']
  1718. + [f'{self.burn_addr},0.01']
  1719. + ([al_id] if al_id else [])
  1720. + add_args,
  1721. exit_val = 2)
  1722. t.expect(expect)
  1723. return t
  1724. def bob_auto_chg_bad1(self):
  1725. return self._usr_auto_chg_bad(
  1726. 'bob',
  1727. 'FFFFFFFF:C',
  1728. 'contains no addresses' )
  1729. def bob_auto_chg_bad2(self):
  1730. return self._usr_auto_chg_bad(
  1731. 'bob',
  1732. '00000000:C',
  1733. 'contains no addresses' )
  1734. def bob_auto_chg_bad3(self):
  1735. return self._usr_auto_chg_bad(
  1736. 'bob',
  1737. self._user_sid('bob') + ':L',
  1738. 'contains no unused addresses from address list' )
  1739. def bob_auto_chg_bad4(self):
  1740. return self._usr_auto_chg_bad(
  1741. 'bob',
  1742. 'L',
  1743. 'contains no unused addresses of address type' )
  1744. def bob_auto_chg_bad5(self):
  1745. sid = self._user_sid('bob')
  1746. return self._usr_auto_chg_bad(
  1747. 'bob',
  1748. None,
  1749. 'More than one change address listed',
  1750. add_args = [f'{sid}:C:4', f'{sid}:C:5'])
  1751. def bob_auto_chg_bad6(self):
  1752. sid = self._user_sid('bob')
  1753. return self._usr_auto_chg_bad(
  1754. 'bob',
  1755. 'L',
  1756. 'More than one',
  1757. add_args = [f'{sid}:C:4'])
  1758. def bob_auto_chg_bad7(self):
  1759. return self._usr_auto_chg_bad(
  1760. 'bob',
  1761. 'L',
  1762. 'More than one change address requested',
  1763. add_args = ['B'])
  1764. def carol_twimport2(self):
  1765. u,b = (4,3) if self.proto.cap('segwit') else (3,2)
  1766. return self.carol_twimport(
  1767. rpc_backend = None,
  1768. add_parms = ['ignore_checksum=true'],
  1769. expect_str2 = f'Found {u} unspent outputs in {b} blocks' )
  1770. def carol_rescan_blockchain(self):
  1771. return self._usr_rescan_blockchain('carol',[])
  1772. def carol_auto_chg1(self):
  1773. return self._usr_auto_chg( 'carol', 'C', '3' )
  1774. def carol_auto_chg2(self):
  1775. return self._usr_auto_chg( 'carol', 'B', '2' )
  1776. def carol_auto_chg3(self):
  1777. return self._usr_auto_chg( 'carol', 'S', '1' )
  1778. def carol_auto_chg_addrtype1(self):
  1779. return self._usr_auto_chg( 'carol', 'C', '3', True )
  1780. def carol_auto_chg_addrtype2(self):
  1781. return self._usr_auto_chg( 'carol', 'B', '2', True )
  1782. def carol_auto_chg_addrtype3(self):
  1783. return self._usr_auto_chg( 'carol', 'S', '1', True )
  1784. def carol_auto_chg_addrtype4(self):
  1785. sid = self._user_sid('bob')
  1786. return self._usr_auto_chg('carol', 'S', '3', True, add_args=[f'{sid}:S:1,0.00345'])
  1787. def carol_auto_chg_bad1(self):
  1788. return self._usr_auto_chg_bad(
  1789. 'carol',
  1790. self._user_sid('bob') + ':L',
  1791. 'contains no unused addresses from address list' )
  1792. def carol_auto_chg_bad2(self):
  1793. return self._usr_auto_chg_bad(
  1794. 'carol',
  1795. 'L',
  1796. 'contains no unused addresses of address type' )
  1797. def stop(self):
  1798. if cfg.no_daemon_stop:
  1799. self.spawn('',msg_only=True)
  1800. msg_r('(leaving daemon running by user request)')
  1801. return 'ok'
  1802. else:
  1803. return self.spawn('mmgen-regtest',['stop'])
  1804. class CmdTestRegtestBDBWallet(CmdTestRegtest):
  1805. bdb_wallet = True