tooltest2.py 36 KB

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