Skip to content

Commit

Permalink
wait for finalization (#684)
Browse files Browse the repository at this point in the history
* wait for finalization

* Blend contracts e2e tests and deployment workflows into one workflow

* addressing comments

Co-authored-by: Mikolaj Gasior <mikolaj@gasior.dev>
  • Loading branch information
fbielejec and mikolajgs committed Oct 28, 2022
1 parent 4d504e1 commit cce8287
Show file tree
Hide file tree
Showing 6 changed files with 136 additions and 152 deletions.
16 changes: 11 additions & 5 deletions .github/scripts/check_finalization.sh
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
#!/bin/bash

RPC_HOST=127.0.0.1
RPC_PORT=9933
## USAGE
## .github/scripts/check_finalization.sh <rpc-host> <rpc-port>
## if <rpc-host> <rpc-port> <network> are empty default values will be used (127.0.0.1, 9933 and host)
##

RPC_HOST=${1:-127.0.0.1}
RPC_PORT=${2:-9933}
NETWORK=${3:-host}

LAST_FINALIZED=""
VALIDATOR=damian

while [[ "$LAST_FINALIZED" =~ "0x0" ]] || [[ -z "$LAST_FINALIZED" ]]; do
block_hash=$(docker run --network container:$VALIDATOR appropriate/curl:latest \
block_hash=$(docker run --network $NETWORK appropriate/curl:latest \
-H "Content-Type: application/json" \
-d '{"id":1, "jsonrpc":"2.0", "method": "chain_getFinalizedHead"}' http://$RPC_HOST:$RPC_PORT | jq '.result')
ret_val=$?
Expand All @@ -15,7 +21,7 @@ while [[ "$LAST_FINALIZED" =~ "0x0" ]] || [[ -z "$LAST_FINALIZED" ]]; do
continue
fi

finalized_block=$(docker run --network container:$VALIDATOR appropriate/curl:latest \
finalized_block=$(docker run --network $NETWORK appropriate/curl:latest \
-H "Content-Type: application/json" \
-d '{"id":1, "jsonrpc":"2.0", "method": "chain_getBlock", "params": ['$block_hash']}' http://$RPC_HOST:$RPC_PORT | jq '.result.block.header.number')

Expand Down
3 changes: 1 addition & 2 deletions .github/scripts/run_smartnet.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,5 @@ docker run --rm -v $(pwd)/docker/data:/data --entrypoint "/bin/sh" -e RUST_LOG=d
export BOOTNODE_PEER_ID=$(docker run --rm -v $(pwd)/docker/data:/data --entrypoint "/bin/sh" -e RUST_LOG=info "${NODE_IMAGE}" -c "aleph-node key inspect-node-key --file /data/$NODE_ID/p2p_secret")

docker network create node-network || true
docker-compose -f docker/smartnet-compose.yml up --remove-orphans

docker-compose -f docker/smartnet-compose.yml up --remove-orphans
exit $?
Original file line number Diff line number Diff line change
@@ -1,40 +1,142 @@
name: Deploy The Button game
name: contracts-e2e-tests-and-deploy

on:
pull_request:
types: [labeled]
paths:
- 'contracts/**'
- '.github/**'
push:
paths:
- 'contracts/**'
- '.github/**'
branches:
- benjamin
paths:
- contracts/**

concurrency:
group: ${{ github.workflow }}
cancel-in-progress: true

env:
CHECKOUT_REF: benjamin
CHECKOUT_BRANCH: benjamin
CACHE_KEY: fe-benjamin-button
CONTRACTS_ENVFILE: fe-benjamin
CARGOCONTRACT_REV: 2b1758756de59bd81e7bed5f8429d364f281cb9a
NODE_VERSION: 16
S3BUCKET_PATH: contracts/fe-benjamin-button
LABEL_DEPLOY_CONTRACTS: '[AZERO] DEPLOY-CONTRACTS'
LABEL_DESTROYED: 'DESTROYED'
LABEL_DEPLOYED: 'DEPLOYED'
LABEL_DEPLOYED_CONTRACTS: 'DEPLOYED-CONTRACTS'

jobs:
checkout_benjamin:
if: (github.event_name == 'push') || (github.event_name == 'pull_request' && github.event.action == 'labeled' && github.event.label.name == '[AZERO] DEPLOY-CONTRACTS')
run-tests:
name: Run smart contracts test suite
runs-on: ubuntu-20.04
env:
RUST_BACKTRACE: full
steps:
- name: Install binaryen
run: |
wget https://github.com/WebAssembly/binaryen/releases/download/version_101/binaryen-version_101-x86_64-linux.tar.gz
tar xvzf binaryen-version_101-x86_64-linux.tar.gz
cd binaryen-version_101
sudo cp -r bin/* /bin
sudo cp -r include/* /usr/include
sudo cp -r lib64/* /lib64
- name: Display binaryen version
shell: bash
run: wasm-opt --version

- name: Checkout Source code
uses: actions/checkout@v3

- name: Install Rust Toolchain
uses: actions-rs/toolchain@v1

- name: Install WASM target
run: rustup target add wasm32-unknown-unknown

- name: Install rust-src
run: rustup component add rust-src

- name: Restore cache
uses: ./.github/actions/restore-cache
with:
target-key: e2e-contracts
cargo-key: e2e-contracts
cache-version: v3
cargo-targets: e2e-tests-contracts/target/

- name: Install cargo-contract
run: |
cargo install cargo-dylint dylint-link --force
# revision merging Hans's PR changes [fix for node URL parsing ]
cargo install --git https://github.com/paritytech/cargo-contract.git --rev 2b1758756de59bd81e7bed5f8429d364f281cb9a --force
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_MAINNET_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_MAINNET_SECRET_ACCESS_KEY }}
aws-region: eu-central-1

- name: Login to Public Amazon ECR
id: login-public-ecr
uses: docker/login-action@v1
with:
registry: public.ecr.aws
username: ${{ secrets.AWS_MAINNET_ACCESS_KEY_ID }}
password: ${{ secrets.AWS_MAINNET_SECRET_ACCESS_KEY }}
env:
AWS_REGION: us-east-1

- name: Run one-node smartnet
shell: bash
run: |
.github/scripts/run_smartnet.sh &
- name: Display node logs
shell: bash
run: |
docker logs smartnode --follow &
# wait some while docker pulls the image and starts the node
- name: Wait for finalization
shell: bash
run: |
.github/scripts/check_finalization.sh
timeout-minutes: 1

- name: Run e2e tests
shell: bash
run: |
source ./contracts/env/dev && ./contracts/scripts/deploy.sh && ./contracts/scripts/test.sh
- name: Cleanup cache
uses: ./.github/actions/post-cache

slack:
name: Slack notification
runs-on: ubuntu-latest
needs: [run-tests]
if: always()
steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Send Slack message
uses: ./.github/actions/slack-notification
with:
notify-on: "failure"
env:
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }}

build_and_deploy_contracts:
name: Deploy contracts on feature environment
needs: [run-tests]
runs-on: ubuntu-20.04
#runs-on: self-hosted
steps:
- name: Checkout repo
uses: actions/checkout@v2.3.4
with:
ref: ${{ env.CHECKOUT_REF }}
ref: ${{ env.CHECKOUT_BRANCH }}

- name: Check if environment is reachable
shell: bash
Expand Down Expand Up @@ -103,15 +205,13 @@ jobs:
aws-region: ${{ env.AWS_REGION }}

- name: Get contracts' target directories cache from S3 bucket
if: (github.event_name == 'push') || (github.event_name == 'pull_request' && contains(github.event.pull_request.labels.*.name, env.LABEL_DEPLOYED_CONTRACTS))
shell: bash
continue-on-error: true
run: |
aws s3 cp s3://${{ secrets.CI_S3BUCKET_NAME }}/${{ env.S3BUCKET_PATH }}/targets.tgz targets.tgz
tar -xzf targets.tgz
- name: Copy metadata.json and addresses.json files from S3 bucket
if: (github.event_name == 'push') || (github.event_name == 'pull_request' && contains(github.event.pull_request.labels.*.name, env.LABEL_DEPLOYED_CONTRACTS))
shell: bash
run: |
aws s3 cp s3://${{ secrets.CI_S3BUCKET_NAME }}/${{ env.S3BUCKET_PATH }}/addresses.json contracts/addresses.json
Expand Down Expand Up @@ -179,28 +279,17 @@ jobs:
contracts/access_control/target
aws s3 cp targets.tgz s3://${{ secrets.CI_S3BUCKET_NAME }}/${{ env.S3BUCKET_PATH }}/targets.tgz
- name: Trigger Indexer deployment workflow
run: |
curl -X POST 'https://api.github.com/repos/Cardinal-Cryptography/indexer/actions/workflows/build-and-deploy-to-devnet.yml/dispatches' \
-H "Accept: application/vnd.github+json" \
-H 'Authorization: Bearer ${{ secrets.CI_GH_TOKEN }}' \
-d '{ "ref":"master" }'
- name: Trigger The Button deployment workflow
run: |
curl -X POST 'https://api.github.com/repos/Cardinal-Cryptography/the-button/actions/workflows/main.yaml/dispatches' \
-H "Accept: application/vnd.github+json" \
-H 'Authorization: Bearer ${{ secrets.CI_GH_TOKEN }}' \
-d '{ "ref":"main", "inputs": { "buildImage": "false", "deployImage": "true" }}'
- name: Add label to mark that contracts have been deployed
uses: actions-ecosystem/action-add-labels@v1.1.0
with:
labels: ${{ env.LABEL_DEPLOYED_CONTRACTS }}
github_token: ${{ secrets.CI_GH_TOKEN }}

- name: Remove request label if exists
if: contains(github.event.pull_request.labels.*.name, env.LABEL_DEPLOY_CONTRACTS)
uses: actions-ecosystem/action-remove-labels@v1.3.0
with:
labels: ${{ env.LABEL_DEPLOY_CONTRACTS }}
github_token: ${{ secrets.CI_GH_TOKEN }}

- name: Create empty target directory so that restore-cache does not fail
run: |
mkdir -p target
touch target/emptyfile
111 changes: 0 additions & 111 deletions .github/workflows/e2e-tests-contracts.yml

This file was deleted.

1 change: 0 additions & 1 deletion contracts/scripts/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,6 @@ ACCESS_CONTROL_PUBKEY=$(docker run --rm --entrypoint "/bin/sh" "${NODE_IMAGE}" -
echo "access control contract address: $ACCESS_CONTROL"
echo "access control contract public key \(hex\): $ACCESS_CONTROL_PUBKEY"


# --- UPLOAD CONTRACTS CODES

upload_contract TICKET_TOKEN_CODE_HASH ticket_token
Expand Down
2 changes: 2 additions & 0 deletions docker/smartnet-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ services:
- WS_PORT=9943
- BOOT_NODES=/ip4/127.0.0.1/tcp/30333/p2p/$BOOTNODE_PEER_ID
- PUBLIC_ADDR=/ip4/127.0.0.1/tcp/30333
- VALIDATOR_PORT=30343
- PUBLIC_VALIDATOR_ADDRESS=127.0.0.1:30343
volumes:
- ./data/:/data/
expose:
Expand Down

0 comments on commit cce8287

Please sign in to comment.