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 workflow - run e2e test #24

Closed
wants to merge 20 commits into from
62 changes: 62 additions & 0 deletions .github/workflows/run-e2e-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
name: Run E2E Test

on:
push:
branches: [ "main" ]

pull_request:
branches: [ "main" ]

workflow_dispatch:

jobs:
build:
runs-on: ubuntu-latest

strategy:
matrix:
node-version: [20.x]

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: Install Foundry
uses: foundry-rs/foundry-toolchain@v1

- name: Fork Sepolia
run: |
anvil --fork-url https://sepolia.infura.io/v3/2f7bda55539a457686c696e9b3be21f1 &

- name: Install Dependencies
run: |
npm install

- name: 'Create env file'
run: |
touch .env
echo WALLET_PRIVATE_KEY_A = ${{ secrets.WALLET_PRIVATE_KEY_A }} >> .env
echo WALLET_PRIVATE_KEY_B = ${{ secrets.WALLET_PRIVATE_KEY_B }} >> .env
echo WALLET_PRIVATE_KEY_C = ${{ secrets.WALLET_PRIVATE_KEY_C }} >> .env
echo SEPOLIA_MINTING_FEE_TOKEN = ${{ secrets.SEPOLIA_MINTING_FEE_TOKEN }} >> .env
echo SEPOLIA_RPC_PROVIDER_URL = http://localhost:8545 >> .env
echo SEPOLIA_NFT_CONTRACT_ADDRESS = ${{ vars.SEPOLIA_NFT_CONTRACT_ADDRESS }} >> .env
echo SEPOLIA_LICENSING_MODULE_ADDRESS = ${{ vars.SEPOLIA_LICENSING_MODULE_ADDRESS }} >> .env
echo SEPOLIA_ROYALTY_POLICY_LAP_ADDRESS = ${{ vars.SEPOLIA_ROYALTY_POLICY_LAP_ADDRESS }} >> .env
echo SEPOLIA_DISPUTE_MODULE_ADDRESS = ${{ vars.SEPOLIA_DISPUTE_MODULE_ADDRESS }} >> .env
cat .env

- name: Run E2E Test in Sepolia
run: |
npm run test:sepolia:e2e
- name: Upload Test Report
uses: actions/upload-artifact@v4
with:
name: sdk-sepolia-test-report
path: |
./mochawesome-report
63 changes: 63 additions & 0 deletions .github/workflows/run-full-regression-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
name: Run E2E Test

on:
push:
branches: [ "add-workflow" ]

pull_request:
branches: [ "main" ]

workflow_dispatch:

jobs:
build:
runs-on: ubuntu-latest

strategy:
matrix:
node-version: [20.x]

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: Install Foundry
uses: foundry-rs/foundry-toolchain@v1

- name: Fork Sepolia
run: |
anvil --fork-url https://sepolia.infura.io/v3/2f7bda55539a457686c696e9b3be21f1 &

- name: Install Dependencies
run: |
npm install

- name: 'Create env file'
run: |
touch .env
echo WALLET_PRIVATE_KEY_A = ${{ secrets.WALLET_PRIVATE_KEY_A }} >> .env
echo WALLET_PRIVATE_KEY_B = ${{ secrets.WALLET_PRIVATE_KEY_B }} >> .env
echo WALLET_PRIVATE_KEY_C = ${{ secrets.WALLET_PRIVATE_KEY_C }} >> .env
echo SEPOLIA_MINTING_FEE_TOKEN = ${{ secrets.SEPOLIA_MINTING_FEE_TOKEN }} >> .env
echo SEPOLIA_RPC_PROVIDER_URL = http://localhost:8545 >> .env
echo SEPOLIA_NFT_CONTRACT_ADDRESS = ${{ vars.SEPOLIA_NFT_CONTRACT_ADDRESS }} >> .env
echo SEPOLIA_LICENSING_MODULE_ADDRESS = ${{ vars.SEPOLIA_LICENSING_MODULE_ADDRESS }} >> .env
echo SEPOLIA_ROYALTY_POLICY_LAP_ADDRESS = ${{ vars.SEPOLIA_ROYALTY_POLICY_LAP_ADDRESS }} >> .env
echo SEPOLIA_DISPUTE_MODULE_ADDRESS = ${{ vars.SEPOLIA_DISPUTE_MODULE_ADDRESS }} >> .env
cat .env

- name: Run E2E Test in Sepolia
run: |
npm run test:sepolia

- name: Upload Test Report
uses: actions/upload-artifact@v4
with:
name: sdk-sepolia-test-report
path: |
./mochawesome-report
3 changes: 3 additions & 0 deletions config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export let royaltyPolicyLAPAddress: Hex;
export let royaltyApproveAddress: Hex;
export let mintingFeeTokenAddress: Hex;
export let arbitrationPolicyAddress: Hex;
export let disputeModuleAddress: Hex;
export let rpcProviderUrl: string;

