tooltest2.py 36 KB

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