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

Update IPAsset tests to support new interface #31

Open
wants to merge 5 commits into
base: main
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
25 changes: 9 additions & 16 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,12 @@ WALLET_PRIVATE_KEY_A=0x0000000000000000000000000000000000000000
WALLET_PRIVATE_KEY_B=0x0000000000000000000000000000000000000000
WALLET_PRIVATE_KEY_C=0x0000000000000000000000000000000000000000

STORY_RPC_PROVIDER_URL=https://story-network.rpc.caldera.xyz/http
STORY_NFT_CONTRACT_ADDRESS=0x0000000000000000000000000000000000000000
STORY_LICENSING_MODULE_ADDRESS=0x0000000000000000000000000000000000000000
STORY_ROYALTY_POLICY_ADDRESS=0x0000000000000000000000000000000000000000
STORY_MINTING_FEE_TOKEN=0x0000000000000000000000000000000000000000
STORY_ROYALTY_POLICY_LAP_ADDRESS=0x0000000000000000000000000000000000000000
STORY_ROYALTY_ERC20=0x0000000000000000000000000000000000000000
STORY_ARBITRATION_POLICY_ADDRESS=0x0000000000000000000000000000000000000000

SEPOLIA_RPC_PROVIDER_URL=https://rpc-sepolia.rockx.com
SEPOLIA_NFT_CONTRACT_ADDRESS=0x0000000000000000000000000000000000000000
SEPOLIA_LICENSING_MODULE_ADDRESS=0x0000000000000000000000000000000000000000
SEPOLIA_ROYALTY_POLICY_ADDRESS=0x0000000000000000000000000000000000000000
SEPOLIA_MINTING_FEE_TOKEN=0x0000000000000000000000000000000000000000
SEPOLIA_ROYALTY_POLICY_LAP_ADDRESS=0x0000000000000000000000000000000000000000
SEPOLIA_ARBITRATION_POLICY_ADDRESS=0x0000000000000000000000000000000000000000
RPC_PROVIDER_URL=https://odyssey.storyrpc.io
MOCK_ERC721_ADDRESS=0x0000000000000000000000000000000000000000
LICENSING_MODULE_ADDRESS=0x0000000000000000000000000000000000000000
ROYALTY_POLICY_LAP_ADDRESS=0x0000000000000000000000000000000000000000
MOCK_ERC20_ADDRESS=0x0000000000000000000000000000000000000000
IPASSET_REGISTRY_ADDRESS=0x0000000000000000000000000000000000000000
ARBITRATION_POLICY_ADDRESS=
DISPUTE_MODULE_ADDRESS=0x0000000000000000000000000000000000000000
LICENSE_TEMPLATE_ADDRESS=0x0000000000000000000000000000000000000000
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ dist
dist-ssr
*.local
.env
test-reports

