Skip to content

Commit

Permalink
Github actions implementation (#46)
Browse files Browse the repository at this point in the history
* Create main.yml

* Update main.yml

* Update main.yml

* Update main.yml

* Update run_all_functional.sh

* Update main.yml

* Update main.yml

* Update run_all_functional.sh

* Update run_all_functional.sh

* Update run_all_functional.sh

* Update main.yml

* Update main.yml

* Update main.yml

* Update reset_environment.sh

* Update reset_environment.sh

* Update reset_environment.sh

* Update main.yml

* Update main.yml

* Update main.yml

* Update main.yml

* tests updated

* Update reset_environment.sh

* Update main.yml

* Update main.yml

* Update main.yml

* Create config

* Update reset_environment.sh

* Update main.yml

* Update run_all_functional.sh

* Update test_sdk_client.py

* Update test_sdk_client.py

* Update test_sdk_client.py

* Update main.yml

* Update main.yml

* Update test_sdk_client.py

* Update test_sdk_client.py

* Update test_sdk_client.py

* Update test_sdk_client.py

* Update test_sdk_client.py

* Update test_sdk_client.py

* Update test_sdk_client.py

* Update main.yml

* Update test_sdk_client.py

* Update test_sdk_client.py

* Update test_sdk_client.py

* Update reset_environment.sh

* Update main.yml

* Update run_all_functional.sh

* Update test_sdk_client.py

* Update main.yml

* Update reset_environment.sh

* Update reset_environment.sh

* Update main.yml

* Update test_prepaid_payment.py

* Update test_prepaid_payment.py

* Update test_prepaid_payment.py

* Update test_prepaid_payment.py

* Update test_prepaid_payment.py

* Update main.yml

* Update main.yml

* Delete testcases/utils/config

* Update test_prepaid_payment.py

* Update main.yml

* Update reset_environment.sh

* Update reset_environment.sh

* Update reset_environment.sh

* Update run_all_functional.sh

* Create config

* Update main.yml

* Update config

* Update main.yml

* Delete testcases/utils/config

* Update reset_environment.sh

* Update main.yml

* Update reset_environment.sh

* Update reset_environment.sh

* tests updated 2

* Update reset_environment.sh

* Update main.yml

* Update reset_environment.sh

* Update reset_environment.sh

* Update reset_environment.sh

* Update reset_environment.sh

* Update main.yml

* Update reset_environment.sh

* Update reset_environment.sh

* Update reset_environment.sh

* Update reset_environment.sh

* Update reset_environment.sh

* Update main.yml

* Update main.yml

* Update reset_environment.sh

* Update main.yml

* Update main.yml

* Create dev.yml

* Rename main.yml to master.yml

* Update dev.yml

* Update master.yml

* Update master.yml

* Create main.yml

* Update main.yml

* Delete .github/workflows/main.yml

* Update master.yml

* Update dev.yml

---------

Co-authored-by: Pavel Yagunov <[email protected]>
  • Loading branch information
Deralden and Pavel Yagunov authored Jun 20, 2024
1 parent 19badda commit ee61b40
Show file tree
Hide file tree
Showing 6 changed files with 280 additions and 133 deletions.
76 changes: 76 additions & 0 deletions .github/workflows/dev.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
name: tests_development
on:
# push:
# branches: [ "development" ]
pull_request:
branches: [ "development" ]
workflow_dispatch:

jobs:
run_tests_development:
runs-on: ubuntu-latest
container: node:20-bookworm
steps:

- name: install packs
run: |
apt update
apt install -y libudev-dev libusb-1.0-0-dev curl jq
apt install -y python3-pip python3.11-venv
echo DEV
- name: install ipfs
run: |
wget https://dist.ipfs.io/go-ipfs/v0.9.0/go-ipfs_v0.9.0_linux-amd64.tar.gz
tar -xvzf go-ipfs_v0.9.0_linux-amd64.tar.gz
bash go-ipfs/install.sh
ipfs --version
node --version
- name: clone repo
uses: actions/checkout@v3

# - name: install platform-contracts
# run: |
# cd ..
# git clone https://github.com/singnet/platform-contracts.git
# cd platform-contracts
# npm install
# npm install ganache-cli
# npm run-script compile

# - name: build example service
# run: |
# git clone https://github.com/singnet/example-service.git
# cd example-service
# pip3 install -r requirements.txt --break-system-packages
# sh buildproto.sh

- name: Set up for snet daemon
run: |
cd ..
mkdir snet-daemon
cd snet-daemon
wget https://github.com/singnet/snet-daemon/releases/download/v5.0.1/snet-daemon-v5.0.1-linux-amd64.tar.gz
tar -xvf snet-daemon-v5.0.1-linux-amd64.tar.gz
cd snet-daemon-v5.0.1-linux-amd64
cp ../../snet-sdk-python/testcases/functional_tests/snetd.config.json .
- name: install pip packages
run: |
pip3 install -r requirements.txt --break-system-packages
# mkdir ~/.snet
# cp ./testcases/utils/config ~/.snet/
# cat ~/.snet/config
- name: install snet-sdk
run: pip3 install -e . --break-system-packages

- name: functional tests for sdk
run: |
export SNET_TEST_WALLET_PRIVATE_KEY=${{ secrets.PRIV_KEY }}
export SNET_TEST_INFURA_KEY=${{ secrets.INF_KEY }}
export FORMER_SNET_TEST_INFURA_KEY=${{ secrets.FORM_INF_KEY }}
export PIP_BREAK_SYSTEM_PACKAGES=1
export PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python
sh -ex ./testcases/utils/run_all_functional.sh
77 changes: 77 additions & 0 deletions .github/workflows/master.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
name: tests_master
on:
# push:
# branches: [ "master" ]
pull_request:
branches: [ "master" ]
workflow_dispatch:

jobs:
run_tests_master:
runs-on: ubuntu-latest
container: node:20-bookworm
steps:

- name: install packs
run: |
apt update
apt install -y libudev-dev libusb-1.0-0-dev curl jq
apt install -y python3-pip python3.11-venv
echo MASTER
- name: install ipfs
run: |
wget https://dist.ipfs.io/go-ipfs/v0.9.0/go-ipfs_v0.9.0_linux-amd64.tar.gz
tar -xvzf go-ipfs_v0.9.0_linux-amd64.tar.gz
bash go-ipfs/install.sh
ipfs --version
node --version
- name: clone repo
uses: actions/checkout@v3

# - name: install platform-contracts
# run: |
# cd ..
# git clone https://github.com/singnet/platform-contracts.git
# cd platform-contracts
# npm install
# npm install ganache-cli
# npm run-script compile

# - name: build example service
# run: |
# git clone https://github.com/singnet/example-service.git
# cd example-service
# pip3 install -r requirements.txt --break-system-packages
# sh buildproto.sh


- name: Set up for snet daemon
run: |
cd ..
mkdir snet-daemon
cd snet-daemon
wget https://github.com/singnet/snet-daemon/releases/download/v5.0.1/snet-daemon-v5.0.1-linux-amd64.tar.gz
tar -xvf snet-daemon-v5.0.1-linux-amd64.tar.gz
cd snet-daemon-v5.0.1-linux-amd64
cp ../../snet-sdk-python/testcases/functional_tests/snetd.config.json .
- name: install pip packages
run: |
pip3 install -r requirements.txt --break-system-packages
# mkdir ~/.snet
# cp ./testcases/utils/config ~/.snet/
# cat ~/.snet/config
- name: install snet-sdk
run: pip3 install -e . --break-system-packages

- name: functional tests for sdk
run: |
export SNET_TEST_WALLET_PRIVATE_KEY=${{ secrets.PRIV_KEY }}
export SNET_TEST_INFURA_KEY=${{ secrets.INF_KEY }}
export FORMER_SNET_TEST_INFURA_KEY=${{ secrets.FORM_INF_KEY }}
export PIP_BREAK_SYSTEM_PACKAGES=1
export PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python
sh -ex ./testcases/utils/run_all_functional.sh
2 changes: 1 addition & 1 deletion testcases/functional_tests/test_prepaid_payment.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def test_sdk():

snet_sdk = sdk.SnetSDK(config)
service_client = snet_sdk.create_service_client(org_id, service_id, examples_service_pb2_grpc.CalculatorStub,
group_name=group_name, concurrent_calls=3)
group_name, concurrent_calls=3)
check_channel_status(service_client, 3000)
make_cuncurrent_calls(service_client)
check_channel_status(service_client, 6000)
Expand Down
199 changes: 96 additions & 103 deletions testcases/functional_tests/test_sdk_client.py
Original file line number Diff line number Diff line change
@@ -1,98 +1,103 @@
from snet import sdk
from snet.sdk.service_client import ServiceClient


