Skip to content

Commit

Permalink
test: Added Github actions for testing local calls
Browse files Browse the repository at this point in the history
Signed-off-by: carlos.vdr <carlos.vdr@semiotic.ai>
  • Loading branch information
carlosvdr committed Oct 27, 2023
1 parent d1b5553 commit f4f7f21
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 23 deletions.
46 changes: 46 additions & 0 deletions .github/workflows/local_tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Local chain tests
on:
push:
branches: [ master ]
pull_request:
jobs:
tests:
strategy:
fail-fast: true
runs-on: ubuntu-latest
name: Build and Test
steps:
- uses: actions/checkout@v4
name: Check out repository
with:
submodules: recursive
- uses: actions/setup-node@v2
name: Set up Node.js
with:
node-version: "lts/gallium"
- name: Install graph CLI
run: npm install -g @graphprotocol/graph-cli
- uses: actions/setup-python@v4
with:
python-version: '3.8'
cache: pip
- name: Install Foundry
uses: foundry-rs/foundry-toolchain@v1
- name: Start Docker Compose
run: docker-compose up -d
working-directory: ./tests
- name: Checking graph-node availability
uses: nick-fields/retry@v2
with:
max_attempts: 3
retry_on: error
timeout_seconds: 5
command: nc -zv 127.0.0.1 8030
- name: Installing python requirements
run: pip install -r requirements.txt
working-directory: ./tests
- run: |
yarn
./contract_init.sh
name: Build and Test
working-directory: ./tests
7 changes: 2 additions & 5 deletions tests/contract_init.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/bin/bash
set -e

GATEWAY=0x90F8bf6A479f320ead074411a4B0e7944Ea8c9C1
SIGNER=0xFFcf8FDEE72ac11b5c542428B35EEF5769C409f0
Expand All @@ -18,8 +19,6 @@ GRAPH_TOKEN=$(jq '."1337".GraphToken.address' addresses.json -r)

command cd $current_dir/timeline-aggregation-protocol-contracts
command yarn
command forge install
command forge update
echo "Graph token address: $GRAPH_TOKEN"
echo "Step 2: Obtain allocation tracker address"
ALLOCATION_VAR=$(forge create --unlocked --from $GATEWAY --rpc-url localhost:8545 src/AllocationIDTracker.sol:AllocationIDTracker --json)
Expand Down Expand Up @@ -51,6 +50,4 @@ yarn create-local
yarn deploy-local

echo "Running escrow contract calls"
python local_contract_calls.py "$ESCROW_AD" "$TAP_VERIFIER_AD" "$GRAPH_TOKEN" "$ISTAKING_AD"


python local_contract_calls.py "$ESCROW_AD" "$TAP_VERIFIER_AD" "$GRAPH_TOKEN" "$ISTAKING_AD"
4 changes: 2 additions & 2 deletions tests/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
version: '3'
services:
graph-node:
image: graphprotocol/graph-node
image: graphprotocol/graph-node:v0.32.0
ports:
- '8000:8000'
- '8001:8001'
Expand Down Expand Up @@ -42,7 +42,7 @@ services:
PGDATA: "/var/lib/postgresql/data"
POSTGRES_INITDB_ARGS: "-E UTF8 --locale=C"
anvil:
image: ghcr.io/foundry-rs/foundry:latest
image: ghcr.io/foundry-rs/foundry:nightly-602460eb99e1645eab970bacc5a6d01368a07457
ports:
- '8545:8545'
command:
Expand Down
7 changes: 4 additions & 3 deletions tests/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from eth_utils.abi import collapse_if_tuple, function_abi_to_4byte_selector
from web3 import Web3

MAX_TRIES = 15
GATEWAY = "0x90F8bf6A479f320ead074411a4B0e7944Ea8c9C1"
GATEWAY_PK = "4f3edf983ac636a65a842ce7c78d9aa706d3b113bce9c46f30d7d21715b23b1d"

Expand Down Expand Up @@ -93,7 +94,7 @@ def increment_nonce(address, nonce_data):
return nonce_data


