tooltest2.py 36 KB

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