tooltest2.py 42 KB

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