tooltest2.py 41 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024
  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.obj import is_wif,is_coin_addr
  30. from mmgen.wallet import is_bip39_mnemonic,is_mmgen_mnemonic
  31. from mmgen.addr import is_xmrseed
  32. from mmgen.baseconv import *
  33. NL = ('\n','\r\n')[g.platform=='win']
  34. def is_str(s):
  35. return type(s) == str
  36. def md5_hash(s):
  37. from hashlib import md5
  38. return md5(s.encode()).hexdigest()
  39. def md5_hash_strip(s):
  40. import re
  41. s = re.sub('\x1b\[[;0-9]+?m','',s) # strip ANSI color sequences
  42. s = s.replace(NL,'\n') # fix DOS newlines
  43. return md5_hash(s.strip())
  44. opts_data = {
  45. 'text': {
  46. 'desc': "Simple test suite for the 'mmgen-tool' utility",
  47. 'usage':'[options] [command]...',
  48. 'options': """
  49. -h, --help Print this help message
  50. -A, --tool-api Test the tool_api subsystem
  51. -C, --coverage Produce code coverage info using trace module
  52. -d, --die-on-missing Abort if no test data found for given command
  53. --, --longhelp Print help message for long options (common options)
  54. -l, --list-tests List the test groups in this test suite
  55. -L, --list-tested-cmds Output the 'mmgen-tool' commands that are tested by this test suite
  56. -n, --names Print command names instead of descriptions
  57. -q, --quiet Produce quieter output
  58. -s, --system Test scripts and modules installed on system rather than
  59. those in the repo root
  60. -t, --type= Specify coin type
  61. -f, --fork Run commands via tool executable instead of importing tool module
  62. -t, --traceback Run tool inside traceback script
  63. -v, --verbose Produce more verbose output
  64. """,
  65. 'notes': """
  66. If no command is given, the whole suite of tests is run.
  67. """
  68. }
  69. }
  70. sample_text_hexdump = (
  71. '000000: 5468 6520 5469 6d65 7320 3033 2f4a 616e{n}' +
  72. '000010: 2f32 3030 3920 4368 616e 6365 6c6c 6f72{n}' +
  73. '000020: 206f 6e20 6272 696e 6b20 6f66 2073 6563{n}' +
  74. '000030: 6f6e 6420 6261 696c 6f75 7420 666f 7220{n}' +
  75. '000040: 6261 6e6b 73').format(n=NL)
  76. kafile_opts = ['-p1','-Ptest/ref/keyaddrfile_password']
  77. kafile_code = (
  78. "\nopt.hash_preset = '1'" +
  79. "\nopt.set_by_user = ['hash_preset']" +
  80. "\nopt.use_old_ed25519 = None" +
  81. "\nopt.passwd_file = 'test/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, 'opt.type="legacy"' ),
  402. ( ['8e34586186551f6320fa3eb2d238a9c61ab8264b'], '3Eevao3DRVXnYym3tdrJDqS3Wc39PQzahn',
  403. ['--type=segwit'], 'opt.type="segwit"' ),
  404. ( ['3057f66ddd26fa6ef826b0d5ca067ec3e8f3c178'], 'bc1qxptlvmwaymaxa7pxkr2u5pn7c0508stcncv7ms',
  405. ['--type=bech32'], 'opt.type="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, 'opt.type="legacy"' ),
  427. ( ['118089d66b4a5853765e94923abdd5de4616c6e5118089d66b4a5853765e9492'],
  428. 'KwojSzt1VvW343mQfWQi3J537siAt5ktL2qbuCg1ZyKR8BLQ6UJm',
  429. ['--type=compressed'], 'opt.type="compressed"' ),
  430. ( ['118089d66b4a5853765e94923abdd5de4616c6e5118089d66b4a5853765e9492'],
  431. 'KwojSzt1VvW343mQfWQi3J537siAt5ktL2qbuCg1ZyKR8BLQ6UJm',
  432. ['--type=segwit'], 'opt.type="segwit"' ),
  433. ( ['118089d66b4a5853765e94923abdd5de4616c6e5118089d66b4a5853765e9492'],
  434. 'KwojSzt1VvW343mQfWQi3J537siAt5ktL2qbuCg1ZyKR8BLQ6UJm',
  435. ['--type=bech32'], 'opt.type="bech32"' ),
  436. ],
  437. },
  438. 'privhex2addr': {
  439. 'btc_mainnet': [
  440. ( ['118089d66b4a5853765e94923abdd5de4616c6e5118089d66b4a5853765e9492'],
  441. '1C5VPtgq9xQ6AcTgMAR3J6GDrs72HC4pS1',
  442. None, 'opt.type="legacy"' ),
  443. ( ['118089d66b4a5853765e94923abdd5de4616c6e5118089d66b4a5853765e9492'],
  444. '1Kz9fVSUMshzPejpzW9D95kScgA3rY6QxF',
  445. ['--type=compressed'], 'opt.type="compressed"' ),
  446. ( ['118089d66b4a5853765e94923abdd5de4616c6e5118089d66b4a5853765e9492'],
  447. '3AhjTiWHhVJAi1s5CfKMcLzYps12x3gZhg',
  448. ['--type=segwit'], 'opt.type="segwit"' ),
  449. ( ['118089d66b4a5853765e94923abdd5de4616c6e5118089d66b4a5853765e9492'],
  450. 'bc1q6pqnfwwakuuejpm9w52ds342f9d5u36v0qnz7c',
  451. ['--type=bech32'], 'opt.type="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'], 'opt.type="zcash_z"' ),
  485. ( ['ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff'],
  486. 'zcY1hqJ3P5ifjnWk1BcXpjrLG5XeJZUSPCiiVTF9LXrejxBzAsFWcNyr6PudwQHm8DnQpD8HEaM3dh8sB6cf91ciAa53YQ1',
  487. ['--type=zcash_z'], 'opt.type="zcash_z"' ),
  488. ( ['0fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff'],
  489. 'zcY1hqJ3P5ifjnWk1BcXpjrLG5XeJZUSPCiiVTF9LXrejxBzAsFWcNyr6PudwQHm8DnQpD8HEaM3dh8sB6cf91ciAa53YQ1',
  490. ['--type=zcash_z'], 'opt.type="zcash_z"' ),
  491. ( ['00000000000000000000000000000000000000000000000000000000000000ff'],
  492. 'zcck12KgVY34LJwVEDLN8sXhL787zmjKqPsP1uBYRHs75bL9sQu4P7wcc5ZJTjKsL376zaSpsYqGxK94JbiYcNoH8DkeGbN',
  493. ['--type=zcash_z'], 'opt.type="zcash_z"' ),
  494. ( ['ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0f'],
  495. 'zcJ9hEezG1Jeye5dciqiMDh6SXtYbUsircGmpVyhHWyzyxDVRRDs5Q8M7hG3c7nDcvd5Pw4u4wV9RAQmq5RCBZq5wVyMQV8',
  496. ['--type=zcash_z'], 'opt.type="zcash_z"' ),
  497. ( ['deadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef'],
  498. 'zchFELwBxqsAubsLQ8yZgPCDDGukjXJssgCbiTPwFNmFwn9haLnDatzfhLdZzJT4PcU4o2yr92B52UFirUzEdF6ZYM2gBkM',
  499. ['--type=zcash_z'], 'opt.type="zcash_z"' ),
  500. ],
  501. },
  502. 'privhex2pubhex': {
  503. 'btc_mainnet': [
  504. ( ['118089d66b4a5853765e94923abdd5de4616c6e5118089d66b4a5853765e9492'],
  505. '044281a85c9ce87279e028410b851410d65136304cfbbbeaaa8e2e3931cf4e972757f3254c322eeaa3cb6bf97cc5ecf8d4387b0df2c0b1e6ee18fe3a6977a7d57a',
  506. None, 'opt.type="legacy"' ),
  507. ( ['118089d66b4a5853765e94923abdd5de4616c6e5118089d66b4a5853765e9492'],
  508. '024281a85c9ce87279e028410b851410d65136304cfbbbeaaa8e2e3931cf4e9727',
  509. ['--type=compressed'], 'opt.type="compressed"' ),
  510. ( ['118089d66b4a5853765e94923abdd5de4616c6e5118089d66b4a5853765e9492'],
  511. '024281a85c9ce87279e028410b851410d65136304cfbbbeaaa8e2e3931cf4e9727',
  512. ['--type=segwit'], 'opt.type="segwit"' ),
  513. ( ['118089d66b4a5853765e94923abdd5de4616c6e5118089d66b4a5853765e9492'],
  514. '024281a85c9ce87279e028410b851410d65136304cfbbbeaaa8e2e3931cf4e9727',
  515. ['--type=bech32'], 'opt.type="bech32"' ),
  516. ],
  517. },
  518. 'pubhex2addr': {
  519. 'btc_mainnet': [
  520. ( ['044281a85c9ce87279e028410b851410d65136304cfbbbeaaa8e2e3931cf4e972757f3254c322eeaa3cb6bf97cc5ecf8d4387b0df2c0b1e6ee18fe3a6977a7d57a'],
  521. '1C5VPtgq9xQ6AcTgMAR3J6GDrs72HC4pS1',
  522. None, 'opt.type="legacy"' ),
  523. ( ['024281a85c9ce87279e028410b851410d65136304cfbbbeaaa8e2e3931cf4e9727'],
  524. '1Kz9fVSUMshzPejpzW9D95kScgA3rY6QxF',
  525. ['--type=compressed'], 'opt.type="compressed"' ),
  526. ( ['024281a85c9ce87279e028410b851410d65136304cfbbbeaaa8e2e3931cf4e9727'],
  527. '3AhjTiWHhVJAi1s5CfKMcLzYps12x3gZhg',
  528. ['--type=segwit'], 'opt.type="segwit"' ),
  529. ( ['024281a85c9ce87279e028410b851410d65136304cfbbbeaaa8e2e3931cf4e9727'],
  530. 'bc1q6pqnfwwakuuejpm9w52ds342f9d5u36v0qnz7c',
  531. ['--type=bech32'], 'opt.type="bech32"' ),
  532. ],
  533. },
  534. 'pubhex2redeem_script': {
  535. 'btc_mainnet': [
  536. ( ['024281a85c9ce87279e028410b851410d65136304cfbbbeaaa8e2e3931cf4e9727'],
  537. '0014d04134b9ddb7399907657514d846aa495b4e474c',
  538. ['--type=segwit'], 'opt.type="segwit"' ),
  539. ],
  540. },
  541. 'redeem_script2addr': {
  542. 'btc_mainnet': [
  543. ( ['0014d04134b9ddb7399907657514d846aa495b4e474c'],
  544. '3AhjTiWHhVJAi1s5CfKMcLzYps12x3gZhg',
  545. ['--type=segwit'], 'opt.type="segwit"' ),
  546. ],
  547. },
  548. 'randpair': {
  549. 'btc_mainnet': [ ( [], [is_wif,is_coin_addr], ['-r0'] ) ],
  550. 'btc_testnet': [ ( [], [is_wif,is_coin_addr], ['-r0'] ) ],
  551. },
  552. 'randwif': {
  553. 'btc_mainnet': [ ( [], is_wif, ['-r0'] ) ],
  554. 'btc_testnet': [ ( [], is_wif, ['-r0'] ) ],
  555. },
  556. 'wif2addr': {
  557. 'btc_mainnet': [
  558. ( ['5HwzecKMWD82ppJK3qMKpC7ohXXAwcyAN5VgdJ9PLFaAzpBG4sX'],
  559. '1C5VPtgq9xQ6AcTgMAR3J6GDrs72HC4pS1', ['--type=legacy'], 'opt.type="legacy"' ),
  560. ( ['KwojSzt1VvW343mQfWQi3J537siAt5ktL2qbuCg1ZyKR8BLQ6UJm'],
  561. '1Kz9fVSUMshzPejpzW9D95kScgA3rY6QxF', ['--type=compressed'], 'opt.type="compressed"' ),
  562. ( ['KwojSzt1VvW343mQfWQi3J537siAt5ktL2qbuCg1ZyKR8BLQ6UJm'],
  563. '3AhjTiWHhVJAi1s5CfKMcLzYps12x3gZhg', ['--type=segwit'], 'opt.type="segwit"' ),
  564. ( ['KwojSzt1VvW343mQfWQi3J537siAt5ktL2qbuCg1ZyKR8BLQ6UJm'],
  565. 'bc1q6pqnfwwakuuejpm9w52ds342f9d5u36v0qnz7c', ['--type=bech32'], 'opt.type="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'], 'opt.type="zcash_z"' ),
  599. ( ['SKxv1peuQvMT4TvqPLqKy1px3oqLm98Evi948VU8N8VKcf7C2umc'],
  600. 'zcY1hqJ3P5ifjnWk1BcXpjrLG5XeJZUSPCiiVTF9LXrejxBzAsFWcNyr6PudwQHm8DnQpD8HEaM3dh8sB6cf91ciAa53YQ1',
  601. ['--type=zcash_z'], 'opt.type="zcash_z"' ),
  602. ( ['SKxv1peuQvMT4TvqPLqKy1px3oqLm98Evi948VU8N8VKcf7C2umc'],
  603. 'zcY1hqJ3P5ifjnWk1BcXpjrLG5XeJZUSPCiiVTF9LXrejxBzAsFWcNyr6PudwQHm8DnQpD8HEaM3dh8sB6cf91ciAa53YQ1',
  604. ['--type=zcash_z'], 'opt.type="zcash_z"' ),
  605. ( ['SKxny894fJe2rmZjeuoE6GVfNkWoXfPp8337VrLLNWG56kQw4qjm'],
  606. 'zcck12KgVY34LJwVEDLN8sXhL787zmjKqPsP1uBYRHs75bL9sQu4P7wcc5ZJTjKsL376zaSpsYqGxK94JbiYcNoH8DkeGbN',
  607. ['--type=zcash_z'], 'opt.type="zcash_z"' ),
  608. ( ['SKxv1peuQvMT4TvqPLqKy1px3oqLm98Evi948VU8N8VKcBwrLwiu'],
  609. 'zcJ9hEezG1Jeye5dciqiMDh6SXtYbUsircGmpVyhHWyzyxDVRRDs5Q8M7hG3c7nDcvd5Pw4u4wV9RAQmq5RCBZq5wVyMQV8',
  610. ['--type=zcash_z'], 'opt.type="zcash_z"' ),
  611. ( ['SKxuS56e99jpCeD9mMQ5o63zoGPakNdM9HCvt4Vt2cypvRjCdvGJ'],
  612. 'zchFELwBxqsAubsLQ8yZgPCDDGukjXJssgCbiTPwFNmFwn9haLnDatzfhLdZzJT4PcU4o2yr92B52UFirUzEdF6ZYM2gBkM',
  613. ['--type=zcash_z'], 'opt.type="zcash_z"' ),
  614. ],
  615. },
  616. 'wif2hex': {
  617. 'btc_mainnet': [
  618. ( ['5HwzecKMWD82ppJK3qMKpC7ohXXAwcyAN5VgdJ9PLFaAzpBG4sX'],
  619. '118089d66b4a5853765e94923abdd5de4616c6e5118089d66b4a5853765e9492',
  620. None, 'opt.type="legacy"' ),
  621. ( ['KwojSzt1VvW343mQfWQi3J537siAt5ktL2qbuCg1ZyKR8BLQ6UJm'],
  622. '118089d66b4a5853765e94923abdd5de4616c6e5118089d66b4a5853765e9492',
  623. ['--type=compressed'], 'opt.type="compressed"' ),
  624. ( ['KwojSzt1VvW343mQfWQi3J537siAt5ktL2qbuCg1ZyKR8BLQ6UJm'],
  625. '118089d66b4a5853765e94923abdd5de4616c6e5118089d66b4a5853765e9492',
  626. ['--type=segwit'], 'opt.type="segwit"' ),
  627. ( ['KwojSzt1VvW343mQfWQi3J537siAt5ktL2qbuCg1ZyKR8BLQ6UJm'],
  628. '118089d66b4a5853765e94923abdd5de4616c6e5118089d66b4a5853765e9492',
  629. ['--type=bech32'], 'opt.type="bech32"' ),
  630. ],
  631. },
  632. 'wif2redeem_script': {
  633. 'btc_mainnet': [
  634. ( ['KwojSzt1VvW343mQfWQi3J537siAt5ktL2qbuCg1ZyKR8BLQ6UJm'],
  635. '0014d04134b9ddb7399907657514d846aa495b4e474c',
  636. ['--type=segwit'], 'opt.type="segwit"' ),
  637. ],
  638. },
  639. 'wif2segwit_pair': {
  640. 'btc_mainnet': [
  641. ( ['KwojSzt1VvW343mQfWQi3J537siAt5ktL2qbuCg1ZyKR8BLQ6UJm'],
  642. ('0014d04134b9ddb7399907657514d846aa495b4e474c','3AhjTiWHhVJAi1s5CfKMcLzYps12x3gZhg'),
  643. ['--type=segwit'], 'opt.type="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'], 'opt.type = "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, kafile_code ),
  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, kafile_code ),
  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, kafile_code ),
  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, kafile_code ),
  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, kafile_code ),
  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'], kafile_code + '\nopt.type = "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, kafile_code ), ],
  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, kafile_code ), ],
  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, kafile_code ), ],
  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, kafile_code ), ],
  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, kafile_code ), ],
  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. def run_test(gid,cmd_name):
  762. data = tests[gid][cmd_name]
  763. # behavior is like test.py: run coin-dependent tests only if g.proto.testnet or g.coin != BTC
  764. if gid in coin_dependent_groups:
  765. k = '{}_{}net'.format((g.token.lower() if g.token else g.coin.lower()),('main','test')[g.proto.testnet])
  766. if k in data:
  767. data = data[k]
  768. m2 = ' ({})'.format(k)
  769. else:
  770. qmsg(f'-- no data for {cmd_name} ({k}) - skipping')
  771. return
  772. else:
  773. if g.coin != 'BTC' or g.proto.testnet:
  774. return
  775. m2 = ''
  776. m = '{} {}{}'.format(purple('Testing'), cmd_name if opt.names else docstring_head(tc[cmd_name]),m2)
  777. msg_r(green(m)+'\n' if opt.verbose else m)
  778. def fork_cmd(cmd_name,args,out,opts,exec_code):
  779. cmd = list(tool_cmd) + (opts or []) + [cmd_name] + args
  780. vmsg('{} {}'.format(green('Executing'),cyan(' '.join(cmd))))
  781. cp = run(cmd,input=stdin_input or None,stdout=PIPE,stderr=PIPE)
  782. try: cmd_out = cp.stdout.decode()
  783. except: cmd_out = cp.stdout
  784. if cp.stderr:
  785. vmsg(cp.stderr.strip().decode())
  786. if cp.returncode != 0:
  787. import re
  788. m = re.match(b"tool command returned '(None|False)'"+NL.encode(),cp.stderr)
  789. if m:
  790. return { b'None': None, b'False': False }[m.group(1)]
  791. else:
  792. ydie(1,f'Spawned program exited with error: {cp.stderr}')
  793. return cmd_out.strip()
  794. def run_func(cmd_name,args,out,opts,exec_code):
  795. vmsg('{}: {}{}'.format(purple('Running'),
  796. ' '.join([cmd_name]+[repr(e) for e in args]),
  797. ' '+exec_code if exec_code else '' ))
  798. if exec_code: exec(exec_code)
  799. aargs,kwargs = tool._process_args(cmd_name,args)
  800. oq_save = opt.quiet
  801. if not opt.verbose:
  802. opt.quiet = True
  803. if stdin_input:
  804. fd0,fd1 = os.pipe()
  805. if os.fork(): # parent
  806. os.close(fd1)
  807. stdin_save = os.dup(0)
  808. os.dup2(fd0,0)
  809. cmd_out = tc.call(cmd_name,*aargs,**kwargs)
  810. os.dup2(stdin_save,0)
  811. os.wait()
  812. opt.quiet = oq_save
  813. return cmd_out
  814. else: # child
  815. os.close(fd0)
  816. os.write(fd1,stdin_input)
  817. vmsg('Input: {!r}'.format(stdin_input))
  818. sys.exit(0)
  819. else:
  820. ret = tc.call(cmd_name,*aargs,**kwargs)
  821. opt.quiet = oq_save
  822. return ret
  823. def tool_api(cmd_name,args,out,opts,exec_code):
  824. from mmgen.tool import tool_api
  825. tool = tool_api()
  826. if opts:
  827. for o in opts:
  828. if o.startswith('--type='):
  829. tool.addrtype = o.split('=')[1]
  830. pargs,kwargs = [],{}
  831. for a in args:
  832. if '=' in a:
  833. a1,a2 = a.split('=')
  834. kwargs[a1] = int(a2) if is_int(a2) else a2
  835. else:
  836. pargs.append(a)
  837. return getattr(tool,cmd_name)(*pargs,**kwargs)
  838. for d in data:
  839. args,out,opts,exec_code = d + tuple([None] * (4-len(d)))
  840. stdin_input = None
  841. if args and type(args[0]) == bytes:
  842. stdin_input = args[0]
  843. args[0] = '-'
  844. if opt.tool_api:
  845. if args and args[0 ]== '-':
  846. continue
  847. cmd_out = tool_api(cmd_name,args,out,opts,exec_code)
  848. elif opt.fork:
  849. cmd_out = fork_cmd(cmd_name,args,out,opts,exec_code)
  850. else:
  851. if stdin_input and g.platform == 'win':
  852. msg('Skipping for MSWin - no os.fork()')
  853. continue
  854. cmd_out = run_func(cmd_name,args,out,opts,exec_code)
  855. try: vmsg('Output:\n{}\n'.format(cmd_out))
  856. except: vmsg('Output:\n{}\n'.format(repr(cmd_out)))
  857. def check_output(out,chk):
  858. if isinstance(chk,str):
  859. chk = chk.encode()
  860. if isinstance(out,int):
  861. out = str(out).encode()
  862. if isinstance(out,str):
  863. out = out.encode()
  864. err_fs = "Output ({!r}) doesn't match expected output ({!r})"
  865. try: outd = out.decode()
  866. except: outd = None
  867. if type(chk).__name__ == 'function':
  868. assert chk(outd), f'{chk.__name__}({outd}) failed!'
  869. elif type(chk) == dict:
  870. for k,v in chk.items():
  871. if k == 'boolfunc':
  872. assert v(outd), f'{v.__name__}({outd}) failed!'
  873. elif k == 'value':
  874. assert outd == v, err_fs.format(outd,v)
  875. else:
  876. outval = getattr(__builtins__,k)(out)
  877. if outval != v:
  878. die(1,f'{k}({out}) returned {outval}, not {v}!')
  879. elif chk is not None:
  880. assert out == chk, err_fs.format(out,chk)
  881. if type(out) == tuple and type(out[0]).__name__ == 'function':
  882. func_out = out[0](cmd_out)
  883. assert func_out == out[1],(
  884. '{}({}) == {} failed!\nOutput: {}'.format(
  885. out[0].__name__,
  886. cmd_out,
  887. out[1],
  888. func_out ))
  889. elif isinstance(out,(list,tuple)):
  890. for co,o in zip(cmd_out.split(NL) if opt.fork else cmd_out,out):
  891. check_output(co,o)
  892. else:
  893. check_output(cmd_out,out)
  894. if not opt.verbose: msg_r('.')
  895. if not opt.verbose:
  896. msg('OK')
  897. def docstring_head(obj):
  898. return obj.__doc__.strip().split('\n')[0]
  899. def do_group(gid):
  900. qmsg(blue('Testing ' +
  901. f'command group {gid!r}' if opt.names else
  902. docstring_head(tc.classes['MMGenToolCmd'+gid]) ))
  903. for cname in tc.classes['MMGenToolCmd'+gid].user_commands:
  904. if cname not in tests[gid]:
  905. m = f'No test for command {cname!r} in group {gid!r}!'
  906. if opt.die_on_missing:
  907. die(1,m+' Aborting')
  908. else:
  909. msg(m)
  910. continue
  911. run_test(gid,cname)
  912. def do_cmd_in_group(cmd):
  913. for gid in tests:
  914. for cname in tests[gid]:
  915. if cname == cmd:
  916. run_test(gid,cname)
  917. return True
  918. return False
  919. def list_tested_cmds():
  920. for gid in tests:
  921. Msg('\n'.join(tests[gid]))
  922. sys.argv = [sys.argv[0]] + ['--skip-cfg-file'] + sys.argv[1:]
  923. cmd_args = opts.init(opts_data,add_opts=['use_old_ed25519'])
  924. if opt.tool_api:
  925. del tests['Wallet']
  926. del tests['File']
  927. import mmgen.tool as tool
  928. tc = tool.MMGenToolCmds
  929. if opt.list_tests:
  930. Msg('Available tests:')
  931. for gid in tests:
  932. Msg(' {:6} - {}'.format(
  933. gid,
  934. docstring_head(tc.classes['MMGenToolCmd'+gid]) ))
  935. sys.exit(0)
  936. if opt.list_tested_cmds:
  937. list_tested_cmds()
  938. sys.exit(0)
  939. if opt.system:
  940. tool_exec = 'mmgen-tool'
  941. sys.path.pop(0)
  942. else:
  943. os.environ['PYTHONPATH'] = repo_root
  944. tool_exec = os.path.relpath(os.path.join('cmds','mmgen-tool'))
  945. if opt.fork:
  946. tool_cmd = (tool_exec,'--skip-cfg-file')
  947. passthru_args = ['coin','type','testnet','token']
  948. tool_cmd += tuple(['--{}{}'.format(k.replace('_','-'),
  949. '='+getattr(opt,k) if getattr(opt,k) != True else ''
  950. ) for k in passthru_args if getattr(opt,k)])
  951. if opt.traceback:
  952. tool_cmd = (os.path.join('scripts','traceback_run.py'),) + tool_cmd
  953. if opt.coverage:
  954. d,f = init_coverage()
  955. tool_cmd = ('python3','-m','trace','--count','--coverdir='+d,'--file='+f) + tool_cmd
  956. elif g.platform == 'win':
  957. tool_cmd = ('python3',) + tool_cmd
  958. else:
  959. opt.usr_randchars = 0
  960. start_time = int(time.time())
  961. def main():
  962. try:
  963. if cmd_args:
  964. for cmd in cmd_args:
  965. if cmd in tests:
  966. await do_group(cmd)
  967. else:
  968. if not do_cmd_in_group(cmd):
  969. die(1,f'{cmd!r}: not a recognized test or test group')
  970. else:
  971. for garg in tests:
  972. await do_group(garg)
  973. except KeyboardInterrupt:
  974. die(1,green('\nExiting at user request'))
  975. main()
  976. t = int(time.time()) - start_time
  977. gmsg('All requested tests finished OK, elapsed time: {:02}:{:02}'.format(t//60,t%60))