diff --git a/.github/scripts/check_finalization.sh b/.github/scripts/check_finalization.sh index 36d21ad191..aa27fefe9d 100755 --- a/.github/scripts/check_finalization.sh +++ b/.github/scripts/check_finalization.sh @@ -1,12 +1,18 @@ #!/bin/bash -RPC_HOST=127.0.0.1 -RPC_PORT=9933 +## USAGE +## .github/scripts/check_finalization.sh +## if 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=$? @@ -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') diff --git a/.github/scripts/run_smartnet.sh b/.github/scripts/run_smartnet.sh index 25f81fc103..d2b1b23a71 100755 --- a/.github/scripts/run_smartnet.sh +++ b/.github/scripts/run_smartnet.sh @@ -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 $? diff --git a/.github/workflows/deploy-the-button.yaml b/.github/workflows/contracts-e2e-tests-and-deploy.yaml similarity index 64% rename from .github/workflows/deploy-the-button.yaml rename to .github/workflows/contracts-e2e-tests-and-deploy.yaml index 2fe39096fb..8c14550c1f 100644 --- a/.github/workflows/deploy-the-button.yaml +++ b/.github/workflows/contracts-e2e-tests-and-deploy.yaml @@ -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 @@ -103,7 +205,6 @@ 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: | @@ -111,7 +212,6 @@ jobs: 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 @@ -179,6 +279,13 @@ 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' \ @@ -186,21 +293,3 @@ jobs: -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 - diff --git a/.github/workflows/e2e-tests-contracts.yml b/.github/workflows/e2e-tests-contracts.yml deleted file mode 100644 index 0840531f52..0000000000 --- a/.github/workflows/e2e-tests-contracts.yml +++ /dev/null @@ -1,111 +0,0 @@ -name: e2e-tests-contracts - -on: - pull_request: - paths: - - 'contracts/**' - push: - paths: - - 'contracts/**' - workflow_dispatch: - -concurrency: - group: ${{ github.ref }}-${{ github.workflow }} - cancel-in-progress: true - -jobs: - run-tests: - name: Run smart contracts test suite - runs-on: ubuntu-latest - 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 & - - # wait some while docker pulls the image and starts the node - - name: Sleep for a while - shell: bash - run: sleep 2 - - - 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 }} diff --git a/contracts/scripts/deploy.sh b/contracts/scripts/deploy.sh index 8fdc148c02..7f6e25e5b1 100755 --- a/contracts/scripts/deploy.sh +++ b/contracts/scripts/deploy.sh @@ -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 diff --git a/docker/smartnet-compose.yml b/docker/smartnet-compose.yml index 2bd1f0394d..4733ebb9c2 100644 --- a/docker/smartnet-compose.yml +++ b/docker/smartnet-compose.yml @@ -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: