tooltest2.py 41 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043
  1. #!/usr/bin/env python3
  2. #
  3. # mmgen = Multi-Mode GENerator, command-line Bitcoin cold storage solution
  4. # Copyright (C)2013-2020 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/tooltest2.py: Simple tests for the 'mmgen-tool' utility
  20. """
  21. # TODO: move all non-interactive 'mmgen-tool' tests in 'test.py' here
  22. # TODO: move all(?) tests in 'tooltest.py' here (or duplicate them?)
  23. import sys,os,time
  24. from subprocess import run,PIPE
  25. from decimal import Decimal
  26. from include.tests_header import repo_root
  27. from mmgen.common import *
  28. from test.include.common import *
  29. from mmgen.wallet import is_bip39_mnemonic,is_mmgen_mnemonic
  30. from mmgen.addr import is_xmrseed
  31. from mmgen.baseconv import *
  32. skipped_tests = ['mn2hex_interactive']
  33. NL = ('\n','\r\n')[g.platform=='win']
  34. def is_str(s):
  35. return type(s) == str
  36. from mmgen.obj import is_wif,is_coin_addr
  37. def is_wif_loc(s):
  38. return is_wif(proto,s)
  39. def is_coin_addr_loc(s):
  40. return is_coin_addr(proto,s)
  41. def md5_hash(s):
  42. from hashlib import md5
  43. return md5(s.encode()).hexdigest()
  44. def md5_hash_strip(s):
  45. import re
  46. s = re.sub('\x1b\[[;0-9]+?m','',s) # strip ANSI color sequences
  47. s = s.replace(NL,'\n') # fix DOS newlines
  48. return md5_hash(s.strip())
  49. opts_data = {
  50. 'text': {
  51. 'desc': "Simple test suite for the 'mmgen-tool' utility",
  52. 'usage':'[options] [command]...',
  53. 'options': """
  54. -h, --help Print this help message
  55. -A, --tool-api Test the tool_api subsystem
  56. -C, --coverage Produce code coverage info using trace module
  57. -d, --die-on-missing Abort if no test data found for given command
  58. --, --longhelp Print help message for long options (common options)
  59. -l, --list-tests List the test groups in this test suite
  60. -L, --list-tested-cmds Output the 'mmgen-tool' commands that are tested by this test suite
  61. -n, --names Print command names instead of descriptions
  62. -q, --quiet Produce quieter output
  63. -s, --system Test scripts and modules installed on system rather than
  64. those in the repo root
  65. -t, --type= Specify coin type
  66. -f, --fork Run commands via tool executable instead of importing tool module
  67. -t, --traceback Run tool inside traceback script
  68. -v, --verbose Produce more verbose output
  69. """,
  70. 'notes': """
  71. If no command is given, the whole suite of tests is run.
  72. """
  73. }
  74. }
  75. sample_text_hexdump = (
  76. '000000: 5468 6520 5469 6d65 7320 3033 2f4a 616e{n}' +
  77. '000010: 2f32 3030 3920 4368 616e 6365 6c6c 6f72{n}' +
  78. '000020: 206f 6e20 6272 696e 6b20 6f66 2073 6563{n}' +
  79. '000030: 6f6e 6420 6261 696c 6f75 7420 666f 7220{n}' +
  80. '000040: 6261 6e6b 73').format(n=NL)
  81. kafile_opts = ['-p1','-Ptest/ref/keyaddrfile_password']
  82. from test.unit_tests_d.ut_bip39 import unit_test as bip39
  83. tests = {
  84. 'Mnemonic': {
  85. 'hex2mn': [
  86. ( ['deadbeefdeadbeefdeadbeefdeadbeef','fmt=mmgen'],
  87. 'table cast forgive master funny gaze sadness ripple million paint moral match' ),
  88. ( ['deadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef'],
  89. ('swirl maybe anymore mix scale stray fog use approach page crime rhyme ' +
  90. 'class former strange window snap soon') ),
  91. ( ['deadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef'],
  92. ('swell type milk figure cheese phone fill black test bloom heard comfort ' +
  93. 'image terrible radio lesson own reply battle goal goodbye need laugh stream') ),
  94. ( ['ffffffffffffffffffffffffffffffff'],
  95. 'yellow yeah show bowl season spider cling defeat poison law shelter reflect' ),
  96. ( ['ffffffffffffffffffffffffffffffffffffffffffffffff'],
  97. ('yeah youth quit fail perhaps drum out person young click skin ' +
  98. 'weird inside silently perfectly together anyone memory') ),
  99. ( ['ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff'],
  100. ('wrote affection object cell opinion here laughter stare honest north cost begin ' +
  101. 'murder something yourself effort acid dot doubt game broke tell guilt innocent') ),
  102. ( ['0000000000000000000000000000000000000000000000000000000000000001'],
  103. ('able able able able able able able able able able able able ' +
  104. 'able able able able able able able able able able able about') ),
  105. ( ['e8164dda6d42bd1e261a3406b2038dcbddadbeefdeadbeefdeadbeefdeadbe0f','fmt=xmrseed'],
  106. ('viewpoint donuts ardent template unveil agile meant unafraid urgent athlete rustled mime azure ' +
  107. 'jaded hawk baby jagged haystack baby jagged haystack ramped oncoming point template') ),
  108. ] + [([a,'fmt=bip39'],b) for a,b in bip39.vectors],
  109. 'mn2hex': [
  110. ( ['table cast forgive master funny gaze sadness ripple million paint moral match','fmt=mmgen'],
  111. 'deadbeefdeadbeefdeadbeefdeadbeef' ),
  112. ( ['swirl maybe anymore mix scale stray fog use approach page crime rhyme ' +
  113. 'class former strange window snap soon'],
  114. 'deadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef'),
  115. ( ['swell type milk figure cheese phone fill black test bloom heard comfort ' +
  116. 'image terrible radio lesson own reply battle goal goodbye need laugh stream'],
  117. 'deadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef' ),
  118. ( ['yellow yeah show bowl season spider cling defeat poison law shelter reflect'],
  119. 'ffffffffffffffffffffffffffffffff' ),
  120. ( ['yeah youth quit fail perhaps drum out person young click skin ' +
  121. 'weird inside silently perfectly together anyone memory'],
  122. 'ffffffffffffffffffffffffffffffffffffffffffffffff' ) ,
  123. ( ['wrote affection object cell opinion here laughter stare honest north cost begin ' +
  124. 'murder something yourself effort acid dot doubt game broke tell guilt innocent'],
  125. 'ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff'),
  126. ( ['able able able able able able able able able able able able ' +
  127. 'able able able able able able able able able able able about'],
  128. '0000000000000000000000000000000000000000000000000000000000000001'),
  129. ( ['viewpoint donuts ardent template unveil agile meant unafraid urgent athlete ' +
  130. 'rustled mime azure jaded hawk baby jagged haystack baby jagged haystack ' +
  131. 'ramped oncoming point template','fmt=xmrseed'],
  132. 'e8164dda6d42bd1e261a3406b2038dcbddadbeefdeadbeefdeadbeefdeadbe0f'),
  133. ] + [([b,'fmt=bip39'],a) for a,b in bip39.vectors],
  134. 'mn_rand128': [
  135. ( [], is_mmgen_mnemonic, ['-r0']),
  136. ( ['fmt=mmgen'], is_mmgen_mnemonic, ['-r0']),
  137. ( ['fmt=bip39'], is_bip39_mnemonic, ['-r0']),
  138. ],
  139. 'mn_rand192': [
  140. ( ['fmt=mmgen'], is_mmgen_mnemonic, ['-r0']),
  141. ( ['fmt=bip39'], is_bip39_mnemonic, ['-r0']),
  142. ],
  143. 'mn_rand256': [
  144. ( ['fmt=mmgen'], is_mmgen_mnemonic, ['-r0']),
  145. ( ['fmt=bip39'], is_bip39_mnemonic, ['-r0']),
  146. ( ['fmt=xmrseed'], is_xmrseed, ['-r0']),
  147. ],
  148. 'mn_stats': [
  149. ( [], is_str ),
  150. ( ['fmt=mmgen'], is_str ),
  151. ( ['fmt=bip39'], is_str ),
  152. ( ['fmt=xmrseed'], is_str ),
  153. ],
  154. 'mn_printlist': [
  155. ( [], is_str ),
  156. ( ['fmt=mmgen'], is_str ),
  157. ( ['fmt=bip39'], is_str ),
  158. ( ['fmt=xmrseed','enum=true'], is_str ),
  159. ],
  160. },
  161. 'Util': {
  162. 'hextob32': [
  163. ( ['deadbeef'], 'DPK3PXP' ),
  164. ( ['deadbeefdeadbeef'], 'N5LN657PK3PXP' ),
  165. ( ['ffffffffffffffff'], 'P777777777777' ),
  166. ( ['0000000000000000'], 'A' ),
  167. ( ['0000000000000000','pad=10'], 'AAAAAAAAAA' ),
  168. ( ['ff','pad=10'], 'AAAAAAAAH7' ),
  169. ],
  170. 'b32tohex': [
  171. ( ['DPK3PXP'], 'deadbeef' ),
  172. ( ['N5LN657PK3PXP'], 'deadbeefdeadbeef' ),
  173. ( ['P777777777777'], 'ffffffffffffffff' ),
  174. ( ['A','pad=16'], '0000000000000000' ),
  175. ( ['AAAAAAAAAA','pad=16'], '0000000000000000' ),
  176. ( ['AAAAAAAAH7','pad=2'], 'ff' ),
  177. ],
  178. 'hextob6d': [
  179. ( ['deadbeef'], '25255 24636 426' ),
  180. ( ['deadbeefdeadbeef'], '43263 51255 35545 36422 42642' ),
  181. ( ['ffffffffffffffff'], '46316 33121 21321 15553 55534' ),
  182. ( ['0000000000000000'], '1' ),
  183. ( ['0000000000000000','pad=10'], '11111 11111' ),
  184. ( ['ff','pad=10'], '11111 12214' ),
  185. ( ['ff'*16],
  186. '34164 46464 12666 61652 46515 46546 53354 43666 45555 21414' ),
  187. ( ['ff'*24],
  188. '24611 14114 33323 36422 24655 66552 32465 25661 21541 62342 '
  189. '61351 63525 45161 35543 13654' ),
  190. ( ['ff'*32],
  191. '21325 21653 31261 31341 45131 42346 54146 36252 11413 12253 '
  192. '24246 31114 16424 56513 41632 24121 46151 43214 22425 65134' ),
  193. ],
  194. 'b6dtohex': [
  195. ( ['25255 24636 426'], 'deadbeef' ),
  196. ( ['43263 51255 35545 36422 42642'], 'deadbeefdeadbeef' ),
  197. ( ['46316 33121 21321 15553 55534'], 'ffffffffffffffff' ),
  198. ( ['1','pad=16'], '0000000000000000' ),
  199. ( ['11111 11111','pad=16'], '0000000000000000' ),
  200. ( ['11111 12214','pad=2'], 'ff' ),
  201. ( ['22222 22222'], 'b88733' ),
  202. ( ['66666 66666'], '039aa3ff' ),
  203. ( ['6'*50], {
  204. 'len': 34,
  205. 'value':'0260154fc36cbf42778f23ffffffffffff' # 130 bits
  206. } ),
  207. ( ['6'*75], {
  208. 'len': 50,
  209. 'value':'03a92ef1c3432e71a7679561bb6817d7ffffffffffffffffff' # 194 bits
  210. } ),
  211. ( ['6'*100], {
  212. 'len': 66,
  213. 'value':'05a4653ca673768565b41f775d6947d55cf3813d0fffffffffffffffffffffffff' # 259 bits
  214. } ),
  215. ],
  216. 'hextob58chk': [
  217. ( ['deadbeef'], 'eFGDJPketnz' ),
  218. ( ['deadbeefdeadbeef'], '5CizhNNRPYpBjrbYX' ),
  219. ( ['ffffffffffffffff'], '5qCHTcgbQwprzjWrb' ),
  220. ( ['0000000000000000'], '111111114FCKVB' ),
  221. ( ['00'], '1Wh4bh' ),
  222. ( ['000000000000000000000000000000000000000000'], '1111111111111111111114oLvT2' ),
  223. ],
  224. 'b58chktohex': [
  225. ( ['eFGDJPketnz'], 'deadbeef' ),
  226. ( ['5CizhNNRPYpBjrbYX'], 'deadbeefdeadbeef' ),
  227. ( ['5qCHTcgbQwprzjWrb'], 'ffffffffffffffff' ),
  228. ( ['111111114FCKVB'], '0000000000000000' ),
  229. ( ['3QJmnh'], '' ),
  230. ( ['1111111111111111111114oLvT2'], '000000000000000000000000000000000000000000' ),
  231. ],
  232. 'bytestob58': [
  233. ( [b'\xde\xad\xbe\xef'], '6h8cQN' ),
  234. ( [b'\xde\xad\xbe\xef\xde\xad\xbe\xef'], 'eFGDJURJykA' ),
  235. ( [b'\xff\xff\xff\xff\xff\xff\xff\xff'], 'jpXCZedGfVQ' ),
  236. ( [b'\x00\x00\x00\x00\x00\x00\x00\x00'], '1' ),
  237. ( [b'\x00\x00\x00\x00\x00\x00\x00\x00','pad=10'], '1111111111' ),
  238. ( [b'\xff','pad=10'], '111111115Q' ),
  239. ],
  240. 'b58tobytes': [
  241. ( ['6h8cQN'], b'\xde\xad\xbe\xef' ),
  242. ( ['eFGDJURJykA'], b'\xde\xad\xbe\xef\xde\xad\xbe\xef' ),
  243. ( ['jpXCZedGfVQ'], b'\xff\xff\xff\xff\xff\xff\xff\xff' ),
  244. ( ['1','pad=8'], b'\x00\x00\x00\x00\x00\x00\x00\x00' ),
  245. ( ['1111111111','pad=8'], b'\x00\x00\x00\x00\x00\x00\x00\x00' ),
  246. ( ['111111115Q','pad=1'], b'\xff' ),
  247. ],
  248. 'hextob58': [
  249. ( ['deadbeef'], '6h8cQN' ),
  250. ( ['deadbeefdeadbeef'], 'eFGDJURJykA' ),
  251. ( ['ffffffffffffffff'], 'jpXCZedGfVQ' ),
  252. ( ['0000000000000000'], '1' ),
  253. ( ['0000000000000000','pad=10'], '1111111111' ),
  254. ( ['ff','pad=10'], '111111115Q' ),
  255. ],
  256. 'b58tohex': [
  257. ( ['6h8cQN'], 'deadbeef' ),
  258. ( ['eFGDJURJykA'], 'deadbeefdeadbeef' ),
  259. ( ['jpXCZedGfVQ'], 'ffffffffffffffff' ),
  260. ( ['1','pad=16'], '0000000000000000' ),
  261. ( ['1111111111','pad=16'], '0000000000000000' ),
  262. ( ['111111115Q','pad=2'], 'ff' ),
  263. ],
  264. 'bytespec': [
  265. ( ['1G'], str(1024*1024*1024) ),
  266. ( ['1234G'], str(1234*1024*1024*1024) ),
  267. ( ['1GB'], str(1000*1000*1000) ),
  268. ( ['1234GB'], str(1234*1000*1000*1000) ),
  269. ( ['1.234MB'], str(1234*1000) ),
  270. ( ['1.234567M'], str(int(Decimal('1.234567')*1024*1024)) ),
  271. ( ['1234'], str(1234) ),
  272. ],
  273. 'hash160': [ # TODO: check that hextob58chk(hash160) = pubhex2addr
  274. ( ['deadbeef'], 'f04df4c4b30d2b7ac6e1ed2445aeb12a9cb4d2ec' ),
  275. ( ['000000000000000000000000000000000000000000'], '2db95e704e2d9b0474acf76182f3f985b7064a8a' ),
  276. ( [''], 'b472a266d0bd89c13706a4132ccfb16f7c3b9fcb' ),
  277. ( ['ffffffffffffffff'], 'f86221f5a1fca059a865c0b7d374dfa9d5f3aeb4' ),
  278. ],
  279. 'hash256': [
  280. ( ['deadbeef'], 'e107944e77a688feae4c2d4db5951923812dd0f72026a11168104ee1b248f8a9' ),
  281. ( ['000000000000000000000000000000000000000000'], 'fd5181fcd097a334ab340569e5edcd09f702fef7994abab01f4b66e86b32ebbe' ),
  282. ( [''], '5df6e0e2761359d30a8275058e299fcc0381534545f55cf43e41983f5d4c9456' ),
  283. ( ['ffffffffffffffff'], '57b2d2c3455e0f76c61c5237ff04fc9fc0f3fe691e587ea9c951949e1a5e0fed' ),
  284. ],
  285. 'hexdump': [
  286. ( [sample_text.encode()], sample_text_hexdump ),
  287. ],
  288. 'unhexdump': [
  289. ( [sample_text_hexdump.encode()], sample_text.encode() ),
  290. ],
  291. 'hexlify': [
  292. ( [b'foobar'], '666f6f626172' ),
  293. ],
  294. 'unhexlify': [
  295. ( ['666f6f626172'], 'foobar' ),
  296. ],
  297. 'hexreverse': [
  298. ( ['deadbeefcafe'], 'fecaefbeadde' ),
  299. ],
  300. 'id6': [
  301. ( [sample_text.encode()], 'a6d72b' ),
  302. ],
  303. 'id8': [
  304. ( [sample_text.encode()], '687C09C2' ),
  305. ],
  306. 'str2id6': [
  307. ( ['74ev zjeq Zw2g DspF RKpE 7H'], '70413d' ), # checked
  308. ],
  309. 'randhex': [
  310. ( [], {'boolfunc':is_hex_str,'len':64}, ['-r0'] ),
  311. ( ['nbytes=16'], {'boolfunc':is_hex_str,'len':32}, ['-r0'] ),
  312. ( ['nbytes=6'], {'boolfunc':is_hex_str,'len':12}, ['-r0'] ),
  313. ],
  314. 'randb58': [
  315. ( [], {'boolfunc':is_b58_str}, ['-r0'] ),
  316. ( ['nbytes=16'], {'boolfunc':is_b58_str}, ['-r0'] ),
  317. ( ['nbytes=12','pad=0'], is_b58_str, ['-r0'] ),
  318. ],
  319. },
  320. 'Wallet': {
  321. 'gen_key': [
  322. ( ['98831F3A:11','wallet=test/ref/98831F3A.mmwords'],
  323. '5JKLcdYbhP6QQ4BXc9HtjfqJ79FFRXP2SZTKUyEuyXJo9QSFUkv'
  324. ),
  325. ( ['98831F3A:C:11','wallet=test/ref/98831F3A.mmwords'],
  326. 'L2LwXv94XTU2HjCbJPXCFuaHjrjucGipWPWUi1hkM5EykgektyqR'
  327. ),
  328. ( ['98831F3A:B:11','wallet=test/ref/98831F3A.mmwords'],
  329. 'L2K4Y9MWb5oUfKKZtwdgCm6FLZdUiWJDHjh9BYxpEvtfcXt4iM5g'
  330. ),
  331. ( ['98831F3A:S:11','wallet=test/ref/98831F3A.mmwords'],
  332. 'KwmkkfC9GghnJhnKoRXRn5KwGCgXrCmDw6Uv83NzE4kJS5axCR9A'
  333. ),
  334. ],
  335. 'gen_addr': [
  336. ( ['98831F3A:11','wallet=test/ref/98831F3A.mmwords'],
  337. '12bYUGXS8SRArZneQDN9YEEYAtEa59Rykm'
  338. ),
  339. ( ['98831F3A:L:11','wallet=test/ref/98831F3A.mmwords'],
  340. '12bYUGXS8SRArZneQDN9YEEYAtEa59Rykm'
  341. ),
  342. ( ['98831F3A:C:11','wallet=test/ref/98831F3A.mmwords'],
  343. '1MPsZ7BY9qikqfPxqmrovE8gLDX2rYArZk'
  344. ),
  345. ( ['98831F3A:B:11','wallet=test/ref/98831F3A.mmwords'],
  346. 'bc1qxptlvmwaymaxa7pxkr2u5pn7c0508stcncv7ms'
  347. ),
  348. ( ['98831F3A:S:11','wallet=test/ref/98831F3A.mmwords'],
  349. '3Eevao3DRVXnYym3tdrJDqS3Wc39PQzahn'
  350. ),
  351. ],
  352. 'get_subseed': [
  353. ( ['3s','wallet=test/ref/98831F3A.mmwords'], '4018EB17' ),
  354. ( ['200','wallet=test/ref/98831F3A.mmwords'], '2B05AE73' ),
  355. ],
  356. 'get_subseed_by_seed_id': [
  357. ( ['4018EB17','wallet=test/ref/98831F3A.mmwords'], '3S' ),
  358. ( ['2B05AE73','wallet=test/ref/98831F3A.mmwords'], None ),
  359. ( ['2B05AE73','wallet=test/ref/98831F3A.mmwords','last_idx=200'], '200L' ),
  360. ],
  361. 'list_subseeds': [
  362. ( ['1-5','wallet=test/ref/98831F3A.mmwords'],
  363. (md5_hash_strip,'996c047e8543d5dde6f82efc3214a6a1')
  364. ),
  365. ],
  366. 'list_shares': [
  367. ( ['3','wallet=test/ref/98831F3A.bip39'],
  368. (md5_hash_strip,'84e8bdaebf9c816a8a3bd2ebec5a2e12')
  369. ),
  370. ( ['3','id_str=default','wallet=test/ref/98831F3A.mmwords'],
  371. (md5_hash_strip,'84e8bdaebf9c816a8a3bd2ebec5a2e12')
  372. ),
  373. ( ['3','id_str=foo','wallet=test/ref/98831F3A.bip39'],
  374. (md5_hash_strip,'d2ac20823c4ea26f15234b5ca8df5d6f')
  375. ),
  376. ( ['3','id_str=foo','master_share=0','wallet=test/ref/98831F3A.mmwords'],
  377. (md5_hash_strip,'d2ac20823c4ea26f15234b5ca8df5d6f')
  378. ),
  379. ( ['3','id_str=foo','master_share=5','wallet=test/ref/98831F3A.mmwords'],
  380. (md5_hash_strip,'c4feedce40bb5959011ee4a996710832')
  381. ),
  382. ( ['3','id_str=βαρ','master_share=5','wallet=test/ref/98831F3A.mmwords'],
  383. (md5_hash_strip,'f7d254798fe2e34b94b5f4ff312998db')
  384. ),
  385. ( ['4','id_str=βαρ','master_share=5','wallet=test/ref/98831F3A.bip39'],
  386. (md5_hash_strip,'d3e479f55792181372a9f32a569c04e5')
  387. ),
  388. ],
  389. },
  390. 'Coin': {
  391. 'addr2pubhash': {
  392. 'btc_mainnet': [
  393. ( ['12bYUGXS8SRArZneQDN9YEEYAtEa59Rykm'], '118089d66b4a5853765e94923abdd5de4616c6e5' ),
  394. ( ['3Eevao3DRVXnYym3tdrJDqS3Wc39PQzahn'], '8e34586186551f6320fa3eb2d238a9c61ab8264b' ),
  395. ( ['bc1qxptlvmwaymaxa7pxkr2u5pn7c0508stcncv7ms'], '3057f66ddd26fa6ef826b0d5ca067ec3e8f3c178' ),
  396. ],
  397. },
  398. 'pubhash2addr': {
  399. 'btc_mainnet': [
  400. ( ['118089d66b4a5853765e94923abdd5de4616c6e5'], '12bYUGXS8SRArZneQDN9YEEYAtEa59Rykm',
  401. None, 'legacy' ),
  402. ( ['8e34586186551f6320fa3eb2d238a9c61ab8264b'], '3Eevao3DRVXnYym3tdrJDqS3Wc39PQzahn',
  403. ['--type=segwit'], 'segwit' ),
  404. ( ['3057f66ddd26fa6ef826b0d5ca067ec3e8f3c178'], 'bc1qxptlvmwaymaxa7pxkr2u5pn7c0508stcncv7ms',
  405. ['--type=bech32'], 'bech32' ),
  406. ],
  407. },
  408. 'addr2scriptpubkey': {
  409. 'btc_mainnet': [
  410. ( ['12bYUGXS8SRArZneQDN9YEEYAtEa59Rykm'], '76a914118089d66b4a5853765e94923abdd5de4616c6e588ac' ),
  411. ( ['3Eevao3DRVXnYym3tdrJDqS3Wc39PQzahn'], 'a9148e34586186551f6320fa3eb2d238a9c61ab8264b87' ),
  412. ( ['bc1qxptlvmwaymaxa7pxkr2u5pn7c0508stcncv7ms'], '00143057f66ddd26fa6ef826b0d5ca067ec3e8f3c178' ),
  413. ],
  414. },
  415. 'scriptpubkey2addr': {
  416. 'btc_mainnet': [
  417. ( ['76a914118089d66b4a5853765e94923abdd5de4616c6e588ac'], '12bYUGXS8SRArZneQDN9YEEYAtEa59Rykm' ),
  418. ( ['a9148e34586186551f6320fa3eb2d238a9c61ab8264b87'], '3Eevao3DRVXnYym3tdrJDqS3Wc39PQzahn' ),
  419. ( ['00143057f66ddd26fa6ef826b0d5ca067ec3e8f3c178'], 'bc1qxptlvmwaymaxa7pxkr2u5pn7c0508stcncv7ms' ),
  420. ],
  421. },
  422. 'hex2wif': {
  423. 'btc_mainnet': [
  424. ( ['118089d66b4a5853765e94923abdd5de4616c6e5118089d66b4a5853765e9492'],
  425. '5HwzecKMWD82ppJK3qMKpC7ohXXAwcyAN5VgdJ9PLFaAzpBG4sX',
  426. None, 'legacy' ),
  427. ( ['118089d66b4a5853765e94923abdd5de4616c6e5118089d66b4a5853765e9492'],
  428. 'KwojSzt1VvW343mQfWQi3J537siAt5ktL2qbuCg1ZyKR8BLQ6UJm',
  429. ['--type=compressed'], 'compressed' ),
  430. ( ['118089d66b4a5853765e94923abdd5de4616c6e5118089d66b4a5853765e9492'],
  431. 'KwojSzt1VvW343mQfWQi3J537siAt5ktL2qbuCg1ZyKR8BLQ6UJm',
  432. ['--type=segwit'], 'segwit' ),
  433. ( ['118089d66b4a5853765e94923abdd5de4616c6e5118089d66b4a5853765e9492'],
  434. 'KwojSzt1VvW343mQfWQi3J537siAt5ktL2qbuCg1ZyKR8BLQ6UJm',
  435. ['--type=bech32'], 'bech32' ),
  436. ],
  437. },
  438. 'privhex2addr': {
  439. 'btc_mainnet': [
  440. ( ['118089d66b4a5853765e94923abdd5de4616c6e5118089d66b4a5853765e9492'],
  441. '1C5VPtgq9xQ6AcTgMAR3J6GDrs72HC4pS1',
  442. None, 'legacy' ),
  443. ( ['118089d66b4a5853765e94923abdd5de4616c6e5118089d66b4a5853765e9492'],
  444. '1Kz9fVSUMshzPejpzW9D95kScgA3rY6QxF',
  445. ['--type=compressed'], 'compressed' ),
  446. ( ['118089d66b4a5853765e94923abdd5de4616c6e5118089d66b4a5853765e9492'],
  447. '3AhjTiWHhVJAi1s5CfKMcLzYps12x3gZhg',
  448. ['--type=segwit'], 'segwit' ),
  449. ( ['118089d66b4a5853765e94923abdd5de4616c6e5118089d66b4a5853765e9492'],
  450. 'bc1q6pqnfwwakuuejpm9w52ds342f9d5u36v0qnz7c',
  451. ['--type=bech32'], 'bech32' ),
  452. ],
  453. 'eth_mainnet': [
  454. ( ['0000000000000000000000000000000000000000000000000000000000000001'],
  455. '7e5f4552091a69125d5dfcb7b8c2659029395bdf'),
  456. ( ['ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff'],
  457. 'b92702b3eefb3c2049aeb845b0335b283e11e9c6'),
  458. ( ['0fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff'],
  459. 'ad30adc7451c1dace34c5d1f328f8a74a4947534'),
  460. ( ['00000000000000000000000000000000000000000000000000000000000000ff'],
  461. '5044a80bd3eff58302e638018534bbda8896c48a'),
  462. ( ['ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0f'],
  463. '8b10f977e27611516f186980d8161b25f8adca5e'),
  464. ( ['deadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef'],
  465. 'c96aaa54e2d44c299564da76e1cd3184a2386b8d'),
  466. ],
  467. 'xmr_mainnet': [
  468. ( ['0000000000000000000000000000000000000000000000000000000000000001'],
  469. '42nsXK8WbVGTNayQ6Kjw5UdgqbQY5KCCufdxdCgF7NgTfjC69Mna7DJSYyie77hZTQ8H92G2HwgFhgEUYnDzrnLnQdF28r3'),
  470. ( ['ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff'],
  471. '49voQEbjouUQSDikRWKUt1PGbS47TBde4hiGyftN46CvTDd8LXCaimjHRGtofCJwY5Ed5QhYwc12P15AH5w7SxUAMCz1nr1'),
  472. ( ['0fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff'],
  473. '45Ee1yJSjXBKuf8aaihf6KgSRGtMBN6NNDtkd9fLJzHiK4ar4NyNxDk6afc7MTRoruAsg6J6792tCJazHqs1sjbv7LuEsLx'),
  474. ( ['00000000000000000000000000000000000000000000000000000000000000ff'],
  475. '43aZyywWW4MYt2Az32XioQYirxyT8xeRBP84EBNA7Cra5SqQNmca6iD9pM487pcR9JAEiKrnw2QwvA5uWiFNokEzLJ5coZ9'),
  476. ( ['ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0f'],
  477. '4AeR1owefiJGbrAdSKCbVL73ME4FGv2cpczjV2peqqkxagm5D4gBqAHJta6NpbtxyuRe3ywaTj6QCHD59savvPW69wfW9my'),
  478. ( ['deadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef'],
  479. '41i7saPWA53EoHenmJVRt34dubPxsXwoWMnw8AdMyx4mTD1svf7qYzcVjxxRfteLNdYrAxWUMmiPegFW9EfoNgXx7vDMExv'),
  480. ],
  481. 'zec_mainnet': [
  482. ( ['0000000000000000000000000000000000000000000000000000000000000001'],
  483. 'zceQDpyNwek7dKqF5ZuFGj7YrNVxh7X1aPkrVxDLVxWSiZAFDEuy5C7XNV8VhyZ3ghTPQ61xjCGiyLT3wqpiN1Yi6mdmaCq',
  484. ['--type=zcash_z'], 'zcash_z' ),
  485. ( ['ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff'],
  486. 'zcY1hqJ3P5ifjnWk1BcXpjrLG5XeJZUSPCiiVTF9LXrejxBzAsFWcNyr6PudwQHm8DnQpD8HEaM3dh8sB6cf91ciAa53YQ1',
  487. ['--type=zcash_z'], 'zcash_z' ),
  488. ( ['0fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff'],
  489. 'zcY1hqJ3P5ifjnWk1BcXpjrLG5XeJZUSPCiiVTF9LXrejxBzAsFWcNyr6PudwQHm8DnQpD8HEaM3dh8sB6cf91ciAa53YQ1',
  490. ['--type=zcash_z'], 'zcash_z' ),
  491. ( ['00000000000000000000000000000000000000000000000000000000000000ff'],
  492. 'zcck12KgVY34LJwVEDLN8sXhL787zmjKqPsP1uBYRHs75bL9sQu4P7wcc5ZJTjKsL376zaSpsYqGxK94JbiYcNoH8DkeGbN',
  493. ['--type=zcash_z'], 'zcash_z' ),
  494. ( ['ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0f'],
  495. 'zcJ9hEezG1Jeye5dciqiMDh6SXtYbUsircGmpVyhHWyzyxDVRRDs5Q8M7hG3c7nDcvd5Pw4u4wV9RAQmq5RCBZq5wVyMQV8',
  496. ['--type=zcash_z'], 'zcash_z' ),
  497. ( ['deadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef'],
  498. 'zchFELwBxqsAubsLQ8yZgPCDDGukjXJssgCbiTPwFNmFwn9haLnDatzfhLdZzJT4PcU4o2yr92B52UFirUzEdF6ZYM2gBkM',
  499. ['--type=zcash_z'], 'zcash_z' ),
  500. ],
  501. },
  502. 'privhex2pubhex': {
  503. 'btc_mainnet': [
  504. ( ['118089d66b4a5853765e94923abdd5de4616c6e5118089d66b4a5853765e9492'],
  505. '044281a85c9ce87279e028410b851410d65136304cfbbbeaaa8e2e3931cf4e972757f3254c322eeaa3cb6bf97cc5ecf8d4387b0df2c0b1e6ee18fe3a6977a7d57a',
  506. None, 'legacy' ),
  507. ( ['118089d66b4a5853765e94923abdd5de4616c6e5118089d66b4a5853765e9492'],
  508. '024281a85c9ce87279e028410b851410d65136304cfbbbeaaa8e2e3931cf4e9727',
  509. ['--type=compressed'], 'compressed' ),
  510. ( ['118089d66b4a5853765e94923abdd5de4616c6e5118089d66b4a5853765e9492'],
  511. '024281a85c9ce87279e028410b851410d65136304cfbbbeaaa8e2e3931cf4e9727',
  512. ['--type=segwit'], 'segwit' ),
  513. ( ['118089d66b4a5853765e94923abdd5de4616c6e5118089d66b4a5853765e9492'],
  514. '024281a85c9ce87279e028410b851410d65136304cfbbbeaaa8e2e3931cf4e9727',
  515. ['--type=bech32'], 'bech32' ),
  516. ],
  517. },
  518. 'pubhex2addr': {
  519. 'btc_mainnet': [
  520. ( ['044281a85c9ce87279e028410b851410d65136304cfbbbeaaa8e2e3931cf4e972757f3254c322eeaa3cb6bf97cc5ecf8d4387b0df2c0b1e6ee18fe3a6977a7d57a'],
  521. '1C5VPtgq9xQ6AcTgMAR3J6GDrs72HC4pS1',
  522. None, 'legacy' ),
  523. ( ['024281a85c9ce87279e028410b851410d65136304cfbbbeaaa8e2e3931cf4e9727'],
  524. '1Kz9fVSUMshzPejpzW9D95kScgA3rY6QxF',
  525. ['--type=compressed'], 'compressed' ),
  526. ( ['024281a85c9ce87279e028410b851410d65136304cfbbbeaaa8e2e3931cf4e9727'],
  527. '3AhjTiWHhVJAi1s5CfKMcLzYps12x3gZhg',
  528. ['--type=segwit'], 'segwit' ),
  529. ( ['024281a85c9ce87279e028410b851410d65136304cfbbbeaaa8e2e3931cf4e9727'],
  530. 'bc1q6pqnfwwakuuejpm9w52ds342f9d5u36v0qnz7c',
  531. ['--type=bech32'], 'bech32' ),
  532. ],
  533. },
  534. 'pubhex2redeem_script': {
  535. 'btc_mainnet': [
  536. ( ['024281a85c9ce87279e028410b851410d65136304cfbbbeaaa8e2e3931cf4e9727'],
  537. '0014d04134b9ddb7399907657514d846aa495b4e474c',
  538. ['--type=segwit'], 'segwit' ),
  539. ],
  540. },
  541. 'redeem_script2addr': {
  542. 'btc_mainnet': [
  543. ( ['0014d04134b9ddb7399907657514d846aa495b4e474c'],
  544. '3AhjTiWHhVJAi1s5CfKMcLzYps12x3gZhg',
  545. ['--type=segwit'], 'segwit' ),
  546. ],
  547. },
  548. 'randpair': {
  549. 'btc_mainnet': [ ( [], [is_wif_loc,is_coin_addr_loc], ['-r0'] ) ],
  550. 'btc_testnet': [ ( [], [is_wif_loc,is_coin_addr_loc], ['-r0'] ) ],
  551. },
  552. 'randwif': {
  553. 'btc_mainnet': [ ( [], is_wif_loc, ['-r0'] ) ],
  554. 'btc_testnet': [ ( [], is_wif_loc, ['-r0'] ) ],
  555. },
  556. 'wif2addr': {
  557. 'btc_mainnet': [
  558. ( ['5HwzecKMWD82ppJK3qMKpC7ohXXAwcyAN5VgdJ9PLFaAzpBG4sX'],
  559. '1C5VPtgq9xQ6AcTgMAR3J6GDrs72HC4pS1', ['--type=legacy'], 'legacy' ),
  560. ( ['KwojSzt1VvW343mQfWQi3J537siAt5ktL2qbuCg1ZyKR8BLQ6UJm'],
  561. '1Kz9fVSUMshzPejpzW9D95kScgA3rY6QxF', ['--type=compressed'], 'compressed' ),
  562. ( ['KwojSzt1VvW343mQfWQi3J537siAt5ktL2qbuCg1ZyKR8BLQ6UJm'],
  563. '3AhjTiWHhVJAi1s5CfKMcLzYps12x3gZhg', ['--type=segwit'], 'segwit' ),
  564. ( ['KwojSzt1VvW343mQfWQi3J537siAt5ktL2qbuCg1ZyKR8BLQ6UJm'],
  565. 'bc1q6pqnfwwakuuejpm9w52ds342f9d5u36v0qnz7c', ['--type=bech32'], 'bech32' ),
  566. ],
  567. 'eth_mainnet': [
  568. ( ['0000000000000000000000000000000000000000000000000000000000000001'],
  569. '7e5f4552091a69125d5dfcb7b8c2659029395bdf'),
  570. ( ['000000000000000000000000000000014551231950b75fc4402da1732fc9bebe'],
  571. 'b92702b3eefb3c2049aeb845b0335b283e11e9c6'),
  572. ( ['0fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff'],
  573. 'ad30adc7451c1dace34c5d1f328f8a74a4947534'),
  574. ( ['00000000000000000000000000000000000000000000000000000000000000ff'],
  575. '5044a80bd3eff58302e638018534bbda8896c48a'),
  576. ( ['000000000000000000000000000000014551231950b75fc4402da1732fc9bdce'],
  577. '8b10f977e27611516f186980d8161b25f8adca5e'),
  578. ( ['deadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef'],
  579. 'c96aaa54e2d44c299564da76e1cd3184a2386b8d'),
  580. ],
  581. 'xmr_mainnet': [
  582. ( ['0000000000000000000000000000000000000000000000000000000000000001'],
  583. '42nsXK8WbVGTNayQ6Kjw5UdgqbQY5KCCufdxdCgF7NgTfjC69Mna7DJSYyie77hZTQ8H92G2HwgFhgEUYnDzrnLnQdF28r3'),
  584. ( ['1c95988d7431ecd670cf7d73f45befc6feffffffffffffffffffffffffffff0f'],
  585. '49voQEbjouUQSDikRWKUt1PGbS47TBde4hiGyftN46CvTDd8LXCaimjHRGtofCJwY5Ed5QhYwc12P15AH5w7SxUAMCz1nr1'),
  586. ( ['2c94988d7431ecd670cf7d73f45befc6feffffffffffffffffffffffffffff0f'],
  587. '45Ee1yJSjXBKuf8aaihf6KgSRGtMBN6NNDtkd9fLJzHiK4ar4NyNxDk6afc7MTRoruAsg6J6792tCJazHqs1sjbv7LuEsLx'),
  588. ( ['1d95988d7431ecd670cf7d73f45befc6feffffffffffffffffffffffffffff0e'],
  589. '43aZyywWW4MYt2Az32XioQYirxyT8xeRBP84EBNA7Cra5SqQNmca6iD9pM487pcR9JAEiKrnw2QwvA5uWiFNokEzLJ5coZ9'),
  590. ( ['ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0f'],
  591. '4AeR1owefiJGbrAdSKCbVL73ME4FGv2cpczjV2peqqkxagm5D4gBqAHJta6NpbtxyuRe3ywaTj6QCHD59savvPW69wfW9my'),
  592. ( ['e8164dda6d42bd1e261a3406b2038dcbddadbeefdeadbeefdeadbeefdeadbe0f'],
  593. '41i7saPWA53EoHenmJVRt34dubPxsXwoWMnw8AdMyx4mTD1svf7qYzcVjxxRfteLNdYrAxWUMmiPegFW9EfoNgXx7vDMExv'),
  594. ],
  595. 'zec_mainnet': [
  596. ( ['SKxny894fJe2rmZjeuoE6GVfNkWoXfPp8337VrLLNWG56FjqVUYR'],
  597. 'zceQDpyNwek7dKqF5ZuFGj7YrNVxh7X1aPkrVxDLVxWSiZAFDEuy5C7XNV8VhyZ3ghTPQ61xjCGiyLT3wqpiN1Yi6mdmaCq',
  598. ['--type=zcash_z'], 'zcash_z' ),
  599. ( ['SKxv1peuQvMT4TvqPLqKy1px3oqLm98Evi948VU8N8VKcf7C2umc'],
  600. 'zcY1hqJ3P5ifjnWk1BcXpjrLG5XeJZUSPCiiVTF9LXrejxBzAsFWcNyr6PudwQHm8DnQpD8HEaM3dh8sB6cf91ciAa53YQ1',
  601. ['--type=zcash_z'], 'zcash_z' ),
  602. ( ['SKxv1peuQvMT4TvqPLqKy1px3oqLm98Evi948VU8N8VKcf7C2umc'],
  603. 'zcY1hqJ3P5ifjnWk1BcXpjrLG5XeJZUSPCiiVTF9LXrejxBzAsFWcNyr6PudwQHm8DnQpD8HEaM3dh8sB6cf91ciAa53YQ1',
  604. ['--type=zcash_z'], 'zcash_z' ),
  605. ( ['SKxny894fJe2rmZjeuoE6GVfNkWoXfPp8337VrLLNWG56kQw4qjm'],
  606. 'zcck12KgVY34LJwVEDLN8sXhL787zmjKqPsP1uBYRHs75bL9sQu4P7wcc5ZJTjKsL376zaSpsYqGxK94JbiYcNoH8DkeGbN',
  607. ['--type=zcash_z'], 'zcash_z' ),
  608. ( ['SKxv1peuQvMT4TvqPLqKy1px3oqLm98Evi948VU8N8VKcBwrLwiu'],
  609. 'zcJ9hEezG1Jeye5dciqiMDh6SXtYbUsircGmpVyhHWyzyxDVRRDs5Q8M7hG3c7nDcvd5Pw4u4wV9RAQmq5RCBZq5wVyMQV8',
  610. ['--type=zcash_z'], 'zcash_z' ),
  611. ( ['SKxuS56e99jpCeD9mMQ5o63zoGPakNdM9HCvt4Vt2cypvRjCdvGJ'],
  612. 'zchFELwBxqsAubsLQ8yZgPCDDGukjXJssgCbiTPwFNmFwn9haLnDatzfhLdZzJT4PcU4o2yr92B52UFirUzEdF6ZYM2gBkM',
  613. ['--type=zcash_z'], 'zcash_z' ),
  614. ],
  615. },
  616. 'wif2hex': {
  617. 'btc_mainnet': [
  618. ( ['5HwzecKMWD82ppJK3qMKpC7ohXXAwcyAN5VgdJ9PLFaAzpBG4sX'],
  619. '118089d66b4a5853765e94923abdd5de4616c6e5118089d66b4a5853765e9492',
  620. None, 'legacy' ),
  621. ( ['KwojSzt1VvW343mQfWQi3J537siAt5ktL2qbuCg1ZyKR8BLQ6UJm'],
  622. '118089d66b4a5853765e94923abdd5de4616c6e5118089d66b4a5853765e9492',
  623. ['--type=compressed'], 'compressed' ),
  624. ( ['KwojSzt1VvW343mQfWQi3J537siAt5ktL2qbuCg1ZyKR8BLQ6UJm'],
  625. '118089d66b4a5853765e94923abdd5de4616c6e5118089d66b4a5853765e9492',
  626. ['--type=segwit'], 'segwit' ),
  627. ( ['KwojSzt1VvW343mQfWQi3J537siAt5ktL2qbuCg1ZyKR8BLQ6UJm'],
  628. '118089d66b4a5853765e94923abdd5de4616c6e5118089d66b4a5853765e9492',
  629. ['--type=bech32'], 'bech32' ),
  630. ],
  631. },
  632. 'wif2redeem_script': {
  633. 'btc_mainnet': [
  634. ( ['KwojSzt1VvW343mQfWQi3J537siAt5ktL2qbuCg1ZyKR8BLQ6UJm'],
  635. '0014d04134b9ddb7399907657514d846aa495b4e474c',
  636. ['--type=segwit'], 'segwit' ),
  637. ],
  638. },
  639. 'wif2segwit_pair': {
  640. 'btc_mainnet': [
  641. ( ['KwojSzt1VvW343mQfWQi3J537siAt5ktL2qbuCg1ZyKR8BLQ6UJm'],
  642. ('0014d04134b9ddb7399907657514d846aa495b4e474c','3AhjTiWHhVJAi1s5CfKMcLzYps12x3gZhg'),
  643. ['--type=segwit'], 'segwit' ),
  644. ],
  645. },
  646. },
  647. # TODO: compressed address files are missing
  648. # 'addrfile_compressed_chk':
  649. # 'btc': ('A33C 4FDE F515 F5BC','6C48 AA57 2056 C8C8'),
  650. # 'ltc': ('3FC0 8F03 C2D6 BD19','4C0A 49B6 2DD1 1BE0'),
  651. 'File': {
  652. 'addrfile_chksum': {
  653. 'btc_mainnet': [
  654. ( ['test/ref/98831F3A[1,31-33,500-501,1010-1011].addrs'],
  655. '6FEF 6FB9 7B13 5D91'),
  656. ( ['test/ref/98831F3A-S[1,31-33,500-501,1010-1011].addrs'],
  657. '06C1 9C87 F25C 4EE6'),
  658. ( ['test/ref/98831F3A-B[1,31-33,500-501,1010-1011].addrs'],
  659. '9D2A D4B6 5117 F02E'),
  660. ],
  661. 'btc_testnet': [
  662. ( ['test/ref/98831F3A[1,31-33,500-501,1010-1011].testnet.addrs'],
  663. '424E 4326 CFFE 5F51'),
  664. ( ['test/ref/98831F3A-S[1,31-33,500-501,1010-1011].testnet.addrs'],
  665. '072C 8B07 2730 CB7A'),
  666. ( ['test/ref/98831F3A-B[1,31-33,500-501,1010-1011].testnet.addrs'],
  667. '0527 9C39 6C1B E39A'),
  668. ],
  669. 'ltc_mainnet': [
  670. ( ['test/ref/litecoin/98831F3A-LTC[1,31-33,500-501,1010-1011].addrs'],
  671. 'AD52 C3FE 8924 AAF0'),
  672. ( ['test/ref/litecoin/98831F3A-LTC-S[1,31-33,500-501,1010-1011].addrs'],
  673. '63DF E42A 0827 21C3'),
  674. ( ['test/ref/litecoin/98831F3A-LTC-B[1,31-33,500-501,1010-1011].addrs'],
  675. 'FF1C 7939 5967 AB82'),
  676. ],
  677. 'ltc_testnet': [
  678. ( ['test/ref/litecoin/98831F3A-LTC[1,31-33,500-501,1010-1011].testnet.addrs'],
  679. '4EBE 2E85 E969 1B30'),
  680. ( ['test/ref/litecoin/98831F3A-LTC-S[1,31-33,500-501,1010-1011].testnet.addrs'],
  681. '5DD1 D186 DBE1 59F2'),
  682. ( ['test/ref/litecoin/98831F3A-LTC-B[1,31-33,500-501,1010-1011].testnet.addrs'],
  683. 'ED3D 8AA4 BED4 0B40'),
  684. ],
  685. 'zec_mainnet': [
  686. ( ['test/ref/zcash/98831F3A-ZEC-C[1,31-33,500-501,1010-1011].addrs'],'903E 7225 DD86 6E01'),
  687. ( ['test/ref/zcash/98831F3A-ZEC-Z[1,31-33,500-501,1010-1011].addrs'], '9C7A 72DC 3D4A B3AF',
  688. ['--type=zcash_z'], 'zcash_z' ),
  689. ],
  690. 'xmr_mainnet': [
  691. ( ['test/ref/monero/98831F3A-XMR-M[1,31-33,500-501,1010-1011].addrs'],'4369 0253 AC2C 0E38'), ],
  692. 'dash_mainnet': [
  693. ( ['test/ref/dash/98831F3A-DASH-C[1,31-33,500-501,1010-1011].addrs'],'FBC1 6B6A 0988 4403'), ],
  694. 'eth_mainnet': [
  695. ( ['test/ref/ethereum/98831F3A-ETH[1,31-33,500-501,1010-1011].addrs'],'E554 076E 7AF6 66A3'), ],
  696. 'etc_mainnet': [
  697. ( ['test/ref/ethereum_classic/98831F3A-ETC[1,31-33,500-501,1010-1011].addrs'],
  698. 'E97A D796 B495 E8BC'), ],
  699. },
  700. 'keyaddrfile_chksum': {
  701. 'btc_mainnet': [
  702. ( ['test/ref/98831F3A[1,31-33,500-501,1010-1011].akeys.mmenc'],
  703. '9F2D D781 1812 8BAD', kafile_opts ),
  704. ],
  705. 'btc_testnet': [
  706. ( ['test/ref/98831F3A[1,31-33,500-501,1010-1011].testnet.akeys.mmenc'],
  707. '88CC 5120 9A91 22C2', kafile_opts ),
  708. ],
  709. 'ltc_mainnet': [
  710. ( ['test/ref/litecoin/98831F3A-LTC[1,31-33,500-501,1010-1011].akeys.mmenc'],
  711. 'B804 978A 8796 3ED4', kafile_opts ),
  712. ],
  713. 'ltc_testnet': [
  714. ( ['test/ref/litecoin/98831F3A-LTC[1,31-33,500-501,1010-1011].testnet.akeys.mmenc'],
  715. '98B5 AC35 F334 0398', kafile_opts ),
  716. ],
  717. 'zec_mainnet': [
  718. ( ['test/ref/zcash/98831F3A-ZEC-C[1,31-33,500-501,1010-1011].akeys.mmenc'],
  719. 'F05A 5A5C 0C8E 2617', kafile_opts ),
  720. ( ['test/ref/zcash/98831F3A-ZEC-Z[1,31-33,500-501,1010-1011].akeys.mmenc'], '6B87 9B2D 0D8D 8D1E',
  721. kafile_opts + ['--type=zcash_z'], 'zcash_z' ),
  722. ],
  723. 'xmr_mainnet': [
  724. ( ['test/ref/monero/98831F3A-XMR-M[1,31-33,500-501,1010-1011].akeys.mmenc'],
  725. 'E0D7 9612 3D67 404A', kafile_opts ), ],
  726. 'dash_mainnet': [
  727. ( ['test/ref/dash/98831F3A-DASH-C[1,31-33,500-501,1010-1011].akeys.mmenc'],
  728. 'E83D 2C63 FEA2 4142', kafile_opts ), ],
  729. 'eth_mainnet': [
  730. ( ['test/ref/ethereum/98831F3A-ETH[1,31-33,500-501,1010-1011].akeys.mmenc'],
  731. 'E400 70D9 0AE3 C7C2', kafile_opts ), ],
  732. 'etc_mainnet': [
  733. ( ['test/ref/ethereum_classic/98831F3A-ETC[1,31-33,500-501,1010-1011].akeys.mmenc'],
  734. 'EF49 967D BD6C FE45', kafile_opts ), ],
  735. },
  736. 'passwdfile_chksum': {
  737. 'btc_mainnet': [
  738. ( ['test/ref/98831F3A-фубар@crypto.org-b58-20[1,4,1100].pws'],
  739. 'DDD9 44B0 CA28 183F', kafile_opts ), ],
  740. },
  741. 'txview': {
  742. 'btc_mainnet': [ ( ['test/ref/0B8D5A[15.31789,14,tl=1320969600].rawtx'], None ), ],
  743. 'btc_testnet': [ ( ['test/ref/0C7115[15.86255,14,tl=1320969600].testnet.rawtx'], None ), ],
  744. 'bch_mainnet': [ ( ['test/ref/460D4D-BCH[10.19764,tl=1320969600].rawtx'], None ), ],
  745. 'bch_testnet': [ ( ['test/ref/359FD5-BCH[6.68868,tl=1320969600].testnet.rawtx'], None ), ],
  746. 'ltc_mainnet': [ ( ['test/ref/litecoin/AF3CDF-LTC[620.76194,1453,tl=1320969600].rawtx'], None ), ],
  747. 'ltc_testnet': [ ( ['test/ref/litecoin/A5A1E0-LTC[1454.64322,1453,tl=1320969600].testnet.rawtx'],
  748. None ), ],
  749. 'eth_mainnet': [ ( ['test/ref/ethereum/88FEFD-ETH[23.45495,40000].rawtx'], None ), ],
  750. 'eth_testnet': [ ( [
  751. 'test/ref/ethereum/B472BD-ETH[23.45495,40000].testnet.rawtx',
  752. 'test/ref/ethereum/B472BD-ETH[23.45495,40000].testnet.sigtx'
  753. ], None ), ],
  754. 'mm1_mainnet': [ ( ['test/ref/ethereum/5881D2-MM1[1.23456,50000].rawtx'], None ), ],
  755. 'mm1_testnet': [ ( ['test/ref/ethereum/6BDB25-MM1[1.23456,50000].testnet.rawtx'], None ), ],
  756. 'etc_mainnet': [ ( ['test/ref/ethereum_classic/ED3848-ETC[1.2345,40000].rawtx'], None ), ],
  757. },
  758. },
  759. }
  760. coin_dependent_groups = ('Coin','File') # TODO: do this as attr of each group in tool.py
  761. async def run_test(gid,cmd_name):
  762. data = tests[gid][cmd_name]
  763. # behavior is like test.py: run coin-dependent tests only if proto.testnet or proto.coin != BTC
  764. if gid in coin_dependent_groups:
  765. k = '{}_{}'.format(
  766. ( g.token.lower() if proto.tokensym else proto.coin.lower() ),
  767. ('mainnet','testnet')[proto.testnet] )
  768. if k in data:
  769. data = data[k]
  770. m2 = ' ({})'.format(k)
  771. else:
  772. qmsg(f'-- no data for {cmd_name} ({k}) - skipping')
  773. return
  774. else:
  775. if proto.coin != 'BTC' or proto.testnet:
  776. return
  777. m2 = ''
  778. m = '{} {}{}'.format(purple('Testing'), cmd_name if opt.names else docstring_head(tc[cmd_name]),m2)
  779. msg_r(green(m)+'\n' if opt.verbose else m)
  780. def fork_cmd(cmd_name,args,out,opts):
  781. cmd = list(tool_cmd) + (opts or []) + [cmd_name] + args
  782. vmsg('{} {}'.format(green('Executing'),cyan(' '.join(cmd))))
  783. cp = run(cmd,input=stdin_input or None,stdout=PIPE,stderr=PIPE)
  784. try: cmd_out = cp.stdout.decode()
  785. except: cmd_out = cp.stdout
  786. if cp.stderr:
  787. vmsg(cp.stderr.strip().decode())
  788. if cp.returncode != 0:
  789. import re
  790. m = re.match(b"tool command returned '(None|False)'"+NL.encode(),cp.stderr)
  791. if m:
  792. return { b'None': None, b'False': False }[m.group(1)]
  793. else:
  794. ydie(1,f'Spawned program exited with error: {cp.stderr}')
  795. return cmd_out.strip()
  796. async def run_func(cmd_name,args,out,opts,mmtype):
  797. vmsg('{}: {}{}'.format(purple('Running'),
  798. ' '.join([cmd_name]+[repr(e) for e in args]),
  799. ' '+mmtype if mmtype else '' ))
  800. aargs,kwargs = tool._process_args(cmd_name,args)
  801. tm = tool.MMGenToolCmdMeta
  802. cls_name = tm.classname(tm,cmd_name)
  803. tobj = getattr(tool,cls_name)(mmtype=mmtype)
  804. method = getattr(tobj,cmd_name)
  805. oq_save = bool(opt.quiet)
  806. if not opt.verbose:
  807. opt.quiet = True
  808. if stdin_input:
  809. fd0,fd1 = os.pipe()
  810. if os.fork(): # parent
  811. os.close(fd1)
  812. stdin_save = os.dup(0)
  813. os.dup2(fd0,0)
  814. cmd_out = method(*aargs,**kwargs)
  815. os.dup2(stdin_save,0)
  816. os.wait()
  817. opt.quiet = oq_save
  818. return cmd_out
  819. else: # child
  820. os.close(fd0)
  821. os.write(fd1,stdin_input)
  822. vmsg('Input: {!r}'.format(stdin_input))
  823. sys.exit(0)
  824. else:
  825. ret = method(*aargs,**kwargs)
  826. if type(ret).__name__ == 'coroutine':
  827. ret = await ret
  828. opt.quiet = oq_save
  829. return ret
  830. def tool_api(cmd_name,args,out,opts):
  831. from mmgen.tool import tool_api
  832. tool = tool_api()
  833. if opts:
  834. for o in opts:
  835. if o.startswith('--type='):
  836. tool.addrtype = o.split('=')[1]
  837. pargs,kwargs = [],{}
  838. for a in args:
  839. if '=' in a:
  840. a1,a2 = a.split('=')
  841. kwargs[a1] = int(a2) if is_int(a2) else a2
  842. else:
  843. pargs.append(a)
  844. return getattr(tool,cmd_name)(*pargs,**kwargs)
  845. for d in data:
  846. args,out,opts,mmtype = d + tuple([None] * (4-len(d)))
  847. stdin_input = None
  848. if args and type(args[0]) == bytes:
  849. stdin_input = args[0]
  850. args[0] = '-'
  851. if opt.tool_api:
  852. if args and args[0 ]== '-':
  853. continue
  854. cmd_out = tool_api(cmd_name,args,out,opts)
  855. elif opt.fork:
  856. cmd_out = fork_cmd(cmd_name,args,out,opts)
  857. else:
  858. if stdin_input and g.platform == 'win':
  859. msg('Skipping for MSWin - no os.fork()')
  860. continue
  861. cmd_out = await run_func(cmd_name,args,out,opts,mmtype)
  862. try: vmsg('Output:\n{}\n'.format(cmd_out))
  863. except: vmsg('Output:\n{}\n'.format(repr(cmd_out)))
  864. def check_output(out,chk):
  865. if isinstance(chk,str):
  866. chk = chk.encode()
  867. if isinstance(out,int):
  868. out = str(out).encode()
  869. if isinstance(out,str):
  870. out = out.encode()
  871. err_fs = "Output ({!r}) doesn't match expected output ({!r})"
  872. try: outd = out.decode()
  873. except: outd = None
  874. if type(chk).__name__ == 'function':
  875. assert chk(outd), f'{chk.__name__}({outd}) failed!'
  876. elif type(chk) == dict:
  877. for k,v in chk.items():
  878. if k == 'boolfunc':
  879. assert v(outd), f'{v.__name__}({outd}) failed!'
  880. elif k == 'value':
  881. assert outd == v, err_fs.format(outd,v)
  882. else:
  883. outval = getattr(__builtins__,k)(out)
  884. if outval != v:
  885. die(1,f'{k}({out}) returned {outval}, not {v}!')
  886. elif chk is not None:
  887. assert out == chk, err_fs.format(out,chk)
  888. if type(out) == tuple and type(out[0]).__name__ == 'function':
  889. func_out = out[0](cmd_out)
  890. assert func_out == out[1],(
  891. '{}({}) == {} failed!\nOutput: {}'.format(
  892. out[0].__name__,
  893. cmd_out,
  894. out[1],
  895. func_out ))
  896. elif isinstance(out,(list,tuple)):
  897. for co,o in zip(cmd_out.split(NL) if opt.fork else cmd_out,out):
  898. check_output(co,o)
  899. else:
  900. check_output(cmd_out,out)
  901. if not opt.verbose: msg_r('.')
  902. if not opt.verbose:
  903. msg('OK')
  904. def docstring_head(obj):
  905. return obj.__doc__.strip().split('\n')[0]
  906. async def do_group(gid):
  907. qmsg(blue('Testing ' +
  908. f'command group {gid!r}' if opt.names else
  909. docstring_head(tc.classes['MMGenToolCmd'+gid]) ))
  910. for cname in tc.classes['MMGenToolCmd'+gid].user_commands:
  911. if cname in skipped_tests:
  912. continue
  913. if cname not in tests[gid]:
  914. m = f'No test for command {cname!r} in group {gid!r}!'
  915. if opt.die_on_missing:
  916. die(1,m+' Aborting')
  917. else:
  918. msg(m)
  919. continue
  920. await run_test(gid,cname)
  921. async def do_cmd_in_group(cmd):
  922. for gid in tests:
  923. for cname in tests[gid]:
  924. if cname == cmd:
  925. await run_test(gid,cname)
  926. return True
  927. return False
  928. def list_tested_cmds():
  929. for gid in tests:
  930. Msg('\n'.join(tests[gid]))
  931. sys.argv = [sys.argv[0]] + ['--skip-cfg-file'] + sys.argv[1:]
  932. cmd_args = opts.init(
  933. opts_data,
  934. add_opts = ['use_old_ed25519'],
  935. init_opts = {
  936. 'usr_randchars': 0,
  937. 'hash_preset': '1',
  938. 'passwd_file': 'test/ref/keyaddrfile_password',
  939. })
  940. from mmgen.protocol import init_proto_from_opts
  941. proto = init_proto_from_opts()
  942. if opt.tool_api:
  943. del tests['Wallet']
  944. del tests['File']
  945. import mmgen.tool as tool
  946. tc = tool.MMGenToolCmds
  947. if opt.list_tests:
  948. Msg('Available tests:')
  949. for gid in tests:
  950. Msg(' {:6} - {}'.format(
  951. gid,
  952. docstring_head(tc.classes['MMGenToolCmd'+gid]) ))
  953. sys.exit(0)
  954. if opt.list_tested_cmds:
  955. list_tested_cmds()
  956. sys.exit(0)
  957. if opt.system:
  958. tool_exec = 'mmgen-tool'
  959. sys.path.pop(0)
  960. else:
  961. os.environ['PYTHONPATH'] = repo_root
  962. tool_exec = os.path.relpath(os.path.join('cmds','mmgen-tool'))
  963. if opt.fork:
  964. tool_cmd = (tool_exec,'--skip-cfg-file')
  965. passthru_args = ['coin','type','testnet','token']
  966. tool_cmd += tuple(['--{}{}'.format(k.replace('_','-'),
  967. '='+getattr(opt,k) if getattr(opt,k) != True else ''
  968. ) for k in passthru_args if getattr(opt,k)])
  969. if opt.traceback:
  970. tool_cmd = (os.path.join('scripts','traceback_run.py'),) + tool_cmd
  971. if opt.coverage:
  972. d,f = init_coverage()
  973. tool_cmd = ('python3','-m','trace','--count','--coverdir='+d,'--file='+f) + tool_cmd
  974. elif g.platform == 'win':
  975. tool_cmd = ('python3',) + tool_cmd
  976. start_time = int(time.time())
  977. async def main():
  978. try:
  979. if cmd_args:
  980. for cmd in cmd_args:
  981. if cmd in tests:
  982. await do_group(cmd)
  983. else:
  984. if not await do_cmd_in_group(cmd):
  985. die(1,f'{cmd!r}: not a recognized test or test group')
  986. else:
  987. for garg in tests:
  988. await do_group(garg)
  989. except KeyboardInterrupt:
  990. die(1,green('\nExiting at user request'))
  991. run_session(main())
  992. t = int(time.time()) - start_time
  993. gmsg('All requested tests finished OK, elapsed time: {:02}:{:02}'.format(t//60,t%60))