Skip to content

Commit

Permalink
#320 add neon proxy version handler (#323)
Browse files Browse the repository at this point in the history
* Introduce neon_proxy_version handler

* Introduce test_01_neon_proxy_version

* Use proxy/plugin/solana_rest_api.py

* Use /opt/proxy/plugin/solana_rest_api.py

* Add echo PROXY_REVISION to check

* set ${PROXY_REVISION:=${REVISION}}

* Debugging

* Debugging

* Do the code clearly

* Set setUpClass empty
  • Loading branch information
vasiliy-zaznobin authored Nov 25, 2021
1 parent fb01a4e commit ed83d90
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 0 deletions.
1 change: 1 addition & 0 deletions .buildkite/steps/build-image.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ docker pull neonlabsorg/evm_loader:${EVM_LOADER_REVISION}
docker build -t neonlabsorg/proxy:${REVISION} \
--build-arg SOLANA_REVISION=${SOLANA_REVISION} \
--build-arg EVM_LOADER_REVISION=${EVM_LOADER_REVISION} \
--build-arg PROXY_REVISION=${REVISION} \
.
2 changes: 2 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ FROM neonlabsorg/solana:${SOLANA_REVISION} AS cli
FROM neonlabsorg/evm_loader:${EVM_LOADER_REVISION} AS spl

FROM ubuntu:20.04
ARG PROXY_REVISION

RUN apt update && \
DEBIAN_FRONTEND=noninteractive apt -y install \
Expand Down Expand Up @@ -41,6 +42,7 @@ COPY --from=spl /opt/solana_utils.py \
COPY --from=spl /opt/neon-cli /spl/bin/emulator

COPY . /opt
RUN sed -i 's/NEON_PROXY_REVISION_TO_BE_REPLACED/'"$PROXY_REVISION"'/g' /opt/proxy/plugin/solana_rest_api.py
COPY proxy/operator-keypair.json /root/.config/solana/id.json
RUN cd /usr/local/lib/python3.8/dist-packages/ && patch -p0 </opt/solana-py.patch

Expand Down
5 changes: 5 additions & 0 deletions proxy/plugin/solana_rest_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@
modelInstanceLock = threading.Lock()
modelInstance = None

NEON_PROXY_PKG_VERSION = '0.4.1-rc0'
NEON_PROXY_REVISION = 'NEON_PROXY_REVISION_TO_BE_REPLACED'

class EthereumModel:
def __init__(self):
Expand Down Expand Up @@ -84,6 +86,9 @@ def get_solana_account() -> Optional[sol_Account]:
solana_account = sol_Account(values)
return solana_account

def neon_proxy_version(self):
return 'Neon-proxy/v' + NEON_PROXY_PKG_VERSION + '-' + NEON_PROXY_REVISION

def web3_clientVersion(self):
neon_config_load(self)
return self.neon_config_dict['web3_clientVersion']
Expand Down
39 changes: 39 additions & 0 deletions proxy/testing/test_neon_proxy_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import unittest
import os
import requests
import json
import inspect

from proxy.plugin.solana_rest_api import NEON_PROXY_PKG_VERSION, NEON_PROXY_REVISION

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_proxy_version(self):
print("https://github.com/neonlabsorg/proxy-model.py/issues/320")
response = json.loads(requests.post(
proxy_url, headers=headers,
data=json.dumps({"jsonrpc": "2.0",
"id": get_line_number(),
"method": "neon_proxy_version",
"params": []
})).text)
print('response:', response)
neon_proxy_version = response['result']
print('neon_proxy_version:', neon_proxy_version)
self.assertEqual(neon_proxy_version, 'Neon-proxy/v' + NEON_PROXY_PKG_VERSION + '-' + NEON_PROXY_REVISION)


if __name__ == '__main__':
unittest.main()

0 comments on commit ed83d90

Please sign in to comment.