@backoff.on_exception(backoff.expo, Exception, max_tries=10)
@backoff.on_exception(backoff.expo, Exception, max_tries=MAX_TRIES)
def obtain_subgraph_info_backoff(endpoint, request_data, entity_to_check):
print(f"Checking subgraph data for {entity_to_check}")
resp = requests.post(endpoint, json=request_data)
Expand Down Expand Up @@ -130,7 +131,7 @@ def check_subgraph_transaction(
raise Exception(f"Subgraph expected info at amount incorrect")


@backoff.on_exception(backoff.expo, Exception, max_tries=10)
@backoff.on_exception(backoff.expo, Exception, max_tries=MAX_TRIES)
def check_subgraph_escrow_account(
sender, receiver, total_amount_thawing, balance, endpoint=subgraph_endpoint
):
Expand Down Expand Up @@ -176,7 +177,7 @@ def error_in_signer_data(signer_data, thawing, authorized):
return error


@backoff.on_exception(backoff.expo, Exception, max_tries=15)
@backoff.on_exception(backoff.expo, Exception, max_tries=MAX_TRIES)
def check_subgraph_signer(
signer, authorized, is_thawing, endpoint=subgraph_endpoint, test_net=False
):
Expand Down
21 changes: 9 additions & 12 deletions tests/local_contract_calls.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,20 +89,18 @@ class ReceiptAggregateVoucher(EIP712Message):
erc20.functions.transfer(SIGNER, 500).transact({"from": GATEWAY})
erc20.functions.transfer(RECEIVER, 500).transact({"from": GATEWAY})
except ContractCustomError as e:
print("Custom Error: %s" % e)
print(decode_custom_error(erc20_abi_json, str(e), w3))
raise ContractCustomError(decode_custom_error(erc20_abi_json, str(e), w3))
except ContractLogicError as e:
print("Logic Error: %s" % e)
raise ContractLogicError(f"Logic Error: {e}")

# MOCK STAKING CONTRACT CALLS
try:
print("Allocate receiver with allocationid")
mockStaking.functions.allocate(ALLOCATION_ID, RECEIVER).transact({"from": GATEWAY})
except ContractCustomError as e:
print("Custom Error: %s" % e)
print(decode_custom_error(mockStaking_abi_json, str(e), w3))
raise ContractCustomError(decode_custom_error(mockStaking_abi_json, str(e), w3))
except ContractLogicError as e:
print("Logic Error: %s" % e)
raise ContractLogicError(f"Logic Error: {e}")

# ESCROW CONTRACT CALLS
try:
Expand Down Expand Up @@ -163,7 +161,7 @@ class ReceiptAggregateVoucher(EIP712Message):
if "SignerAlreadyAuthorized" in error:
print("Skip, signer already authorized")
else:
print(error)
raise ContractCustomError(error)
check_subgraph_signer(SIGNER, True, False)

print("--- Executing deposit for redeem")
Expand Down Expand Up @@ -205,16 +203,15 @@ class ReceiptAggregateVoucher(EIP712Message):
print(f"Signer still thawing, time left: {time_left}")
time.sleep(time_left + 1)
else:
print(error)
raise ContractCustomError(error)
print("Done revoking")

check_subgraph_signer(SIGNER, False, False)

print("Transactions ran succesfully")
except ContractCustomError as e:
print("Custom Error: %s" % e)
print(decode_custom_error(escrow_abi_json, str(e), w3))
raise ContractCustomError(decode_custom_error(escrow_abi_json, str(e), w3))
except ContractLogicError as e:
print("Logic Error: %s" % e)
raise ContractLogicError(f"Logic Error: {e}")
except Exception as e:
print(e)
raise Exception(e)
3 changes: 2 additions & 1 deletion tests/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ eip712==0.2.1
eth-account==0.8.0
eth-utils==2.2.0
web3==6.8.0
requests==2.31.0
requests==2.31.0
backoff==2.2.1

0 comments on commit f4f7f21

Please sign in to comment.