tooltest2.py 40 KB

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