ts_misc.py 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  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. )
  78. }
  79. @property
  80. def ticker_args(self):
  81. return [ f'--cachedir={self.tmpdir}', '--proxy=http://asdfzxcv:32459' ]
  82. @property
  83. def nt_datadir(self):
  84. return os.path.join( g.data_dir_root, 'node_tools' )
  85. def ticker_setup(self):
  86. self.spawn('',msg_only=True)
  87. shutil.copy2(os.path.join(refdir,'ticker.json'),self.tmpdir)
  88. shutil.copy2(os.path.join(refdir,'ticker-btc.json'),self.tmpdir)
  89. return 'ok'
  90. def ticker(self,args=[],expect_list=None,cached=True):
  91. t = self.spawn(
  92. f'mmnode-ticker',
  93. (['--cached-data'] if cached else []) + self.ticker_args + args )
  94. if expect_list:
  95. t.match_expect_list(expect_list)
  96. return t
  97. def ticker1(self):
  98. t = self.ticker(['--help'])
  99. t.expect('USAGE:')
  100. return t
  101. def ticker2(self):
  102. t = self.ticker(cached=False)
  103. if not opt.skipping_deps:
  104. t.expect('Creating')
  105. t.expect('Creating')
  106. t.expect('proxy host could not be resolved')
  107. t.req_exit_val = 3
  108. return t
  109. def ticker3(self):
  110. return self.ticker(
  111. [],
  112. [
  113. 'USD BTC',
  114. 'BTC 23250.77 1.00000000 ETH 1659.66 0.07146397'
  115. ])
  116. def ticker4(self):
  117. return self.ticker(
  118. ['--wide','--add-columns=eur,inr-indian-rupee:79.5'],
  119. [
  120. r'EUR \(EURO TOKEN\) = 1.0186 USD ' +
  121. r'INR \(INDIAN RUPEE\) = 0.012579 USD',
  122. 'USD EUR INR BTC CHG_7d CHG_24h UPDATED',
  123. 'BITCOIN',
  124. r'ETHEREUM 1,659.66 1,629.3906 131,943.14 0.07146397 \+21.42 \+1.82',
  125. r'MONERO 158.97 156.0734 12,638.36 0.00684527 \+7.28 \+1.21 2022-08-02 18:25:59',
  126. r'INDIAN RUPEE 0.01 0.0123 1.00 0.00000054 -- --',
  127. ])
  128. def ticker5(self):
  129. shutil.copy2(os.path.join(refdir,'ticker-cfg.yaml'),self.nt_datadir)
  130. t = self.ticker(
  131. ['--wide','--adjust=-0.766'],
  132. [
  133. 'Adjusting prices by -0.77%',
  134. 'USD BTC CHG_7d CHG_24h UPDATED',
  135. r'LITECOIN 58.56 0.00252162 \+12.79 \+0.40 2022-08-02 18:25:59',
  136. r'MONERO 157.76 0.00679284 \+7.28 \+1.21'
  137. ])
  138. os.unlink(os.path.join(self.nt_datadir,'ticker-cfg.yaml'))
  139. return t
  140. def ticker6(self):
  141. t = self.ticker( ['--wide','--portfolio'], None )
  142. t.expect('No portfolio')
  143. t.req_exit_val = 1
  144. return t
  145. def ticker7(self): # demo
  146. shutil.copy2(os.path.join(refdir,'ticker-portfolio.yaml'),self.nt_datadir)
  147. t = self.ticker(
  148. ['--wide','--portfolio'],
  149. [
  150. 'USD BTC CHG_7d CHG_24h UPDATED',
  151. r'ETHEREUM 1,659.66 0.07146397 \+21.42 \+1.82 2022-08-02 18:25:59',
  152. 'CARDANO','ALGORAND',
  153. 'PORTFOLIO','BITCOIN','ETHEREUM','MONERO','CARDANO','ALGORAND','TOTAL'
  154. ])
  155. os.unlink(os.path.join(self.nt_datadir,'ticker-portfolio.yaml'))
  156. return t
  157. def ticker8(self):
  158. return self.ticker(
  159. ['--wide','--elapsed'],
  160. [
  161. 'USD BTC CHG_7d CHG_24h UPDATED',
  162. r'BITCOIN 23,250.77 1.00000000 \+11.15 \+0.89 10 minutes ago'
  163. ])
  164. def ticker9(self):
  165. shutil.copy2(
  166. os.path.join(refdir,'ticker-portfolio-bad.yaml'),
  167. os.path.join(self.nt_datadir,'ticker-portfolio.yaml') )
  168. t = self.ticker(
  169. ['--wide','--portfolio','--elapsed','--add-rows=fake-fakecoin:0.0123','--add-precision=2'],
  170. [
  171. 'USD BTC CHG_7d CHG_24h UPDATED',
  172. r'BITCOIN 23,250.7741 1.0000000000 \+11.15 \+0.89 10 minutes ago',
  173. r'FAKECOIN 81.3008 0.0034966927 -- -- just now',
  174. r'\(no data for noc-nocoin\)',
  175. ])
  176. os.unlink(os.path.join(self.nt_datadir,'ticker-portfolio.yaml'))
  177. return t
  178. def ticker10(self):
  179. return self.ticker(
  180. ['XMR:17.234'],
  181. [
  182. r'XMR \(MONERO\) = 158.97 USD ' +
  183. 'Amount: 17.234 XMR',
  184. 'SPOT PRICE',
  185. 'BTC 0.11783441',
  186. 'XMR 17.23400000',
  187. 'XAU','NDX',
  188. ])
  189. def ticker11(self):
  190. return self.ticker(
  191. ['XMR:17.234:BTC'],
  192. [
  193. r'XMR \(MONERO\) = 158.97 USD ' +
  194. r'BTC \(BITCOIN\) = 23250.77 USD ' +
  195. 'Amount: 17.234 XMR',
  196. 'SPOT PRICE',
  197. 'XMR 17.23400000 BTC 0.11783441',
  198. ])
  199. def ticker12(self):
  200. return self.ticker(
  201. ['--adjust=1.23','--wide','XMR:17.234:BTC'],
  202. [
  203. r'XMR \(MONERO\) = 158.97 USD ' +
  204. r'BTC \(BITCOIN\) = 23,250.77 USD ' +
  205. 'Amount: 17.234 XMR',
  206. r'Adjusting prices by \+1.23%',
  207. 'SPOT PRICE ADJUSTED PRICE',
  208. 'MONERO 17.23400000 17.44597820 2022-08-02 18:25:59 ' +
  209. 'BITCOIN 0.11783441 0.11928377 2022-08-02 18:25:59',
  210. ])
  211. def ticker13(self):
  212. return self.ticker(
  213. ['-wE','-c','inr-indian-rupee:79.5','inr:200000:btc:0.1'],
  214. [
  215. 'Offer: 200,000 INR',
  216. 'Offered price differs from spot by -7.58%',
  217. 'SPOT PRICE OFFERED PRICE UPDATED',
  218. 'INDIAN RUPEE 200,000.00000000 184,843.65372424 10 minutes ago ' +
  219. 'BITCOIN 0.10819955 0.10000000 10 minutes ago'
  220. ])
  221. def ticker14(self):
  222. shutil.copy2(os.path.join(refdir,'ticker-portfolio.yaml'),self.nt_datadir)
  223. t = self.ticker(
  224. ['--btc','--wide','--portfolio','--elapsed'],
  225. [
  226. 'PRICES',
  227. r'BITCOIN 23,368.86 \+6.05 -1.87 33 hours, 2 minutes ago',
  228. 'PORTFOLIO',
  229. r'BITCOIN 28,850.44 \+6.05 -1.87 1.23456789'
  230. ])
  231. os.unlink(os.path.join(self.nt_datadir,'ticker-portfolio.yaml'))
  232. return t
  233. def ticker15(self):
  234. return self.ticker(
  235. ['--btc','--wide','--elapsed','-r','inr:79.5','btc:2:usd:45000'],
  236. [
  237. r'BTC \(BITCOIN\) = 23,368.86 USD',
  238. 'Offered price differs from spot by -3.72%',
  239. 'SPOT PRICE OFFERED PRICE UPDATED',
  240. 'BITCOIN 2.00000000 1.92563954 33 hours, 2 minutes ago ' +
  241. 'US DOLLAR 46,737.71911598 45,000.00000000 33 hours, 2 minutes ago',
  242. ])
  243. def ticker16(self):
  244. return self.ticker(
  245. ['--wide','--elapsed','-c','eur,omr-omani-rial:2.59r'],
  246. [
  247. r'EUR \(EURO TOKEN\) = 1.0186 USD ' +
  248. r'OMR \(OMANI RIAL\) = 2.5900 USD',
  249. 'USD EUR OMR BTC CHG_7d CHG_24h UPDATED',
  250. r'BITCOIN 23,250.77 22,826.6890 8,977.1328 1.00000000 \+11.15 \+0.89 10 minutes ago',
  251. 'OMANI RIAL 2.59 2.5428 1.0000 0.00011139 -- -- just now'
  252. ])