ts_regtest.py 38 KB

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