# Editor directories and files
.vscode/*
Expand Down
91 changes: 38 additions & 53 deletions config/config.ts
Original file line number Diff line number Diff line change
@@ -1,49 +1,44 @@
import { Hex, http, Address, Chain, defineChain } from "viem";
import { Hex, http, Address, defineChain, Chain } from "viem";
import { privateKeyToAccount } from "viem/accounts";
import { StoryClient, StoryConfig } from "@story-protocol/core-sdk";
import { SupportedChainIds } from "@story-protocol/core-sdk/dist/declarations/src/types/config";

const TEST_ENV = process.env.TEST_ENV as SupportedChainIds;

export let licensingModuleAddress: Hex;
export let licenseTokenAddress: Hex;
export let nftContractAddress: Hex;
export let royaltyPolicyAddress: Hex;
export let royaltyPolicyLAPAddress: Hex;
export let royaltyApproveAddress: Hex;
export let mintingFeeTokenAddress: Hex;
export let mockERC20Address: Hex;
export let arbitrationPolicyAddress: Hex;
export let disputeModuleAddress: Hex;
export let ipAssetRegistryAddress: Hex;
export let licenseTemplateAddress: Hex;
export let rpcProviderUrl: string;
export let chainId: number;

if (String(TEST_ENV) === "sepolia") {
chainId = 11155111;
rpcProviderUrl = process.env.SEPOLIA_RPC_PROVIDER_URL as string;
licensingModuleAddress = process.env.SEPOLIA_LICENSING_MODULE_ADDRESS as Hex;
licenseTokenAddress = process.env.SEPOLIA_LICENSE_TOKEN_ADDRESS as Hex;
nftContractAddress = process.env.SEPOLIA_MOCK_ERC721_ADDRESS as Hex;
royaltyPolicyAddress = process.env.SEPOLIA_ROYALTY_POLICY_ADDRESS as Hex;
royaltyPolicyLAPAddress = process.env.SEPOLIA_ROYALTY_POLICY_LAP_ADDRESS as Hex;
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;
ipAssetRegistryAddress = process.env.SEPOLIA_IPASSET_REGISTRY_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;
nftContractAddress = process.env.STORY_MOCK_ERC721_ADDRESS as Hex;
royaltyPolicyAddress = process.env.STORY_ROYALTY_POLICY_ADDRESS as Hex;
royaltyPolicyLAPAddress = process.env.STORY_ROYALTY_POLICY_LAP_ADDRESS as Hex;
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;
ipAssetRegistryAddress = process.env.STORY_IPASSET_REGISTRY_ADDRESS as Hex;
disputeModuleAddress = process.env.STORY_DISPUTE_MODULE_ADDRESS as Hex;
} else {
throw new Error(`Unknown TEST_ENV value: ${TEST_ENV}`);
chainId = 1516;
rpcProviderUrl = process.env.RPC_PROVIDER_URL as string;
licensingModuleAddress = process.env.LICENSING_MODULE_ADDRESS as Hex;
licenseTokenAddress = process.env.LICENSING_TOKEN_ADDRESS as Hex;
nftContractAddress = process.env.MOCK_ERC721_ADDRESS as Hex;
royaltyPolicyAddress = process.env.SEPOLIA_ROYALTY_POLICY_ADDRESS as Hex;
royaltyPolicyLAPAddress = process.env.ROYALTY_POLICY_LAP_ADDRESS as Hex;
royaltyApproveAddress = process.env.MOCK_ERC20_ADDRESS as Hex;
mockERC20Address = process.env.MOCK_ERC20_ADDRESS as Hex;
arbitrationPolicyAddress = process.env.ARBITRATION_POLICY_ADDRESS as Hex;
disputeModuleAddress = process.env.DISPUTE_MODULE_ADDRESS as Hex;
ipAssetRegistryAddress = process.env.IPASSET_REGISTRY_ADDRESS as Hex;
licenseTemplateAddress = process.env.LICENSE_TEMPLATE_ADDRESS as Hex;

export function chainStringToViemChain(chainId: SupportedChainIds): Chain {
switch (chainId.toString()) {
case "1516":
case "odyssey":
return odyssey;
default:
throw new Error(`chainId ${chainId as string} not supported`);
}
}

export const privateKeyA = process.env.WALLET_PRIVATE_KEY_A as Hex;
Expand All @@ -56,54 +51,44 @@ export const accountC = privateKeyToAccount(privateKeyC as Address);

export const configA: StoryConfig = {
account: accountA,
chainId: TEST_ENV,
transport: http(rpcProviderUrl),
}

export const configB: StoryConfig = {
account: accountB,
chainId: TEST_ENV,
transport: http(rpcProviderUrl),
}

export const configC: StoryConfig = {
account: accountC,
chainId: TEST_ENV,
transport: http(rpcProviderUrl),
}

export const clientA = StoryClient.newClient(configA)
export const clientB = StoryClient.newClient(configB)
export const clientC = StoryClient.newClient(configC)

export function chainStringToViemChain(chainId: SupportedChainIds): Chain {
switch (chainId) {
case "sepolia":
// case "storyTestnet":
// return storyTestnet;
default:
throw new Error(`chainId ${chainId as string} not supported`);
}
}

export const storyTestnet = defineChain({
id: 15_13,
name: "story-network",
nativeCurrency: { name: "Ether", symbol: "SEP", decimals: 18 },
export const odyssey = defineChain({
id: 15_16,
name: "odyssey",
nativeCurrency: { name: "IP", symbol: "IP", decimals: 18 },
rpcUrls: {
default: {
http: ["https://story-network.rpc.caldera.xyz/http"],
webSocket: ["wss://story-network.rpc.caldera.xyz/ws"],
}
default: {
http: ["https://odyssey.storyrpc.io/"],
},
},
blockExplorers: {
default: { name: "Explorer", url: "https://story-network.explorer.caldera.xyz" },
default: {
name: "Explorer",
url: "https://odyssey-testnet-explorer.storyscan.xyz/",
},
},
contracts: {
//TODO: need to confirm the addresses
multicall3: {
address: "0xcA11bde05977b3631167028862bE2a173976CA11",
blockCreated: 5882,
},
},
testnet: true
testnet: true,
});
14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
"description": "",
"main": "index.js",
"scripts": {
"test:sepolia:smoke": "env TEST_ENV='sepolia' mocha -r ts-node/register -r mocha-steps --grep '\\[smoke\\]' './test/**/**/*.test.ts' --timeout 240000 --reporter mochawesome --reporter-options reportDir='test-reports',reportFilename='[status]_[datetime]_sdk-test-report',timestamp='mm-dd-yyyy_HHMMss',reportTitle='SDK Test Report'",
"test:story:smoke": "env TEST_ENV='storyTestnet' mocha -r ts-node/register -r mocha-steps --grep '\\[smoke\\]' './test/**/**/*.test.ts' --timeout 240000 --reporter mochawesome --reporter-options reportDir='test-reports',reportFilename='[status]_[datetime]_sdk-test-report',timestamp='mm-dd-yyyy_HHMMss',reportTitle='SDK Test Report'",
"test:sepolia:e2e": "env TEST_ENV='sepolia' mocha -r ts-node/register -r mocha-steps './test/**/e2e/*.test.ts' --timeout 240000 --reporter mochawesome --reporter-options reportDir='test-reports',reportFilename='[status]_[datetime]_sdk-test-report',timestamp='mm-dd-yyyy_HHMMss',reportTitle='SDK Test Report'",
"test:story:e2e": "env TEST_ENV='storyTestnet' mocha -r ts-node/register -r mocha-steps './test/**/e2e/*.test.ts' --timeout 240000 --reporter mochawesome --reporter-options reportDir='test-reports',reportFilename='[status]_[datetime]_sdk-test-report',timestamp='mm-dd-yyyy_HHMMss',reportTitle='SDK Test Report'",
"test:sepolia": "env TEST_ENV='sepolia' mocha -r ts-node/register -r mocha-steps './test/**/**/**.test.ts' --timeout 240000 --reporter mochawesome --reporter-options reportDir='test-reports',reportFilename='[status]_[datetime]_sdk-test-report',timestamp='mm-dd-yyyy_HHMMss',reportTitle='SDK Test Report'",
"test:story": "env TEST_ENV='storyTestnet' mocha -r ts-node/register -r mocha-steps './test/**/**/*.test.ts' --timeout 240000 --reporter mochawesome --reporter-options reportDir='test-reports',reportFilename='[status]_[datetime]_sdk-test-report',timestamp='mm-dd-yyyy_HHMMss',reportTitle='SDK Test Report'",
"test:smoke": "mocha -r ts-node/register -r mocha-steps --grep '\\[smoke\\]' './test/**/**/*.test.ts' --timeout 240000 --reporter mochawesome --reporter-options reportDir='test-reports',reportFilename='[status]_[datetime]_sdk-test-report',timestamp='mm-dd-yyyy_HHMMss',reportTitle='SDK Test Report'",
"test:ipAsset": "mocha -r ts-node/register -r mocha-steps './test/ipAsset/**.test.ts' --timeout 240000 --reporter mochawesome --reporter-options reportDir='test-reports',reportFilename='[status]_[datetime]_sdk-test-report',timestamp='mm-dd-yyyy_HHMMss',reportTitle='SDK Test Report'",
"test:license": "mocha -r ts-node/register -r mocha-steps './test/license/**.test.ts' --timeout 240000 --reporter mochawesome --reporter-options reportDir='test-reports',reportFilename='[status]_[datetime]_sdk-test-report',timestamp='mm-dd-yyyy_HHMMss',reportTitle='SDK Test Report'",
"test:nftClient": "mocha -r ts-node/register -r mocha-steps './test/nftClient/**.test.ts' --timeout 240000 --reporter mochawesome --reporter-options reportDir='test-reports',reportFilename='[status]_[datetime]_sdk-test-report',timestamp='mm-dd-yyyy_HHMMss',reportTitle='SDK Test Report'",
"test:permission": "mocha -r ts-node/register -r mocha-steps './test/permission/**.test.ts' --timeout 240000 --reporter mochawesome --reporter-options reportDir='test-reports',reportFilename='[status]_[datetime]_sdk-test-report',timestamp='mm-dd-yyyy_HHMMss',reportTitle='SDK Test Report'",
"test:e2e": "mocha -r ts-node/register -r mocha-steps './test/**/e2e/**.test.ts' --timeout 240000 --reporter mochawesome --reporter-options reportDir='test-reports',reportFilename='[status]_[datetime]_sdk-test-report',timestamp='mm-dd-yyyy_HHMMss',reportTitle='SDK Test Report'",
"open:report": "open test-reports/*.html",
"test:sepolia:open:report": "rm -rf test-reports && npm run test:sepolia && npm run open:report"
},
Expand All @@ -18,7 +18,7 @@
"url": "https://github.com/storyprotocol/sdk-e2e-tests.git"
},
"dependencies": {
"@story-protocol/core-sdk": "1.0.0-rc.14",
"@story-protocol/core-sdk": "1.2.0-rc.1",
"viem": "^2.8.12"
},
"devDependencies": {
Expand Down
6 changes: 3 additions & 3 deletions test/dispute/raiseDispute.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,19 @@ describe("SDK Test", function () {
let ipIdA: any;
const response = await expect(
raiseDispute("B", ipIdA, arbitrationPolicyAddress, "test", "PLAGIARISM", waitForTransaction)
).to.be.rejectedWith("Failed to raise dispute: Address \"undefined\" is invalid.");
).to.be.rejectedWith(`Failed to raise dispute: request.targetIpId address is invalid: undefined, Address must be a hex value of 20 bytes (40 hex characters) and match its checksum counterpart.`);
});

it("Raise dispute fail as invalid ipId", async function () {
const response = await expect(
raiseDispute("B", "0x0000", arbitrationPolicyAddress, "test", "PLAGIARISM", waitForTransaction)
).to.be.rejectedWith("Failed to raise dispute: Address \"0x0000\" is invalid.");
).to.be.rejectedWith(`Failed to raise dispute: request.targetIpId address is invalid: 0x0000, Address must be a hex value of 20 bytes (40 hex characters) and match its checksum counterpart.`);
});

it("Raise dispute fail as non-existent ipId", async function () {
const response = await expect(
raiseDispute("B", "0x8Dcd7f0be38Be6adbe2a7d8fb58032b1e20E3681", arbitrationPolicyAddress, "test", "PLAGIARISM", waitForTransaction)
).to.be.rejectedWith("Failed to raise dispute: Address \"0x8Dcd7f0be38Be6adbe2a7d8fb58032b1e20E3681\" is invalid.");
).to.be.rejectedWith(`Failed to raise dispute: The contract function "raiseDispute" reverted.`, `Error: DisputeModule__NotRegisteredIpId()`);
});

it("Raise dispute fail as undefined linkToDisputeEvidence", async function () {
Expand Down
26 changes: 13 additions & 13 deletions test/dispute/resolveDispute.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,41 +51,41 @@ describe("SDK Test", function () {
let disputeId1: any;
const response = await expect(
resolveDispute("B", disputeId1, "0x", true)
).to.be.rejectedWith("Failed to cancel dispute: Cannot convert undefined to a BigInt");
).to.be.rejectedWith(`Failed to resolve dispute: Cannot convert undefined to a BigInt`);
});

it("Resolve dispute fail as invalid disputeId", async function () {
const response = await expect(
resolveDispute("B", "test", "0x", true)
).to.be.rejectedWith("Failed to cancel dispute: Cannot convert test to a BigInt");
).to.be.rejectedWith(`Failed to resolve dispute: Cannot convert test to a BigInt`);
});

it("Resolve dispute fail as non-existent disputeId", async function () {
const response = await expect(
resolveDispute("B", "999999", "0x", true)
).to.be.rejectedWith("Failed to cancel dispute: The contract function \"resolveDispute\" reverted.",
"Error: DisputeModule__NotDisputeInitiator()");
).to.be.rejectedWith(`Failed to resolve dispute: The contract function "resolveDispute" reverted.`,
`Error: DisputeModule__NotDisputeInitiator()`);
});

it("Resolve dispute fail as undefined data", async function () {
let data: any;
const response = await expect(
resolveDispute("B", disputeId1, data, true)
).to.be.rejectedWith("Failed to cancel dispute: Cannot read properties of undefined (reading 'length')");
).to.be.rejectedWith(`Failed to resolve dispute: Cannot read properties of undefined (reading 'length')`);
});

it("Resolve dispute fail as not dispute initiator", async function () {
const response = await expect(
resolveDispute("A", disputeId1, "0x", true)
).to.be.rejectedWith("Failed to cancel dispute: The contract function \"resolveDispute\" reverted.",
"Error: DisputeModule__NotDisputeInitiator()");
).to.be.rejectedWith(`Failed to resolve dispute: The contract function "resolveDispute" reverted.`,
`Error: DisputeModule__NotDisputeInitiator()`);
});

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()");
).to.be.rejectedWith(`Failed to resolve dispute: The contract function "resolveDispute" reverted.`,
`Error: DisputeModule__NotAbleToResolve()`);
});

it("Resolve dispute fail as judgement decision is false", async function () {
Expand All @@ -94,15 +94,15 @@ describe("SDK Test", 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()");
).to.be.rejectedWith(`Failed to resolve 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", false)
).to.be.rejectedWith("Failed to cancel dispute: The contract function \"resolveDispute\" reverted.",
"Error: DisputeModule__NotDisputeInitiator()");
).to.be.rejectedWith(`Failed to resolve dispute: The contract function "resolveDispute" reverted.`,
`Error: DisputeModule__NotAbleToResolve()`);
});

it("Resolve dispute with waitForTransaction: false", async function () {
Expand Down
8 changes: 4 additions & 4 deletions test/e2e/derivativeIP.comUsePIL.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { privateKeyA, privateKeyB, privateKeyC, accountA, accountB, accountC, nftContractAddress } from '../../config/config'
import { mintNFTWithRetry } from '../../utils/utils'
import { registerIpAsset, attachLicenseTerms, mintLicenseTokens, registerDerivative, registerDerivativeWithLicenseTokens } from '../../utils/sdkUtils'
import { expect } from 'chai'
import { privateKeyA, privateKeyB, privateKeyC, accountA, accountB, accountC, nftContractAddress } from '../../config/config';
import { mintNFTWithRetry } from '../../utils/utils';
import { registerIpAsset, attachLicenseTerms, mintLicenseTokens, registerDerivative, registerDerivativeWithLicenseTokens } from '../../utils/sdkUtils';
import { expect } from 'chai';

import chai from 'chai';
import chaiAsPromised from 'chai-as-promised';
Expand Down
Loading