def verify_when_no_open_channel(service_client: ServiceClient):
channels = service_client.load_open_channels()
assert len(channels) == 0


def make_first_free_call(service_client: ServiceClient):
result = service_client.call_rpc("mul", "Numbers", a=20, b=4)
assert result.value == 80.0


def make_second_free_call(service_client: ServiceClient):
result = service_client.call_rpc("mul", "Numbers", a=20, b=5)
assert result.value == 100.0


def open_first_channel(service_client: ServiceClient):
channel = service_client.open_channel(123456, 33333)
assert channel.channel_id == 0
assert channel.state['nonce'] == 0
assert channel.state['last_signed_amount'] == 0


def first_call_to_service_after_opening_first_channel(service_client: ServiceClient):
result = service_client.call_rpc("mul", "Numbers", a=20, b=3)
assert result.value == 60.0


def verify_channel_state_after_opening_first_channel_and_first_call_to_service(service_client: ServiceClient):
service_client.update_channel_states()
channels = service_client.load_open_channels()
assert channels[0].channel_id == 0
assert channels[0].state['nonce'] == 0
assert channels[0].state['last_signed_amount'] == 1000

import unittest
import shutil
import os

def second_call_to_service_after_opening_first_channel(service_client: ServiceClient):
result = service_client.call_rpc("mul", "Numbers", a=20, b=3)
assert result.value == 60.0


