ts_misc.py 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  1. #!/usr/bin/env python3
  2. #
  3. # mmgen = Multi-Mode GENerator, a command-line cryptocurrency wallet
  4. # Copyright (C)2013-2022 The MMGen Project <mmgen@tuta.io>
  5. # Licensed under the GNU General Public License, Version 3:
  6. # https://www.gnu.org/licenses
  7. # Public project repositories:
  8. # https://github.com/mmgen/mmgen-node-tools
  9. # https://gitlab.com/mmgen/mmgen-node-tools
  10. """
  11. ts_misc.py: Miscellaneous test groups for the test.py test suite
  12. """
  13. import shutil
  14. from ..include.common import *
  15. from .common import *
  16. from .ts_base import *
  17. class TestSuiteHelp(TestSuiteBase):
  18. 'help, info and usage screens'
  19. networks = ('btc','ltc','bch')
  20. tmpdir_nums = []
  21. passthru_opts = ('daemon_data_dir','rpc_port','coin','testnet')
  22. cmd_group = (
  23. ('version', (1,'version message',[])),
  24. ('helpscreens', (1,'help screens', [])),
  25. ('longhelpscreens', (1,'help screens (--longhelp)',[])),
  26. )
  27. color = True
  28. def version(self):
  29. t = self.spawn(f'mmnode-netrate',['--version'])
  30. t.expect('MMNODE-NETRATE version')
  31. return t
  32. def helpscreens(self,arg='--help',scripts=(),expect='USAGE:.*OPTIONS:'):
  33. scripts = list(scripts) or [s for s in os.listdir('cmds') if s.startswith('mmnode-')]
  34. for s in sorted(scripts):
  35. t = self.spawn(s,[arg],extra_desc=f'({s})')
  36. t.expect(expect,regex=True)
  37. t.read()
  38. t.ok()
  39. t.skip_ok = True
  40. return t
  41. def longhelpscreens(self):
  42. return self.helpscreens(arg='--longhelp',expect='USAGE:.*LONG OPTIONS:')
  43. refdir = os.path.join('test','ref','ticker')
  44. class TestSuiteScripts(TestSuiteBase):
  45. 'scripts not requiring a coin daemon'
  46. networks = ('btc',)
  47. tmpdir_nums = [2]
  48. passthru_opts = ()
  49. color = True
  50. cmd_group_in = (
  51. ('subgroup.ticker_setup', []),
  52. ('subgroup.ticker', ['ticker_setup']),
  53. )
  54. cmd_subgroups = {
  55. 'ticker_setup': (
  56. "setup for 'ticker' subgroup",
  57. ('ticker_setup', 'ticker setup'),
  58. ),
  59. 'ticker': (
  60. "'mmnode-ticker' script",
  61. ('ticker1', 'ticker [--help)'),
  62. ('ticker2', 'ticker (bad proxy)'),
  63. ('ticker3', 'ticker [--cached-data]'),
  64. ('ticker4', 'ticker [--cached-data --wide]'),
  65. ('ticker5', 'ticker [--cached-data --wide --adjust=-0.766] (usr cfg file)'),
  66. ('ticker6', 'ticker [--cached-data --wide --portfolio] (missing portfolio)'),
  67. ('ticker7', 'ticker [--cached-data --wide --portfolio]'),
  68. ('ticker8', 'ticker [--cached-data --wide --elapsed]'),
  69. ('ticker9', 'ticker [--cached-data --wide --portfolio --elapsed --add-rows=fake-fakecoin:0.0123 --add-precision=2]'),
  70. ('ticker10', 'ticker [--cached-data xmr:17.234]'),
  71. ('ticker11', 'ticker [--cached-data xmr:17.234:btc]'),
  72. ('ticker12', 'ticker [--cached-data --adjust=1.23 xmr:17.234:btc]'),
  73. ('ticker13', 'ticker [--cached-data --wide --elapsed -c inr-indian-rupee:79.5 inr:200000:btc:0.1]'),
  74. ('ticker14', 'ticker [--cached-data --wide --btc]'),
  75. ('ticker15', 'ticker [--cached-data --wide --btc btc:2:usd:45000]'),
  76. ('ticker16', 'ticker [--cached-data --wide --elapsed -c eur,omr-omani-rial:2.59r'),
  77. ('ticker17', 'ticker [--cached-data --wide --elapsed -c bgn-bulgarian-lev:0.5113r:eur'),
  78. ('ticker18', 'ticker [--cached-data --wide --elapsed -c eur,bgn-bulgarian-lev:0.5113r:eur-euro-token'),
  79. )
  80. }
  81. @property
  82. def ticker_args(self):
  83. return [ f'--cachedir={self.tmpdir}', '--proxy=http://asdfzxcv:32459' ]
  84. @property
  85. def nt_datadir(self):
  86. return os.path.join( g.data_dir_root, 'node_tools' )
  87. def ticker_setup(self):
  88. self.spawn('',msg_only=True)
  89. shutil.copy2(os.path.join(refdir,'ticker.json'),self.tmpdir)
  90. shutil.copy2(os.path.join(refdir,'ticker-btc.json'),self.tmpdir)
  91. return 'ok'
  92. def ticker(self,args=[],expect_list=None,cached=True):
  93. t = self.spawn(
  94. f'mmnode-ticker',
  95. (['--cached-data'] if cached else []) + self.ticker_args + args )
  96. if expect_list:
  97. t.match_expect_list(expect_list)
  98. return t
  99. def ticker1(self):
  100. t = self.ticker(['--help'])
  101. t.expect('USAGE:')
  102. return t
  103. def ticker2(self):
  104. t = self.ticker(cached=False)
  105. if not opt.skipping_deps:
  106. t.expect('Creating')
  107. t.expect('Creating')
  108. t.expect('proxy host could not be resolved')
  109. t.req_exit_val = 3
  110. return t
  111. def ticker3(self):
  112. return self.ticker(
  113. [],
  114. [
  115. 'USD BTC',
  116. 'BTC 23250.77 1.00000000 ETH 1659.66 0.07146397'
  117. ])
  118. def ticker4(self):
  119. return self.ticker(
  120. ['--wide','--add-columns=eur,inr-indian-rupee:79.5'],
  121. [
  122. r'EUR \(EURO TOKEN\) = 1.0186 USD ' +
  123. r'INR \(INDIAN RUPEE\) = 0.012579 USD',
  124. 'USD EUR INR BTC CHG_7d CHG_24h UPDATED',
  125. 'BITCOIN',
  126. r'ETHEREUM 1,659.66 1,629.3906 131,943.14 0.07146397 \+21.42 \+1.82',
  127. r'MONERO 158.97 156.0734 12,638.36 0.00684527 \+7.28 \+1.21 2022-08-02 18:25:59',
  128. r'INDIAN RUPEE 0.01 0.0123 1.00 0.00000054 -- --',
  129. ])
  130. def ticker5(self):
  131. shutil.copy2(os.path.join(refdir,'ticker-cfg.yaml'),self.nt_datadir)
  132. t = self.ticker(
  133. ['--wide','--adjust=-0.766'],
  134. [
  135. 'Adjusting prices by -0.77%',
  136. 'USD BTC CHG_7d CHG_24h UPDATED',
  137. r'LITECOIN 58.56 0.00252162 \+12.79 \+0.40 2022-08-02 18:25:59',
  138. r'MONERO 157.76 0.00679284 \+7.28 \+1.21'
  139. ])
  140. os.unlink(os.path.join(self.nt_datadir,'ticker-cfg.yaml'))
  141. return t
  142. def ticker6(self):
  143. t = self.ticker( ['--wide','--portfolio'], None )
  144. t.expect('No portfolio')
  145. t.req_exit_val = 1
  146. return t
  147. def ticker7(self): # demo
  148. shutil.copy2(os.path.join(refdir,'ticker-portfolio.yaml'),self.nt_datadir)
  149. t = self.ticker(
  150. ['--wide','--portfolio'],
  151. [
  152. 'USD BTC CHG_7d CHG_24h UPDATED',
  153. r'ETHEREUM 1,659.66 0.07146397 \+21.42 \+1.82 2022-08-02 18:25:59',
  154. 'CARDANO','ALGORAND',
  155. 'PORTFOLIO','BITCOIN','ETHEREUM','MONERO','CARDANO','ALGORAND','TOTAL'
  156. ])
  157. os.unlink(os.path.join(self.nt_datadir,'ticker-portfolio.yaml'))
  158. return t
  159. def ticker8(self):
  160. return self.ticker(
  161. ['--wide','--elapsed'],
  162. [
  163. 'USD BTC CHG_7d CHG_24h UPDATED',
  164. r'BITCOIN 23,250.77 1.00000000 \+11.15 \+0.89 10 minutes ago'
  165. ])
  166. def ticker9(self):
  167. shutil.copy2(
  168. os.path.join(refdir,'ticker-portfolio-bad.yaml'),
  169. os.path.join(self.nt_datadir,'ticker-portfolio.yaml') )
  170. t = self.ticker(
  171. ['--wide','--portfolio','--elapsed','--add-rows=fake-fakecoin:0.0123','--add-precision=2'],
  172. [
  173. 'USD BTC CHG_7d CHG_24h UPDATED',
  174. r'BITCOIN 23,250.7741 1.0000000000 \+11.15 \+0.89 10 minutes ago',
  175. r'FAKECOIN 81.3008 0.0034966927 -- -- just now',
  176. r'\(no data for noc-nocoin\)',
  177. ])
  178. os.unlink(os.path.join(self.nt_datadir,'ticker-portfolio.yaml'))
  179. return t
  180. def ticker10(self):
  181. return self.ticker(
  182. ['XMR:17.234'],
  183. [
  184. r'XMR \(MONERO\) = 158.97 USD ' +
  185. 'Amount: 17.234 XMR',
  186. 'SPOT PRICE',
  187. 'BTC 0.11783441',
  188. 'XMR 17.23400000',
  189. 'XAU','NDX',
  190. ])
  191. def ticker11(self):
  192. return self.ticker(
  193. ['XMR:17.234:BTC'],
  194. [
  195. r'XMR \(MONERO\) = 158.97 USD ' +
  196. r'BTC \(BITCOIN\) = 23250.77 USD ' +
  197. 'Amount: 17.234 XMR',
  198. 'SPOT PRICE',
  199. 'XMR 17.23400000 BTC 0.11783441',
  200. ])
  201. def ticker12(self):
  202. return self.ticker(
  203. ['--adjust=1.23','--wide','XMR:17.234:BTC'],
  204. [
  205. r'XMR \(MONERO\) = 158.97 USD ' +
  206. r'BTC \(BITCOIN\) = 23,250.77 USD ' +
  207. 'Amount: 17.234 XMR',
  208. r'Adjusting prices by \+1.23%',
  209. 'SPOT PRICE ADJUSTED PRICE',
  210. 'MONERO 17.23400000 17.44597820 2022-08-02 18:25:59 ' +
  211. 'BITCOIN 0.11783441 0.11928377 2022-08-02 18:25:59',
  212. ])
  213. def ticker13(self):
  214. return self.ticker(
  215. ['-wE','-c','inr-indian-rupee:79.5','inr:200000:btc:0.1'],
  216. [
  217. 'Offer: 200,000 INR',
  218. 'Offered price differs from spot by -7.58%',
  219. 'SPOT PRICE OFFERED PRICE UPDATED',
  220. 'INDIAN RUPEE 200,000.00000000 184,843.65372424 10 minutes ago ' +
  221. 'BITCOIN 0.10819955 0.10000000 10 minutes ago'
  222. ])
  223. def ticker14(self):
  224. shutil.copy2(os.path.join(refdir,'ticker-portfolio.yaml'),self.nt_datadir)
  225. t = self.ticker(
  226. ['--btc','--wide','--portfolio','--elapsed'],
  227. [
  228. 'PRICES',
  229. r'BITCOIN 23,368.86 \+6.05 -1.87 1 day 9 hours 2 minutes ago',
  230. 'PORTFOLIO',
  231. r'BITCOIN 28,850.44 \+6.05 -1.87 1.23456789'
  232. ])
  233. os.unlink(os.path.join(self.nt_datadir,'ticker-portfolio.yaml'))
  234. return t
  235. def ticker15(self):
  236. return self.ticker(
  237. ['--btc','--wide','--elapsed','-r','inr:79.5','btc:2:usd:45000'],
  238. [
  239. r'BTC \(BITCOIN\) = 23,368.86 USD',
  240. 'Offered price differs from spot by -3.72%',
  241. 'SPOT PRICE OFFERED PRICE UPDATED',
  242. 'BITCOIN 2.00000000 1.92563954 1 day 9 hours 2 minutes ago ' +
  243. 'US DOLLAR 46,737.71911598 45,000.00000000 1 day 9 hours 2 minutes ago',
  244. ])
  245. def ticker16(self):
  246. return self.ticker(
  247. ['--wide','--elapsed','-c','eur,omr-omani-rial:2.59r'],
  248. [
  249. r'EUR \(EURO TOKEN\) = 1.0186 USD ' +
  250. r'OMR \(OMANI RIAL\) = 2.5900 USD',
  251. 'USD EUR OMR BTC CHG_7d CHG_24h UPDATED',
  252. r'BITCOIN 23,250.77 22,826.6890 8,977.1328 1.00000000 \+11.15 \+0.89 10 minutes ago',
  253. 'OMANI RIAL 2.59 2.5428 1.0000 0.00011139 -- -- just now'
  254. ])
  255. def ticker17(self):
  256. # BGN pegged at 0.5113 EUR
  257. return self.ticker(
  258. ['--wide','--elapsed','-c','bgn-bulgarian-lev:0.5113r:eur'],
  259. [
  260. r'BGN \(BULGARIAN LEV\) = 0.52080 USD',
  261. 'USD BGN BTC CHG_7d CHG_24h UPDATED',
  262. 'BITCOIN 23,250.77 44,644.414 1.00000000',
  263. 'BULGARIAN LEV 0.52 1.000 0.00002240',
  264. ])
  265. def ticker18(self):
  266. return self.ticker(
  267. ['--wide','--elapsed','-c','eur,bgn-bulgarian-lev:0.5113r:eur-euro-token'],
  268. [
  269. r'BGN \(BULGARIAN LEV\) = 0.52080 USD',
  270. 'USD EUR BGN BTC CHG_7d CHG_24h UPDATED',
  271. 'BITCOIN 23,250.77 22,826.6890 44,644.414 1.00000000',
  272. 'BULGARIAN LEV 0.52 0.5113 1.000 0.00002240',
  273. ])