diff --git a/.env.example b/.env.example index 6576cd5c..a099c014 100644 --- a/.env.example +++ b/.env.example @@ -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 = diff --git a/.github/workflows/hardhat_e2e.yml b/.github/workflows/hardhat_e2e.yml new file mode 100644 index 00000000..82add9cf --- /dev/null +++ b/.github/workflows/hardhat_e2e.yml @@ -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 + diff --git a/hardhat.config.ts b/hardhat.config.ts index ad78b862..f9c85dd8 100644 --- a/hardhat.config.ts +++ b/hardhat.config.ts @@ -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({ @@ -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, diff --git a/test/hardhat/e2e/constants.ts b/test/hardhat/e2e/constants.ts index 3c101540..d9d8e22c 100644 --- a/test/hardhat/e2e/constants.ts +++ b/test/hardhat/e2e/constants.ts @@ -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; diff --git a/test/hardhat/e2e/setup.ts b/test/hardhat/e2e/setup.ts index 30c2f8c2..d4c5bcec 100644 --- a/test/hardhat/e2e/setup.ts +++ b/test/hardhat/e2e/setup.ts @@ -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;