Skip to content

Commit

Permalink
System tests: implement observer-proxy adapter, sketch workflow.
Browse files Browse the repository at this point in the history
  • Loading branch information
andreibancioiu committed Aug 1, 2024
1 parent 665560a commit dc64a4d
Show file tree
Hide file tree
Showing 4 changed files with 162 additions and 3 deletions.
2 changes: 2 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[flake8]
ignore = E501
29 changes: 29 additions & 0 deletions .github/workflows/construction_native.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Test construction (native currency)

on:
pull_request:
workflow_dispatch:

jobs:
localnet:
runs-on: ubuntu-latest

steps:
- uses: actions/setup-python@v5
with:
python-version: 3.11

- uses: actions/checkout@v4

- name: Install mesh-cli
run: |
curl -sSfL https://raw.githubusercontent.com/coinbase/mesh-cli/master/scripts/install.sh | sh -s
- name: Build rosetta
run: |
cd cmd/rosetta && go build .
- name: Smoke test
run: |
cd cmd/rosetta && ./rosetta --version
rosetta-cli version
23 changes: 20 additions & 3 deletions systemtests/devnet-construction.ros
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,22 @@ transfer(1){
}
};

max_fee = "50000000000000";
max_transfer_amount = "10000000000000000";
recipient_amount = random_number({"minimum": "1", "maximum": {{max_transfer_amount}}});

print_message({"recipient_amount":{{recipient_amount}}});

sender_amount = 0-{{recipient_amount}};
recipient = {
"account_identifier": {
"address": "erd1xtslmt67utuewwv8jsx729mxjxaa8dvyyzp7492hy99dl7hvcuqq30l98v"
},
"currency": {
"symbol": "EGLD",
"decimals": 18
}
};
transfer.confirmation_depth = "10";
transfer.operations = [
{
Expand All @@ -28,10 +38,17 @@ transfer(1){
"value":{{sender_amount}},
"currency":{{native_currency}}
}
},
{
"operation_identifier":{"index":1},
"related_operations": [{"index": 0}],
"type":"Transfer",
"account":{{recipient.account_identifier}},
"amount":{
"value":{{recipient_amount}},
"currency":{{native_currency}}
}
}
];
transfer.preprocess_metadata = {
"receiver": "erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th"
};
}
}
111 changes: 111 additions & 0 deletions systemtests/proxy_to_observer_adapter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
import logging
from argparse import ArgumentParser
from typing import Any

import requests
from bottle import Bottle, request, response # type: ignore

app: Any = Bottle()


class Configuration:
def __init__(self):
self.shard = 0
self.proxy = ""


configuration = Configuration()

logging.basicConfig(level=logging.DEBUG)


@app.route("/node/status")
def get_node_status() -> Any:
url = f"{configuration.proxy}/network/status/{configuration.shard}"
logging.info(f"get_node_status(): {url}")

proxy_response = requests.get(url)
proxy_response.raise_for_status()
proxy_response_json = proxy_response.json()

proxy_response_json["data"]["metrics"] = proxy_response_json["data"]["status"]
proxy_response_json["data"]["metrics"]["erd_app_version"] = "v1.2.3"
proxy_response_json["data"]["metrics"]["erd_public_key_block_sign"] = "abba"
del proxy_response_json["data"]["status"]

return proxy_response_json


@app.route("/node/epoch-start/<epoch:int>")
def get_epoch_start(epoch: int) -> Any:
url = f"{configuration.proxy}/network/epoch-start/{configuration.shard}/by-epoch/{epoch}"
logging.info(f"get_epoch_start(): {url}")

proxy_response = requests.get(url)
proxy_response.raise_for_status()
return proxy_response.json()


@app.route("/block/by-nonce/<nonce:int>")
def get_block_by_nonce(nonce: int) -> Any:
url = f"{configuration.proxy}/block/{configuration.shard}/by-nonce/{nonce}"
logging.info(f"get_block_by_nonce(): {url}")

params: Any = dict(request.query) # type: ignore
proxy_response = requests.get(url, params=params)
proxy_response.raise_for_status()
return proxy_response.json()


@app.route("/address/<address>/esdt/<token>")
def get_account_esdt(address: str, token: str) -> Any:
url = f"{configuration.proxy}/address/{address}/esdt/{token}"
logging.info(f"get_account_esdt(): {url}")

params: Any = dict(request.query) # type: ignore
proxy_response = requests.get(url, params=params)
proxy_response.raise_for_status()
return proxy_response.json()


@app.route("/address/<address>")
def get_account(address: str) -> Any:
url = f"{configuration.proxy}/address/{address}"
logging.info(f"get_account(): {url}")

params: Any = dict(request.query) # type: ignore
proxy_response = requests.get(url, params=params)
proxy_response_json = proxy_response.json()
proxy_response.raise_for_status()

return proxy_response_json


@app.route("/transaction/send", method="POST")
def send_transaction():
url = f"{configuration.proxy}/transaction/send"
logging.info(f"send_transaction(): {url}")

data = request.json
proxy_response = requests.post(url, json=data)
proxy_response_json = proxy_response.json()

response.status = proxy_response.status_code

return proxy_response_json


def main():
parser = ArgumentParser()
parser.add_argument("--proxy", default="https://devnet-gateway.multiversx.com")
parser.add_argument("--shard", type=int, default=0)
args = parser.parse_args()

configuration.proxy = args.proxy
configuration.shard = args.shard

app.run(host="localhost", port=8080)


if __name__ == "__main__":
main()

0 comments on commit dc64a4d

Please sign in to comment.