if (String(TEST_ENV) === "sepolia") {
Expand All @@ -23,6 +24,7 @@ if (String(TEST_ENV) === "sepolia") {
royaltyApproveAddress = process.env.SEPOLIA_ROYALTY_ERC20 as Hex;
mintingFeeTokenAddress = process.env.SEPOLIA_MINTING_FEE_TOKEN as Hex;
arbitrationPolicyAddress = process.env.SEPOLIA_ARBITRATION_POLICY_ADDRESS as Hex;
disputeModuleAddress = process.env.SEPOLIA_DISPUTE_MODULE_ADDRESS as Hex;
} else if (String(TEST_ENV) === "storyTestnet") {
rpcProviderUrl = process.env.STORY_RPC_PROVIDER_URL as string;
licensingModuleAddress = process.env.STORY_LICENSING_MODULE_ADDRESS as Hex;
Expand All @@ -32,6 +34,7 @@ if (String(TEST_ENV) === "sepolia") {
royaltyApproveAddress = process.env.STORY_ROYALTY_ERC20 as Hex;
mintingFeeTokenAddress = process.env.STORY_MINTING_FEE_TOKEN as Hex;
arbitrationPolicyAddress = process.env.STORY_ARBITRATION_POLICY_ADDRESS as Hex;
disputeModuleAddress = process.env.STORY_DISPUTE_MODULE_ADDRESS as Hex;
} else {
throw new Error(`Unknown TEST_ENV value: ${TEST_ENV}`);
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"url": "https://github.com/storyprotocol/sdk-e2e-tests.git"
},
"dependencies": {
"@story-protocol/core-sdk": "1.0.0-rc.6",
"@story-protocol/core-sdk": "1.0.0-rc.10",
"viem": "^2.8.12"
},
"devDependencies": {
Expand Down
46 changes: 38 additions & 8 deletions test/dispute/resolveDispute.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { privateKeyA, nftContractAddress, arbitrationPolicyAddress } from '../../config/config';
import { mintNFTWithRetry, checkMintResult } from '../../utils/utils';
import { registerIpAsset, raiseDispute, cancelDispute, resolveDispute } from '../../utils/sdkUtils';
import { privateKeyA, nftContractAddress, arbitrationPolicyAddress, privateKeyC } from '../../config/config';
import { mintNFTWithRetry, checkMintResult, setDisputeJudgement, sleep } from '../../utils/utils';
import { registerIpAsset, raiseDispute, resolveDispute } from '../../utils/sdkUtils';
import { Hex } from 'viem';
import chai from 'chai';
import chaiAsPromised from 'chai-as-promised';
Expand All @@ -11,13 +11,13 @@ import '../setup';
let tokenIdA: string;
let ipIdA: Hex;
let disputeId1: string;
let disputeId2: string;

describe("SDK Test", function () {
describe("Test dispute.resolveDispute Function", async function () {
before("Register IP assets and raise disputes", async function () {
tokenIdA = await mintNFTWithRetry(privateKeyA);
checkMintResult(tokenIdA);
expect(tokenIdA).not.empty;

const responseRegisterIpAsset = await expect(
registerIpAsset("A", nftContractAddress, tokenIdA, true)
Expand All @@ -36,6 +36,15 @@ describe("SDK Test", function () {
expect(responseRaiseDispute1.disputeId).to.be.a("string").and.not.empty;

disputeId1 = responseRaiseDispute1.disputeId;

const responseRaiseDispute2 = await expect(
raiseDispute("B", ipIdA, arbitrationPolicyAddress, "test2", "PLAGIARISM", true)
).to.not.be.rejected;

expect(responseRaiseDispute2.txHash).to.be.a("string").and.not.empty;
expect(responseRaiseDispute2.disputeId).to.be.a("string").and.not.empty;

disputeId2 = responseRaiseDispute2.disputeId;
});

it("Resolve dispute fail as undefined disputeId", async function () {
Expand Down Expand Up @@ -72,18 +81,39 @@ describe("SDK Test", function () {
"Error: DisputeModule__NotDisputeInitiator()");
});

it("Resolve dispute with waitForTransaction: true", async function () {
it("Resolve dispute fail as not set judgement", async function () {
const response = await expect(
resolveDispute("B", disputeId1, "0x0000", true)
).to.be.rejectedWith("Failed to cancel dispute: The contract function \"resolveDispute\" reverted.",
"Error: DisputeModule__NotAbleToResolve()");
"Error: DisputeModule__NotAbleToResolve()");
});

it("Resolve dispute fail as judgement decision is false", async function () {
await setDisputeJudgement(privateKeyC, disputeId1, false, "0x");
await sleep(10);

const response = await expect(
resolveDispute("B", disputeId1, "0x0000", true)
).to.be.rejectedWith("Failed to cancel dispute: The contract function \"resolveDispute\" reverted.",
"Error: DisputeModule__NotAbleToResolve()");
});

it("Resolve dispute faile as already resolved", async function () {
const response = await expect(
resolveDispute("B", disputeId1, "0x0000", true)
resolveDispute("B", disputeId1, "0x0000", false)
).to.be.rejectedWith("Failed to cancel dispute: The contract function \"resolveDispute\" reverted.",
"Error: DisputeModule__NotDisputeInitiator()");
});

it("Resolve dispute with waitForTransaction: false", async function () {
await setDisputeJudgement(privateKeyC, disputeId2, true, "0x");
await sleep(10);

const response = await expect(
resolveDispute("B", disputeId2, "0x0000", false)
).to.not.be.rejected;

expect(response.txHash).to.be.a("string").and.not.empty;
});
});
});
});
Loading
Loading