ts_regtest.py 54 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476
  1. #!/usr/bin/env python3
  2. #
  3. # mmgen = Multi-Mode GENerator, command-line Bitcoin cold storage solution
  4. # Copyright (C)2013-2022 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.test_py_d.ts_regtest: Regtest tests for the test.py test suite
  20. """
  21. import os,json,time
  22. from decimal import Decimal
  23. from mmgen.globalvars import g
  24. from mmgen.opts import opt
  25. from mmgen.util import die,gmsg
  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. from .common import *
  31. pat_date = r'\b\d\d-\d\d-\d\d\b'
  32. pat_date_time = r'\b\d\d\d\d-\d\d-\d\d\s+\d\d:\d\d\b'
  33. dfl_wcls = get_wallet_cls('mmgen')
  34. rt_pw = 'abc-α'
  35. rt_data = {
  36. 'tx_fee': {'btc':'0.0001','bch':'0.001','ltc':'0.01'},
  37. 'rtFundAmt': {'btc':'500','bch':'500','ltc':'5500'},
  38. 'rtFee': {
  39. 'btc': ('20s','10s','60s','31s','10s','20s'),
  40. 'bch': ('20s','10s','60s','0.0001','10s','20s'),
  41. 'ltc': ('1000s','500s','1500s','0.05','400s','1000s')
  42. },
  43. 'rtBals': {
  44. 'btc': ('499.9999488','399.9998282','399.9998147','399.9996877',
  45. '52.99980410','946.99933647','999.99914057','52.9999',
  46. '946.99933647','0.4169328','6.24987417'),
  47. 'bch': ('499.9999484','399.9999194','399.9998972','399.9997692',
  48. '46.78890380','953.20966920','999.99857300','46.789',
  49. '953.2096692','0.4169328','39.58187387'),
  50. 'ltc': ('5499.99744','5399.994425','5399.993885','5399.987535',
  51. '52.98520500','10946.93753500','10999.92274000','52.99',
  52. '10946.937535','0.41364','6.24846787'),
  53. },
  54. 'rtBals_gb': {
  55. 'btc': {
  56. '0conf0': {
  57. 'mmgen': ('283.22339537','283.22339537'),
  58. 'nonmm': ('16.77647763','116.77629233'),
  59. 'total': ('299.999873','399.9996877'),
  60. },
  61. '0conf1': {
  62. 'mmgen': ('283.22339537','0'),
  63. 'nonmm': ('16.77647763','99.9998147'),
  64. 'total': ('299.999873','99.9998147'),
  65. },
  66. '1conf1': {
  67. 'mmgen': ('0','283.22339537'),
  68. 'nonmm': ('0','116.77629233'),
  69. 'total': ('0','399.9996877'),
  70. },
  71. '1conf2': {
  72. 'mmgen': ('0','283.22339537','0'),
  73. 'nonmm': ('0','16.77647763','99.9998147'),
  74. 'total': ('0','299.999873','99.9998147'),
  75. },
  76. },
  77. 'bch': {
  78. '0conf0': {
  79. 'mmgen': ('283.22339437','283.22339437'),
  80. 'nonmm': ('16.77647763','116.77637483'),
  81. 'total': ('299.999872','399.9997692'),
  82. },
  83. '0conf1': {
  84. 'mmgen': ('283.22339437','0'),
  85. 'nonmm': ('16.77647763','99.9998972'),
  86. 'total': ('299.999872','99.9998972'),
  87. },
  88. '1conf1': {
  89. 'mmgen': ('0','283.22339437'),
  90. 'nonmm': ('0','116.77637483'),
  91. 'total': ('0','399.9997692'),
  92. },
  93. '1conf2': {
  94. 'mmgen': ('0','283.22339437','0'),
  95. 'nonmm': ('0','16.77647763','99.9998972'),
  96. 'total': ('0','299.999872','99.9998972'),
  97. },
  98. },
  99. 'ltc': {
  100. '0conf0': {
  101. 'mmgen': ('283.21717237','283.21717237'),
  102. 'nonmm': ('16.77647763','5116.77036263'),
  103. 'total': ('299.99365','5399.987535'),
  104. },
  105. '0conf1': {
  106. 'mmgen': ('283.21717237','0'),
  107. 'nonmm': ('16.77647763','5099.993885'),
  108. 'total': ('299.99365','5099.993885'),
  109. },
  110. '1conf1': {
  111. 'mmgen': ('0','283.21717237'),
  112. 'nonmm': ('0','5116.77036263'),
  113. 'total': ('0','5399.987535'),
  114. },
  115. '1conf2': {
  116. 'mmgen': ('0','283.21717237','0'),
  117. 'nonmm': ('0','16.77647763','5099.993885'),
  118. 'total': ('0','299.99365','5099.993885'),
  119. },
  120. }
  121. },
  122. 'rtBobOp3': {'btc':'S:2','bch':'L:3','ltc':'S:2'},
  123. 'rtAmts': {
  124. 'btc': ('500','500'),
  125. 'bch': ('500','560'),
  126. 'ltc': ('5500','5500')
  127. }
  128. }
  129. def make_burn_addr(proto):
  130. from mmgen.tool.coin import tool_cmd
  131. return tool_cmd(
  132. cmdname = 'pubhash2addr',
  133. proto = proto,
  134. mmtype = 'compressed' ).pubhash2addr('00'*20)
  135. from .ts_base import *
  136. from .ts_shared import *
  137. class TestSuiteRegtest(TestSuiteBase,TestSuiteShared):
  138. 'transacting and tracking wallet operations via regtest mode'
  139. networks = ('btc','ltc','bch')
  140. passthru_opts = ('coin','rpc_backend')
  141. extra_spawn_args = ['--regtest=1']
  142. tmpdir_nums = [17]
  143. color = True
  144. deterministic = False
  145. test_rbf = False
  146. cmd_group_in = (
  147. ('setup', 'regtest (Bob and Alice) mode setup'),
  148. ('subgroup.misc', []),
  149. ('subgroup.init_bob', []),
  150. ('subgroup.init_alice', []),
  151. ('subgroup.fund_users', ['init_bob','init_alice']),
  152. ('subgroup.msg', ['init_bob']),
  153. ('subgroup.twexport', ['fund_users']),
  154. ('subgroup.rescan', ['fund_users']),
  155. ('subgroup.main', ['fund_users']),
  156. ('subgroup.txhist', ['main']),
  157. ('subgroup.label', ['main']),
  158. ('subgroup.view', ['label']),
  159. ('subgroup.auto_chg', ['view']),
  160. ('stop', 'stopping regtest daemon'),
  161. )
  162. cmd_subgroups = {
  163. 'misc': (
  164. 'miscellaneous commands',
  165. ('daemon_version', 'mmgen-tool daemon_version'),
  166. ('halving_calculator_bob', 'halving calculator (Bob)'),
  167. ),
  168. 'init_bob': (
  169. 'creating Bob’s MMGen wallet and tracking wallet',
  170. ('walletgen_bob', 'wallet generation (Bob)'),
  171. ('addrgen_bob', 'address generation (Bob)'),
  172. ('addrimport_bob', "importing Bob's addresses"),
  173. ),
  174. 'init_alice': (
  175. 'creating Alice’s MMGen wallet and tracking wallet',
  176. ('walletgen_alice', 'wallet generation (Alice)'),
  177. ('addrgen_alice', 'address generation (Alice)'),
  178. ('addrimport_alice', "importing Alice's addresses"),
  179. ),
  180. 'fund_users': (
  181. 'funding Bob and Alice’s wallets',
  182. ('bob_import_miner_addr', "importing miner’s coinbase addr into Bob’s wallet"),
  183. ('fund_bob_deterministic', "funding Bob’s first MMGen address (deterministic method)"),
  184. ('fund_alice_deterministic', "funding Alice’s first MMGen address (deterministic method)"),
  185. ('bob_recreate_tracking_wallet', 'creation of new tracking wallet (Bob)'),
  186. ('addrimport_bob2', "reimporting Bob's addresses"),
  187. ('fund_bob', "funding Bob's wallet"),
  188. ('fund_alice', "funding Alice's wallet"),
  189. ('generate', 'mining a block'),
  190. ('bob_bal1', "Bob's balance"),
  191. ('generate_extra_deterministic', "generate extra blocks for deterministic run"),
  192. ),
  193. 'msg': (
  194. 'message signing',
  195. ('bob_msgcreate', 'creating a message file for signing'),
  196. ('bob_msgsign', 'signing the message file (default wallet)'),
  197. ('bob_walletconv_words', 'creating an MMGen mnemonic wallet'),
  198. ('bob_subwalletgen_bip39', 'creating a BIP39 mnemonic subwallet'),
  199. ('bob_msgsign_userwallet', 'signing the message file (user-specified wallet)'),
  200. ('bob_msgsign_userwallets', 'signing the message file (user-specified wallets)'),
  201. ('bob_msgverify', 'verifying the message file (all addresses)'),
  202. ('bob_msgverify_raw', 'verifying the raw message file (all addresses)'),
  203. ('bob_msgverify_single', 'verifying the message file (single address)'),
  204. ('bob_msgexport_single', 'exporting the message file (single address)'),
  205. ('bob_msgexport', 'exporting the message file (all addresses)'),
  206. ('bob_msgverify_export', 'verifying the exported JSON data (all addresses)'),
  207. ('bob_msgverify_export_single', 'verifying the exported JSON data (single address)'),
  208. ),
  209. 'twexport': (
  210. 'exporting and importing tracking wallet to JSON',
  211. ('bob_twexport', 'exporting a tracking wallet to JSON'),
  212. ('carol_twimport', 'importing a tracking wallet JSON dump'),
  213. ('carol_delete_wallet', 'unloading and deleting Carol’s tracking wallet'),
  214. ('bob_twexport_noamt', 'exporting a tracking wallet to JSON (include_amts=0)'),
  215. ('carol_twimport_nochksum', 'importing a tracking wallet JSON dump (ignore_checksum=1)'),
  216. ('carol_delete_wallet', 'unloading and deleting Carol’s tracking wallet'),
  217. ('carol_twimport_batch', 'importing a tracking wallet JSON dump (batch=1)'),
  218. ('bob_twexport_pretty', 'exporting a tracking wallet to JSON (pretty=1)'),
  219. ('bob_edit_json_twdump', 'editing a tracking wallet JSON dump'),
  220. ('carol_delete_wallet', 'unloading and deleting Carol’s tracking wallet'),
  221. ('carol_twimport_pretty', 'importing an edited tracking wallet JSON dump (ignore_checksum=1)'),
  222. ('carol_listaddresses', 'viewing Carol’s tracking wallet'),
  223. ('carol_delete_wallet', 'unloading and deleting Carol’s tracking wallet'),
  224. ),
  225. 'rescan': (
  226. 'rescanning address and blockchain',
  227. ('bob_resolve_addr', 'resolving an address in the tracking wallet'),
  228. ('bob_rescan_addr', 'rescanning an address'),
  229. ('bob_rescan_blockchain_all', 'rescanning the blockchain (full rescan)'),
  230. ('bob_rescan_blockchain_gb', 'rescanning the blockchain (Genesis block)'),
  231. ('bob_rescan_blockchain_one', 'rescanning the blockchain (single block)'),
  232. ('bob_rescan_blockchain_ss', 'rescanning the blockchain (range of blocks)'),
  233. ),
  234. 'main': (
  235. 'creating, signing, sending and bumping transactions',
  236. ('bob_add_comment', "adding an 80-screen-width label (lat+cyr+gr)"),
  237. ('bob_twview1', "viewing Bob's tracking wallet"),
  238. ('bob_split1', "splitting Bob's funds"),
  239. ('generate', 'mining a block'),
  240. ('bob_bal2', "Bob's balance"),
  241. ('bob_rbf_1output_create', 'creating RBF tx with one output'),
  242. ('bob_rbf_1output_bump', 'bumping RBF tx with one output'),
  243. ('bob_bal2a', "Bob's balance (age_fmt=confs)"),
  244. ('bob_bal2b', "Bob's balance (showempty=1)"),
  245. ('bob_bal2c', "Bob's balance (showempty=1 minconf=2 age_fmt=days)"),
  246. ('bob_bal2d', "Bob's balance (minconf=2)"),
  247. ('bob_bal2e', "Bob's balance (showempty=1 sort=age)"),
  248. ('bob_bal2f', "Bob's balance (showempty=1 sort=age,reverse)"),
  249. ('bob_send_maybe_rbf', 'sending funds to Alice (RBF, if supported)'),
  250. ('get_mempool1', 'mempool (before RBF bump)'),
  251. ('bob_rbf_status1', 'getting status of transaction'),
  252. ('bob_rbf_bump', 'bumping RBF transaction'),
  253. ('get_mempool2', 'mempool (after RBF bump)'),
  254. ('bob_rbf_status2', 'getting status of transaction after replacement'),
  255. ('bob_rbf_status3', 'getting status of replacement transaction (mempool)'),
  256. ('generate', 'mining a block'),
  257. ('bob_rbf_status4', 'getting status of transaction after confirmed (1) replacement'),
  258. ('bob_rbf_status5', 'getting status of replacement transaction (confirmed)'),
  259. ('generate', 'mining a block'),
  260. ('bob_rbf_status6', 'getting status of transaction after confirmed (2) replacement'),
  261. ('bob_bal3', "Bob's balance"),
  262. ('bob_pre_import', 'sending to non-imported address'),
  263. ('generate', 'mining a block'),
  264. ('bob_import_addr', 'importing non-MMGen address'),
  265. ('bob_bal4', "Bob's balance (after import)"),
  266. ('bob_import_list', 'importing flat address list'),
  267. ('bob_import_list_rescan', 'importing flat address list with --rescan'),
  268. ('bob_import_list_rescan_aio', 'importing flat address list with --rescan (aiohttp backend)'),
  269. ('bob_split2', "splitting Bob's funds"),
  270. ('bob_0conf0_getbalance', "Bob's balance (unconfirmed, minconf=0)"),
  271. ('bob_0conf1_getbalance', "Bob's balance (unconfirmed, minconf=1)"),
  272. ('generate', 'mining a block'),
  273. ('bob_1conf1_getbalance', "Bob's balance (confirmed, minconf=1)"),
  274. ('bob_1conf2_getbalance', "Bob's balance (confirmed, minconf=2)"),
  275. ('bob_bal5', "Bob's balance"),
  276. ('bob_send_non_mmgen', 'sending funds to Alice (from non-MMGen addrs)'),
  277. ('generate', 'mining a block'),
  278. ('alice_send_estimatefee', 'tx creation with no fee on command line'),
  279. ('generate', 'mining a block'),
  280. ('bob_bal6', "Bob's balance"),
  281. ('bob_subwallet_addrgen1', "generating Bob's addrs from subwallet 29L"),
  282. ('bob_subwallet_addrgen2', "generating Bob's addrs from subwallet 127S"),
  283. ('bob_subwallet_addrimport1', "importing Bob's addrs from subwallet 29L"),
  284. ('bob_subwallet_addrimport2', "importing Bob's addrs from subwallet 127S"),
  285. ('bob_subwallet_fund', "funding Bob's subwallet addrs"),
  286. ('generate', 'mining a block'),
  287. ('bob_twview2', "viewing Bob's tracking wallet"),
  288. ('bob_twview3', "viewing Bob's tracking wallet"),
  289. ('bob_subwallet_txcreate', 'creating a transaction with subwallet inputs'),
  290. ('bob_subwallet_txsign', 'signing a transaction with subwallet inputs'),
  291. ('bob_subwallet_txdo', "sending from Bob's subwallet addrs"),
  292. ('generate', 'mining a block'),
  293. ('bob_twview4', "viewing Bob's tracking wallet"),
  294. ('bob_alice_bal', "Bob and Alice's balances"),
  295. ('bob_nochg_burn', 'zero-change transaction to burn address'),
  296. ('generate', 'mining a block'),
  297. ),
  298. 'txhist': (
  299. 'viewing transaction history',
  300. ('bob_txhist1', "viewing Bob's transaction history (sort=age)"),
  301. ('bob_txhist2', "viewing Bob's transaction history (sort=blockheight reverse=1)"),
  302. ('bob_txhist3', "viewing Bob's transaction history (sort=blockheight sinceblock=-7)"),
  303. ('bob_txhist4', "viewing Bob's transaction history (sinceblock=399 detail=1)"),
  304. ('bob_txhist_interactive', "viewing Bob's transaction history (age_fmt=date_time interactive=true)"),
  305. ),
  306. 'label': (
  307. 'adding, removing and editing labels',
  308. ('alice_bal2', "Alice's balance"),
  309. ('alice_add_comment1', 'adding a label'),
  310. ('alice_chk_comment1', 'the label'),
  311. ('alice_add_comment2', 'adding a label'),
  312. ('alice_chk_comment2', 'the label'),
  313. ('alice_edit_comment1', 'editing a label (zh)'),
  314. ('alice_edit_comment2', 'editing a label (lat+cyr+gr)'),
  315. ('alice_chk_comment3', 'the label'),
  316. ('alice_remove_comment1', 'removing a label'),
  317. ('alice_chk_comment4', 'the label'),
  318. ('alice_add_comment_coinaddr', 'adding a label using the coin address'),
  319. ('alice_chk_comment_coinaddr', 'the label'),
  320. ('alice_add_comment_badaddr1', 'adding a label with invalid address'),
  321. ('alice_add_comment_badaddr2', 'adding a label with invalid address for this chain'),
  322. ('alice_add_comment_badaddr3', 'adding a label with wrong MMGen address'),
  323. ('alice_add_comment_badaddr4', 'adding a label with wrong coin address'),
  324. ),
  325. 'view': (
  326. 'viewing addresses and unspent outputs',
  327. ('alice_listaddresses1', 'listaddresses'),
  328. ('alice_listaddresses_days', 'listaddresses (age_fmt=days)'),
  329. ('alice_listaddresses_date', 'listaddresses (age_fmt=date)'),
  330. ('alice_listaddresses_date_time', 'listaddresses (age_fmt=date_time)'),
  331. ('alice_twview1', 'twview'),
  332. ('alice_twview_days', 'twview (age_fmt=days)'),
  333. ('alice_twview_date', 'twview (age_fmt=date)'),
  334. ('alice_twview_date_time', 'twview (age_fmt=date_time)'),
  335. ('alice_txcreate_info', 'txcreate -i'),
  336. ('alice_txcreate_info_term', 'txcreate -i (pexpect_spawn)'),
  337. ),
  338. 'auto_chg': (
  339. 'automatic change address selection',
  340. ('bob_split3', 'splitting Bob’s funds'),
  341. ('generate', 'mining a block'),
  342. ('bob_auto_chg1', 'creating an automatic change address transaction (C)'),
  343. ('bob_auto_chg2', 'creating an automatic change address transaction (B)'),
  344. ('bob_auto_chg3', 'creating an automatic change address transaction (S)'),
  345. ('bob_auto_chg4', 'creating an automatic change address transaction (single address)'),
  346. ('bob_auto_chg_bad1', 'error handling for auto change address transaction (bad ID FFFFFFFF:C)'),
  347. ('bob_auto_chg_bad2', 'error handling for auto change address transaction (bad ID 00000000:C)'),
  348. ('bob_auto_chg_bad3', 'error handling for auto change address transaction (no unused addresses)'),
  349. ),
  350. }
  351. def __init__(self,trunner,cfgs,spawn):
  352. TestSuiteBase.__init__(self,trunner,cfgs,spawn)
  353. if trunner == None:
  354. return
  355. if self.proto.testnet:
  356. die(2,'--testnet and --regtest options incompatible with regtest test suite')
  357. self.proto = init_proto(self.proto.coin,network='regtest',need_amt=True)
  358. coin = self.proto.coin.lower()
  359. import test.test_py_d.ts_regtest as rt_mod
  360. for k in rt_data:
  361. setattr( rt_mod, k, rt_data[k][coin] if coin in rt_data[k] else None )
  362. if self.proto.coin == 'BTC':
  363. self.test_rbf = True # tests are non-coin-dependent, so run just once for BTC
  364. if g.test_suite_deterministic:
  365. self.deterministic = True
  366. self.miner_addr = 'bcrt1qaq8t3pakcftpk095tnqfv5cmmczysls024atnd' # regtest.create_hdseed()
  367. self.miner_wif = 'cTyMdQ2BgfAsjopRVZrj7AoEGp97pKfrC2NkqLuwHr4KHfPNAKwp'
  368. os.environ['MMGEN_BOGUS_SEND'] = ''
  369. self.write_to_tmpfile('wallet_password',rt_pw)
  370. self.dfl_mmtype = 'C' if self.proto.coin == 'BCH' else 'B'
  371. self.burn_addr = make_burn_addr(self.proto)
  372. def __del__(self):
  373. os.environ['MMGEN_BOGUS_SEND'] = '1'
  374. def _add_comments_to_addr_file(self,addrfile,outfile,use_comments=False):
  375. silence()
  376. gmsg(f'Adding comments to address file {addrfile!r}')
  377. a = AddrList(self.proto,addrfile)
  378. for n,idx in enumerate(a.idxs(),1):
  379. if use_comments:
  380. a.set_comment(idx,get_comment())
  381. else:
  382. if n % 2: a.set_comment(idx,f'Test address {n}')
  383. af = a.get_file()
  384. af.format(add_comments=True)
  385. from mmgen.fileutil import write_data_to_file
  386. write_data_to_file(outfile,af.fmt_data,quiet=True,ignore_opt_outdir=True)
  387. end_silence()
  388. def setup(self):
  389. stop_test_daemons(self.proto.network_id,force=True,remove_datadir=True)
  390. from shutil import rmtree
  391. try: rmtree(joinpath(self.tr.data_dir,'regtest'))
  392. except: pass
  393. t = self.spawn('mmgen-regtest',['-n','setup'])
  394. for s in ('Starting','Creating','Creating','Creating','Mined','Setup complete'):
  395. t.expect(s)
  396. return t
  397. def daemon_version(self):
  398. t = self.spawn('mmgen-tool', ['--bob','daemon_version'])
  399. t.expect('version')
  400. return t
  401. def halving_calculator_bob(self):
  402. t = self.spawn('halving-calculator.py',['--bob'],cmd_dir='examples')
  403. t.expect('time until halving')
  404. return t
  405. def walletgen(self,user):
  406. t = self.spawn('mmgen-walletgen',['-q','-r0','-p1','--'+user])
  407. t.passphrase_new('new '+dfl_wcls.desc,rt_pw)
  408. t.label()
  409. t.expect('move it to the data directory? (Y/n): ','y')
  410. t.written_to_file(capfirst(dfl_wcls.desc))
  411. return t
  412. def walletgen_bob(self): return self.walletgen('bob')
  413. def walletgen_alice(self): return self.walletgen('alice')
  414. def _user_dir(self,user,coin=None):
  415. return joinpath(self.tr.data_dir,'regtest',coin or self.proto.coin.lower(),user)
  416. def _user_sid(self,user):
  417. return os.path.basename(get_file_with_ext(self._user_dir(user),'mmdat'))[:8]
  418. def _get_user_subsid(self,user,subseed_idx):
  419. fn = get_file_with_ext(self._user_dir(user),dfl_wcls.ext)
  420. silence()
  421. w = Wallet( fn=fn, passwd_file=os.path.join(self.tmpdir,'wallet_password') )
  422. end_silence()
  423. return w.seed.subseed(subseed_idx).sid
  424. def addrgen(self,user,wf=None,addr_range='1-5',subseed_idx=None,mmtypes=[]):
  425. from mmgen.addr import MMGenAddrType
  426. for mmtype in mmtypes or self.proto.mmtypes:
  427. t = self.spawn('mmgen-addrgen',
  428. ['--quiet','--'+user,'--type='+mmtype,f'--outdir={self._user_dir(user)}'] +
  429. ([wf] if wf else []) +
  430. (['--subwallet='+subseed_idx] if subseed_idx else []) +
  431. [addr_range],
  432. extra_desc='({})'.format( MMGenAddrType.mmtypes[mmtype].name ))
  433. t.passphrase(dfl_wcls.desc,rt_pw)
  434. t.written_to_file('Addresses')
  435. ok_msg()
  436. t.skip_ok = True
  437. return t
  438. def addrgen_bob(self): return self.addrgen('bob')
  439. def addrgen_alice(self): return self.addrgen('alice')
  440. def addrimport(self,user,sid=None,addr_range='1-5',num_addrs=5,mmtypes=[],batch=True,quiet=True):
  441. id_strs = { 'legacy':'', 'compressed':'-C', 'segwit':'-S', 'bech32':'-B' }
  442. if not sid: sid = self._user_sid(user)
  443. from mmgen.addr import MMGenAddrType
  444. for mmtype in mmtypes or self.proto.mmtypes:
  445. desc = MMGenAddrType.mmtypes[mmtype].name
  446. addrfile = joinpath(self._user_dir(user),
  447. '{}{}{}[{}]{x}.regtest.addrs'.format(
  448. sid,self.altcoin_pfx,id_strs[desc],addr_range,
  449. x='-α' if g.debug_utf8 else ''))
  450. if mmtype == self.proto.mmtypes[0] and user == 'bob':
  451. self._add_comments_to_addr_file(addrfile,addrfile,use_comments=True)
  452. t = self.spawn(
  453. 'mmgen-addrimport',
  454. args = (
  455. (['--quiet'] if quiet else []) +
  456. ['--'+user] +
  457. (['--batch'] if batch else []) +
  458. [addrfile] ),
  459. extra_desc = f'({desc})' )
  460. if g.debug:
  461. t.expect("Type uppercase 'YES' to confirm: ",'YES\n')
  462. t.expect('Importing')
  463. if batch:
  464. t.expect(f'{num_addrs} addresses imported')
  465. else:
  466. t.expect(f'import completed OK')
  467. t.ok()
  468. t.skip_ok = True
  469. return t
  470. def addrimport_bob(self): return self.addrimport('bob')
  471. def addrimport_alice(self): return self.addrimport('alice',batch=False,quiet=False)
  472. def bob_import_miner_addr(self):
  473. if not self.deterministic:
  474. return 'skip'
  475. return self.spawn(
  476. 'mmgen-addrimport',
  477. [ '--bob', '--rescan', '--quiet', f'--address={self.miner_addr}' ] )
  478. def fund_wallet_deterministic(self,user,addr,utxo_nums,skip_passphrase=False):
  479. """
  480. the deterministic funding method using specific inputs
  481. """
  482. if not self.deterministic:
  483. return 'skip'
  484. self.write_to_tmpfile('miner.key',f'{self.miner_wif}\n')
  485. keyfile = joinpath(self.tmpdir,'miner.key')
  486. return self.user_txdo(
  487. 'bob', '40s',
  488. [ f'{addr},{rtFundAmt}', self.burn_addr ],
  489. utxo_nums,
  490. extra_args = [f'--keys-from-file={keyfile}'],
  491. skip_passphrase = skip_passphrase )
  492. def fund_bob_deterministic(self):
  493. return self.fund_wallet_deterministic( 'bob', f'{self._user_sid("bob")}:C:1', '1-11' )
  494. def fund_alice_deterministic(self):
  495. sid = self._user_sid('alice')
  496. mmtype = ('L','S')[self.proto.cap('segwit')]
  497. addr = self.get_addr_from_addrlist('alice',sid,mmtype,0,addr_range='1-5')
  498. return self.fund_wallet_deterministic( 'alice', addr, '1-11', skip_passphrase=True )
  499. def generate_extra_deterministic(self):
  500. if not self.deterministic:
  501. return 'skip'
  502. return self.generate(num_blocks=2) # do this so block count matches non-deterministic run
  503. async def bob_recreate_tracking_wallet(self):
  504. if not self.deterministic:
  505. return 'skip'
  506. self.spawn('',msg_only=True)
  507. from mmgen.proto.btc.regtest import MMGenRegtest
  508. rt = MMGenRegtest(self.proto.coin)
  509. await rt.stop()
  510. from shutil import rmtree
  511. imsg(f'Deleting Bob’s old tracking wallet')
  512. rmtree(os.path.join(rt.d.datadir,'regtest','wallets','bob'),ignore_errors=True)
  513. rt.init_daemon()
  514. rt.d.start(silent=True)
  515. imsg(f'Creating Bob’s new tracking wallet')
  516. await rt.rpc_call('createwallet','bob',True,True,None,False,False,False)
  517. await rt.stop()
  518. await rt.start()
  519. return 'ok'
  520. def addrimport_bob2(self):
  521. if not self.deterministic:
  522. return 'skip'
  523. return self.addrimport('bob')
  524. def fund_wallet(self,user,mmtype,amt,sid=None,addr_range='1-5'):
  525. if self.deterministic:
  526. return 'skip'
  527. if not sid:
  528. sid = self._user_sid(user)
  529. addr = self.get_addr_from_addrlist(user,sid,mmtype,0,addr_range=addr_range)
  530. t = self.spawn('mmgen-regtest', ['send',str(addr),str(amt)])
  531. t.expect(f'Sending {amt} miner {self.proto.coin}')
  532. t.expect('Mined 1 block')
  533. return t
  534. def fund_bob(self):
  535. return self.fund_wallet('bob','C',rtFundAmt)
  536. def fund_alice(self):
  537. return self.fund_wallet('alice',('L','S')[self.proto.cap('segwit')],rtFundAmt)
  538. def user_twview(self,user,chk,sort='age'):
  539. t = self.spawn('mmgen-tool',['--'+user,'twview','sort='+sort])
  540. if chk:
  541. t.expect(r'{}\b.*\D{}\b'.format(*chk),regex=True)
  542. return t
  543. def bob_twview1(self): return self.user_twview('bob', chk = ('1',rtAmts[0]) )
  544. def user_bal(self,user,bal,args=['showempty=1'],skip_check=False):
  545. t = self.spawn('mmgen-tool',['--'+user,'listaddresses'] + args)
  546. if not skip_check:
  547. cmp_or_die(f'{bal} {self.proto.coin}',strip_ansi_escapes(t.expect_getend('TOTAL: ')))
  548. return t
  549. def alice_bal1(self):
  550. return self.user_bal('alice',rtFundAmt)
  551. def alice_bal2(self):
  552. return self.user_bal('alice',rtBals[8])
  553. def bob_bal1(self):
  554. return self.user_bal('bob',rtFundAmt)
  555. def bob_bal2(self):
  556. return self.user_bal('bob',rtBals[0])
  557. def bob_bal2a(self):
  558. return self.user_bal('bob',rtBals[0],args=['showempty=1','age_fmt=confs'])
  559. def bob_bal2b(self):
  560. return self.user_bal('bob',rtBals[0],args=['showempty=1'])
  561. def bob_bal2c(self):
  562. return self.user_bal('bob',rtBals[0],args=['showempty=1','minconf=2','age_fmt=days'],skip_check=True)
  563. def bob_bal2d(self):
  564. return self.user_bal('bob',rtBals[0],args=['minconf=2'],skip_check=True)
  565. def bob_bal2e(self):
  566. return self.user_bal('bob',rtBals[0],args=['showempty=1','sort=amt'])
  567. def bob_bal2f(self):
  568. return self.user_bal('bob',rtBals[0],args=['showempty=0','sort=twmmid','reverse=1'])
  569. def bob_bal3(self):
  570. return self.user_bal('bob',rtBals[1])
  571. def bob_bal4(self):
  572. return self.user_bal('bob',rtBals[2])
  573. def bob_bal5(self):
  574. return self.user_bal('bob',rtBals[3])
  575. def bob_bal6(self):
  576. return self.user_bal('bob',rtBals[7])
  577. def bob_subwallet_addrgen1(self):
  578. return self.addrgen('bob',subseed_idx='29L',mmtypes=['C']) # 29L: 2FA7BBA8
  579. def bob_subwallet_addrgen2(self):
  580. return self.addrgen('bob',subseed_idx='127S',mmtypes=['C']) # 127S: '09E8E286'
  581. def subwallet_addrimport(self,user,subseed_idx):
  582. sid = self._get_user_subsid(user,subseed_idx)
  583. return self.addrimport(user,sid=sid,mmtypes=['C'])
  584. def bob_subwallet_addrimport1(self): return self.subwallet_addrimport('bob','29L')
  585. def bob_subwallet_addrimport2(self): return self.subwallet_addrimport('bob','127S')
  586. def bob_subwallet_fund(self):
  587. sid1 = self._get_user_subsid('bob','29L')
  588. sid2 = self._get_user_subsid('bob','127S')
  589. chg_addr = self._user_sid('bob') + (':B:1',':L:1')[self.proto.coin=='BCH']
  590. return self.user_txdo(
  591. user = 'bob',
  592. fee = rtFee[1],
  593. outputs_cl = [sid1+':C:2,0.29',sid2+':C:3,0.127',chg_addr],
  594. outputs_list = ('3','1')[self.proto.coin=='BCH'],
  595. extra_args = ['--subseeds=127'],
  596. used_chg_addr_resp = (None,'y')[self.proto.coin=='BCH'] )
  597. def bob_twview2(self):
  598. sid1 = self._get_user_subsid('bob','29L')
  599. return self.user_twview('bob',chk=(sid1+':C:2','0.29'),sort='twmmid')
  600. def bob_twview3(self):
  601. sid2 = self._get_user_subsid('bob','127S')
  602. return self.user_twview('bob',chk=(sid2+':C:3','0.127'),sort='amt')
  603. def bob_subwallet_txcreate(self):
  604. sid1 = self._get_user_subsid('bob','29L')
  605. sid2 = self._get_user_subsid('bob','127S')
  606. outputs_cl = [sid1+':C:5,0.0159',sid2+':C:5']
  607. t = self.spawn('mmgen-txcreate',['-d',self.tmpdir,'-B','--bob'] + outputs_cl)
  608. return self.txcreate_ui_common(t,
  609. menu = ['a'],
  610. inputs = ('1,2','2,3')[self.proto.coin=='BCH'],
  611. interactive_fee = '0.00001')
  612. def bob_subwallet_txsign(self):
  613. fn = get_file_with_ext(self.tmpdir,'rawtx')
  614. t = self.spawn('mmgen-txsign',['-d',self.tmpdir,'--bob','--subseeds=127',fn])
  615. t.view_tx('t')
  616. t.passphrase(dfl_wcls.desc,rt_pw)
  617. t.do_comment(None)
  618. t.expect('(Y/n): ','y')
  619. t.written_to_file('Signed transaction')
  620. return t
  621. def bob_subwallet_txdo(self):
  622. outputs_cl = [self._user_sid('bob')+':L:5']
  623. inputs = ('1,2','2,3')[self.proto.coin=='BCH']
  624. return self.user_txdo('bob',rtFee[5],outputs_cl,inputs,menu=['a'],extra_args=['--subseeds=127']) # sort: amt
  625. def bob_twview4(self):
  626. sid = self._user_sid('bob')
  627. return self.user_twview('bob',chk=(sid+':L:5',rtBals[9]),sort='twmmid')
  628. def user_txhist(self,user,args,expect):
  629. t = self.spawn('mmgen-tool',['--'+user,'txhist'] + args)
  630. res = strip_ansi_escapes(t.read()).replace('\r','')
  631. m = re.search(expect,res,re.DOTALL)
  632. assert m, f'Expected: {expect}'
  633. return t
  634. def bob_txhist1(self):
  635. return self.user_txhist('bob',
  636. args = ['sort=age'],
  637. expect = fr'\s1\).*\s{rtFundAmt}\s' )
  638. def bob_txhist2(self):
  639. return self.user_txhist('bob',
  640. args = ['sort=blockheight','reverse=1','age_fmt=block'],
  641. expect = fr'\s1\).*:{self.dfl_mmtype}:1\s' )
  642. def bob_txhist3(self):
  643. return self.user_txhist('bob',
  644. args = ['sort=blockheight','sinceblock=-7','age_fmt=block'],
  645. expect = fr'Displaying transactions since block 399.*\s6\)\s+405\s.*\s{rtBals[9]}\s.*:L:5.*\s7\)'
  646. )
  647. def bob_txhist4(self):
  648. return self.user_txhist('bob',
  649. args = ['sort=blockheight','sinceblock=399','age_fmt=block','detail=1'],
  650. expect = fr'Displaying transactions since block 399.*\s7\).*Block:.*406.*Value:.*{rtBals[10]}'
  651. )
  652. def bob_txhist_interactive(self):
  653. self.get_file_with_ext('out',delete_all=True)
  654. t = self.spawn('mmgen-tool',
  655. ['--bob',f'--outdir={self.tmpdir}','txhist','age_fmt=date_time','interactive=true'] )
  656. for resp in ('u','i','t','a','m','T','A','r','r','D','D','D','D','p','P','b','V'):
  657. t.expect('draw:\b',resp,regex=True)
  658. if t.pexpect_spawn:
  659. t.expect(r'Block:.*\b394\b',regex=True)
  660. time.sleep(1)
  661. t.send('q')
  662. time.sleep(0.2)
  663. t.send('b')
  664. t.expect('draw:\b','q',regex=True)
  665. else:
  666. txnum,idx = (8,1) if self.proto.coin == 'BCH' else (9,3)
  667. t.expect(f'\s{txnum}\).*Inputs:.*:L:{idx}.*Outputs \(3\):.*:C:2.*\s10\)','q',regex=True)
  668. return t
  669. def bob_getbalance(self,bals,confs=1):
  670. for i in range(len(bals['mmgen'])):
  671. assert Decimal(bals['mmgen'][i]) + Decimal(bals['nonmm'][i]) == Decimal(bals['total'][i])
  672. sid = self._user_sid('bob')
  673. t = self.spawn('mmgen-tool',['--bob','getbalance',f'minconf={confs}'])
  674. t.expect('Wallet')
  675. for k,lbl in (
  676. ('mmgen',f'{sid}:'),
  677. ('nonmm','Non-MMGen:'),
  678. ('total',f'TOTAL {self.proto.coin}')
  679. ):
  680. ret = strip_ansi_escapes(t.expect_getend(lbl + ' '))
  681. cmp_or_die(
  682. ' '.join(bals[k]),
  683. ' '.join(ret.split()),
  684. desc = k,
  685. )
  686. return t
  687. def bob_0conf0_getbalance(self): return self.bob_getbalance(rtBals_gb['0conf0'],confs=0)
  688. def bob_0conf1_getbalance(self): return self.bob_getbalance(rtBals_gb['0conf1'],confs=1)
  689. def bob_1conf1_getbalance(self): return self.bob_getbalance(rtBals_gb['1conf1'],confs=1)
  690. def bob_1conf2_getbalance(self): return self.bob_getbalance(rtBals_gb['1conf2'],confs=2)
  691. def bob_nochg_burn(self):
  692. return self.user_txdo('bob',
  693. fee = '0.00009713',
  694. outputs_cl = [self.burn_addr],
  695. outputs_list = '1' )
  696. def bob_alice_bal(self):
  697. t = self.spawn('mmgen-regtest',['balances'])
  698. ret = t.expect_getend("Bob's balance:").strip()
  699. cmp_or_die(rtBals[4],ret)
  700. ret = t.expect_getend("Alice's balance:").strip()
  701. cmp_or_die(rtBals[5],ret)
  702. ret = t.expect_getend("Total balance:").strip()
  703. cmp_or_die(rtBals[6],ret)
  704. return t
  705. def user_txsend_status(self,user,tx_file,exp1='',exp2='',extra_args=[]):
  706. t = self.spawn('mmgen-txsend',['-d',self.tmpdir,'--'+user,'--status'] + extra_args + [tx_file])
  707. if exp1: t.expect(exp1,regex=True)
  708. if exp2: t.expect(exp2,regex=True)
  709. return t
  710. def user_txdo( self, user, fee, outputs_cl, outputs_list,
  711. extra_args = [],
  712. wf = None,
  713. do_label = False,
  714. bad_locktime = False,
  715. full_tx_view = False,
  716. menu = ['M'],
  717. skip_passphrase = False,
  718. used_chg_addr_resp = None ):
  719. t = self.spawn('mmgen-txdo',
  720. ['-d',self.tmpdir,'-B','--'+user] +
  721. (['--tx-fee='+fee] if fee else []) +
  722. extra_args + ([],[wf])[bool(wf)] + outputs_cl)
  723. self.txcreate_ui_common(t,
  724. caller = 'txdo',
  725. menu = menu,
  726. inputs = outputs_list,
  727. file_desc = 'Signed transaction',
  728. interactive_fee = (tx_fee,'')[bool(fee)],
  729. add_comment = tx_comment_jp,
  730. view = 't',
  731. save = True,
  732. used_chg_addr_resp = used_chg_addr_resp )
  733. if not skip_passphrase:
  734. t.passphrase(dfl_wcls.desc,rt_pw)
  735. t.written_to_file('Signed transaction')
  736. self._do_confirm_send(t)
  737. s,exit_val = (('Transaction sent',0),("can't be included",1))[bad_locktime]
  738. t.expect(s)
  739. t.req_exit_val = exit_val
  740. return t
  741. def bob_split1(self):
  742. sid = self._user_sid('bob')
  743. outputs_cl = [sid+':C:1,100', sid+':L:2,200',sid+':'+rtBobOp3]
  744. return self.user_txdo('bob',rtFee[0],outputs_cl,'1',do_label=True,full_tx_view=True)
  745. def get_addr_from_addrlist(self,user,sid,mmtype,idx,addr_range='1-5'):
  746. id_str = { 'L':'', 'S':'-S', 'C':'-C', 'B':'-B' }[mmtype]
  747. ext = '{}{}{}[{}]{x}.regtest.addrs'.format(
  748. sid,self.altcoin_pfx,id_str,addr_range,x='-α' if g.debug_utf8 else '')
  749. addrfile = get_file_with_ext(self._user_dir(user),ext,no_dot=True)
  750. silence()
  751. addr = AddrList(self.proto,addrfile).data[idx].addr
  752. end_silence()
  753. return addr
  754. def _create_tx_outputs(self,user,data):
  755. sid = self._user_sid(user)
  756. return [self.get_addr_from_addrlist(user,sid,mmtype,idx-1)+amt_str for mmtype,idx,amt_str in data]
  757. def bob_rbf_1output_create(self):
  758. if not self.test_rbf:
  759. return 'skip'
  760. out_addr = self._create_tx_outputs('alice',(('B',5,''),))
  761. t = self.spawn('mmgen-txcreate',['-d',self.tr.trash_dir,'-B','--bob','--rbf'] + out_addr)
  762. return self.txcreate_ui_common(t,menu=[],inputs='3',interactive_fee='3s') # out amt: 199.99999343
  763. def bob_rbf_1output_bump(self):
  764. if not self.test_rbf:
  765. return 'skip'
  766. ext = '9343,3]{x}.regtest.rawtx'.format(x='-α' if g.debug_utf8 else '')
  767. txfile = get_file_with_ext(self.tr.trash_dir,ext,delete=False,no_dot=True)
  768. return self.user_txbump('bob',
  769. self.tr.trash_dir,
  770. txfile,
  771. '8s',
  772. has_label = False,
  773. signed_tx = False,
  774. one_output = True )
  775. def bob_send_maybe_rbf(self):
  776. outputs_cl = self._create_tx_outputs('alice',(('L',1,',60'),('C',1,',40'))) # alice_sid:L:1, alice_sid:C:1
  777. outputs_cl += [self._user_sid('bob')+':'+rtBobOp3]
  778. return self.user_txdo('bob',rtFee[1],outputs_cl,'3',
  779. extra_args = ([],['--rbf'])[self.proto.cap('rbf')],
  780. used_chg_addr_resp = 'y' )
  781. def bob_send_non_mmgen(self):
  782. outputs_cl = self._create_tx_outputs('alice',(
  783. (('L','S')[self.proto.cap('segwit')],2,',10'),
  784. (('L','S')[self.proto.cap('segwit')],3,'')
  785. )) # alice_sid:S:2, alice_sid:S:3
  786. keyfile = joinpath(self.tmpdir,'non-mmgen.keys')
  787. return self.user_txdo('bob',rtFee[3],outputs_cl,'1,4-10',
  788. extra_args=['--keys-from-file='+keyfile,'--vsize-adj=1.02'])
  789. def alice_send_estimatefee(self):
  790. outputs_cl = self._create_tx_outputs('bob',(('L',1,''),)) # bob_sid:L:1
  791. return self.user_txdo('alice',None,outputs_cl,'1') # fee=None
  792. def user_txbump(self,user,outdir,txfile,fee,add_args=[],has_label=True,signed_tx=True,one_output=False):
  793. if not self.proto.cap('rbf'):
  794. return 'skip'
  795. t = self.spawn('mmgen-txbump',
  796. ['-d',outdir,'--'+user,'--tx-fee='+fee,'--output-to-reduce=c'] + add_args + [txfile])
  797. if not one_output:
  798. t.expect('OK? (Y/n): ','y') # output OK?
  799. t.expect('OK? (Y/n): ','y') # fee OK?
  800. t.do_comment(False,has_label=has_label)
  801. if signed_tx:
  802. t.passphrase(dfl_wcls.desc,rt_pw)
  803. t.written_to_file('Signed transaction')
  804. self.txsend_ui_common(t,caller='txdo',bogus_send=False,file_desc='Signed transaction')
  805. else:
  806. t.expect('Save fee-bumped transaction? (y/N): ','y')
  807. t.written_to_file('Fee-bumped transaction')
  808. return t
  809. def bob_rbf_bump(self):
  810. ext = ',{}]{x}.regtest.sigtx'.format(rtFee[1][:-1],x='-α' if g.debug_utf8 else '')
  811. txfile = self.get_file_with_ext(ext,delete=False,no_dot=True)
  812. return self.user_txbump('bob',self.tmpdir,txfile,rtFee[2],add_args=['--send'])
  813. def generate(self,num_blocks=1):
  814. int(num_blocks)
  815. t = self.spawn('mmgen-regtest',['generate',str(num_blocks)])
  816. t.expect(f'Mined {num_blocks} block')
  817. return t
  818. def _get_mempool(self):
  819. if not g.debug_utf8:
  820. disable_debug()
  821. ret = self.spawn('mmgen-regtest',['mempool']).read()
  822. if not g.debug_utf8:
  823. restore_debug()
  824. m = re.search(r'(\[\s*"[a-f0-9]{64}"\s*])',ret) # allow for extra output by handler at end
  825. return json.loads(m.group(1))
  826. def get_mempool1(self):
  827. mp = self._get_mempool()
  828. if len(mp) != 1:
  829. die(4,'Mempool has more or less than one TX!')
  830. self.write_to_tmpfile('rbf_txid',mp[0]+'\n')
  831. return 'ok'
  832. def bob_rbf_status(self,fee,exp1,exp2=''):
  833. if not self.proto.cap('rbf'):
  834. return 'skip'
  835. ext = ',{}]{x}.regtest.sigtx'.format(fee[:-1],x='-α' if g.debug_utf8 else '')
  836. txfile = self.get_file_with_ext(ext,delete=False,no_dot=True)
  837. return self.user_txsend_status('bob',txfile,exp1,exp2)
  838. def bob_rbf_status1(self):
  839. if not self.proto.cap('rbf'):
  840. return 'skip'
  841. return self.bob_rbf_status(rtFee[1],'in mempool, replaceable')
  842. def get_mempool2(self):
  843. if not self.proto.cap('rbf'):
  844. return 'skip'
  845. mp = self._get_mempool()
  846. if len(mp) != 1:
  847. die(4,'Mempool has more or less than one TX!')
  848. chk = self.read_from_tmpfile('rbf_txid')
  849. if chk.strip() == mp[0]:
  850. die(4,'TX in mempool has not changed! RBF bump failed')
  851. self.write_to_tmpfile('rbf_txid2',mp[0]+'\n')
  852. return 'ok'
  853. def bob_rbf_status2(self):
  854. if not self.proto.cap('rbf'):
  855. return 'skip'
  856. new_txid = self.read_from_tmpfile('rbf_txid2').strip()
  857. return self.bob_rbf_status(rtFee[1],
  858. 'Transaction has been replaced',f'{new_txid} in mempool')
  859. def bob_rbf_status3(self):
  860. if not self.proto.cap('rbf'):
  861. return 'skip'
  862. return self.bob_rbf_status(rtFee[2],'status: in mempool, replaceable')
  863. def bob_rbf_status4(self):
  864. if not self.proto.cap('rbf'):
  865. return 'skip'
  866. new_txid = self.read_from_tmpfile('rbf_txid2').strip()
  867. return self.bob_rbf_status(rtFee[1],
  868. 'Replacement transaction has 1 confirmation',
  869. f'Replacing transactions:\s+{new_txid}' )
  870. def bob_rbf_status5(self):
  871. if not self.proto.cap('rbf'):
  872. return 'skip'
  873. return self.bob_rbf_status(rtFee[2],'Transaction has 1 confirmation')
  874. def bob_rbf_status6(self):
  875. if not self.proto.cap('rbf'):
  876. return 'skip'
  877. new_txid = self.read_from_tmpfile('rbf_txid2').strip()
  878. return self.bob_rbf_status(rtFee[1],
  879. 'Replacement transaction has 2 confirmations',
  880. f'Replacing transactions:\s+{new_txid}' )
  881. def _gen_pairs(self,n):
  882. from mmgen.tool.api import tool_api
  883. t = tool_api()
  884. t.init_coin(self.proto.coin,self.proto.network)
  885. def gen_addr(Type):
  886. t.addrtype = Type
  887. wif = t.hex2wif(getrandhex(32))
  888. return ( wif, t.wif2addr(wif) )
  889. return [gen_addr('legacy')] + [gen_addr('compressed') for i in range(n-1)]
  890. def bob_pre_import(self):
  891. pairs = self._gen_pairs(5)
  892. self.write_to_tmpfile('non-mmgen.keys','\n'.join([a[0] for a in pairs])+'\n')
  893. self.write_to_tmpfile('non-mmgen.addrs','\n'.join([a[1] for a in pairs])+'\n')
  894. return self.user_txdo('bob',rtFee[4],[pairs[0][1]],'3')
  895. def user_import(self,user,args,nAddr):
  896. t = self.spawn('mmgen-addrimport',['--'+user]+args)
  897. if g.debug:
  898. t.expect("Type uppercase 'YES' to confirm: ",'YES\n')
  899. t.expect(f'Importing {nAddr} address')
  900. if '--rescan' in args:
  901. if not '--quiet' in args:
  902. t.expect('Continue? (Y/n): ','y')
  903. t.expect('Rescanning block')
  904. return t
  905. def bob_import_addr(self):
  906. addr = self.read_from_tmpfile('non-mmgen.addrs').split()[0]
  907. return self.user_import('bob',['--quiet','--address='+addr],nAddr=1)
  908. def bob_import_list_rescan_aio(self):
  909. addrfile = joinpath(self.tmpdir,'non-mmgen.addrs')
  910. return self.user_import('bob',['--rescan','--rpc-backend=aio','--addrlist',addrfile],nAddr=5)
  911. def bob_resolve_addr(self):
  912. mmaddr = '{}:C:1'.format(self._user_sid('bob'))
  913. t = self.spawn('mmgen-tool',['--bob','resolve_address',mmaddr])
  914. coinaddr = t.read().split()[0].strip()
  915. t = self.spawn('mmgen-tool',['--bob','resolve_address',coinaddr],no_msg=True)
  916. mmaddr_res = t.read().split()[0].strip()
  917. assert mmaddr == mmaddr_res, f'{mmaddr} != {mmaddr_res}'
  918. return t
  919. def bob_import_list(self):
  920. addrfile = joinpath(self.tmpdir,'non-mmgen.addrs')
  921. return self.user_import('bob',['--quiet','--addrlist',addrfile],nAddr=5)
  922. def bob_import_list_rescan(self):
  923. addrfile = joinpath(self.tmpdir,'non-mmgen.addrs')
  924. return self.user_import('bob',['--quiet','--rescan','--addrlist',addrfile],nAddr=5)
  925. def bob_rescan_addr(self):
  926. sid = self._user_sid('bob')
  927. t = self.spawn('mmgen-tool',['--bob','rescan_address',f'{sid}:C:1'])
  928. t.expect('Found 1 unspent output')
  929. t.expect('updated successfully')
  930. return t
  931. def bob_rescan_blockchain(self,add_args,expect):
  932. t = self.spawn('mmgen-tool',['--bob','rescan_blockchain'] + add_args)
  933. t.expect(f'Scanning blocks {expect}')
  934. t.expect('Done')
  935. return t
  936. def bob_rescan_blockchain_all(self):
  937. return self.bob_rescan_blockchain([],'300-396')
  938. def bob_rescan_blockchain_gb(self):
  939. return self.bob_rescan_blockchain(['start_block=0','stop_block=0'],'0-0')
  940. def bob_rescan_blockchain_one(self):
  941. return self.bob_rescan_blockchain(['start_block=300','stop_block=300'],'300-300')
  942. def bob_rescan_blockchain_ss(self):
  943. return self.bob_rescan_blockchain(['start_block=300','stop_block=302'],'300-302')
  944. def bob_twexport(self,add_args=[]):
  945. t = self.spawn('mmgen-tool',['--bob',f'--outdir={self.tmpdir}','twexport'] + add_args)
  946. t.written_to_file('JSON data')
  947. return t
  948. def bob_twexport_noamt(self):
  949. return self.bob_twexport(add_args=['include_amts=0'])
  950. def bob_twexport_pretty(self):
  951. return self.bob_twexport(add_args=['pretty=1'])
  952. def bob_edit_json_twdump(self):
  953. self.spawn('',msg_only=True)
  954. from mmgen.tw.json import TwJSON
  955. fn = TwJSON.Base(self.proto).dump_fn
  956. text = json.loads(self.read_from_tmpfile(fn))
  957. text['data']['entries'][3][3] = f'edited comment [фубар] [{gr_uc}]'
  958. self.write_to_tmpfile( fn, json.dumps(text,indent=4) )
  959. return 'ok'
  960. def carol_twimport(self,add_args=[],add_parms=[],expect_str=None):
  961. from mmgen.tw.json import TwJSON
  962. fn = joinpath( self.tmpdir, TwJSON.Base(self.proto).dump_fn )
  963. t = self.spawn('mmgen-tool', add_args + ['--carol','twimport',fn] + add_parms)
  964. t.expect('(y/N): ','y')
  965. if expect_str:
  966. t.expect(expect_str)
  967. elif 'batch=true' in add_parms:
  968. t.expect('{} addresses imported'.format(10 if self.proto.coin == 'BCH' else 20))
  969. else:
  970. t.expect('import completed OK')
  971. t.expect('Found 1 unspent output')
  972. return t
  973. def carol_twimport_nochksum(self):
  974. return self.carol_twimport(add_args=['--rpc-backend=aio'],add_parms=['ignore_checksum=true'])
  975. def carol_twimport_batch(self):
  976. return self.carol_twimport(add_parms=['batch=true'])
  977. def carol_twimport_pretty(self):
  978. return self.carol_twimport(add_parms=['ignore_checksum=true'],expect_str='ignoring incorrect checksum')
  979. def carol_listaddresses(self):
  980. return self.spawn('mmgen-tool',['--carol','listaddresses','showempty=1'])
  981. async def carol_delete_wallet(self):
  982. imsg(f'Unloading Carol’s tracking wallet')
  983. t = self.spawn('mmgen-regtest',['cli','unloadwallet','carol'])
  984. t.ok()
  985. from mmgen.rpc import rpc_init
  986. rpc = await rpc_init(self.proto)
  987. wdir = joinpath(rpc.daemon.network_datadir,'wallets','carol')
  988. from shutil import rmtree
  989. imsg(f'Deleting Carol’s tracking wallet')
  990. rmtree(wdir)
  991. return 'silent'
  992. def bob_split2(self):
  993. addrs = self.read_from_tmpfile('non-mmgen.addrs').split()
  994. amts = (1.12345678,2.87654321,3.33443344,4.00990099,5.43214321)
  995. outputs1 = list(map('{},{}'.format,addrs,amts))
  996. sid = self._user_sid('bob')
  997. l1,l2 = (
  998. (':S',':B') if 'B' in self.proto.mmtypes else
  999. (':S',':S') if self.proto.cap('segwit') else
  1000. (':L',':L') )
  1001. outputs2 = [sid+':C:2,6.333', sid+':L:3,6.667',sid+l1+':4,0.123',sid+l2+':5']
  1002. return self.user_txdo('bob',rtFee[5],outputs1+outputs2,'1-2')
  1003. def user_add_comment(self,user,addr,comment):
  1004. t = self.spawn('mmgen-tool',['--'+user,'add_label',addr,comment])
  1005. t.expect('Added label.*in tracking wallet',regex=True)
  1006. return t
  1007. def user_remove_comment(self,user,addr):
  1008. t = self.spawn('mmgen-tool',['--'+user,'remove_label',addr])
  1009. t.expect('Removed label.*in tracking wallet',regex=True)
  1010. return t
  1011. def bob_add_comment(self):
  1012. sid = self._user_sid('bob')
  1013. return self.user_add_comment('bob',sid+':C:1',tw_comment_lat_cyr_gr)
  1014. def alice_add_comment1(self):
  1015. sid = self._user_sid('alice')
  1016. return self.user_add_comment('alice',sid+':C:1','Original Label - 月へ')
  1017. def alice_add_comment2(self):
  1018. sid = self._user_sid('alice')
  1019. return self.user_add_comment('alice',sid+':C:1','Replacement Label')
  1020. def _user_chk_comment(self,user,addr,comment,extra_args=[]):
  1021. t = self.spawn('mmgen-tool',['--'+user,'listaddresses','all_labels=1']+extra_args)
  1022. ret = strip_ansi_escapes(t.expect_getend(addr)).strip().split(None,2)[2]
  1023. cmp_or_die( # squeezed display, double-width chars, so truncate to min field width
  1024. ret[:3].strip(),
  1025. comment[:3].strip())
  1026. return t
  1027. def alice_add_comment_coinaddr(self):
  1028. mmid = self._user_sid('alice') + (':S:1',':L:1')[self.proto.coin=='BCH']
  1029. t = self.spawn('mmgen-tool',['--alice','listaddress',mmid,'wide=true'],no_msg=True)
  1030. addr = [i for i in strip_ansi_escapes(t.read()).splitlines() if re.search(rf'\b{mmid}\b',i)][0].split()[3]
  1031. return self.user_add_comment('alice',addr,'Label added using coin address of MMGen address')
  1032. def alice_chk_comment_coinaddr(self):
  1033. mmid = self._user_sid('alice') + (':S:1',':L:1')[self.proto.coin=='BCH']
  1034. return self._user_chk_comment('alice',mmid,'Label added using coin address of MMGen address')
  1035. def alice_add_comment_badaddr(self,addr,reply,exit_val):
  1036. if os.getenv('PYTHONOPTIMIZE'):
  1037. omsg(yellow(f'PYTHONOPTIMIZE set, skipping test {self.test_name!r}'))
  1038. return 'skip'
  1039. t = self.spawn('mmgen-tool',['--alice','add_label',addr,'(none)'])
  1040. t.expect(reply,regex=True)
  1041. t.req_exit_val = exit_val
  1042. return t
  1043. def alice_add_comment_badaddr1(self):
  1044. return self.alice_add_comment_badaddr( rt_pw, 'invalid address', 2 )
  1045. def alice_add_comment_badaddr2(self):
  1046. addr = init_proto(self.proto.coin,network='mainnet').pubhash2addr(bytes(20),False) # mainnet zero address
  1047. return self.alice_add_comment_badaddr( addr, 'invalid address', 2 )
  1048. def alice_add_comment_badaddr3(self):
  1049. addr = self._user_sid('alice') + ':C:123'
  1050. return self.alice_add_comment_badaddr( addr, f'MMGen address {addr!r} not found in tracking wallet', 2 )
  1051. def alice_add_comment_badaddr4(self):
  1052. addr = self.proto.pubhash2addr(bytes(20),False) # regtest (testnet) zero address
  1053. return self.alice_add_comment_badaddr( addr, f'Coin address {addr!r} not found in tracking wallet', 2 )
  1054. def alice_remove_comment1(self):
  1055. sid = self._user_sid('alice')
  1056. mmid = sid + (':S:3',':L:3')[self.proto.coin=='BCH']
  1057. return self.user_remove_comment('alice',mmid)
  1058. def alice_chk_comment1(self):
  1059. sid = self._user_sid('alice')
  1060. return self._user_chk_comment('alice',sid+':C:1','Original Label - 月へ')
  1061. def alice_chk_comment2(self):
  1062. sid = self._user_sid('alice')
  1063. return self._user_chk_comment('alice',sid+':C:1','Replacement Label',extra_args=['age_fmt=block'])
  1064. def alice_edit_comment1(self): return self.user_edit_comment('alice','4',tw_comment_lat_cyr_gr)
  1065. def alice_edit_comment2(self): return self.user_edit_comment('alice','3',tw_comment_zh)
  1066. def alice_chk_comment3(self):
  1067. sid = self._user_sid('alice')
  1068. mmid = sid + (':S:3',':L:3')[self.proto.coin=='BCH']
  1069. return self._user_chk_comment('alice',mmid,tw_comment_lat_cyr_gr,extra_args=['age_fmt=date'])
  1070. def alice_chk_comment4(self):
  1071. sid = self._user_sid('alice')
  1072. mmid = sid + (':S:3',':L:3')[self.proto.coin=='BCH']
  1073. return self._user_chk_comment('alice',mmid,'-',extra_args=['age_fmt=date_time'])
  1074. def user_edit_comment(self,user,output,comment):
  1075. t = self.spawn('mmgen-txcreate',['-B','--'+user,'-i'])
  1076. t.expect(r'add \[l\]abel:.','M',regex=True)
  1077. t.expect(r'add \[l\]abel:.','l',regex=True)
  1078. t.expect(r"Enter unspent.*return to main menu\):.",output+'\n',regex=True)
  1079. t.expect(r"Enter label text.*:.",comment+'\n',regex=True)
  1080. t.expect(r'\[q\]uit view, .*?:.','q',regex=True)
  1081. return t
  1082. def alice_listaddresses(self,args,expect):
  1083. t = self.spawn('mmgen-tool',['--alice','listaddresses','showempty=1'] + args)
  1084. expect_str = r'\D{}\D.*\b{}'.format(*expect)
  1085. t.expect(expect_str,regex=True)
  1086. return t
  1087. def alice_listaddresses1(self):
  1088. return self.alice_listaddresses(
  1089. args = [],
  1090. expect = (rtAmts[1],r'\d+') )
  1091. def alice_listaddresses_days(self):
  1092. return self.alice_listaddresses(
  1093. args = ['age_fmt=days'],
  1094. expect = (rtAmts[1],r'\d+') )
  1095. def alice_listaddresses_date(self):
  1096. return self.alice_listaddresses(
  1097. args = ['age_fmt=date'],
  1098. expect = (rtAmts[1],pat_date) )
  1099. def alice_listaddresses_date_time(self):
  1100. return self.alice_listaddresses(
  1101. args = ['age_fmt=date_time'],
  1102. expect = (rtAmts[1],pat_date_time) )
  1103. def alice_twview(self,args,expect):
  1104. t = self.spawn('mmgen-tool',['--alice','twview'] + args)
  1105. expect_str = r'\D{}\D.*\b{}'.format(*expect)
  1106. t.expect(expect_str,regex=True)
  1107. return t
  1108. def alice_twview1(self):
  1109. return self.alice_twview(
  1110. args = [],
  1111. expect = (rtAmts[0],r'\d+') )
  1112. def alice_twview_days(self):
  1113. return self.alice_twview(
  1114. args = ['age_fmt=days'],
  1115. expect = (rtAmts[0],r'\d+') )
  1116. def alice_twview_date(self):
  1117. return self.alice_twview(
  1118. args = ['age_fmt=date'],
  1119. expect = (rtAmts[0],pat_date) )
  1120. def alice_twview_date_time(self):
  1121. return self.alice_twview(
  1122. args = ['age_fmt=date_time'],
  1123. expect = (rtAmts[0],pat_date_time) )
  1124. def alice_txcreate_info(self,pexpect_spawn=False):
  1125. t = self.spawn('mmgen-txcreate',['--alice','-Bi'],pexpect_spawn=pexpect_spawn)
  1126. pats = (
  1127. ( '\d+', 'w'),
  1128. ( '\d+', 'D'),
  1129. ( '\d+', 'D'),
  1130. ( '\d+', 'D'),
  1131. ( pat_date, 'q'),
  1132. )
  1133. for d,s in pats:
  1134. t.expect(
  1135. r'\D{}\D.*\b{}\b'.format( rtAmts[0], d ),
  1136. s,
  1137. regex=True )
  1138. if t.pexpect_spawn and s == 'w':
  1139. t.expect(r'Total.*','q',regex=True,delay=1 if opt.exact_output else t.send_delay)
  1140. time.sleep(t.send_delay)
  1141. t.send('e')
  1142. return t
  1143. def alice_txcreate_info_term(self):
  1144. if self.skip_for_win():
  1145. return 'skip'
  1146. return self.alice_txcreate_info(pexpect_spawn=True)
  1147. def bob_msgcreate(self):
  1148. sid1 = self._user_sid('bob')
  1149. sid2 = self._get_user_subsid('bob','29L')
  1150. return self.spawn(
  1151. 'mmgen-msg', [
  1152. '--bob',
  1153. f'--outdir={self.tmpdir}',
  1154. 'create',
  1155. '16/3/2022 Earthquake strikes Fukushima coast',
  1156. f'{sid1}:{self.dfl_mmtype}:1-4',
  1157. f'{sid2}:C:3-7,87,98'
  1158. ])
  1159. def bob_msgsign(self,wallets=[]):
  1160. fn = get_file_with_ext(self.tmpdir,'rawmsg.json')
  1161. t = self.spawn(
  1162. 'mmgen-msg', [
  1163. '--bob',
  1164. f'--outdir={self.tmpdir}',
  1165. 'sign',
  1166. fn
  1167. ] + wallets )
  1168. if not wallets:
  1169. t.passphrase(dfl_wcls.desc,rt_pw)
  1170. return t
  1171. def bob_walletconv_words(self):
  1172. t = self.spawn(
  1173. 'mmgen-walletconv', [ '--bob', f'--outdir={self.tmpdir}', '--out-fmt=words' ] )
  1174. t.passphrase(dfl_wcls.desc,rt_pw)
  1175. t.written_to_file('data')
  1176. return t
  1177. def bob_subwalletgen_bip39(self):
  1178. t = self.spawn(
  1179. 'mmgen-subwalletgen', [ '--bob', f'--outdir={self.tmpdir}', '--out-fmt=bip39', '29L' ] )
  1180. t.passphrase(dfl_wcls.desc,rt_pw)
  1181. t.written_to_file('data')
  1182. return t
  1183. def bob_msgsign_userwallet(self):
  1184. fn1 = get_file_with_ext(self.tmpdir,'mmwords')
  1185. return self.bob_msgsign([fn1])
  1186. def bob_msgsign_userwallets(self):
  1187. fn1 = get_file_with_ext(self.tmpdir,'mmwords')
  1188. fn2 = get_file_with_ext(self.tmpdir,'bip39')
  1189. return self.bob_msgsign([fn2,fn1])
  1190. def bob_msgverify(self,addr=None,ext='sigmsg.json',cmd='verify',msgfile=None):
  1191. return self.spawn(
  1192. 'mmgen-msg', [
  1193. '--bob',
  1194. f'--outdir={self.tmpdir}',
  1195. cmd,
  1196. msgfile or get_file_with_ext(self.tmpdir,ext),
  1197. ] + ([addr] if addr else []) )
  1198. def bob_msgverify_raw(self):
  1199. t = self.bob_msgverify(ext='rawmsg.json')
  1200. t.expect('No signatures')
  1201. t.req_exit_val = 1
  1202. return t
  1203. def bob_msgverify_single(self):
  1204. sid = self._user_sid('bob')
  1205. return self.bob_msgverify(addr=f'{sid}:{self.dfl_mmtype}:1')
  1206. def bob_msgexport(self,addr=None):
  1207. t = self.bob_msgverify( addr=addr, cmd='export' )
  1208. t.written_to_file('data')
  1209. return t
  1210. def bob_msgexport_single(self):
  1211. sid = self._user_sid('bob')
  1212. return self.bob_msgexport(addr=f'{sid}:{self.dfl_mmtype}:1')
  1213. def bob_msgverify_export(self):
  1214. return self.bob_msgverify(
  1215. msgfile = os.path.join(self.tmpdir,'signatures.json')
  1216. )
  1217. def bob_msgverify_export_single(self):
  1218. sid = self._user_sid('bob')
  1219. mmid = f'{sid}:{self.dfl_mmtype}:1'
  1220. args = [ '--bob', '--color=0', 'listaddress', mmid, 'wide=true' ]
  1221. imsg(f'Running mmgen-tool {fmt_list(args,fmt="bare")}')
  1222. t = self.spawn('mmgen-tool', args, no_msg=True)
  1223. addr = t.expect_getend(mmid).split()[1]
  1224. t.close()
  1225. return self.bob_msgverify(
  1226. addr = addr,
  1227. msgfile = os.path.join(self.tmpdir,'signatures.json')
  1228. )
  1229. def bob_split3(self):
  1230. if not self.proto.cap('segwit'):
  1231. return 'skip'
  1232. sid = self._user_sid('bob')
  1233. return self.user_txdo(
  1234. user = 'bob',
  1235. fee = '23s',
  1236. outputs_cl = [sid+':C:5,0.0135', sid+':L:4'],
  1237. outputs_list = '1' )
  1238. def _bob_auto_chg(self,al_id,include_dest=True):
  1239. dest = [self.burn_addr+',0.01'] if include_dest else []
  1240. t = self.spawn(
  1241. 'mmgen-txcreate',
  1242. ['-d',self.tr.trash_dir,'-B','--bob', al_id] + dest)
  1243. return self.txcreate_ui_common(t,
  1244. menu = [],
  1245. inputs = '1',
  1246. interactive_fee = '20s',
  1247. auto_chg_al_id = al_id )
  1248. def bob_auto_chg1(self):
  1249. return self._bob_auto_chg(self._user_sid('bob') + ':C')
  1250. def bob_auto_chg2(self):
  1251. if not self.proto.cap('segwit'):
  1252. return 'skip'
  1253. return self._bob_auto_chg(self._user_sid('bob') + ':B')
  1254. def bob_auto_chg3(self):
  1255. if not self.proto.cap('segwit'):
  1256. return 'skip'
  1257. return self._bob_auto_chg(self._user_sid('bob') + ':S')
  1258. def bob_auto_chg4(self):
  1259. return self._bob_auto_chg( self._user_sid('bob') + ':C', include_dest=False )
  1260. def _bob_auto_chg_bad(self,al_id,expect):
  1261. t = self.spawn(
  1262. 'mmgen-txcreate',
  1263. ['-d',self.tr.trash_dir,'-B','--bob', self.burn_addr+',0.01', al_id] )
  1264. t.req_exit_val = 2
  1265. t.expect(expect)
  1266. return t
  1267. def bob_auto_chg_bad1(self):
  1268. return self._bob_auto_chg_bad(
  1269. 'FFFFFFFF:C',
  1270. 'contains no addresses' )
  1271. def bob_auto_chg_bad2(self):
  1272. return self._bob_auto_chg_bad(
  1273. '00000000:C',
  1274. 'contains no addresses' )
  1275. def bob_auto_chg_bad3(self):
  1276. return self._bob_auto_chg_bad(
  1277. self._user_sid('bob') + ':L',
  1278. 'contains no unused addresses' )
  1279. def stop(self):
  1280. if opt.no_daemon_stop:
  1281. self.spawn('',msg_only=True)
  1282. msg_r('(leaving daemon running by user request)')
  1283. return 'ok'
  1284. else:
  1285. return self.spawn('mmgen-regtest',['stop'])