Skip to content

Commit

Permalink
add e2e test workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
tyitang committed Dec 27, 2024
1 parent 23afff8 commit a760443
Show file tree
Hide file tree
Showing 4 changed files with 141 additions and 14 deletions.
12 changes: 6 additions & 6 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ TENDERLY_PRIVATEKEY =
ETHERSCAN_API_KEY = ETHERSCANAPIKEYETHERSCANAPIKEY

# TESTNET
DEVNET_URL = http://
DEVNET_CHAINID = 1315
DEVNET_PRIVATEKEY =
DEVNET_USER1 =
DEVNET_USER2 =
DEVNET_ERC721 =
STORY_URL = http://
STORY_CHAINID = 1315
STORY_PRIVATEKEY =
STORY_USER1 =
STORY_USER2 =
STORY_ERC721 =
125 changes: 125 additions & 0 deletions .github/workflows/hardhat_e2e.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
name: HardHat E2E Test

on:
# pull_request:
# branches:
# - main
workflow_dispatch:
inputs:
devnet_version:
description: 'devnet; mainnet;'
required: true
default: 'devnet'
type: choice
options:
- devnet
- mainnet

workflow_call:
inputs:
devnet_version:
description: 'devnet; mainnet;'
required: false
default: 'devnet'
type: string
jobs:
print-config:
runs-on: ubuntu-latest

steps:
- name: Print Inputs
run: |
echo "Inputs:"
echo "devnet_version: ${{ inputs.devnet_version || github.event.inputs.devnet_version || 'devnet' }}"
build:
runs-on: ubuntu-latest

strategy:
matrix:
node-version: [20.0.0]

steps:
- name: Check Out Repository Code
uses: actions/checkout@v4

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}

- name: Run install
uses: borales/actions-yarn@v4
with:
cmd: install # will run `yarn install` command

- name: Install Foundry
uses: foundry-rs/foundry-toolchain@v1
with:
version: nightly

- name: 'Create env file'
run: |
touch .env
echo "MAINNET_PRIVATEKEY=${{ secrets.STORY_PRIVATEKEY }}" >> .env
echo "SEPOLIA_PRIVATEKEY=${{ secrets.STORY_PRIVATEKEY }}" >> .env
echo "STORY_PRIVATEKEY=${{ secrets.STORY_PRIVATEKEY }}" >> .env
echo "STORY_USER1=${{ secrets.STORY_USER1 }}" >> .env
echo "STORY_USER2=${{ secrets.STORY_USER1 }}" >> .env
- name: Deploy MockERC721 Contract
run: |
devnet_version=${{ inputs.devnet_version || github.event.inputs.devnet_version || 'devnet' }}
if [[ "$devnet_version" == "devnet" ]]; then
rpcurl = "http://r1-d.odyssey-devnet.storyrpc.io:8545"
chainid = 1315
else
rpcurl = "https://public.storyrpc.io"
chainid = 1514
fi
result=$(forge create --rpc-url $rpcurl --optimize --optimizer-runs 30000 --private-key ${{ secrets.STORY_PRIVATEKEY }} test/foundry/mocks/token/MockERC721.sol:MockERC721 --constructor-args "MockERC" "MockERC" --legacy 2>&1)
echo $result
erc721 = $(echo $result | grep "Deployed to:" | cut -d ":" -f 2 | tr -d ' ')
echo $erc721
echo "STORY_URL=$rpcurl" >> .env
echo "STORY_CHAINID=$chainid" >> .env
echo "STORY_ERC721=$erc721" >> .env
# add one more blank line to .env
echo "" >> .env
- name: Run test
run: |
npx hardhat test --network odyssey
- name: Upload Test Report
uses: actions/upload-artifact@v4
with:
name: poc-test-report
path: |
./mochawesome-report
if: always()

- name: Copy report to date folder
id: create_folder
run: |
folder_name=$(date +%Y%m%d)
echo "Folder name: $folder_name"
# Determine version_name based on devnet_version
env_name=${{ inputs.devnet_version || github.event.inputs.devnet_version || 'devnet' }}
mkdir -p ./tmp/$folder_name/$env_name
cp -R ./mochawesome-report/* ./tmp/$folder_name/$env_name
- name: Deploy report to GitHub Pages
if: ${{ inputs.deploy_report == 'true' }}
uses: peaceiris/actions-gh-pages@v4
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./tmp
publish_branch: gh-pages
keep_files: true

16 changes: 8 additions & 8 deletions hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ const USE_TENDERLY = process.env.USE_TENDERLY === "true"
const ETHERSCAN_API_KEY = process.env.ETHERSCAN_API_KEY || "key"
const COINMARKETCAP_API_KEY = process.env.COINMARKETCAP_API_KEY || "key"

const DEVNET_URL = process.env.DEVNET_URL || "http://"
const DEVNET_CHAINID = Number(process.env.DEVNET_CHAINID) || 1513
const DEVNET_PRIVATEKEY = process.env.DEVNET_PRIVATEKEY || "0xkey"
const DEVNET_USER1 = process.env.DEVNET_USER1 || "0xkey"
const DEVNET_USER2 = process.env.DEVNET_USER2 || "0xkey"
const STORY_URL = process.env.STORY_URL || "http://"
const STORY_CHAINID = Number(process.env.STORY_CHAINID) || 1513
const STORY_PRIVATEKEY = process.env.STORY_PRIVATEKEY || "0xkey"
const STORY_USER1 = process.env.STORY_USER1 || "0xkey"
const STORY_USER2 = process.env.STORY_USER2 || "0xkey"

if (USE_TENDERLY) {
tdly.setup({
Expand Down Expand Up @@ -70,9 +70,9 @@ const config: HardhatUserConfig = {
chainId: 31337,
},
odyssey: {
chainId: DEVNET_CHAINID,
url: DEVNET_URL,
accounts: [DEVNET_PRIVATEKEY, DEVNET_USER1, DEVNET_USER2],
chainId: STORY_CHAINID,
url: STORY_URL,
accounts: [STORY_PRIVATEKEY, STORY_USER1, STORY_USER2],
},
localhost: {
chainId: 31337,
Expand Down
2 changes: 2 additions & 0 deletions test/hardhat/e2e/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ before(async function () {

console.log(`================= Load Users =================`);
[this.owner, this.user1, this.user2] = await hre.ethers.getSigners();
await this.owner.sendTransaction({ to: this.user1.address, value: hre.ethers.parseEther("10") });
await this.owner.sendTransaction({ to: this.user2.address, value: hre.ethers.parseEther("10") });

console.log(`================= Chain ID =================`);
const networkConfig = network.config;
Expand Down

0 comments on commit a760443

Please sign in to comment.