def verify_channel_state_after_opening_first_channel_and_second_call_to_service(service_client: ServiceClient):
service_client.update_channel_states()
channels = service_client.load_open_channels()
assert channels[0].channel_id == 0
assert channels[0].state['nonce'] == 0
assert channels[0].state['last_signed_amount'] == 2000


def open_second_channel(service_client: ServiceClient):
channel = service_client.open_channel(1234321, 123456)
assert channel.channel_id == 1
assert channel.state['nonce'] == 0
assert channel.state['last_signed_amount'] == 0


def verify_number_of_channel_after_opening_second_channel(service_client: ServiceClient):
service_client.update_channel_states()
channels = service_client.load_open_channels()
assert channels[0].channel_id == 0
assert channels[0].state['nonce'] == 0
assert channels[0].state['last_signed_amount'] == 2000
assert channels[1].channel_id == 1
assert channels[1].state['nonce'] == 0
assert channels[1].state['last_signed_amount'] == 0


def first_call_to_service_after_opening_second_channel(service_client: ServiceClient):
result = service_client.call_rpc("mul", "Numbers", a=20, b=3)
assert result.value == 60.0


def verify_channel_state_after_opening_second_channel_and_first_call_to_service(service_client: ServiceClient):
service_client.update_channel_states()
channels = service_client.load_open_channels()
assert channels[0].channel_id == 0
assert channels[0].state['nonce'] == 0
assert channels[0].state['last_signed_amount'] == 3000
assert channels[1].channel_id == 1
assert channels[1].state['nonce'] == 0
assert channels[1].state['last_signed_amount'] == 0
from snet import sdk


def test_sdk():
class TestSDKClient(unittest.TestCase):
def setUp(self):
self.service_client, self.path_to_pb_files = get_test_service_data()

# TODO update/replace/remove tests that are commented out

# def test_verify_when_no_open_channel(self):
# channels = self.service_client.load_open_channels()
# self.assertEqual(0, len(channels))

# def test_make_first_free_call(self):
# result = self.service_client.call_rpc("mul", "Numbers", a=20, b=4)
# self.assertEqual(80.0, result.value)

# def test_make_second_free_call(self):
# result = self.service_client.call_rpc("mul", "Numbers", a=20, b=5)
# self.assertEqual(100.0, result.value)

def test_open_first_channel(self):
channel = self.service_client.open_channel(123456, 33333)
# self.assertEqual(0, channel.channel_id)
# self.assertEqual(0, channel.state['nonce'])
# self.assertEqual(0, channel.state['last_signed_amount'])

def test_first_call_to_service_after_opening_first_channel(self):
result = self.service_client.call_rpc("mul", "Numbers", a=20, b=3)
self.assertEqual(60.0, result.value)

# def test_verify_channel_state_after_opening_first_channel_and_first_call_to_service(self):
# self.service_client.update_channel_states()
# channels = self.service_client.load_open_channels()
# self.assertEqual(0, channels[0].channel_id)
# self.assertEqual(0, channels[0].state['nonce'])
# self.assertEqual(1000, channels[0].state['last_signed_amount'])

