From f4f7f21bc4a97af4074a75a9588137b8b9b8db54 Mon Sep 17 00:00:00 2001 From: "carlos.vdr" Date: Mon, 23 Oct 2023 13:45:56 -0600 Subject: [PATCH] test: Added Github actions for testing local calls Signed-off-by: carlos.vdr --- .github/workflows/local_tests.yml | 46 +++++++++++++++++++++++++++++++ tests/contract_init.sh | 7 ++--- tests/docker-compose.yml | 4 +-- tests/helpers.py | 7 +++-- tests/local_contract_calls.py | 21 ++++++-------- tests/requirements.txt | 3 +- 6 files changed, 65 insertions(+), 23 deletions(-) create mode 100644 .github/workflows/local_tests.yml diff --git a/.github/workflows/local_tests.yml b/.github/workflows/local_tests.yml new file mode 100644 index 0000000..503b7e4 --- /dev/null +++ b/.github/workflows/local_tests.yml @@ -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 \ No newline at end of file diff --git a/tests/contract_init.sh b/tests/contract_init.sh index 29c82a4..d9d90bf 100755 --- a/tests/contract_init.sh +++ b/tests/contract_init.sh @@ -1,4 +1,5 @@ #!/bin/bash +set -e GATEWAY=0x90F8bf6A479f320ead074411a4B0e7944Ea8c9C1 SIGNER=0xFFcf8FDEE72ac11b5c542428B35EEF5769C409f0 @@ -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) @@ -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" \ No newline at end of file diff --git a/tests/docker-compose.yml b/tests/docker-compose.yml index a1b0864..d14787f 100644 --- a/tests/docker-compose.yml +++ b/tests/docker-compose.yml @@ -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' @@ -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: diff --git a/tests/helpers.py b/tests/helpers.py index 32fcbe8..b0d01d6 100644 --- a/tests/helpers.py +++ b/tests/helpers.py @@ -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" @@ -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) @@ -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 ): @@ -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 ): diff --git a/tests/local_contract_calls.py b/tests/local_contract_calls.py index f9b6be6..725448a 100644 --- a/tests/local_contract_calls.py +++ b/tests/local_contract_calls.py @@ -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: @@ -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") @@ -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) diff --git a/tests/requirements.txt b/tests/requirements.txt index cf1cadf..688860b 100644 --- a/tests/requirements.txt +++ b/tests/requirements.txt @@ -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 \ No newline at end of file +requests==2.31.0 +backoff==2.2.1 \ No newline at end of file