ts_regtest.py 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973
  1. #!/usr/bin/env python3
  2. #
  3. # mmgen = Multi-Mode GENerator, command-line Bitcoin cold storage solution
  4. # Copyright (C)2013-2021 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. ts_regtest.py: Regtest tests for the test.py test suite
  20. """
  21. import os,json
  22. from decimal import Decimal
  23. from mmgen.globalvars import g
  24. from mmgen.opts import opt
  25. from mmgen.util import die,gmsg,write_data_to_file
  26. from mmgen.protocol import init_proto
  27. from mmgen.addr import AddrList
  28. from mmgen.wallet import MMGenWallet
  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 = MMGenWallet
  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'),
  47. 'bch': ('499.9999484','399.9999194','399.9998972','399.9997692',
  48. '46.78890380','953.20966920','999.99857300','46.789',
  49. '953.2096692'),
  50. 'ltc': ('5499.99744','5399.994425','5399.993885','5399.987535',
  51. '52.98520500','10946.93753500','10999.92274000','52.99',
  52. '10946.937535'),
  53. },
  54. 'rtBals_gb': {
  55. 'btc': {
  56. '0conf0': {
  57. 'mmgen': ('283.22339537','0','283.22339537'),
  58. 'nonmm': ('16.77647763','0','116.77629233'),
  59. 'total': ('299.999873','0','399.9996877'),
  60. },
  61. '0conf1': {
  62. 'mmgen': ('283.22339537','283.22339537','0'),
  63. 'nonmm': ('16.77647763','16.77647763','99.9998147'),
  64. 'total': ('299.999873','299.999873','99.9998147'),
  65. },
  66. '1conf1': {
  67. 'mmgen': ('0','0','283.22339537'),
  68. 'nonmm': ('0','0','116.77629233'),
  69. 'total': ('0','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','0','283.22339437'),
  80. 'nonmm': ('16.77647763','0','116.77637483'),
  81. 'total': ('299.999872','0','399.9997692'),
  82. },
  83. '0conf1': {
  84. 'mmgen': ('283.22339437','283.22339437','0'),
  85. 'nonmm': ('16.77647763','16.77647763','99.9998972'),
  86. 'total': ('299.999872','299.999872','99.9998972'),
  87. },
  88. '1conf1': {
  89. 'mmgen': ('0','0','283.22339437'),
  90. 'nonmm': ('0','0','116.77637483'),
  91. 'total': ('0','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','0','283.21717237'),
  102. 'nonmm': ('16.77647763','0','5116.77036263'),
  103. 'total': ('299.99365','0','5399.987535'),
  104. },
  105. '0conf1': {
  106. 'mmgen': ('283.21717237','283.21717237','0'),
  107. 'nonmm': ('16.77647763','16.77647763','5099.993885'),
  108. 'total': ('299.99365','299.99365','5099.993885'),
  109. },
  110. '1conf1': {
  111. 'mmgen': ('0','0','283.21717237'),
  112. 'nonmm': ('0','0','5116.77036263'),
  113. 'total': ('0','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. from .ts_base import *
  130. from .ts_shared import *
  131. class TestSuiteRegtest(TestSuiteBase,TestSuiteShared):
  132. 'transacting and tracking wallet operations via regtest mode'
  133. networks = ('btc','ltc','bch')
  134. passthru_opts = ('coin',)
  135. extra_spawn_args = ['--regtest=1']
  136. tmpdir_nums = [17]
  137. color = True
  138. cmd_group = (
  139. ('setup', 'regtest (Bob and Alice) mode setup'),
  140. ('daemon_version', 'mmgen-tool daemon_version'),
  141. ('current_user', 'current user'),
  142. ('halving_calculator_bob', 'halving calculator (Bob)'),
  143. ('walletgen_bob', 'wallet generation (Bob)'),
  144. ('walletgen_alice', 'wallet generation (Alice)'),
  145. ('addrgen_bob', 'address generation (Bob)'),
  146. ('addrgen_alice', 'address generation (Alice)'),
  147. ('addrimport_bob', "importing Bob's addresses"),
  148. ('addrimport_alice', "importing Alice's addresses"),
  149. ('fund_bob', "funding Bob's wallet"),
  150. ('fund_alice', "funding Alice's wallet"),
  151. ('bob_bal1', "Bob's balance"),
  152. ('bob_add_label', "adding an 80-screen-width label (lat+cyr+gr)"),
  153. ('bob_twview1', "viewing Bob's tracking wallet"),
  154. ('bob_split1', "splitting Bob's funds"),
  155. ('generate', 'mining a block'),
  156. ('bob_bal2', "Bob's balance"),
  157. ('bob_rbf_1output_create', 'creating RBF tx with one output'),
  158. ('bob_rbf_1output_bump', 'bumping RBF tx with one output'),
  159. ('bob_bal2a', "Bob's balance (age_fmt=confs)"),
  160. ('bob_bal2b', "Bob's balance (showempty=1)"),
  161. ('bob_bal2c', "Bob's balance (showempty=1 minconf=2 age_fmt=days)"),
  162. ('bob_bal2d', "Bob's balance (minconf=2)"),
  163. ('bob_bal2e', "Bob's balance (showempty=1 sort=age)"),
  164. ('bob_bal2f', "Bob's balance (showempty=1 sort=age,reverse)"),
  165. ('bob_send_maybe_rbf', 'sending funds to Alice (RBF, if supported)'),
  166. ('get_mempool1', 'mempool (before RBF bump)'),
  167. ('bob_rbf_status1', 'getting status of transaction'),
  168. ('bob_rbf_bump', 'bumping RBF transaction'),
  169. ('get_mempool2', 'mempool (after RBF bump)'),
  170. ('bob_rbf_status2', 'getting status of transaction after replacement'),
  171. ('bob_rbf_status3', 'getting status of replacement transaction (mempool)'),
  172. ('generate', 'mining a block'),
  173. ('bob_rbf_status4', 'getting status of transaction after confirmed (1) replacement'),
  174. ('bob_rbf_status5', 'getting status of replacement transaction (confirmed)'),
  175. ('generate', 'mining a block'),
  176. ('bob_rbf_status6', 'getting status of transaction after confirmed (2) replacement'),
  177. ('bob_bal3', "Bob's balance"),
  178. ('bob_pre_import', 'sending to non-imported address'),
  179. ('generate', 'mining a block'),
  180. ('bob_import_addr', 'importing non-MMGen address with --rescan'),
  181. ('bob_bal4', "Bob's balance (after import with rescan)"),
  182. ('bob_import_list', 'importing flat address list'),
  183. ('bob_import_list_rescan', 'importing flat address list with --rescan'),
  184. ('bob_split2', "splitting Bob's funds"),
  185. ('bob_0conf0_getbalance', "Bob's balance (unconfirmed, minconf=0)"),
  186. ('bob_0conf1_getbalance', "Bob's balance (unconfirmed, minconf=1)"),
  187. ('generate', 'mining a block'),
  188. ('bob_1conf1_getbalance', "Bob's balance (confirmed, minconf=1)"),
  189. ('bob_1conf2_getbalance', "Bob's balance (confirmed, minconf=2)"),
  190. ('bob_bal5', "Bob's balance"),
  191. ('bob_send_non_mmgen', 'sending funds to Alice (from non-MMGen addrs)'),
  192. ('generate', 'mining a block'),
  193. ('alice_bal_rpcfail', 'RPC failure code'),
  194. ('alice_send_estimatefee', 'tx creation with no fee on command line'),
  195. ('generate', 'mining a block'),
  196. ('bob_bal6', "Bob's balance"),
  197. ('bob_subwallet_addrgen1', "generating Bob's addrs from subwallet 29L"),
  198. ('bob_subwallet_addrgen2', "generating Bob's addrs from subwallet 127S"),
  199. ('bob_subwallet_addrimport1', "importing Bob's addrs from subwallet 29L"),
  200. ('bob_subwallet_addrimport2', "importing Bob's addrs from subwallet 127S"),
  201. ('bob_subwallet_fund', "funding Bob's subwallet addrs"),
  202. ('generate', 'mining a block'),
  203. ('bob_twview2', "viewing Bob's tracking wallet"),
  204. ('bob_twview3', "viewing Bob's tracking wallet"),
  205. ('bob_subwallet_txcreate', 'creating a transaction with subwallet inputs'),
  206. ('bob_subwallet_txsign', 'signing a transaction with subwallet inputs'),
  207. ('bob_subwallet_txdo', "sending from Bob's subwallet addrs"),
  208. ('generate', 'mining a block'),
  209. ('bob_twview4', "viewing Bob's tracking wallet"),
  210. ('bob_alice_bal', "Bob and Alice's balances"),
  211. ('alice_bal2', "Alice's balance"),
  212. ('alice_add_label1', 'adding a label'),
  213. ('alice_chk_label1', 'the label'),
  214. ('alice_add_label2', 'adding a label'),
  215. ('alice_chk_label2', 'the label'),
  216. ('alice_edit_label1', 'editing a label (zh)'),
  217. ('alice_edit_label2', 'editing a label (lat+cyr+gr)'),
  218. ('alice_chk_label3', 'the label'),
  219. ('alice_remove_label1', 'removing a label'),
  220. ('alice_chk_label4', 'the label'),
  221. ('alice_add_label_coinaddr', 'adding a label using the coin address'),
  222. ('alice_chk_label_coinaddr', 'the label'),
  223. ('alice_add_label_badaddr1', 'adding a label with invalid address'),
  224. ('alice_add_label_badaddr2', 'adding a label with invalid address for this chain'),
  225. ('alice_add_label_badaddr3', 'adding a label with wrong MMGen address'),
  226. ('alice_add_label_badaddr4', 'adding a label with wrong coin address'),
  227. ('alice_listaddresses1', 'listaddresses'),
  228. ('alice_listaddresses_days', 'listaddresses (age_fmt=days)'),
  229. ('alice_listaddresses_date', 'listaddresses (age_fmt=date)'),
  230. ('alice_listaddresses_date_time', 'listaddresses (age_fmt=date_time)'),
  231. ('alice_twview1', 'twview'),
  232. ('alice_twview_days', 'twview (age_fmt=days)'),
  233. ('alice_twview_date', 'twview (age_fmt=date)'),
  234. ('alice_twview_date_time', 'twview (age_fmt=date_time)'),
  235. ('alice_txcreate_info', 'txcreate -i'),
  236. ('stop', 'stopping regtest daemon'),
  237. )
  238. usr_subsids = { 'bob': {}, 'alice': {} }
  239. def __init__(self,trunner,cfgs,spawn):
  240. TestSuiteBase.__init__(self,trunner,cfgs,spawn)
  241. os.environ['MMGEN_TEST_SUITE_REGTEST'] = '1'
  242. if self.proto.testnet:
  243. die(2,'--testnet and --regtest options incompatible with regtest test suite')
  244. self.proto = init_proto(self.proto.coin,network='regtest')
  245. coin = self.proto.coin.lower()
  246. for k in rt_data:
  247. globals()[k] = rt_data[k][coin] if coin in rt_data[k] else None
  248. def _add_comments_to_addr_file(self,addrfile,outfile,use_labels=False):
  249. silence()
  250. gmsg("Adding comments to address file '{}'".format(addrfile))
  251. a = AddrList(self.proto,addrfile)
  252. for n,idx in enumerate(a.idxs(),1):
  253. if use_labels:
  254. a.set_comment(idx,get_label())
  255. else:
  256. if n % 2: a.set_comment(idx,'Test address {}'.format(n))
  257. a.format(add_comments=True)
  258. write_data_to_file(outfile,a.fmt_data,quiet=True,ignore_opt_outdir=True)
  259. end_silence()
  260. def setup(self):
  261. try: shutil.rmtree(joinpath(self.tr.data_dir,'regtest'))
  262. except: pass
  263. os.environ['MMGEN_TEST_SUITE'] = '' # mnemonic is piped to stdin, so stop being a terminal
  264. t = self.spawn('mmgen-regtest',['-n','setup'])
  265. os.environ['MMGEN_TEST_SUITE'] = '1'
  266. for s in ('Starting','Creating','Mined','Creating','Creating','Setup complete'):
  267. t.expect(s)
  268. return t
  269. def daemon_version(self):
  270. t = self.spawn('mmgen-tool', ['--bob','daemon_version'])
  271. t.expect('version')
  272. return t
  273. def current_user(self):
  274. t = self.spawn('mmgen-regtest', ['user'])
  275. t.expect('Bob')
  276. return t
  277. def halving_calculator_bob(self):
  278. t = self.spawn('halving-calculator.py',['--bob'],cmd_dir='examples')
  279. t.expect('time until halving')
  280. t.read()
  281. return t
  282. def walletgen(self,user):
  283. t = self.spawn('mmgen-walletgen',['-q','-r0','-p1','--'+user])
  284. t.passphrase_new('new '+dfl_wcls.desc,rt_pw)
  285. t.label()
  286. t.expect('move it to the data directory? (Y/n): ','y')
  287. t.written_to_file(capfirst(dfl_wcls.desc))
  288. return t
  289. def walletgen_bob(self): return self.walletgen('bob')
  290. def walletgen_alice(self): return self.walletgen('alice')
  291. def _user_dir(self,user,coin=None):
  292. return joinpath(self.tr.data_dir,'regtest',coin or self.proto.coin.lower(),user)
  293. def _user_sid(self,user):
  294. return os.path.basename(get_file_with_ext(self._user_dir(user),'mmdat'))[:8]
  295. def _get_user_subsid(self,user,subseed_idx):
  296. if subseed_idx in self.usr_subsids[user]:
  297. return self.usr_subsids[user][subseed_idx]
  298. icls = MMGenWallet
  299. fn = get_file_with_ext(self._user_dir(user),icls.ext)
  300. t = self.spawn('mmgen-tool',['get_subseed',subseed_idx,'wallet='+fn],no_msg=True)
  301. t.passphrase(icls.desc,rt_pw)
  302. sid = t.read().strip()[:8]
  303. self.usr_subsids[user][subseed_idx] = sid
  304. return sid
  305. def addrgen(self,user,wf=None,addr_range='1-5',subseed_idx=None,mmtypes=[]):
  306. from mmgen.addr import MMGenAddrType
  307. for mmtype in mmtypes or self.proto.mmtypes:
  308. t = self.spawn('mmgen-addrgen',
  309. ['--quiet','--'+user,'--type='+mmtype,'--outdir={}'.format(self._user_dir(user))] +
  310. ([wf] if wf else []) +
  311. (['--subwallet='+subseed_idx] if subseed_idx else []) +
  312. [addr_range],
  313. extra_desc='({})'.format(MMGenAddrType.mmtypes[mmtype].name))
  314. t.passphrase(dfl_wcls.desc,rt_pw)
  315. t.written_to_file('Addresses')
  316. ok_msg()
  317. t.skip_ok = True
  318. return t
  319. def addrgen_bob(self): return self.addrgen('bob')
  320. def addrgen_alice(self): return self.addrgen('alice')
  321. def addrimport(self,user,sid=None,addr_range='1-5',num_addrs=5,mmtypes=[]):
  322. id_strs = { 'legacy':'', 'compressed':'-C', 'segwit':'-S', 'bech32':'-B' }
  323. if not sid: sid = self._user_sid(user)
  324. from mmgen.addr import MMGenAddrType
  325. for mmtype in mmtypes or self.proto.mmtypes:
  326. desc = MMGenAddrType.mmtypes[mmtype].name
  327. addrfile = joinpath(self._user_dir(user),
  328. '{}{}{}[{}]{x}.regtest.addrs'.format(
  329. sid,self.altcoin_pfx,id_strs[desc],addr_range,
  330. x='-α' if g.debug_utf8 else ''))
  331. if mmtype == self.proto.mmtypes[0] and user == 'bob':
  332. self._add_comments_to_addr_file(addrfile,addrfile,use_labels=True)
  333. t = self.spawn( 'mmgen-addrimport',
  334. ['--quiet', '--'+user, '--batch', addrfile],
  335. extra_desc='({})'.format(desc))
  336. if g.debug:
  337. t.expect("Type uppercase 'YES' to confirm: ",'YES\n')
  338. t.expect('Importing')
  339. t.expect('{} addresses imported'.format(num_addrs))
  340. ok_msg()
  341. t.skip_ok = True
  342. return t
  343. def addrimport_bob(self): return self.addrimport('bob')
  344. def addrimport_alice(self): return self.addrimport('alice')
  345. def fund_wallet(self,user,mmtype,amt,sid=None,addr_range='1-5'):
  346. if not sid: sid = self._user_sid(user)
  347. addr = self.get_addr_from_addrlist(user,sid,mmtype,0,addr_range=addr_range)
  348. t = self.spawn('mmgen-regtest', ['send',str(addr),str(amt)])
  349. t.expect(f'Sending {amt} miner {self.proto.coin}')
  350. t.expect('Mined 1 block')
  351. return t
  352. def fund_bob(self):
  353. return self.fund_wallet('bob','C',rtFundAmt)
  354. def fund_alice(self):
  355. return self.fund_wallet('alice',('L','S')[self.proto.cap('segwit')],rtFundAmt)
  356. def user_twview(self,user,chk,sort='age'):
  357. t = self.spawn('mmgen-tool',['--'+user,'twview','sort='+sort])
  358. if chk:
  359. t.expect(r'{}\b.*\D{}\b'.format(*chk),regex=True)
  360. t.read()
  361. return t
  362. def bob_twview1(self): return self.user_twview('bob', chk = ('1',rtAmts[0]) )
  363. def user_bal(self,user,bal,args=['showempty=1'],skip_check=False,exit_val=0):
  364. t = self.spawn('mmgen-tool',['--'+user,'listaddresses'] + args)
  365. if skip_check:
  366. t.read()
  367. else:
  368. cmp_or_die(f'{bal} {self.proto.coin}',strip_ansi_escapes(t.expect_getend('TOTAL: ')))
  369. t.req_exit_val = exit_val
  370. return t
  371. def alice_bal1(self):
  372. return self.user_bal('alice',rtFundAmt)
  373. def alice_bal2(self):
  374. return self.user_bal('alice',rtBals[8])
  375. def bob_bal1(self):
  376. return self.user_bal('bob',rtFundAmt)
  377. def bob_bal2(self):
  378. return self.user_bal('bob',rtBals[0])
  379. def bob_bal2a(self):
  380. return self.user_bal('bob',rtBals[0],args=['showempty=1','age_fmt=confs'])
  381. def bob_bal2b(self):
  382. return self.user_bal('bob',rtBals[0],args=['showempty=1'])
  383. def bob_bal2c(self):
  384. return self.user_bal('bob',rtBals[0],args=['showempty=1','minconf=2','age_fmt=days'],skip_check=True)
  385. def bob_bal2d(self):
  386. return self.user_bal('bob',rtBals[0],args=['minconf=2'],skip_check=True)
  387. def bob_bal2e(self):
  388. return self.user_bal('bob',rtBals[0],args=['showempty=1','sort=age'])
  389. def bob_bal2f(self):
  390. return self.user_bal('bob',rtBals[0],args=['showempty=1','sort=age,reverse'])
  391. def bob_bal3(self):
  392. return self.user_bal('bob',rtBals[1])
  393. def bob_bal4(self):
  394. return self.user_bal('bob',rtBals[2])
  395. def bob_bal5(self):
  396. return self.user_bal('bob',rtBals[3])
  397. def bob_bal6(self):
  398. return self.user_bal('bob',rtBals[7])
  399. def bob_subwallet_addrgen1(self):
  400. return self.addrgen('bob',subseed_idx='29L',mmtypes=['C']) # 29L: 2FA7BBA8
  401. def bob_subwallet_addrgen2(self):
  402. return self.addrgen('bob',subseed_idx='127S',mmtypes=['C']) # 127S: '09E8E286'
  403. def subwallet_addrimport(self,user,subseed_idx):
  404. sid = self._get_user_subsid(user,subseed_idx)
  405. return self.addrimport(user,sid=sid,mmtypes=['C'])
  406. def bob_subwallet_addrimport1(self): return self.subwallet_addrimport('bob','29L')
  407. def bob_subwallet_addrimport2(self): return self.subwallet_addrimport('bob','127S')
  408. def bob_subwallet_fund(self):
  409. sid1 = self._get_user_subsid('bob','29L')
  410. sid2 = self._get_user_subsid('bob','127S')
  411. chg_addr = self._user_sid('bob') + (':B:1',':L:1')[self.proto.coin=='BCH']
  412. outputs_cl = [sid1+':C:2,0.29',sid2+':C:3,0.127',chg_addr]
  413. inputs = ('3','1')[self.proto.coin=='BCH']
  414. return self.user_txdo('bob',rtFee[1],outputs_cl,inputs,extra_args=['--subseeds=127'])
  415. def bob_twview2(self):
  416. sid1 = self._get_user_subsid('bob','29L')
  417. return self.user_twview('bob',chk=(sid1+':C:2','0.29'),sort='twmmid')
  418. def bob_twview3(self):
  419. sid2 = self._get_user_subsid('bob','127S')
  420. return self.user_twview('bob',chk=(sid2+':C:3','0.127'),sort='amt')
  421. def bob_subwallet_txcreate(self):
  422. sid1 = self._get_user_subsid('bob','29L')
  423. sid2 = self._get_user_subsid('bob','127S')
  424. outputs_cl = [sid1+':C:5,0.0159',sid2+':C:5']
  425. t = self.spawn('mmgen-txcreate',['-d',self.tmpdir,'-B','--bob'] + outputs_cl)
  426. return self.txcreate_ui_common(t,
  427. menu = ['a'],
  428. inputs = ('1,2','2,3')[self.proto.coin=='BCH'],
  429. interactive_fee = '0.00001')
  430. def bob_subwallet_txsign(self):
  431. fn = get_file_with_ext(self.tmpdir,'rawtx')
  432. t = self.spawn('mmgen-txsign',['-d',self.tmpdir,'--bob','--subseeds=127',fn])
  433. t.view_tx('t')
  434. t.passphrase(dfl_wcls.desc,rt_pw)
  435. t.do_comment(None)
  436. t.expect('(Y/n): ','y')
  437. t.written_to_file('Signed transaction')
  438. return t
  439. def bob_subwallet_txdo(self):
  440. outputs_cl = [self._user_sid('bob')+':L:5']
  441. inputs = ('1,2','2,3')[self.proto.coin=='BCH']
  442. return self.user_txdo('bob',rtFee[5],outputs_cl,inputs,menu=['a'],extra_args=['--subseeds=127']) # sort: amt
  443. def bob_twview4(self):
  444. sid = self._user_sid('bob')
  445. amt = ('0.4169328','0.41364')[self.proto.coin=='LTC']
  446. return self.user_twview('bob',chk=(sid+':L:5',amt),sort='twmmid')
  447. def bob_getbalance(self,bals,confs=1):
  448. for i in (0,1,2):
  449. assert Decimal(bals['mmgen'][i]) + Decimal(bals['nonmm'][i]) == Decimal(bals['total'][i])
  450. t = self.spawn('mmgen-tool',['--bob','getbalance','minconf={}'.format(confs)])
  451. t.expect('Wallet')
  452. for k in ('mmgen','nonmm','total'):
  453. ret = strip_ansi_escapes(t.expect_getend(r'\S+: ',regex=True))
  454. cmp_or_die(
  455. ' '.join(bals[k]),
  456. re.sub(rf'\s+{self.proto.coin}\s*',' ',ret).strip(),
  457. desc=k,
  458. )
  459. t.read()
  460. return t
  461. def bob_0conf0_getbalance(self): return self.bob_getbalance(rtBals_gb['0conf0'],confs=0)
  462. def bob_0conf1_getbalance(self): return self.bob_getbalance(rtBals_gb['0conf1'],confs=1)
  463. def bob_1conf1_getbalance(self): return self.bob_getbalance(rtBals_gb['1conf1'],confs=1)
  464. def bob_1conf2_getbalance(self): return self.bob_getbalance(rtBals_gb['1conf2'],confs=2)
  465. def bob_alice_bal(self):
  466. t = self.spawn('mmgen-regtest',['balances'])
  467. t.expect('Switching')
  468. ret = t.expect_getend("Alice's balance:").strip()
  469. cmp_or_die(rtBals[5],ret)
  470. ret = t.expect_getend("Bob's balance:").strip()
  471. cmp_or_die(rtBals[4],ret)
  472. ret = t.expect_getend("Total balance:").strip()
  473. cmp_or_die(rtBals[6],ret)
  474. return t
  475. def user_txsend_status(self,user,tx_file,exp1='',exp2='',extra_args=[],bogus_send=False):
  476. os.environ['MMGEN_BOGUS_SEND'] = ('','1')[bool(bogus_send)]
  477. t = self.spawn('mmgen-txsend',['-d',self.tmpdir,'--'+user,'--status'] + extra_args + [tx_file])
  478. os.environ['MMGEN_BOGUS_SEND'] = '1'
  479. if exp1: t.expect(exp1,regex=True)
  480. if exp2: t.expect(exp2,regex=True)
  481. return t
  482. def user_txdo( self, user, fee, outputs_cl, outputs_list,
  483. extra_args = [],
  484. wf = None,
  485. do_label = False,
  486. bad_locktime = False,
  487. full_tx_view = False,
  488. menu = ['M'],
  489. bogus_send = False):
  490. os.environ['MMGEN_BOGUS_SEND'] = ('','1')[bool(bogus_send)]
  491. t = self.spawn('mmgen-txdo',
  492. ['-d',self.tmpdir,'-B','--'+user] +
  493. (['--tx-fee='+fee] if fee else []) +
  494. extra_args + ([],[wf])[bool(wf)] + outputs_cl)
  495. os.environ['MMGEN_BOGUS_SEND'] = '1'
  496. self.txcreate_ui_common(t,
  497. caller = 'txdo',
  498. menu = menu,
  499. inputs = outputs_list,
  500. file_desc = 'Signed transaction',
  501. interactive_fee = (tx_fee,'')[bool(fee)],
  502. add_comment = tx_label_jp,
  503. view = 't',save=True)
  504. t.passphrase(dfl_wcls.desc,rt_pw)
  505. t.written_to_file('Signed transaction')
  506. self._do_confirm_send(t)
  507. s,exit_val = (('Transaction sent',0),("can't be included",1))[bad_locktime]
  508. t.expect(s)
  509. t.req_exit_val = exit_val
  510. return t
  511. def bob_split1(self):
  512. sid = self._user_sid('bob')
  513. outputs_cl = [sid+':C:1,100', sid+':L:2,200',sid+':'+rtBobOp3]
  514. return self.user_txdo('bob',rtFee[0],outputs_cl,'1',do_label=True,full_tx_view=True)
  515. def get_addr_from_addrlist(self,user,sid,mmtype,idx,addr_range='1-5'):
  516. id_str = { 'L':'', 'S':'-S', 'C':'-C', 'B':'-B' }[mmtype]
  517. ext = '{}{}{}[{}]{x}.regtest.addrs'.format(
  518. sid,self.altcoin_pfx,id_str,addr_range,x='-α' if g.debug_utf8 else '')
  519. addrfile = get_file_with_ext(self._user_dir(user),ext,no_dot=True)
  520. silence()
  521. addr = AddrList(self.proto,addrfile).data[idx].addr
  522. end_silence()
  523. return addr
  524. def _create_tx_outputs(self,user,data):
  525. sid = self._user_sid(user)
  526. return [self.get_addr_from_addrlist(user,sid,mmtype,idx-1)+amt_str for mmtype,idx,amt_str in data]
  527. def bob_rbf_1output_create(self):
  528. if self.proto.coin != 'BTC': # non-coin-dependent test, so run just once for BTC
  529. return 'skip'
  530. out_addr = self._create_tx_outputs('alice',(('B',5,''),))
  531. t = self.spawn('mmgen-txcreate',['-d',self.tr.trash_dir,'-B','--bob','--rbf'] + out_addr)
  532. return self.txcreate_ui_common(t,menu=[],inputs='3',interactive_fee='3s') # out amt: 199.99999343
  533. def bob_rbf_1output_bump(self):
  534. if self.proto.coin != 'BTC':
  535. return 'skip'
  536. ext = '9343,3]{x}.regtest.rawtx'.format(x='-α' if g.debug_utf8 else '')
  537. txfile = get_file_with_ext(self.tr.trash_dir,ext,delete=False,no_dot=True)
  538. return self.user_txbump('bob',
  539. self.tr.trash_dir,
  540. txfile,
  541. '8s',
  542. has_label = False,
  543. signed_tx = False,
  544. one_output = True )
  545. def bob_send_maybe_rbf(self):
  546. outputs_cl = self._create_tx_outputs('alice',(('L',1,',60'),('C',1,',40'))) # alice_sid:L:1, alice_sid:C:1
  547. outputs_cl += [self._user_sid('bob')+':'+rtBobOp3]
  548. return self.user_txdo('bob',rtFee[1],outputs_cl,'3',
  549. extra_args=([],['--rbf'])[self.proto.cap('rbf')])
  550. def bob_send_non_mmgen(self):
  551. outputs_cl = self._create_tx_outputs('alice',(
  552. (('L','S')[self.proto.cap('segwit')],2,',10'),
  553. (('L','S')[self.proto.cap('segwit')],3,'')
  554. )) # alice_sid:S:2, alice_sid:S:3
  555. keyfile = joinpath(self.tmpdir,'non-mmgen.keys')
  556. return self.user_txdo('bob',rtFee[3],outputs_cl,'1,4-10',
  557. extra_args=['--keys-from-file='+keyfile,'--vsize-adj=1.02'])
  558. def alice_send_estimatefee(self):
  559. outputs_cl = self._create_tx_outputs('bob',(('L',1,''),)) # bob_sid:L:1
  560. return self.user_txdo('alice',None,outputs_cl,'1') # fee=None
  561. def user_txbump(self,user,outdir,txfile,fee,add_args=[],has_label=True,signed_tx=True,one_output=False):
  562. if not self.proto.cap('rbf'):
  563. return 'skip'
  564. os.environ['MMGEN_BOGUS_SEND'] = ''
  565. t = self.spawn('mmgen-txbump',
  566. ['-d',outdir,'--'+user,'--tx-fee='+fee,'--output-to-reduce=c'] + add_args + [txfile])
  567. os.environ['MMGEN_BOGUS_SEND'] = '1'
  568. if not one_output:
  569. t.expect('OK? (Y/n): ','y') # output OK?
  570. t.expect('OK? (Y/n): ','y') # fee OK?
  571. t.do_comment(False,has_label=has_label)
  572. if signed_tx:
  573. t.passphrase(dfl_wcls.desc,rt_pw)
  574. t.written_to_file('Signed transaction')
  575. self.txsend_ui_common(t,caller='txdo',bogus_send=False,file_desc='Signed transaction')
  576. else:
  577. t.expect('Save fee-bumped transaction? (y/N): ','y')
  578. t.written_to_file('Fee-bumped transaction')
  579. t.read()
  580. return t
  581. def bob_rbf_bump(self):
  582. ext = ',{}]{x}.regtest.sigtx'.format(rtFee[1][:-1],x='-α' if g.debug_utf8 else '')
  583. txfile = self.get_file_with_ext(ext,delete=False,no_dot=True)
  584. return self.user_txbump('bob',self.tmpdir,txfile,rtFee[2],add_args=['--send'])
  585. def generate(self,coin=None,num_blocks=1):
  586. int(num_blocks)
  587. t = self.spawn('mmgen-regtest',['generate',str(num_blocks)])
  588. t.expect('Mined {} block'.format(num_blocks))
  589. return t
  590. def _get_mempool(self):
  591. if not g.debug_utf8:
  592. disable_debug()
  593. ret = self.spawn('mmgen-regtest',['mempool']).read()
  594. if not g.debug_utf8:
  595. restore_debug()
  596. m = re.search(r'(\[\s*"[a-f0-9]{64}"\s*])',ret) # allow for extra output by handler at end
  597. return json.loads(m.group(1))
  598. def get_mempool1(self):
  599. mp = self._get_mempool()
  600. if len(mp) != 1:
  601. rdie(2,'Mempool has more or less than one TX!')
  602. self.write_to_tmpfile('rbf_txid',mp[0]+'\n')
  603. return 'ok'
  604. def bob_rbf_status(self,fee,exp1,exp2=''):
  605. if not self.proto.cap('rbf'):
  606. return 'skip'
  607. ext = ',{}]{x}.regtest.sigtx'.format(fee[:-1],x='-α' if g.debug_utf8 else '')
  608. txfile = self.get_file_with_ext(ext,delete=False,no_dot=True)
  609. return self.user_txsend_status('bob',txfile,exp1,exp2)
  610. def bob_rbf_status1(self):
  611. if not self.proto.cap('rbf'):
  612. return 'skip'
  613. return self.bob_rbf_status(rtFee[1],'in mempool, replaceable')
  614. def get_mempool2(self):
  615. if not self.proto.cap('rbf'):
  616. return 'skip'
  617. mp = self._get_mempool()
  618. if len(mp) != 1:
  619. rdie(2,'Mempool has more or less than one TX!')
  620. chk = self.read_from_tmpfile('rbf_txid')
  621. if chk.strip() == mp[0]:
  622. rdie(2,'TX in mempool has not changed! RBF bump failed')
  623. self.write_to_tmpfile('rbf_txid2',mp[0]+'\n')
  624. return 'ok'
  625. def bob_rbf_status2(self):
  626. if not self.proto.cap('rbf'):
  627. return 'skip'
  628. new_txid = self.read_from_tmpfile('rbf_txid2').strip()
  629. return self.bob_rbf_status(rtFee[1],
  630. 'Transaction has been replaced','{} in mempool'.format(new_txid))
  631. def bob_rbf_status3(self):
  632. if not self.proto.cap('rbf'):
  633. return 'skip'
  634. return self.bob_rbf_status(rtFee[2],'status: in mempool, replaceable')
  635. def bob_rbf_status4(self):
  636. if not self.proto.cap('rbf'):
  637. return 'skip'
  638. new_txid = self.read_from_tmpfile('rbf_txid2').strip()
  639. return self.bob_rbf_status(rtFee[1],
  640. 'Replacement transaction has 1 confirmation',
  641. 'Replacing transactions:\s+{}'.format(new_txid))
  642. def bob_rbf_status5(self):
  643. if not self.proto.cap('rbf'):
  644. return 'skip'
  645. return self.bob_rbf_status(rtFee[2],'Transaction has 1 confirmation')
  646. def bob_rbf_status6(self):
  647. if not self.proto.cap('rbf'):
  648. return 'skip'
  649. new_txid = self.read_from_tmpfile('rbf_txid2').strip()
  650. return self.bob_rbf_status(rtFee[1],
  651. 'Replacement transaction has 2 confirmations',
  652. 'Replacing transactions:\s+{}'.format(new_txid))
  653. @staticmethod
  654. def _gen_pairs(n):
  655. if not g.debug_utf8:
  656. disable_debug()
  657. from subprocess import run,PIPE
  658. ret = [run(['python3',joinpath('cmds','mmgen-tool'),'--regtest=1'] +
  659. (['--type=compressed'],[])[i==0] +
  660. ['-r0','randpair'],
  661. stdout=PIPE,check=True
  662. ).stdout.decode().split() for i in range(n)]
  663. if not g.debug_utf8:
  664. restore_debug()
  665. return ret
  666. def bob_pre_import(self):
  667. pairs = self._gen_pairs(5)
  668. self.write_to_tmpfile('non-mmgen.keys','\n'.join([a[0] for a in pairs])+'\n')
  669. self.write_to_tmpfile('non-mmgen.addrs','\n'.join([a[1] for a in pairs])+'\n')
  670. return self.user_txdo('bob',rtFee[4],[pairs[0][1]],'3')
  671. def user_import(self,user,args):
  672. t = self.spawn('mmgen-addrimport',['--'+user]+args)
  673. if g.debug:
  674. t.expect("Type uppercase 'YES' to confirm: ",'YES\n')
  675. t.expect('Importing')
  676. t.expect('OK')
  677. t.read()
  678. return t
  679. def bob_import_addr(self):
  680. addr = self.read_from_tmpfile('non-mmgen.addrs').split()[0]
  681. return self.user_import('bob',['--quiet','--address='+addr])
  682. def bob_import_list(self):
  683. addrfile = joinpath(self.tmpdir,'non-mmgen.addrs')
  684. return self.user_import('bob',['--quiet','--addrlist',addrfile])
  685. def bob_import_list_rescan(self):
  686. addrfile = joinpath(self.tmpdir,'non-mmgen.addrs')
  687. return self.user_import('bob',['--quiet','--rescan','--addrlist',addrfile])
  688. def bob_split2(self):
  689. addrs = self.read_from_tmpfile('non-mmgen.addrs').split()
  690. amts = (1.12345678,2.87654321,3.33443344,4.00990099,5.43214321)
  691. outputs1 = list(map('{},{}'.format,addrs,amts))
  692. sid = self._user_sid('bob')
  693. l1,l2 = (
  694. (':S',':B') if 'B' in self.proto.mmtypes else
  695. (':S',':S') if self.proto.cap('segwit') else
  696. (':L',':L') )
  697. outputs2 = [sid+':C:2,6.333', sid+':L:3,6.667',sid+l1+':4,0.123',sid+l2+':5']
  698. return self.user_txdo('bob',rtFee[5],outputs1+outputs2,'1-2')
  699. def user_add_label(self,user,addr,label):
  700. t = self.spawn('mmgen-tool',['--'+user,'add_label',addr,label])
  701. t.expect('Added label.*in tracking wallet',regex=True)
  702. return t
  703. def user_remove_label(self,user,addr):
  704. t = self.spawn('mmgen-tool',['--'+user,'remove_label',addr])
  705. t.expect('Removed label.*in tracking wallet',regex=True)
  706. return t
  707. def bob_add_label(self):
  708. sid = self._user_sid('bob')
  709. return self.user_add_label('bob',sid+':C:1',tw_label_lat_cyr_gr)
  710. def alice_add_label1(self):
  711. sid = self._user_sid('alice')
  712. return self.user_add_label('alice',sid+':C:1','Original Label - 月へ')
  713. def alice_add_label2(self):
  714. sid = self._user_sid('alice')
  715. return self.user_add_label('alice',sid+':C:1','Replacement Label')
  716. def _user_chk_label(self,user,addr,label):
  717. t = self.spawn('mmgen-tool',['--'+user,'listaddresses','all_labels=1'])
  718. ret = strip_ansi_escapes(t.expect_getend(addr)).strip().split(None,1)[1]
  719. cmp_or_die(ret[:len(label)],label)
  720. return t
  721. def alice_add_label_coinaddr(self):
  722. mmid = self._user_sid('alice') + (':S:1',':L:1')[self.proto.coin=='BCH']
  723. t = self.spawn('mmgen-tool',['--alice','listaddress',mmid],no_msg=True)
  724. addr = [i for i in strip_ansi_escapes(t.read()).splitlines() if i.startswith(mmid)][0].split()[1]
  725. return self.user_add_label('alice',addr,'Label added using coin address of MMGen address')
  726. def alice_chk_label_coinaddr(self):
  727. mmid = self._user_sid('alice') + (':S:1',':L:1')[self.proto.coin=='BCH']
  728. return self._user_chk_label('alice',mmid,'Label added using coin address of MMGen address')
  729. def alice_add_label_badaddr(self,addr,reply):
  730. t = self.spawn('mmgen-tool',['--alice','add_label',addr,'(none)'])
  731. t.expect(reply,regex=True)
  732. return t
  733. def alice_add_label_badaddr1(self):
  734. return self.alice_add_label_badaddr( rt_pw,'Invalid coin address for this chain: ')
  735. def alice_add_label_badaddr2(self):
  736. addr = init_proto(self.proto.coin,network='mainnet').pubhash2addr('00'*20,False) # mainnet zero address
  737. return self.alice_add_label_badaddr( addr, f'Invalid coin address for this chain: {addr}' )
  738. def alice_add_label_badaddr3(self):
  739. addr = self._user_sid('alice') + ':C:123'
  740. return self.alice_add_label_badaddr( addr, f'MMGen address {addr!r} not found in tracking wallet' )
  741. def alice_add_label_badaddr4(self):
  742. addr = self.proto.pubhash2addr('00'*20,False) # regtest (testnet) zero address
  743. return self.alice_add_label_badaddr( addr, f'Address {addr!r} not found in tracking wallet' )
  744. def alice_bal_rpcfail(self):
  745. addr = self._user_sid('alice') + ':C:2'
  746. os.environ['MMGEN_RPC_FAIL_ON_COMMAND'] = 'listunspent'
  747. t = self.spawn('mmgen-tool',['--alice','getbalance'])
  748. os.environ['MMGEN_RPC_FAIL_ON_COMMAND'] = ''
  749. t.expect('Method not found')
  750. t.read()
  751. t.req_exit_val = 3
  752. return t
  753. def alice_remove_label1(self):
  754. sid = self._user_sid('alice')
  755. mmid = sid + (':S:3',':L:3')[self.proto.coin=='BCH']
  756. return self.user_remove_label('alice',mmid)
  757. def alice_chk_label1(self):
  758. sid = self._user_sid('alice')
  759. return self._user_chk_label('alice',sid+':C:1','Original Label - 月へ')
  760. def alice_chk_label2(self):
  761. sid = self._user_sid('alice')
  762. return self._user_chk_label('alice',sid+':C:1','Replacement Label')
  763. def alice_edit_label1(self): return self.user_edit_label('alice','4',tw_label_lat_cyr_gr)
  764. def alice_edit_label2(self): return self.user_edit_label('alice','3',tw_label_zh)
  765. def alice_chk_label3(self):
  766. sid = self._user_sid('alice')
  767. mmid = sid + (':S:3',':L:3')[self.proto.coin=='BCH']
  768. return self._user_chk_label('alice',mmid,tw_label_lat_cyr_gr)
  769. def alice_chk_label4(self):
  770. sid = self._user_sid('alice')
  771. mmid = sid + (':S:3',':L:3')[self.proto.coin=='BCH']
  772. return self._user_chk_label('alice',mmid,'-')
  773. def user_edit_label(self,user,output,label):
  774. t = self.spawn('mmgen-txcreate',['-B','--'+user,'-i'])
  775. t.expect(r'add \[l\]abel:.','M',regex=True)
  776. t.expect(r'add \[l\]abel:.','l',regex=True)
  777. t.expect(r"Enter unspent.*return to main menu\):.",output+'\n',regex=True)
  778. t.expect(r"Enter label text.*return to main menu\):.",label+'\n',regex=True)
  779. t.expect(r'\[q\]uit view, .*?:.','q',regex=True)
  780. return t
  781. def alice_listaddresses(self,args,expect):
  782. t = self.spawn('mmgen-tool',['--alice','listaddresses','showempty=1'] + args)
  783. expect_str = r'\D{}\D.*\b{}'.format(*expect)
  784. t.expect(expect_str,regex=True)
  785. t.read()
  786. return t
  787. def alice_listaddresses1(self):
  788. return self.alice_listaddresses(
  789. args = [],
  790. expect = (rtAmts[1],r'\d+') )
  791. def alice_listaddresses_days(self):
  792. return self.alice_listaddresses(
  793. args = ['age_fmt=days'],
  794. expect = (rtAmts[1],r'\d+') )
  795. def alice_listaddresses_date(self):
  796. return self.alice_listaddresses(
  797. args = ['age_fmt=date'],
  798. expect = (rtAmts[1],pat_date) )
  799. def alice_listaddresses_date_time(self):
  800. return self.alice_listaddresses(
  801. args = ['age_fmt=date_time'],
  802. expect = (rtAmts[1],pat_date_time) )
  803. def alice_twview(self,args,expect):
  804. t = self.spawn('mmgen-tool',['--alice','twview'] + args)
  805. expect_str = r'\D{}\D.*\b{}'.format(*expect)
  806. t.expect(expect_str,regex=True)
  807. t.read()
  808. return t
  809. def alice_twview1(self):
  810. return self.alice_twview(
  811. args = [],
  812. expect = (rtAmts[0],r'\d+') )
  813. def alice_twview_days(self):
  814. return self.alice_twview(
  815. args = ['age_fmt=days'],
  816. expect = (rtAmts[0],r'\d+') )
  817. def alice_twview_date(self):
  818. return self.alice_twview(
  819. args = ['age_fmt=date'],
  820. expect = (rtAmts[0],pat_date) )
  821. def alice_twview_date_time(self):
  822. return self.alice_twview(
  823. args = ['age_fmt=date_time'],
  824. expect = (rtAmts[0],pat_date_time) )
  825. def alice_txcreate_info(self,args=[]):
  826. t = self.spawn('mmgen-txcreate',['--alice','-Bi'])
  827. for d,s in (
  828. ( '\d+', 'D'),
  829. ( '\d+', 'D'),
  830. ( '\d+', 'D'),
  831. ( pat_date, 'w'),
  832. ( '\d+\s+\d+\s+'+pat_date_time,'q'),
  833. ):
  834. t.expect(
  835. r'\D{}\D.*\b{}\b'.format(rtAmts[0],d),
  836. s,
  837. regex=True )
  838. t.read()
  839. return t
  840. def stop(self):
  841. if opt.no_daemon_stop:
  842. self.spawn('',msg_only=True)
  843. msg_r('(leaving daemon running by user request)')
  844. return 'ok'
  845. else:
  846. return self.spawn('mmgen-regtest',['stop'])