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

add e2e test workflow #369

Open
wants to merge 16 commits into
base: main
Choose a base branch
from
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 =
132 changes: 132 additions & 0 deletions .github/workflows/hardhat_e2e.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
name: HardHat E2E Test

on:
push:
branches:
- add-e2e-workflow

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: [21.x]

steps:
- name: Check Out Repository Code
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
with:
submodules: recursive
fetch-depth: 0

- 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

echo $rpcurl
echo $chainid

result=$(forge create --rpc-url $rpcurl --use 0.8.26 --optimize --optimizer-runs 30000 --legacy --json --private-key ${{ secrets.STORY_PRIVATEKEY }} test/foundry/mocks/token/MockERC721.sol:MockERC721 --constructor-args "MockERC" "MockERC" 2>&1)
echo $result
erc721=$(echo $result | grep deployedTo | jq -r '.deployedTo')
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: 1 addition & 1 deletion test/hardhat/e2e/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ export const RoyaltyPolicyLAP = "0x28b4F70ffE5ba7A26aEF979226f77Eb57fb9Fdb6";
export const RoyaltyPolicyLRP = "0x7D2d9af4E4ab14Afcfd86436BC348928B40963Dd";

// Mock ERC721 contract address
export const MockERC721 = process.env.DEVNET_ERC721 as string;
export const MockERC721 = process.env.STORY_ERC721 as string;
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
Loading