Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BLOCK-2590 - Deploy EVM contract #4

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions .github/workflows/generate_code_hash.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#!/usr/bin/env bash
set -eo pipefail

# Run nodeos if not
get_info=$(cleos get info && echo 1 || echo 0)
if [ $get_info == 0 ]; then
nodeos -e -p eosio --plugin eosio::chain_api_plugin --delete-all-blocks >> nodeos.log 2>&1 &
sleep 5
fi

SCRIPT_DIR=$(dirname "$0")
CONTRACTS_DIR=$SCRIPT_DIR/../../build/evm_runtime
HASH_FILE=$CONTRACTS_DIR/hash.txt

if [ ! -d "$CONTRACTS_DIR" ]; then
echo "Directory $CONTRACTS_DIR does not exist. Please run ./build.sh first."
exit 1
fi

ABI_FILES=$(find $CONTRACTS_DIR -type f -name "*.abi")
WASM_FILES=$(find $CONTRACTS_DIR -type f -name "*.wasm" -not -name "CMake*")

if [ ! -z "$WASM_FILES" ]; then
> $HASH_FILE
else
echo "No .wasm file is found."
exit 1
fi

for abiFile in $ABI_FILES
do
CONTRACT_JSON=$(cleos set abi eosio $abiFile -p eosio -d --suppress-duplicate-check -j -s)
ABIHEX=$(echo $CONTRACT_JSON | jq '.actions[] | select (.name=="setabi")' | jq -r '.data')
ABIHASH=$(cleos convert unpack_action_data eosio setabi "$ABIHEX" | jq -r '.abi' | xxd -r -p | sha256sum | cut -d " " -f1)

if [ ! -z "$ABIHASH" ]; then
echo "`basename $abiFile`: $ABIHASH" >> $HASH_FILE
fi
done

