tooltest2.py 41 KB

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