# def test_second_call_to_service_after_opening_first_channel(self):
# result = self.service_client.call_rpc("mul", "Numbers", a=20, b=3)
# self.assertEqual(60.0, result.value)

# def test_verify_channel_state_after_opening_first_channel_and_second_call_to_service(self):
# self.service_client.update_channel_states()
# channels = self.service_client.load_open_channels()
# self.assertEqual(0, channels[0].channel_id)
# self.assertEqual(0, channels[0].state['nonce'])
# self.assertEqual(2000, channels[0].state['last_signed_amount'])

# def test_open_second_channel(self):
# channel = self.service_client.open_channel(1234321, 123456)
# self.assertEqual(1, channel.channel_id)
# self.assertEqual(0, channel.state['nonce'])
# self.assertEqual(0, channel.state['last_signed_amount'])

# def test_verify_number_of_channel_after_opening_second_channel(self):
# self.service_client.update_channel_states()
# channels = self.service_client.load_open_channels()
# self.assertEqual(0, channels[0].channel_id)
# self.assertEqual(0, channels[0].state['nonce'])
# self.assertEqual(2000, channels[0].state['last_signed_amount'])
# self.assertEqual(1, channels[1].channel_id)
# self.assertEqual(0, channels[1].state['nonce'])
# self.assertEqual(0, channels[1].state['last_signed_amount'])

# def test_first_call_to_service_after_opening_second_channel(self):
# result = self.service_client.call_rpc("mul", "Numbers", a=20, b=3)
# self.assertEqual(60.0, result.value)

# def test_verify_channel_state_after_opening_second_channel_and_first_call_to_service(self):
# self.service_client.update_channel_states()
# channels = self.service_client.load_open_channels()
# self.assertEqual(0, channels[0].channel_id)
# self.assertEqual(0, channels[0].state['nonce'])
# self.assertEqual(3000, channels[0].state['last_signed_amount'])
# self.assertEqual(1, channels[1].channel_id)
# self.assertEqual(0, channels[1].state['nonce'])
# self.assertEqual(0, channels[1].state['last_signed_amount'])

def tearDown(self):
try:
shutil.rmtree(self.path_to_pb_files)
print(f"Directory '{self.path_to_pb_files}' has been removed successfully after testing.")
except OSError as e:
print(f"Error: {self.path_to_pb_files} : {e.strerror}")


def get_test_service_data():
org_id = "26072b8b6a0e448180f8c0e702ab6d2f"
service_id = "Exampleservice"
group_name="default_group"
group_name = "default_group"

config = {
"private_key": "51ec611f164a078a13dba33e5afefcd62c8460545b2d48177a27443971482b4a",
"eth_rpc_endpoint": "https://sepolia.infura.io/v3/09027f4a13e841d48dbfefc67e7685d5",
"email":"[email protected]",
"private_key": os.environ['SNET_TEST_WALLET_PRIVATE_KEY'],
"eth_rpc_endpoint": f"https://sepolia.infura.io/v3/{os.environ['SNET_TEST_INFURA_KEY']}",
"email": "[email protected]",
# "free_call_auth_token-bin":"f5533eb0f01f0d45239c11b411bdfd4221fd3b125e4250db1f7bc044466108bc10ce95ab62ae224b6578b68d0ce337b4ec36e4b9dfbe6653e04973107813cbc01c",
# "free-call-token-expiry-block":19690819,
"concurrency": False,
Expand All @@ -104,21 +109,9 @@ def test_sdk():

snet_sdk = sdk.SnetSDK(config)
service_client = snet_sdk.create_service_client(org_id, service_id, group_name)


make_first_free_call(service_client)
make_second_free_call(service_client)
verify_when_no_open_channel(service_client)
open_first_channel(service_client)
first_call_to_service_after_opening_first_channel(service_client)
verify_channel_state_after_opening_first_channel_and_first_call_to_service(service_client)
second_call_to_service_after_opening_first_channel(service_client)
verify_channel_state_after_opening_first_channel_and_second_call_to_service(service_client)
open_second_channel(service_client)
verify_number_of_channel_after_opening_second_channel(service_client)
first_call_to_service_after_opening_second_channel(service_client)
verify_channel_state_after_opening_second_channel_and_first_call_to_service(service_client)
path_to_pb_files = snet_sdk.get_path_to_pb_files(org_id, service_id)
return service_client, path_to_pb_files


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

0 comments on commit ee61b40

Please sign in to comment.