for file in $WASM_FILES
do
hash=$(od -An -vtx1 $file | xxd -r -p | sha256sum | cut -d " " -f1)
name=${file##*/}
# name=${name%.*}
if [ ! -z "$hash" ]; then
echo "$name: $hash" >> $HASH_FILE
fi
done


echo "-- Contracts code hash have been written to: $HASH_FILE"
pkill nodeos
122 changes: 121 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,124 @@ jobs:
uses: peter-murray/workflow-application-token-action@v2
with:
application_id: ${{ secrets.APPLICATION_ID }}
application_private_key: ${{ secrets.APPLICATION_PRIVATE_KEY }}
application_private_key: ${{ secrets.APPLICATION_PRIVATE_KEY }}

- name: "Set env vars"
run: |
echo "EOSIO_VERSION=${{ github.event.inputs.eosio }}" >> $GITHUB_ENV
echo "RELEASE_VERSION=${{ github.event.inputs.contracts }}" >> $GITHUB_ENV
echo "CDT_TAG=${{ github.event.inputs.cdt-tag }}" >> $GITHUB_ENV
echo "CDT_VERSION=${{ github.event.inputs.cdt-tag }}" >> $GITHUB_ENV
echo "ULTRA_PATH=/__w/eos-evm-contract/eos-evm-contract/ultra/" >> $GITHUB_ENV

# Update dependencies
- name: 'Update dependencies'
run: |
apt-get update -y \
&& apt-get install tree clang jq xxd -y

- name: Checkout Repo
uses: actions/checkout@v4
with:
fetch-depth: 0
submodules: 'recursive'
ref: '${{ env.RELEASE_VERSION }}'

# Download the EOSIO.CDT Deb
- name: Download EOSIO.CDT Debian Image
uses: Legion2/[email protected]
with:
repository: ultraio/eosio.cdt
tag: '${{ github.event.inputs.cdt-tag }}'
path: ./ultra
file: eosio-cdt-${{ env.CDT_TAG }}.deb
token: '${{ steps.application_token.outputs.token }}'

# Install EOSIO.CDT Debian Image
- name: Install EOSIO.CDT Debian Image
run: apt install ./ultra/eosio-cdt-${{ env.CDT_TAG }}.deb -y

- name: Check EOSIO.CDT Install
run: cdt-cpp --version

# Download the EOSIO Deb
- name: Download EOSIO Debian Image
uses: Legion2/[email protected]
with:
repository: ultraio/eosio
tag: '${{ github.event.inputs.eosio }}'
path: ./ultra
file: eosio-${{ env.EOSIO_VERSION }}.deb
token: '${{ steps.application_token.outputs.token }}'

# Install EOSIO Debian Image
- name: Install EOSIO Debian Image
run: apt install ./ultra/eosio-${{ env.EOSIO_VERSION }}.deb -y

- name: Run nodeos
run: |
nodeos -e -p eosio \
--plugin eosio::chain_api_plugin \
--resource-monitor-not-shutdown-on-threshold-exceeded \
--delete-all-blocks >> nodeos.log 2>&1 &
sleep 5
tail -20 ./nodeos.log

# Check if the hash generator is present in build script.
- name: Check if code hash generator is existed
working-directory: ./
id: main
continue-on-error: true
run: |
echo HAS_HASH_GENERATION=$(test -e ./.github/workflows/generate_code_hash.sh && echo 1 || echo 0) >> $GITHUB_ENV
echo ${{ env.HAS_HASH_GENERATION }}

- name: Download hash generation script if it is missing
if: ${{ env.HAS_HASH_GENERATION == 0 }}
working-directory: ./
run: |
wget 'https://raw.githubusercontent.com/ultraio/eos-evm-contract/refs/heads/feature/BLOCK-2590-deploy-evm-contract-develop/.github/workflows/generate_code_hash.sh' -O ./.github/workflows/generate_code_hash.sh
chmod +x ./.github/workflows/generate_code_hash.sh

- name: Build EOS EVM Contract
run: .github/workflows/build-contract.sh
env:
DWITH_TEST_ACTIONS: false

# Build EOSIO.CONTRACTS Repository
# This one builds with the -g tag when it is present.
- name: Code Hash Generations
working-directory: ./
run: |
./.github/workflows/generate_code_hash.sh
sed 's/^/* /;s/$//' ./build/evm_runtime/hash.txt >> ./CHANGELOG.txt
mv ./build/evm_runtime/hash.txt ./build/evm_runtime/eos-evm-contract-${{ env.RELEASE_VERSION }}-hash.txt

- name: ZIP Contracts and rename code hash
working-directory: ./build/evm_runtime
run: |
rm -rf ./CMakeFiles
find ../evm_runtime -type f \( -name \*\.abi -o -name \*\.wasm \) | xargs tar -rf eos-evm-contract-${{ env.RELEASE_VERSION }}.tar.gz
sha256sum ./eos-evm-contract-${{ env.RELEASE_VERSION }}.tar.gz > eos-evm-contract-${{ env.RELEASE_VERSION }}-checksum.txt

- name: Rename build directory archive
run: |
ls -l
mv ./contract.tar.gz ./build.tar.gz

- name: Release with Code Hashes
uses: ultraio/action-gh-release@master
env:
GITHUB_TOKEN: ${{ steps.application_token.outputs.token }}
with:
name: Release ${{ env.RELEASE_VERSION }}
tag_name: ${{ env.RELEASE_VERSION }}
files: |
./build/evm_runtime/eos-evm-contract-${{ env.RELEASE_VERSION }}.tar.gz
./build/evm_runtime/*-checksum.txt
./build/evm_runtime/*-hash.txt
./build.tar.gz
body_path: ./CHANGELOG.txt
retries: 3
retry_interval: 1000
delete_on_existing: true
170 changes: 170 additions & 0 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
name: "Validate build and run tests"
on:
pull_request:
types:
- opened
- synchronize
- reopened

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

jobs:
# start-runner:
# name: Start Runner
# runs-on: ubuntu-latest
# steps:
# - name: Get Token
# id: application_token
# uses: peter-murray/workflow-application-token-action@v2
# with:
# application_id: ${{ secrets.APPLICATION_ID }}
# application_private_key: ${{ secrets.APPLICATION_PRIVATE_KEY }}

# - name: Trigger start-runner job
# uses: convictional/[email protected]
# with:
# owner: ultraio
# repo: blockchain-manager
# github_token: ${{ steps.application_token.outputs.token }}
# workflow_file_name: start-runner.yml
# job-cleanup:
# needs: start-runner
# name: "Cleanup"
# timeout-minutes: 5
# runs-on: "self-hosted"
# steps:
# - name: "Cleanup Previous Run"
# run: |
# sudo rm -rf ./* || true
# sudo rm -rf ./.??* || true
# sudo rm -rf $GITHUB_WORKSPACE || true
# mkdir $GITHUB_WORKSPACE
build-contracts:
name: "Build contracts and run tests"
timeout-minutes: 10
runs-on: ubuntu-latest
container:
# This repository can be found / pushed to in: ultraio/eosio-docker-starter
image: quay.io/ultra.io/eosio-docker-starter:5.0.0
options: >-
--init
--cpus 2
permissions:
contents: 'read'
id-token: 'write'
steps:
- name: Get Token
id: application_token
uses: peter-murray/workflow-application-token-action@v2
with:
application_id: ${{ secrets.APPLICATION_ID }}
application_private_key: ${{ secrets.APPLICATION_PRIVATE_KEY }}

- name: "Set env vars"
run: |
echo "ULTRA_PATH=/__w/eos-evm-contract/eos-evm-contract/ultra/" >> $GITHUB_ENV
# Update dependencies
- name: 'Update dependencies'
run: |
apt-get update -y \
&& apt-get install tree clang jq xxd -y
- name: Checkout Repo
uses: actions/checkout@v4
with:
fetch-depth: 0
submodules: 'recursive'

# Download latest version of CDT from releases
- uses: robinraju/[email protected]
with:
repository: "ultraio/eosio.cdt"
latest: true
fileName: "*.deb"
out-file-path: "./ultra/cdt"
token: '${{ steps.application_token.outputs.token }}'

# Install EOSIO.CDT Debian Image
- name: Install EOSIO.CDT Debian Image
run: apt install ./ultra/cdt/*.deb -y

- name: Build EOS EVM Contract
run: .github/workflows/build-contract.sh
env:
DWITH_TEST_ACTIONS: true

# Clone eosio.contracts repository
- uses: actions/checkout@v3
name: 'Clone eosio.contracts'
with:
repository: 'ultraio/eosio.contracts'
token: '${{ steps.application_token.outputs.token }}'
path: './ultra/eosio.contracts'
submodules: 'recursive'
fetch-depth: 0
ref: 'master'

# Download latest `eosio.contracts` release
- uses: robinraju/[email protected]
with:
repository: "ultraio/eosio.contracts"
latest: true
fileName: "*.tar.gz"
out-file-path: "./ultra/eosio.contracts"
token: '${{ steps.application_token.outputs.token }}'

- name: Extract eosio.contracts.tar.gz
run: |
mkdir -p ./ultra/eosio.contracts/build
tar -xf ./ultra/eosio.contracts/eosio-contracts-*.tar.gz -C ./ultra/eosio.contracts/build
# Download latest eosio
- name: Download latest eosio
uses: dsaltares/fetch-gh-release-asset@master
with:
repo: 'ultraio/eosio'
regex: true
# match eosio-***.deb
# don't match eosio-***-ubuntu20.deb
file: eosio-.*\.deb(?<!ubuntu20\.deb)$
token: '${{ steps.application_token.outputs.token }}'

# Install EOSIO Debian Image
- name: Install EOSIO Debian Image
run: |
ls -l
dpkg -i ./eosio*.deb

- uses: actions/setup-node@v3
with:
node-version: 20

- name: "Extract branch name"
run: |
GIT_BRANCH=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}
echo "branch=$GIT_BRANCH" >> $GITHUB_OUTPUT
id: extract_branch

- name: "Clone Ultratest2 with main"
uses: actions/checkout@v3
with:
repository: "ultraio/ultratest2"
token: "${{ steps.application_token.outputs.token }}"
path: "./ultra/ultratest2"
fetch-depth: 0
ref: "main"

- name: "Check if ultratest2 has branch with the same name"
continue-on-error: true
run: cd ./ultra/ultratest2 && git checkout ${{ steps.extract_branch.outputs.branch }}

- name: Install ultratest2
working-directory: ./ultra/ultratest2
run: |
npm install
npm link --force
- name: Run eosio.contracts ultratests2
if: always() && !cancelled()
working-directory: ./ultratests
shell: bash
run: ultratest2 --contracts-dir-path=$ULTRA_PATH/eosio.contracts/build/contracts
13 changes: 13 additions & 0 deletions ultratests/evmSetup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,19 @@ export class EvmContractHelpers {
},
]);
}

async open(owner: string): Promise<SignerLibTransactResponse> {
return await this.parent.transactOrThrow([
{
account: 'eosio.evm',
name: 'open',
data: {
owner: owner
},
authorization: [{ actor: owner, permission: 'active' }],
},
]);
}
}

export default function evmSetup(): Plugin {
Expand Down
Loading
Loading