tooltest2.py 36 KB

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