ts_regtest.py 58 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586
  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', ['twexport','label']),
  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_listaddresses_empty', 'listaddresses (no data)'),
  328. ('alice_listaddresses_menu', 'listaddresses (menu items)'),
  329. ('alice_listaddresses1', 'listaddresses'),
  330. ('alice_listaddresses_days', 'listaddresses (age_fmt=days)'),
  331. ('alice_listaddresses_date', 'listaddresses (age_fmt=date)'),
  332. ('alice_listaddresses_date_time', 'listaddresses (age_fmt=date_time)'),
  333. ('alice_twview1', 'twview'),
  334. ('alice_twview_days', 'twview (age_fmt=days)'),
  335. ('alice_twview_date', 'twview (age_fmt=date)'),
  336. ('alice_twview_date_time', 'twview (age_fmt=date_time)'),
  337. ('alice_txcreate_info', 'txcreate -i'),
  338. ('alice_txcreate_info_term', 'txcreate -i (pexpect_spawn)'),
  339. ),
  340. 'auto_chg': (
  341. 'automatic change address selection',
  342. ('bob_split3', 'splitting Bob’s funds'),
  343. ('generate', 'mining a block'),
  344. ('bob_auto_chg1', 'creating an automatic change address transaction (C)'),
  345. ('bob_auto_chg2', 'creating an automatic change address transaction (B)'),
  346. ('bob_auto_chg3', 'creating an automatic change address transaction (S)'),
  347. ('bob_auto_chg4', 'creating an automatic change address transaction (single address)'),
  348. ('bob_auto_chg_addrtype1', 'creating an automatic change address transaction by addrtype (C)'),
  349. ('bob_auto_chg_addrtype2', 'creating an automatic change address transaction by addrtype (B)'),
  350. ('bob_auto_chg_addrtype3', 'creating an automatic change address transaction by addrtype (S)'),
  351. ('bob_auto_chg_addrtype4', 'creating an automatic change address transaction by addrtype (single address)'),
  352. ('bob_auto_chg_bad1', 'error handling for auto change address transaction (bad ID FFFFFFFF:C)'),
  353. ('bob_auto_chg_bad2', 'error handling for auto change address transaction (bad ID 00000000:C)'),
  354. ('bob_auto_chg_bad3', 'error handling for auto change address transaction (no unused addresses)'),
  355. ('bob_auto_chg_bad4', 'error handling for auto change address transaction by addrtype (no unused addresses)'),
  356. ('carol_twimport2', 'recreating Carol’s tracking wallet from JSON dump'),
  357. ('carol_rescan_blockchain', 'rescanning the blockchain (full rescan)'),
  358. ('carol_auto_chg1', 'creating an automatic change address transaction (C)'),
  359. ('carol_auto_chg2', 'creating an automatic change address transaction (B)'),
  360. ('carol_auto_chg3', 'creating an automatic change address transaction (S)'),
  361. ('carol_auto_chg_addrtype1', 'creating an automatic change address transaction by addrtype (C)'),
  362. ('carol_auto_chg_addrtype2', 'creating an automatic change address transaction by addrtype (B)'),
  363. ('carol_auto_chg_addrtype3', 'creating an automatic change address transaction by addrtype (S)'),
  364. ('carol_auto_chg_bad1', 'error handling for auto change address transaction (no unused addresses)'),
  365. ('carol_auto_chg_bad2', 'error handling for auto change address transaction by addrtype (no unused addresses)'),
  366. ('carol_delete_wallet', 'unloading and deleting Carol’s tracking wallet'),
  367. ),
  368. }
  369. def __init__(self,trunner,cfgs,spawn):
  370. TestSuiteBase.__init__(self,trunner,cfgs,spawn)
  371. if trunner == None:
  372. return
  373. if self.proto.testnet:
  374. die(2,'--testnet and --regtest options incompatible with regtest test suite')
  375. self.proto = init_proto(self.proto.coin,network='regtest',need_amt=True)
  376. coin = self.proto.coin.lower()
  377. import test.test_py_d.ts_regtest as rt_mod
  378. for k in rt_data:
  379. setattr( rt_mod, k, rt_data[k][coin] if coin in rt_data[k] else None )
  380. if self.proto.coin == 'BTC':
  381. self.test_rbf = True # tests are non-coin-dependent, so run just once for BTC
  382. if g.test_suite_deterministic:
  383. self.deterministic = True
  384. self.miner_addr = 'bcrt1qaq8t3pakcftpk095tnqfv5cmmczysls024atnd' # regtest.create_hdseed()
  385. self.miner_wif = 'cTyMdQ2BgfAsjopRVZrj7AoEGp97pKfrC2NkqLuwHr4KHfPNAKwp'
  386. os.environ['MMGEN_BOGUS_SEND'] = ''
  387. self.write_to_tmpfile('wallet_password',rt_pw)
  388. self.dfl_mmtype = 'C' if self.proto.coin == 'BCH' else 'B'
  389. self.burn_addr = make_burn_addr(self.proto)
  390. def __del__(self):
  391. os.environ['MMGEN_BOGUS_SEND'] = '1'
  392. def _add_comments_to_addr_file(self,addrfile,outfile,use_comments=False):
  393. silence()
  394. gmsg(f'Adding comments to address file {addrfile!r}')
  395. a = AddrList(self.proto,addrfile)
  396. for n,idx in enumerate(a.idxs(),1):
  397. if use_comments:
  398. a.set_comment(idx,get_comment())
  399. else:
  400. if n % 2: a.set_comment(idx,f'Test address {n}')
  401. af = a.get_file()
  402. af.format(add_comments=True)
  403. from mmgen.fileutil import write_data_to_file
  404. write_data_to_file(outfile,af.fmt_data,quiet=True,ignore_opt_outdir=True)
  405. end_silence()
  406. def setup(self):
  407. stop_test_daemons(self.proto.network_id,force=True,remove_datadir=True)
  408. from shutil import rmtree
  409. try: rmtree(joinpath(self.tr.data_dir,'regtest'))
  410. except: pass
  411. t = self.spawn('mmgen-regtest',['-n','setup'])
  412. for s in ('Starting','Creating','Creating','Creating','Mined','Setup complete'):
  413. t.expect(s)
  414. return t
  415. def daemon_version(self):
  416. t = self.spawn('mmgen-tool', ['--bob','daemon_version'])
  417. t.expect('version')
  418. return t
  419. def halving_calculator_bob(self):
  420. t = self.spawn('halving-calculator.py',['--bob'],cmd_dir='examples')
  421. t.expect('time until halving')
  422. return t
  423. def walletgen(self,user):
  424. t = self.spawn('mmgen-walletgen',['-q','-r0','-p1','--'+user])
  425. t.passphrase_new('new '+dfl_wcls.desc,rt_pw)
  426. t.label()
  427. t.expect('move it to the data directory? (Y/n): ','y')
  428. t.written_to_file(capfirst(dfl_wcls.desc))
  429. return t
  430. def walletgen_bob(self): return self.walletgen('bob')
  431. def walletgen_alice(self): return self.walletgen('alice')
  432. def _user_dir(self,user,coin=None):
  433. return joinpath(self.tr.data_dir,'regtest',coin or self.proto.coin.lower(),user)
  434. def _user_sid(self,user):
  435. return os.path.basename(get_file_with_ext(self._user_dir(user),'mmdat'))[:8]
  436. def _get_user_subsid(self,user,subseed_idx):
  437. fn = get_file_with_ext(self._user_dir(user),dfl_wcls.ext)
  438. silence()
  439. w = Wallet( fn=fn, passwd_file=os.path.join(self.tmpdir,'wallet_password') )
  440. end_silence()
  441. return w.seed.subseed(subseed_idx).sid
  442. def addrgen(self,user,wf=None,addr_range='1-5',subseed_idx=None,mmtypes=[]):
  443. from mmgen.addr import MMGenAddrType
  444. for mmtype in mmtypes or self.proto.mmtypes:
  445. t = self.spawn('mmgen-addrgen',
  446. ['--quiet','--'+user,'--type='+mmtype,f'--outdir={self._user_dir(user)}'] +
  447. ([wf] if wf else []) +
  448. (['--subwallet='+subseed_idx] if subseed_idx else []) +
  449. [addr_range],
  450. extra_desc='({})'.format( MMGenAddrType.mmtypes[mmtype].name ))
  451. t.passphrase(dfl_wcls.desc,rt_pw)
  452. t.written_to_file('Addresses')
  453. ok_msg()
  454. t.skip_ok = True
  455. return t
  456. def addrgen_bob(self): return self.addrgen('bob')
  457. def addrgen_alice(self): return self.addrgen('alice')
  458. def addrimport(self,user,sid=None,addr_range='1-5',num_addrs=5,mmtypes=[],batch=True,quiet=True):
  459. id_strs = { 'legacy':'', 'compressed':'-C', 'segwit':'-S', 'bech32':'-B' }
  460. if not sid: sid = self._user_sid(user)
  461. from mmgen.addr import MMGenAddrType
  462. for mmtype in mmtypes or self.proto.mmtypes:
  463. desc = MMGenAddrType.mmtypes[mmtype].name
  464. addrfile = joinpath(self._user_dir(user),
  465. '{}{}{}[{}]{x}.regtest.addrs'.format(
  466. sid,self.altcoin_pfx,id_strs[desc],addr_range,
  467. x='-α' if g.debug_utf8 else ''))
  468. if mmtype == self.proto.mmtypes[0] and user == 'bob':
  469. self._add_comments_to_addr_file(addrfile,addrfile,use_comments=True)
  470. t = self.spawn(
  471. 'mmgen-addrimport',
  472. args = (
  473. (['--quiet'] if quiet else []) +
  474. ['--'+user] +
  475. (['--batch'] if batch else []) +
  476. [addrfile] ),
  477. extra_desc = f'({desc})' )
  478. if g.debug:
  479. t.expect("Type uppercase 'YES' to confirm: ",'YES\n')
  480. t.expect('Importing')
  481. if batch:
  482. t.expect(f'{num_addrs} addresses imported')
  483. else:
  484. t.expect(f'import completed OK')
  485. t.ok()
  486. t.skip_ok = True
  487. return t
  488. def addrimport_bob(self): return self.addrimport('bob')
  489. def addrimport_alice(self): return self.addrimport('alice',batch=False,quiet=False)
  490. def bob_import_miner_addr(self):
  491. if not self.deterministic:
  492. return 'skip'
  493. return self.spawn(
  494. 'mmgen-addrimport',
  495. [ '--bob', '--rescan', '--quiet', f'--address={self.miner_addr}' ] )
  496. def fund_wallet_deterministic(self,user,addr,utxo_nums,skip_passphrase=False):
  497. """
  498. the deterministic funding method using specific inputs
  499. """
  500. if not self.deterministic:
  501. return 'skip'
  502. self.write_to_tmpfile('miner.key',f'{self.miner_wif}\n')
  503. keyfile = joinpath(self.tmpdir,'miner.key')
  504. return self.user_txdo(
  505. 'bob', '40s',
  506. [ f'{addr},{rtFundAmt}', self.burn_addr ],
  507. utxo_nums,
  508. extra_args = [f'--keys-from-file={keyfile}'],
  509. skip_passphrase = skip_passphrase )
  510. def fund_bob_deterministic(self):
  511. return self.fund_wallet_deterministic( 'bob', f'{self._user_sid("bob")}:C:1', '1-11' )
  512. def fund_alice_deterministic(self):
  513. sid = self._user_sid('alice')
  514. mmtype = ('L','S')[self.proto.cap('segwit')]
  515. addr = self.get_addr_from_addrlist('alice',sid,mmtype,0,addr_range='1-5')
  516. return self.fund_wallet_deterministic( 'alice', addr, '1-11', skip_passphrase=True )
  517. def generate_extra_deterministic(self):
  518. if not self.deterministic:
  519. return 'skip'
  520. return self.generate(num_blocks=2) # do this so block count matches non-deterministic run
  521. async def bob_recreate_tracking_wallet(self):
  522. if not self.deterministic:
  523. return 'skip'
  524. self.spawn('',msg_only=True)
  525. from mmgen.proto.btc.regtest import MMGenRegtest
  526. rt = MMGenRegtest(self.proto.coin)
  527. await rt.stop()
  528. from shutil import rmtree
  529. imsg(f'Deleting Bob’s old tracking wallet')
  530. rmtree(os.path.join(rt.d.datadir,'regtest','wallets','bob'),ignore_errors=True)
  531. rt.init_daemon()
  532. rt.d.start(silent=True)
  533. imsg(f'Creating Bob’s new tracking wallet')
  534. await rt.rpc_call('createwallet','bob',True,True,None,False,False,False)
  535. await rt.stop()
  536. await rt.start()
  537. return 'ok'
  538. def addrimport_bob2(self):
  539. if not self.deterministic:
  540. return 'skip'
  541. return self.addrimport('bob')
  542. def fund_wallet(self,user,mmtype,amt,sid=None,addr_range='1-5'):
  543. if self.deterministic:
  544. return 'skip'
  545. if not sid:
  546. sid = self._user_sid(user)
  547. addr = self.get_addr_from_addrlist(user,sid,mmtype,0,addr_range=addr_range)
  548. t = self.spawn('mmgen-regtest', ['send',str(addr),str(amt)])
  549. t.expect(f'Sending {amt} miner {self.proto.coin}')
  550. t.expect('Mined 1 block')
  551. return t
  552. def fund_bob(self):
  553. return self.fund_wallet('bob','C',rtFundAmt)
  554. def fund_alice(self):
  555. return self.fund_wallet('alice',('L','S')[self.proto.cap('segwit')],rtFundAmt)
  556. def user_twview(self,user,chk,sort='age'):
  557. t = self.spawn('mmgen-tool',['--'+user,'twview','sort='+sort])
  558. if chk:
  559. t.expect(r'{}\b.*\D{}\b'.format(*chk),regex=True)
  560. return t
  561. def bob_twview1(self): return self.user_twview('bob', chk = ('1',rtAmts[0]) )
  562. def user_bal(self,user,bal,args=['showempty=1'],skip_check=False):
  563. t = self.spawn('mmgen-tool',['--'+user,'listaddresses'] + args)
  564. if not skip_check:
  565. cmp_or_die(f'{bal} {self.proto.coin}',strip_ansi_escapes(t.expect_getend('TOTAL: ')))
  566. return t
  567. def alice_bal1(self):
  568. return self.user_bal('alice',rtFundAmt)
  569. def alice_bal2(self):
  570. return self.user_bal('alice',rtBals[8])
  571. def bob_bal1(self):
  572. return self.user_bal('bob',rtFundAmt)
  573. def bob_bal2(self):
  574. return self.user_bal('bob',rtBals[0])
  575. def bob_bal2a(self):
  576. return self.user_bal('bob',rtBals[0],args=['showempty=1','age_fmt=confs'])
  577. def bob_bal2b(self):
  578. return self.user_bal('bob',rtBals[0],args=['showempty=1'])
  579. def bob_bal2c(self):
  580. return self.user_bal('bob',rtBals[0],args=['showempty=1','minconf=2','age_fmt=days'],skip_check=True)
  581. def bob_bal2d(self):
  582. return self.user_bal('bob',rtBals[0],args=['minconf=2'],skip_check=True)
  583. def bob_bal2e(self):
  584. return self.user_bal('bob',rtBals[0],args=['showempty=1','sort=amt'])
  585. def bob_bal2f(self):
  586. return self.user_bal('bob',rtBals[0],args=['showempty=0','sort=twmmid','reverse=1'])
  587. def bob_bal3(self):
  588. return self.user_bal('bob',rtBals[1])
  589. def bob_bal4(self):
  590. return self.user_bal('bob',rtBals[2])
  591. def bob_bal5(self):
  592. return self.user_bal('bob',rtBals[3])
  593. def bob_bal6(self):
  594. return self.user_bal('bob',rtBals[7])
  595. def bob_subwallet_addrgen1(self):
  596. return self.addrgen('bob',subseed_idx='29L',mmtypes=['C']) # 29L: 2FA7BBA8
  597. def bob_subwallet_addrgen2(self):
  598. return self.addrgen('bob',subseed_idx='127S',mmtypes=['C']) # 127S: '09E8E286'
  599. def subwallet_addrimport(self,user,subseed_idx):
  600. sid = self._get_user_subsid(user,subseed_idx)
  601. return self.addrimport(user,sid=sid,mmtypes=['C'])
  602. def bob_subwallet_addrimport1(self): return self.subwallet_addrimport('bob','29L')
  603. def bob_subwallet_addrimport2(self): return self.subwallet_addrimport('bob','127S')
  604. def bob_subwallet_fund(self):
  605. sid1 = self._get_user_subsid('bob','29L')
  606. sid2 = self._get_user_subsid('bob','127S')
  607. chg_addr = self._user_sid('bob') + (':B:1',':L:1')[self.proto.coin=='BCH']
  608. return self.user_txdo(
  609. user = 'bob',
  610. fee = rtFee[1],
  611. outputs_cl = [sid1+':C:2,0.29',sid2+':C:3,0.127',chg_addr],
  612. outputs_list = ('3','1')[self.proto.coin=='BCH'],
  613. extra_args = ['--subseeds=127'],
  614. used_chg_addr_resp = (None,'y')[self.proto.coin=='BCH'] )
  615. def bob_twview2(self):
  616. sid1 = self._get_user_subsid('bob','29L')
  617. return self.user_twview('bob',chk=(sid1+':C:2','0.29'),sort='twmmid')
  618. def bob_twview3(self):
  619. sid2 = self._get_user_subsid('bob','127S')
  620. return self.user_twview('bob',chk=(sid2+':C:3','0.127'),sort='amt')
  621. def bob_subwallet_txcreate(self):
  622. sid1 = self._get_user_subsid('bob','29L')
  623. sid2 = self._get_user_subsid('bob','127S')
  624. outputs_cl = [sid1+':C:5,0.0159',sid2+':C:5']
  625. t = self.spawn('mmgen-txcreate',['-d',self.tmpdir,'-B','--bob'] + outputs_cl)
  626. return self.txcreate_ui_common(t,
  627. menu = ['a'],
  628. inputs = ('1,2','2,3')[self.proto.coin=='BCH'],
  629. interactive_fee = '0.00001')
  630. def bob_subwallet_txsign(self):
  631. fn = get_file_with_ext(self.tmpdir,'rawtx')
  632. t = self.spawn('mmgen-txsign',['-d',self.tmpdir,'--bob','--subseeds=127',fn])
  633. t.view_tx('t')
  634. t.passphrase(dfl_wcls.desc,rt_pw)
  635. t.do_comment(None)
  636. t.expect('(Y/n): ','y')
  637. t.written_to_file('Signed transaction')
  638. return t
  639. def bob_subwallet_txdo(self):
  640. outputs_cl = [self._user_sid('bob')+':L:5']
  641. inputs = ('1,2','2,3')[self.proto.coin=='BCH']
  642. return self.user_txdo('bob',rtFee[5],outputs_cl,inputs,menu=['a'],extra_args=['--subseeds=127']) # sort: amt
  643. def bob_twview4(self):
  644. sid = self._user_sid('bob')
  645. return self.user_twview('bob',chk=(sid+':L:5',rtBals[9]),sort='twmmid')
  646. def user_txhist(self,user,args,expect):
  647. t = self.spawn('mmgen-tool',['--'+user,'txhist'] + args)
  648. res = strip_ansi_escapes(t.read()).replace('\r','')
  649. m = re.search(expect,res,re.DOTALL)
  650. assert m, f'Expected: {expect}'
  651. return t
  652. def bob_txhist1(self):
  653. return self.user_txhist('bob',
  654. args = ['sort=age'],
  655. expect = fr'\s1\).*\s{rtFundAmt}\s' )
  656. def bob_txhist2(self):
  657. return self.user_txhist('bob',
  658. args = ['sort=blockheight','reverse=1','age_fmt=block'],
  659. expect = fr'\s1\).*:{self.dfl_mmtype}:1\s' )
  660. def bob_txhist3(self):
  661. return self.user_txhist('bob',
  662. args = ['sort=blockheight','sinceblock=-7','age_fmt=block'],
  663. expect = fr'Displaying transactions since block 399.*\s6\)\s+405\s.*\s{rtBals[9]}\s.*:L:5.*\s7\)'
  664. )
  665. def bob_txhist4(self):
  666. return self.user_txhist('bob',
  667. args = ['sort=blockheight','sinceblock=399','age_fmt=block','detail=1'],
  668. expect = fr'Displaying transactions since block 399.*\s7\).*Block:.*406.*Value:.*{rtBals[10]}'
  669. )
  670. def bob_txhist_interactive(self):
  671. self.get_file_with_ext('out',delete_all=True)
  672. t = self.spawn('mmgen-tool',
  673. ['--bob',f'--outdir={self.tmpdir}','txhist','age_fmt=date_time','interactive=true'] )
  674. for resp in ('u','i','t','a','m','T','A','r','r','D','D','D','D','p','P','b','V'):
  675. t.expect('draw:\b',resp,regex=True)
  676. if t.pexpect_spawn:
  677. t.expect(r'Block:.*\b394\b',regex=True)
  678. time.sleep(1)
  679. t.send('q')
  680. time.sleep(0.2)
  681. t.send('b')
  682. t.expect('draw:\b','q',regex=True)
  683. else:
  684. txnum,idx = (8,1) if self.proto.coin == 'BCH' else (9,3)
  685. t.expect(f'\s{txnum}\).*Inputs:.*:L:{idx}.*Outputs \(3\):.*:C:2.*\s10\)','q',regex=True)
  686. return t
  687. def bob_getbalance(self,bals,confs=1):
  688. for i in range(len(bals['mmgen'])):
  689. assert Decimal(bals['mmgen'][i]) + Decimal(bals['nonmm'][i]) == Decimal(bals['total'][i])
  690. sid = self._user_sid('bob')
  691. t = self.spawn('mmgen-tool',['--bob','getbalance',f'minconf={confs}'])
  692. t.expect('Wallet')
  693. for k,lbl in (
  694. ('mmgen',f'{sid}:'),
  695. ('nonmm','Non-MMGen:'),
  696. ('total',f'TOTAL {self.proto.coin}')
  697. ):
  698. ret = strip_ansi_escapes(t.expect_getend(lbl + ' '))
  699. cmp_or_die(
  700. ' '.join(bals[k]),
  701. ' '.join(ret.split()),
  702. desc = k,
  703. )
  704. return t
  705. def bob_0conf0_getbalance(self): return self.bob_getbalance(rtBals_gb['0conf0'],confs=0)
  706. def bob_0conf1_getbalance(self): return self.bob_getbalance(rtBals_gb['0conf1'],confs=1)
  707. def bob_1conf1_getbalance(self): return self.bob_getbalance(rtBals_gb['1conf1'],confs=1)
  708. def bob_1conf2_getbalance(self): return self.bob_getbalance(rtBals_gb['1conf2'],confs=2)
  709. def bob_nochg_burn(self):
  710. return self.user_txdo('bob',
  711. fee = '0.00009713',
  712. outputs_cl = [self.burn_addr],
  713. outputs_list = '1' )
  714. def bob_alice_bal(self):
  715. t = self.spawn('mmgen-regtest',['balances'])
  716. ret = t.expect_getend("Bob's balance:").strip()
  717. cmp_or_die(rtBals[4],ret)
  718. ret = t.expect_getend("Alice's balance:").strip()
  719. cmp_or_die(rtBals[5],ret)
  720. ret = t.expect_getend("Total balance:").strip()
  721. cmp_or_die(rtBals[6],ret)
  722. return t
  723. def user_txsend_status(self,user,tx_file,exp1='',exp2='',extra_args=[]):
  724. t = self.spawn('mmgen-txsend',['-d',self.tmpdir,'--'+user,'--status'] + extra_args + [tx_file])
  725. if exp1: t.expect(exp1,regex=True)
  726. if exp2: t.expect(exp2,regex=True)
  727. return t
  728. def user_txdo( self, user, fee, outputs_cl, outputs_list,
  729. extra_args = [],
  730. wf = None,
  731. do_label = False,
  732. bad_locktime = False,
  733. full_tx_view = False,
  734. menu = ['M'],
  735. skip_passphrase = False,
  736. used_chg_addr_resp = None ):
  737. t = self.spawn('mmgen-txdo',
  738. ['-d',self.tmpdir,'-B','--'+user] +
  739. (['--fee='+fee] if fee else []) +
  740. extra_args + ([],[wf])[bool(wf)] + outputs_cl)
  741. self.txcreate_ui_common(t,
  742. caller = 'txdo',
  743. menu = menu,
  744. inputs = outputs_list,
  745. file_desc = 'Signed transaction',
  746. interactive_fee = (tx_fee,'')[bool(fee)],
  747. add_comment = tx_comment_jp,
  748. view = 't',
  749. save = True,
  750. used_chg_addr_resp = used_chg_addr_resp )
  751. if not skip_passphrase:
  752. t.passphrase(dfl_wcls.desc,rt_pw)
  753. t.written_to_file('Signed transaction')
  754. self._do_confirm_send(t)
  755. s,exit_val = (('Transaction sent',0),("can't be included",1))[bad_locktime]
  756. t.expect(s)
  757. t.req_exit_val = exit_val
  758. return t
  759. def bob_split1(self):
  760. sid = self._user_sid('bob')
  761. outputs_cl = [sid+':C:1,100', sid+':L:2,200',sid+':'+rtBobOp3]
  762. return self.user_txdo('bob',rtFee[0],outputs_cl,'1',do_label=True,full_tx_view=True)
  763. def get_addr_from_addrlist(self,user,sid,mmtype,idx,addr_range='1-5'):
  764. id_str = { 'L':'', 'S':'-S', 'C':'-C', 'B':'-B' }[mmtype]
  765. ext = '{}{}{}[{}]{x}.regtest.addrs'.format(
  766. sid,self.altcoin_pfx,id_str,addr_range,x='-α' if g.debug_utf8 else '')
  767. addrfile = get_file_with_ext(self._user_dir(user),ext,no_dot=True)
  768. silence()
  769. addr = AddrList(self.proto,addrfile).data[idx].addr
  770. end_silence()
  771. return addr
  772. def _create_tx_outputs(self,user,data):
  773. sid = self._user_sid(user)
  774. return [self.get_addr_from_addrlist(user,sid,mmtype,idx-1)+amt_str for mmtype,idx,amt_str in data]
  775. def bob_rbf_1output_create(self):
  776. if not self.test_rbf:
  777. return 'skip'
  778. out_addr = self._create_tx_outputs('alice',(('B',5,''),))
  779. t = self.spawn('mmgen-txcreate',['-d',self.tr.trash_dir,'-B','--bob','--rbf'] + out_addr)
  780. return self.txcreate_ui_common(t,menu=[],inputs='3',interactive_fee='3s') # out amt: 199.99999343
  781. def bob_rbf_1output_bump(self):
  782. if not self.test_rbf:
  783. return 'skip'
  784. ext = '9343,3]{x}.regtest.rawtx'.format(x='-α' if g.debug_utf8 else '')
  785. txfile = get_file_with_ext(self.tr.trash_dir,ext,delete=False,no_dot=True)
  786. return self.user_txbump('bob',
  787. self.tr.trash_dir,
  788. txfile,
  789. '8s',
  790. has_label = False,
  791. signed_tx = False,
  792. one_output = True )
  793. def bob_send_maybe_rbf(self):
  794. outputs_cl = self._create_tx_outputs('alice',(('L',1,',60'),('C',1,',40'))) # alice_sid:L:1, alice_sid:C:1
  795. outputs_cl += [self._user_sid('bob')+':'+rtBobOp3]
  796. return self.user_txdo('bob',rtFee[1],outputs_cl,'3',
  797. extra_args = ([],['--rbf'])[self.proto.cap('rbf')],
  798. used_chg_addr_resp = 'y' )
  799. def bob_send_non_mmgen(self):
  800. outputs_cl = self._create_tx_outputs('alice',(
  801. (('L','S')[self.proto.cap('segwit')],2,',10'),
  802. (('L','S')[self.proto.cap('segwit')],3,'')
  803. )) # alice_sid:S:2, alice_sid:S:3
  804. keyfile = joinpath(self.tmpdir,'non-mmgen.keys')
  805. return self.user_txdo('bob',rtFee[3],outputs_cl,'1,4-10',
  806. extra_args=['--keys-from-file='+keyfile,'--vsize-adj=1.02'])
  807. def alice_send_estimatefee(self):
  808. outputs_cl = self._create_tx_outputs('bob',(('L',1,''),)) # bob_sid:L:1
  809. return self.user_txdo('alice',None,outputs_cl,'1') # fee=None
  810. def user_txbump(self,user,outdir,txfile,fee,add_args=[],has_label=True,signed_tx=True,one_output=False):
  811. if not self.proto.cap('rbf'):
  812. return 'skip'
  813. t = self.spawn('mmgen-txbump',
  814. ['-d',outdir,'--'+user,'--fee='+fee,'--output-to-reduce=c'] + add_args + [txfile])
  815. if not one_output:
  816. t.expect('OK? (Y/n): ','y') # output OK?
  817. t.expect('OK? (Y/n): ','y') # fee OK?
  818. t.do_comment(False,has_label=has_label)
  819. if signed_tx:
  820. t.passphrase(dfl_wcls.desc,rt_pw)
  821. t.written_to_file('Signed transaction')
  822. self.txsend_ui_common(t,caller='txdo',bogus_send=False,file_desc='Signed transaction')
  823. else:
  824. t.expect('Save fee-bumped transaction? (y/N): ','y')
  825. t.written_to_file('Fee-bumped transaction')
  826. return t
  827. def bob_rbf_bump(self):
  828. ext = ',{}]{x}.regtest.sigtx'.format(rtFee[1][:-1],x='-α' if g.debug_utf8 else '')
  829. txfile = self.get_file_with_ext(ext,delete=False,no_dot=True)
  830. return self.user_txbump('bob',self.tmpdir,txfile,rtFee[2],add_args=['--send'])
  831. def generate(self,num_blocks=1):
  832. int(num_blocks)
  833. t = self.spawn('mmgen-regtest',['generate',str(num_blocks)])
  834. t.expect(f'Mined {num_blocks} block')
  835. return t
  836. def _get_mempool(self):
  837. if not g.debug_utf8:
  838. disable_debug()
  839. ret = self.spawn('mmgen-regtest',['mempool']).read()
  840. if not g.debug_utf8:
  841. restore_debug()
  842. m = re.search(r'(\[\s*"[a-f0-9]{64}"\s*])',ret) # allow for extra output by handler at end
  843. return json.loads(m.group(1))
  844. def get_mempool1(self):
  845. mp = self._get_mempool()
  846. if len(mp) != 1:
  847. die(4,'Mempool has more or less than one TX!')
  848. self.write_to_tmpfile('rbf_txid',mp[0]+'\n')
  849. return 'ok'
  850. def bob_rbf_status(self,fee,exp1,exp2=''):
  851. if not self.proto.cap('rbf'):
  852. return 'skip'
  853. ext = ',{}]{x}.regtest.sigtx'.format(fee[:-1],x='-α' if g.debug_utf8 else '')
  854. txfile = self.get_file_with_ext(ext,delete=False,no_dot=True)
  855. return self.user_txsend_status('bob',txfile,exp1,exp2)
  856. def bob_rbf_status1(self):
  857. if not self.proto.cap('rbf'):
  858. return 'skip'
  859. return self.bob_rbf_status(rtFee[1],'in mempool, replaceable')
  860. def get_mempool2(self):
  861. if not self.proto.cap('rbf'):
  862. return 'skip'
  863. mp = self._get_mempool()
  864. if len(mp) != 1:
  865. die(4,'Mempool has more or less than one TX!')
  866. chk = self.read_from_tmpfile('rbf_txid')
  867. if chk.strip() == mp[0]:
  868. die(4,'TX in mempool has not changed! RBF bump failed')
  869. self.write_to_tmpfile('rbf_txid2',mp[0]+'\n')
  870. return 'ok'
  871. def bob_rbf_status2(self):
  872. if not self.proto.cap('rbf'):
  873. return 'skip'
  874. new_txid = self.read_from_tmpfile('rbf_txid2').strip()
  875. return self.bob_rbf_status(rtFee[1],
  876. 'Transaction has been replaced',f'{new_txid} in mempool')
  877. def bob_rbf_status3(self):
  878. if not self.proto.cap('rbf'):
  879. return 'skip'
  880. return self.bob_rbf_status(rtFee[2],'status: in mempool, replaceable')
  881. def bob_rbf_status4(self):
  882. if not self.proto.cap('rbf'):
  883. return 'skip'
  884. new_txid = self.read_from_tmpfile('rbf_txid2').strip()
  885. return self.bob_rbf_status(rtFee[1],
  886. 'Replacement transaction has 1 confirmation',
  887. f'Replacing transactions:\s+{new_txid}' )
  888. def bob_rbf_status5(self):
  889. if not self.proto.cap('rbf'):
  890. return 'skip'
  891. return self.bob_rbf_status(rtFee[2],'Transaction has 1 confirmation')
  892. def bob_rbf_status6(self):
  893. if not self.proto.cap('rbf'):
  894. return 'skip'
  895. new_txid = self.read_from_tmpfile('rbf_txid2').strip()
  896. return self.bob_rbf_status(rtFee[1],
  897. 'Replacement transaction has 2 confirmations',
  898. f'Replacing transactions:\s+{new_txid}' )
  899. def _gen_pairs(self,n):
  900. from mmgen.tool.api import tool_api
  901. t = tool_api()
  902. t.init_coin(self.proto.coin,self.proto.network)
  903. def gen_addr(Type):
  904. t.addrtype = Type
  905. wif = t.hex2wif(getrandhex(32))
  906. return ( wif, t.wif2addr(wif) )
  907. return [gen_addr('legacy')] + [gen_addr('compressed') for i in range(n-1)]
  908. def bob_pre_import(self):
  909. pairs = self._gen_pairs(5)
  910. self.write_to_tmpfile('non-mmgen.keys','\n'.join([a[0] for a in pairs])+'\n')
  911. self.write_to_tmpfile('non-mmgen.addrs','\n'.join([a[1] for a in pairs])+'\n')
  912. return self.user_txdo('bob',rtFee[4],[pairs[0][1]],'3')
  913. def user_import(self,user,args,nAddr):
  914. t = self.spawn('mmgen-addrimport',['--'+user]+args)
  915. if g.debug:
  916. t.expect("Type uppercase 'YES' to confirm: ",'YES\n')
  917. t.expect(f'Importing {nAddr} address')
  918. if '--rescan' in args:
  919. if not '--quiet' in args:
  920. t.expect('Continue? (Y/n): ','y')
  921. t.expect('Rescanning block')
  922. return t
  923. def bob_import_addr(self):
  924. addr = self.read_from_tmpfile('non-mmgen.addrs').split()[0]
  925. return self.user_import('bob',['--quiet','--address='+addr],nAddr=1)
  926. def bob_import_list_rescan_aio(self):
  927. addrfile = joinpath(self.tmpdir,'non-mmgen.addrs')
  928. return self.user_import('bob',['--rescan','--rpc-backend=aio','--addrlist',addrfile],nAddr=5)
  929. def bob_resolve_addr(self):
  930. mmaddr = '{}:C:1'.format(self._user_sid('bob'))
  931. t = self.spawn('mmgen-tool',['--bob','resolve_address',mmaddr])
  932. coinaddr = t.read().split()[0].strip()
  933. t = self.spawn('mmgen-tool',['--bob','resolve_address',coinaddr],no_msg=True)
  934. mmaddr_res = t.read().split()[0].strip()
  935. assert mmaddr == mmaddr_res, f'{mmaddr} != {mmaddr_res}'
  936. return t
  937. def bob_import_list(self):
  938. addrfile = joinpath(self.tmpdir,'non-mmgen.addrs')
  939. return self.user_import('bob',['--quiet','--addrlist',addrfile],nAddr=5)
  940. def bob_import_list_rescan(self):
  941. addrfile = joinpath(self.tmpdir,'non-mmgen.addrs')
  942. return self.user_import('bob',['--quiet','--rescan','--addrlist',addrfile],nAddr=5)
  943. def bob_rescan_addr(self):
  944. sid = self._user_sid('bob')
  945. t = self.spawn('mmgen-tool',['--bob','rescan_address',f'{sid}:C:1'])
  946. t.expect('Found 1 unspent output')
  947. t.expect('updated successfully')
  948. return t
  949. def _usr_rescan_blockchain(self,user,add_args,expect):
  950. t = self.spawn('mmgen-tool',[f'--{user}','rescan_blockchain'] + add_args)
  951. t.expect(f'Scanning blocks {expect}')
  952. t.expect('Done')
  953. return t
  954. def bob_rescan_blockchain_all(self):
  955. return self._usr_rescan_blockchain('bob',[],'300-396')
  956. def bob_rescan_blockchain_gb(self):
  957. return self._usr_rescan_blockchain('bob',['start_block=0','stop_block=0'],'0-0')
  958. def bob_rescan_blockchain_one(self):
  959. return self._usr_rescan_blockchain('bob',['start_block=300','stop_block=300'],'300-300')
  960. def bob_rescan_blockchain_ss(self):
  961. return self._usr_rescan_blockchain('bob',['start_block=300','stop_block=302'],'300-302')
  962. def bob_twexport(self,add_args=[]):
  963. t = self.spawn('mmgen-tool',['--bob',f'--outdir={self.tmpdir}','twexport'] + add_args)
  964. t.written_to_file('JSON data')
  965. return t
  966. def bob_twexport_noamt(self):
  967. return self.bob_twexport(add_args=['include_amts=0'])
  968. def bob_twexport_pretty(self):
  969. return self.bob_twexport(add_args=['pretty=1'])
  970. def bob_edit_json_twdump(self):
  971. self.spawn('',msg_only=True)
  972. from mmgen.tw.json import TwJSON
  973. fn = TwJSON.Base(self.proto).dump_fn
  974. text = json.loads(self.read_from_tmpfile(fn))
  975. text['data']['entries'][3][3] = f'edited comment [фубар] [{gr_uc}]'
  976. self.write_to_tmpfile( fn, json.dumps(text,indent=4) )
  977. return 'ok'
  978. def carol_twimport(self,rpc_backend='http',add_parms=[],expect_str=None,expect_str2='Found 1 unspent output'):
  979. from mmgen.tw.json import TwJSON
  980. fn = joinpath( self.tmpdir, TwJSON.Base(self.proto).dump_fn )
  981. t = self.spawn(
  982. 'mmgen-tool',
  983. ([f'--rpc-backend={rpc_backend}'] if rpc_backend else [])
  984. + ['--carol','twimport',fn]
  985. + add_parms )
  986. t.expect('(y/N): ','y')
  987. if expect_str:
  988. t.expect(expect_str)
  989. elif 'batch=true' in add_parms:
  990. t.expect('{} addresses imported'.format(10 if self.proto.coin == 'BCH' else 20))
  991. else:
  992. t.expect('import completed OK')
  993. t.expect(expect_str2)
  994. return t
  995. def carol_twimport_nochksum(self):
  996. return self.carol_twimport(rpc_backend=None,add_parms=['ignore_checksum=true'])
  997. def carol_twimport_batch(self):
  998. return self.carol_twimport(add_parms=['batch=true'])
  999. def carol_twimport_pretty(self):
  1000. return self.carol_twimport(add_parms=['ignore_checksum=true'],expect_str='ignoring incorrect checksum')
  1001. def carol_listaddresses(self):
  1002. return self.spawn('mmgen-tool',['--carol','listaddresses','showempty=1'])
  1003. async def carol_delete_wallet(self):
  1004. imsg(f'Unloading Carol’s tracking wallet')
  1005. t = self.spawn('mmgen-regtest',['cli','unloadwallet','carol'])
  1006. t.ok()
  1007. from mmgen.rpc import rpc_init
  1008. rpc = await rpc_init(self.proto)
  1009. wdir = joinpath(rpc.daemon.network_datadir,'wallets','carol')
  1010. from shutil import rmtree
  1011. imsg(f'Deleting Carol’s tracking wallet')
  1012. rmtree(wdir)
  1013. return 'silent'
  1014. def bob_split2(self):
  1015. addrs = self.read_from_tmpfile('non-mmgen.addrs').split()
  1016. amts = (1.12345678,2.87654321,3.33443344,4.00990099,5.43214321)
  1017. outputs1 = list(map('{},{}'.format,addrs,amts))
  1018. sid = self._user_sid('bob')
  1019. l1,l2 = (
  1020. (':S',':B') if 'B' in self.proto.mmtypes else
  1021. (':S',':S') if self.proto.cap('segwit') else
  1022. (':L',':L') )
  1023. outputs2 = [sid+':C:2,6.333', sid+':L:3,6.667',sid+l1+':4,0.123',sid+l2+':5']
  1024. return self.user_txdo('bob',rtFee[5],outputs1+outputs2,'1-2')
  1025. def user_add_comment(self,user,addr,comment):
  1026. t = self.spawn('mmgen-tool',['--'+user,'add_label',addr,comment])
  1027. t.expect('Added label.*in tracking wallet',regex=True)
  1028. return t
  1029. def user_remove_comment(self,user,addr):
  1030. t = self.spawn('mmgen-tool',['--'+user,'remove_label',addr])
  1031. t.expect('Removed label.*in tracking wallet',regex=True)
  1032. return t
  1033. def bob_add_comment(self):
  1034. sid = self._user_sid('bob')
  1035. return self.user_add_comment('bob',sid+':C:1',tw_comment_lat_cyr_gr)
  1036. def alice_add_comment1(self):
  1037. sid = self._user_sid('alice')
  1038. return self.user_add_comment('alice',sid+':C:1','Original Label - 月へ')
  1039. def alice_add_comment2(self):
  1040. sid = self._user_sid('alice')
  1041. return self.user_add_comment('alice',sid+':C:1','Replacement Label')
  1042. def _user_chk_comment(self,user,addr,comment,extra_args=[]):
  1043. t = self.spawn('mmgen-tool',['--'+user,'listaddresses','all_labels=1']+extra_args)
  1044. ret = strip_ansi_escapes(t.expect_getend(addr)).strip().split(None,2)[2]
  1045. cmp_or_die( # squeezed display, double-width chars, so truncate to min field width
  1046. ret[:3].strip(),
  1047. comment[:3].strip())
  1048. return t
  1049. def alice_add_comment_coinaddr(self):
  1050. mmid = self._user_sid('alice') + (':S:1',':L:1')[self.proto.coin=='BCH']
  1051. t = self.spawn('mmgen-tool',['--alice','listaddress',mmid,'wide=true'],no_msg=True)
  1052. addr = [i for i in strip_ansi_escapes(t.read()).splitlines() if re.search(rf'\b{mmid}\b',i)][0].split()[3]
  1053. return self.user_add_comment('alice',addr,'Label added using coin address of MMGen address')
  1054. def alice_chk_comment_coinaddr(self):
  1055. mmid = self._user_sid('alice') + (':S:1',':L:1')[self.proto.coin=='BCH']
  1056. return self._user_chk_comment('alice',mmid,'Label added using coin address of MMGen address')
  1057. def alice_add_comment_badaddr(self,addr,reply,exit_val):
  1058. if os.getenv('PYTHONOPTIMIZE'):
  1059. omsg(yellow(f'PYTHONOPTIMIZE set, skipping test {self.test_name!r}'))
  1060. return 'skip'
  1061. t = self.spawn('mmgen-tool',['--alice','add_label',addr,'(none)'])
  1062. t.expect(reply,regex=True)
  1063. t.req_exit_val = exit_val
  1064. return t
  1065. def alice_add_comment_badaddr1(self):
  1066. return self.alice_add_comment_badaddr( rt_pw, 'invalid address', 2 )
  1067. def alice_add_comment_badaddr2(self):
  1068. addr = init_proto(self.proto.coin,network='mainnet').pubhash2addr(bytes(20),False) # mainnet zero address
  1069. return self.alice_add_comment_badaddr( addr, 'invalid address', 2 )
  1070. def alice_add_comment_badaddr3(self):
  1071. addr = self._user_sid('alice') + ':C:123'
  1072. return self.alice_add_comment_badaddr( addr, f'MMGen address {addr!r} not found in tracking wallet', 2 )
  1073. def alice_add_comment_badaddr4(self):
  1074. addr = self.proto.pubhash2addr(bytes(20),False) # regtest (testnet) zero address
  1075. return self.alice_add_comment_badaddr( addr, f'Coin address {addr!r} not found in tracking wallet', 2 )
  1076. def alice_remove_comment1(self):
  1077. sid = self._user_sid('alice')
  1078. mmid = sid + (':S:3',':L:3')[self.proto.coin=='BCH']
  1079. return self.user_remove_comment('alice',mmid)
  1080. def alice_chk_comment1(self):
  1081. sid = self._user_sid('alice')
  1082. return self._user_chk_comment('alice',sid+':C:1','Original Label - 月へ')
  1083. def alice_chk_comment2(self):
  1084. sid = self._user_sid('alice')
  1085. return self._user_chk_comment('alice',sid+':C:1','Replacement Label',extra_args=['age_fmt=block'])
  1086. def alice_edit_comment1(self): return self.user_edit_comment('alice','4',tw_comment_lat_cyr_gr)
  1087. def alice_edit_comment2(self): return self.user_edit_comment('alice','3',tw_comment_zh)
  1088. def alice_chk_comment3(self):
  1089. sid = self._user_sid('alice')
  1090. mmid = sid + (':S:3',':L:3')[self.proto.coin=='BCH']
  1091. return self._user_chk_comment('alice',mmid,tw_comment_lat_cyr_gr,extra_args=['age_fmt=date'])
  1092. def alice_chk_comment4(self):
  1093. sid = self._user_sid('alice')
  1094. mmid = sid + (':S:3',':L:3')[self.proto.coin=='BCH']
  1095. return self._user_chk_comment('alice',mmid,'-',extra_args=['age_fmt=date_time'])
  1096. def user_edit_comment(self,user,output,comment):
  1097. t = self.spawn('mmgen-txcreate',['-B','--'+user,'-i'])
  1098. t.expect(r'add \[l\]abel:.','M',regex=True)
  1099. t.expect(r'add \[l\]abel:.','l',regex=True)
  1100. t.expect(r"Enter unspent.*return to main menu\):.",output+'\n',regex=True)
  1101. t.expect(r"Enter label text.*:.",comment+'\n',regex=True)
  1102. t.expect(r'\[q\]uit view, .*?:.','q',regex=True)
  1103. return t
  1104. def _alice_listaddresses_interactive(self,expect=(),expect_menu=()):
  1105. t = self.spawn('mmgen-tool',['--alice','listaddresses','interactive=1'])
  1106. for s in expect_menu:
  1107. t.expect('abel:\b',s)
  1108. for p,s in expect:
  1109. t.expect(p,s)
  1110. return t
  1111. def alice_listaddresses_empty(self):
  1112. return self._alice_listaddresses_interactive(expect_menu='uuEq')
  1113. def alice_listaddresses_menu(self):
  1114. return self._alice_listaddresses_interactive(expect_menu='aAMrDDDDLeq')
  1115. def alice_listaddresses(self,args,expect):
  1116. t = self.spawn('mmgen-tool',['--alice','listaddresses','showempty=1'] + args)
  1117. expect_str = r'\D{}\D.*\b{}'.format(*expect)
  1118. t.expect(expect_str,regex=True)
  1119. return t
  1120. def alice_listaddresses1(self):
  1121. return self.alice_listaddresses(
  1122. args = [],
  1123. expect = (rtAmts[1],r'\d+') )
  1124. def alice_listaddresses_days(self):
  1125. return self.alice_listaddresses(
  1126. args = ['age_fmt=days'],
  1127. expect = (rtAmts[1],r'\d+') )
  1128. def alice_listaddresses_date(self):
  1129. return self.alice_listaddresses(
  1130. args = ['age_fmt=date'],
  1131. expect = (rtAmts[1],pat_date) )
  1132. def alice_listaddresses_date_time(self):
  1133. return self.alice_listaddresses(
  1134. args = ['age_fmt=date_time'],
  1135. expect = (rtAmts[1],pat_date_time) )
  1136. def alice_twview(self,args,expect):
  1137. t = self.spawn('mmgen-tool',['--alice','twview'] + args)
  1138. expect_str = r'\D{}\D.*\b{}'.format(*expect)
  1139. t.expect(expect_str,regex=True)
  1140. return t
  1141. def alice_twview1(self):
  1142. return self.alice_twview(
  1143. args = [],
  1144. expect = (rtAmts[0],r'\d+') )
  1145. def alice_twview_days(self):
  1146. return self.alice_twview(
  1147. args = ['age_fmt=days'],
  1148. expect = (rtAmts[0],r'\d+') )
  1149. def alice_twview_date(self):
  1150. return self.alice_twview(
  1151. args = ['age_fmt=date'],
  1152. expect = (rtAmts[0],pat_date) )
  1153. def alice_twview_date_time(self):
  1154. return self.alice_twview(
  1155. args = ['age_fmt=date_time'],
  1156. expect = (rtAmts[0],pat_date_time) )
  1157. def alice_txcreate_info(self,pexpect_spawn=False):
  1158. t = self.spawn('mmgen-txcreate',['--alice','-Bi'],pexpect_spawn=pexpect_spawn)
  1159. pats = (
  1160. ( '\d+', 'w'),
  1161. ( '\d+', 'D'),
  1162. ( '\d+', 'D'),
  1163. ( '\d+', 'D'),
  1164. ( pat_date, 'q'),
  1165. )
  1166. for d,s in pats:
  1167. t.expect(
  1168. r'\D{}\D.*\b{}\b'.format( rtAmts[0], d ),
  1169. s,
  1170. regex=True )
  1171. if t.pexpect_spawn and s == 'w':
  1172. t.expect(r'Total.*','q',regex=True,delay=1 if opt.exact_output else t.send_delay)
  1173. time.sleep(t.send_delay)
  1174. t.send('e')
  1175. return t
  1176. def alice_txcreate_info_term(self):
  1177. if self.skip_for_win():
  1178. return 'skip'
  1179. return self.alice_txcreate_info(pexpect_spawn=True)
  1180. def bob_msgcreate(self):
  1181. sid1 = self._user_sid('bob')
  1182. sid2 = self._get_user_subsid('bob','29L')
  1183. return self.spawn(
  1184. 'mmgen-msg', [
  1185. '--bob',
  1186. f'--outdir={self.tmpdir}',
  1187. 'create',
  1188. '16/3/2022 Earthquake strikes Fukushima coast',
  1189. f'{sid1}:{self.dfl_mmtype}:1-4',
  1190. f'{sid2}:C:3-7,87,98'
  1191. ])
  1192. def bob_msgsign(self,wallets=[]):
  1193. fn = get_file_with_ext(self.tmpdir,'rawmsg.json')
  1194. t = self.spawn(
  1195. 'mmgen-msg', [
  1196. '--bob',
  1197. f'--outdir={self.tmpdir}',
  1198. 'sign',
  1199. fn
  1200. ] + wallets )
  1201. if not wallets:
  1202. t.passphrase(dfl_wcls.desc,rt_pw)
  1203. return t
  1204. def bob_walletconv_words(self):
  1205. t = self.spawn(
  1206. 'mmgen-walletconv', [ '--bob', f'--outdir={self.tmpdir}', '--out-fmt=words' ] )
  1207. t.passphrase(dfl_wcls.desc,rt_pw)
  1208. t.written_to_file('data')
  1209. return t
  1210. def bob_subwalletgen_bip39(self):
  1211. t = self.spawn(
  1212. 'mmgen-subwalletgen', [ '--bob', f'--outdir={self.tmpdir}', '--out-fmt=bip39', '29L' ] )
  1213. t.passphrase(dfl_wcls.desc,rt_pw)
  1214. t.written_to_file('data')
  1215. return t
  1216. def bob_msgsign_userwallet(self):
  1217. fn1 = get_file_with_ext(self.tmpdir,'mmwords')
  1218. return self.bob_msgsign([fn1])
  1219. def bob_msgsign_userwallets(self):
  1220. fn1 = get_file_with_ext(self.tmpdir,'mmwords')
  1221. fn2 = get_file_with_ext(self.tmpdir,'bip39')
  1222. return self.bob_msgsign([fn2,fn1])
  1223. def bob_msgverify(self,addr=None,ext='sigmsg.json',cmd='verify',msgfile=None):
  1224. return self.spawn(
  1225. 'mmgen-msg', [
  1226. '--bob',
  1227. f'--outdir={self.tmpdir}',
  1228. cmd,
  1229. msgfile or get_file_with_ext(self.tmpdir,ext),
  1230. ] + ([addr] if addr else []) )
  1231. def bob_msgverify_raw(self):
  1232. t = self.bob_msgverify(ext='rawmsg.json')
  1233. t.expect('No signatures')
  1234. t.req_exit_val = 1
  1235. return t
  1236. def bob_msgverify_single(self):
  1237. sid = self._user_sid('bob')
  1238. return self.bob_msgverify(addr=f'{sid}:{self.dfl_mmtype}:1')
  1239. def bob_msgexport(self,addr=None):
  1240. t = self.bob_msgverify( addr=addr, cmd='export' )
  1241. t.written_to_file('data')
  1242. return t
  1243. def bob_msgexport_single(self):
  1244. sid = self._user_sid('bob')
  1245. return self.bob_msgexport(addr=f'{sid}:{self.dfl_mmtype}:1')
  1246. def bob_msgverify_export(self):
  1247. return self.bob_msgverify(
  1248. msgfile = os.path.join(self.tmpdir,'signatures.json')
  1249. )
  1250. def bob_msgverify_export_single(self):
  1251. sid = self._user_sid('bob')
  1252. mmid = f'{sid}:{self.dfl_mmtype}:1'
  1253. args = [ '--bob', '--color=0', 'listaddress', mmid, 'wide=true' ]
  1254. imsg(f'Running mmgen-tool {fmt_list(args,fmt="bare")}')
  1255. t = self.spawn('mmgen-tool', args, no_msg=True)
  1256. addr = t.expect_getend(mmid).split()[1]
  1257. t.close()
  1258. return self.bob_msgverify(
  1259. addr = addr,
  1260. msgfile = os.path.join(self.tmpdir,'signatures.json')
  1261. )
  1262. def bob_split3(self):
  1263. if not self.proto.cap('segwit'):
  1264. return 'skip'
  1265. sid = self._user_sid('bob')
  1266. return self.user_txdo(
  1267. user = 'bob',
  1268. fee = '23s',
  1269. outputs_cl = [sid+':C:5,0.0135', sid+':L:4'],
  1270. outputs_list = '1' )
  1271. def _usr_auto_chg(self,user,arg,include_dest=True,choices=1):
  1272. dest = [self.burn_addr+',0.01'] if include_dest else []
  1273. t = self.spawn(
  1274. 'mmgen-txcreate',
  1275. ['-d',self.tr.trash_dir,'-B',f'--{user}', arg] + dest)
  1276. return self.txcreate_ui_common(t,
  1277. menu = [],
  1278. inputs = '1',
  1279. interactive_fee = '20s',
  1280. auto_chg_arg = arg,
  1281. auto_chg_choices = choices )
  1282. def bob_auto_chg1(self):
  1283. return self._usr_auto_chg( 'bob', self._user_sid('bob') + ':C' )
  1284. def bob_auto_chg2(self):
  1285. if not self.proto.cap('segwit'):
  1286. return 'skip'
  1287. return self._usr_auto_chg( 'bob', self._user_sid('bob') + ':B' )
  1288. def bob_auto_chg3(self):
  1289. if not self.proto.cap('segwit'):
  1290. return 'skip'
  1291. return self._usr_auto_chg( 'bob', self._user_sid('bob') + ':S' )
  1292. def bob_auto_chg4(self):
  1293. return self._usr_auto_chg( 'bob', self._user_sid('bob') + ':C', include_dest=False )
  1294. def bob_auto_chg_addrtype1(self):
  1295. return self._usr_auto_chg( 'bob', 'C', choices=3 )
  1296. def bob_auto_chg_addrtype2(self):
  1297. if not self.proto.cap('segwit'):
  1298. return 'skip'
  1299. return self._usr_auto_chg( 'bob', 'B', choices=1 )
  1300. def bob_auto_chg_addrtype3(self):
  1301. if not self.proto.cap('segwit'):
  1302. return 'skip'
  1303. return self._usr_auto_chg( 'bob', 'S', choices=1 )
  1304. def bob_auto_chg_addrtype4(self):
  1305. return self._usr_auto_chg( 'bob', 'C', choices=3, include_dest=False )
  1306. def _usr_auto_chg_bad(self,user,al_id,expect):
  1307. t = self.spawn(
  1308. 'mmgen-txcreate',
  1309. ['-d',self.tr.trash_dir,'-B',f'--{user}', self.burn_addr+',0.01', al_id] )
  1310. t.req_exit_val = 2
  1311. t.expect(expect)
  1312. return t
  1313. def bob_auto_chg_bad1(self):
  1314. return self._usr_auto_chg_bad(
  1315. 'bob',
  1316. 'FFFFFFFF:C',
  1317. 'contains no addresses' )
  1318. def bob_auto_chg_bad2(self):
  1319. return self._usr_auto_chg_bad(
  1320. 'bob',
  1321. '00000000:C',
  1322. 'contains no addresses' )
  1323. def bob_auto_chg_bad3(self):
  1324. return self._usr_auto_chg_bad(
  1325. 'bob',
  1326. self._user_sid('bob') + ':L',
  1327. 'contains no unused addresses from address list' )
  1328. def bob_auto_chg_bad4(self):
  1329. return self._usr_auto_chg_bad(
  1330. 'bob',
  1331. 'L',
  1332. 'contains no unused addresses of address type' )
  1333. def carol_twimport2(self):
  1334. u,b = (4,3) if self.proto.cap('segwit') else (3,2)
  1335. return self.carol_twimport(
  1336. rpc_backend = None,
  1337. add_parms = ['ignore_checksum=true'],
  1338. expect_str2 = f'Found {u} unspent outputs in {b} blocks' )
  1339. def carol_rescan_blockchain(self):
  1340. return self._usr_rescan_blockchain('carol',[],'400-407')
  1341. def carol_auto_chg1(self):
  1342. return self._usr_auto_chg( 'carol', self._user_sid('bob') + ':C' )
  1343. def carol_auto_chg2(self):
  1344. if not self.proto.cap('segwit'):
  1345. return 'skip'
  1346. return self._usr_auto_chg( 'carol', self._user_sid('bob') + ':B' )
  1347. def carol_auto_chg3(self):
  1348. if not self.proto.cap('segwit'):
  1349. return 'skip'
  1350. return self._usr_auto_chg( 'carol', self._user_sid('bob') + ':S' )
  1351. def carol_auto_chg_addrtype1(self):
  1352. return self._usr_auto_chg( 'carol', 'C' )
  1353. def carol_auto_chg_addrtype2(self):
  1354. if not self.proto.cap('segwit'):
  1355. return 'skip'
  1356. return self._usr_auto_chg( 'carol', 'B' )
  1357. def carol_auto_chg_addrtype3(self):
  1358. if not self.proto.cap('segwit'):
  1359. return 'skip'
  1360. return self._usr_auto_chg( 'carol', 'S' )
  1361. def carol_auto_chg_bad1(self):
  1362. return self._usr_auto_chg_bad(
  1363. 'carol',
  1364. self._user_sid('bob') + ':L',
  1365. 'contains no unused addresses from address list' )
  1366. def carol_auto_chg_bad2(self):
  1367. return self._usr_auto_chg_bad(
  1368. 'carol',
  1369. 'L',
  1370. 'contains no unused addresses of address type' )
  1371. def stop(self):
  1372. if opt.no_daemon_stop:
  1373. self.spawn('',msg_only=True)
  1374. msg_r('(leaving daemon running by user request)')
  1375. return 'ok'
  1376. else:
  1377. return self.spawn('mmgen-regtest',['stop'])