diff --git a/proxy/environment.py b/proxy/environment.py index 7ba268c0a..b06465798 100644 --- a/proxy/environment.py +++ b/proxy/environment.py @@ -19,7 +19,6 @@ def call(self, *args): logger.debug("Calling: " + " ".join(cmd)) return subprocess.check_output(cmd, universal_newlines=True) except subprocess.CalledProcessError as err: - import sys logger.debug("ERR: solana error {}".format(err)) raise @@ -35,7 +34,16 @@ def call(self, *args): logger.debug("Calling: " + " ".join(cmd)) return subprocess.check_output(cmd, timeout=neon_cli_timeout, universal_newlines=True) except subprocess.CalledProcessError as err: - import sys + logger.debug("ERR: neon-cli error {}".format(err)) + raise + + def version(self): + try: + cmd = ["neon-cli", + "--version"] + logger.debug("Calling: " + " ".join(cmd)) + return subprocess.check_output(cmd, timeout=neon_cli_timeout, universal_newlines=True).split()[1] + except subprocess.CalledProcessError as err: logger.debug("ERR: neon-cli error {}".format(err)) raise diff --git a/proxy/plugin/solana_rest_api.py b/proxy/plugin/solana_rest_api.py index 2c1a44dcc..53655b7cf 100644 --- a/proxy/plugin/solana_rest_api.py +++ b/proxy/plugin/solana_rest_api.py @@ -93,6 +93,9 @@ def eth_chainId(self): # NEON_CHAIN_ID is a string in decimal form return hex(int(self.neon_config_dict['NEON_CHAIN_ID'])) + def neon_cli_version(self): + return neon_cli().version() + def net_version(self): neon_config_load(self) # NEON_CHAIN_ID is a string in decimal form diff --git a/proxy/testing/test_neon_cli_version.py b/proxy/testing/test_neon_cli_version.py new file mode 100644 index 000000000..66b82d68e --- /dev/null +++ b/proxy/testing/test_neon_cli_version.py @@ -0,0 +1,39 @@ +import unittest +import os +import requests +import json +import inspect + +from proxy.environment import neon_cli + +proxy_url = os.environ.get('PROXY_URL', 'http://localhost:9090/solana') +headers = {'Content-type': 'application/json'} + + +def get_line_number(): + cf = inspect.currentframe() + return cf.f_back.f_lineno + + +class TestNeonProxyVersion(unittest.TestCase): + @classmethod + def setUpClass(cls): + pass + + def test_01_neon_cli_version(self): + print("https://github.com/neonlabsorg/proxy-model.py/issues/319") + response = json.loads(requests.post( + proxy_url, headers=headers, + data=json.dumps({"jsonrpc": "2.0", + "id": get_line_number(), + "method": "neon_cli_version", + "params": [] + })).text) + print('response:', response) + neon_cli_version = response['result'] + print('neon_cli_version:', neon_cli_version) + self.assertEqual(neon_cli_version, neon_cli().version()) + + +if __name__ == '__main__': + unittest.main()