diff --git a/.github/workflows/run-e2e-test.yml b/.github/workflows/run-e2e-test.yml new file mode 100644 index 0000000..285f9f6 --- /dev/null +++ b/.github/workflows/run-e2e-test.yml @@ -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 diff --git a/.github/workflows/run-full-regression-test.yml b/.github/workflows/run-full-regression-test.yml new file mode 100644 index 0000000..6d3f99a --- /dev/null +++ b/.github/workflows/run-full-regression-test.yml @@ -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 diff --git a/config/config.ts b/config/config.ts index cd10d80..1e18d26 100644 --- a/config/config.ts +++ b/config/config.ts @@ -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") { @@ -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; @@ -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}`); } diff --git a/package.json b/package.json index 75a86af..a8002d8 100644 --- a/package.json +++ b/package.json @@ -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": { diff --git a/test/dispute/resolveDispute.test.ts b/test/dispute/resolveDispute.test.ts index 86c81b2..5fe912a 100644 --- a/test/dispute/resolveDispute.test.ts +++ b/test/dispute/resolveDispute.test.ts @@ -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'; @@ -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) @@ -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 () { @@ -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; + }); }); -}); \ No newline at end of file +}); diff --git a/test/e2e/derivativeIP.comRemixPIL.test.ts b/test/e2e/derivativeIP.comRemixPIL.test.ts index 9599bff..bb1b0d0 100644 --- a/test/e2e/derivativeIP.comRemixPIL.test.ts +++ b/test/e2e/derivativeIP.comRemixPIL.test.ts @@ -1,6 +1,6 @@ -import { privateKeyA, privateKeyB, privateKeyC, accountA, accountB, accountC, nftContractAddress, mintingFeeTokenAddress } from '../../config/config' -import { mintNFTWithRetry } from '../../utils/utils' -import { registerCommercialRemixPIL, registerIpAsset, attachLicenseTerms, mintLicenseTokens, registerDerivative, registerDerivativeWithLicenseTokens } from '../../utils/sdkUtils' +import { privateKeyA, privateKeyB, privateKeyC, accountA, accountB, accountC, nftContractAddress } from '../../config/config' +import { checkMintResult, mintNFTWithRetry } from '../../utils/utils' +import { registerIpAsset, attachLicenseTerms, mintLicenseTokens, registerDerivative, registerDerivativeWithLicenseTokens } from '../../utils/sdkUtils' import { expect } from 'chai' import chai from 'chai'; @@ -8,6 +8,7 @@ import chaiAsPromised from 'chai-as-promised'; chai.use(chaiAsPromised); import '../setup'; import { Hex } from 'viem'; +import { comRemixLicenseTermsId1 } from '../setup'; let tokenIdA: string; let tokenIdB: string; @@ -15,7 +16,6 @@ let tokenIdC: string; let ipIdA: Hex; let ipIdB: Hex; let ipIdC: Hex; -let licenseTermsId1: string; let licenseTokenIdA: string; let licenseTokenIdB: string; @@ -23,20 +23,11 @@ const waitForTransaction: boolean = true; describe('SDK E2E Test', function () { describe("Register Derivative IP Asset with Commercial Remix PIL", function () { - before("Register commercial remix PIL", async function () { - const responsePolicy = await expect( - registerCommercialRemixPIL("A", "1", 100, mintingFeeTokenAddress, waitForTransaction) - ).to.not.be.rejected; - - licenseTermsId1 = responsePolicy.licenseTermsId; - }); - describe("[smoke]Register a derivative IP asset with/without license tokens", async function () { step("Mint a NFT to Wallet A and get a tokenId (tokenIdA)", async function () { tokenIdA = await mintNFTWithRetry(privateKeyA); - if (tokenIdA === '') { - throw new Error('Unable to mint NFT'); - }; + checkMintResult(tokenIdA); + expect(tokenIdA).not.empty; }); @@ -51,9 +42,9 @@ describe('SDK E2E Test', function () { ipIdA = response.ipId; }); - step("Wallet A attach licenseTermsId1(commercial remix PIL) to ipIdA", async function () { + step("Wallet A attach comRemixLicenseTermsId1(commercial remix PIL) to ipIdA", async function () { const response = await expect( - attachLicenseTerms("A", ipIdA, licenseTermsId1, waitForTransaction) + attachLicenseTerms("A", ipIdA, comRemixLicenseTermsId1, waitForTransaction) ).to.not.be.rejected; expect(response.txHash).to.be.a("string").and.not.empty; @@ -61,7 +52,7 @@ describe('SDK E2E Test', function () { step("Wallet A mint a license token with the receiverAddress set as Wallet B, get a licenseTokenId (licenseTokenIdA)", async function () { const response = await expect( - mintLicenseTokens("A", ipIdA, licenseTermsId1, 2, accountB.address, waitForTransaction) + mintLicenseTokens("A", ipIdA, comRemixLicenseTermsId1, 2, accountB.address, waitForTransaction) ).to.not.be.rejected; expect(response.txHash).to.be.a("string").and.not.empty; @@ -72,9 +63,8 @@ describe('SDK E2E Test', function () { step("Mint a NFT to Wallet B and get a tokenId (tokenIdB)", async function () { tokenIdB = await mintNFTWithRetry(privateKeyB); - if (tokenIdB === '') { - throw new Error('Unable to mint NFT'); - }; + checkMintResult(tokenIdB); + expect(tokenIdB).not.empty; }); @@ -99,9 +89,8 @@ describe('SDK E2E Test', function () { step("Mint a NFT to WalletC and get a tokenId(tokenIdC)", async function () { tokenIdC = await mintNFTWithRetry(privateKeyC); - if (tokenIdC === '') { - throw new Error('Unable to mint NFT'); - } + checkMintResult(tokenIdC); + expect(tokenIdC).not.empty; }); @@ -125,7 +114,7 @@ describe('SDK E2E Test', function () { step("Wallet C can register a derivative IP asset without licenseTokenId", async function () { const response = await expect( - registerDerivative("C", ipIdC, [ipIdA], [licenseTermsId1], waitForTransaction) + registerDerivative("C", ipIdC, [ipIdA], [comRemixLicenseTermsId1], waitForTransaction) ).to.not.be.rejected; expect(response.txHash).to.be.a("string").and.not.empty; @@ -135,9 +124,8 @@ describe('SDK E2E Test', function () { describe('Register a derivative IP asset with multiple parent IP assets', async function () { step("Mint a NFT to Wallet A and get a tokenId (tokenIdA)", async function () { tokenIdA = await mintNFTWithRetry(privateKeyA); - if (tokenIdA === "") { - throw new Error("Unable to mint NFT"); - }; + checkMintResult(tokenIdA); + expect(tokenIdA).not.empty; }); @@ -152,9 +140,9 @@ describe('SDK E2E Test', function () { ipIdA = response.ipId; }); - step("Wallet A attach licenseTermsId1(commercial remix PIL) to ipIdA", async function () { + step("Wallet A attach comRemixLicenseTermsId1(commercial remix PIL) to ipIdA", async function () { const response = await expect( - attachLicenseTerms("A", ipIdA, licenseTermsId1, waitForTransaction) + attachLicenseTerms("A", ipIdA, comRemixLicenseTermsId1, waitForTransaction) ).to.not.be.rejected; expect(response.txHash).to.be.a("string").and.not.empty; @@ -162,9 +150,8 @@ describe('SDK E2E Test', function () { step("Mint a NFT to WalletB, get a tokenId (tokenidB)", async function () { tokenIdB = await mintNFTWithRetry(privateKeyB); - if (tokenIdB === '') { - throw new Error('Unable to mint NFT'); - }; + checkMintResult(tokenIdB); + expect(tokenIdB).not.empty; }); @@ -179,9 +166,9 @@ describe('SDK E2E Test', function () { ipIdB = response.ipId; }); - step("Wallet B attach licenseTermsId1(commercial remix PIL) to ipIdA", async function () { + step("Wallet B attach comRemixLicenseTermsId1(commercial remix PIL) to ipIdA", async function () { const response = await expect( - attachLicenseTerms("B", ipIdB, licenseTermsId1, waitForTransaction) + attachLicenseTerms("B", ipIdB, comRemixLicenseTermsId1, waitForTransaction) ).to.not.be.rejected; expect(response.txHash).to.be.a("string").and.not.empty; @@ -189,9 +176,8 @@ describe('SDK E2E Test', function () { step("Mint a NFT to WalletC, get a tokenId (tokenidC)", async function () { tokenIdC = await mintNFTWithRetry(privateKeyC); - if (tokenIdC === '') { - throw new Error('Unable to mint NFT'); - }; + checkMintResult(tokenIdC); + expect(tokenIdC).not.empty; }); @@ -208,7 +194,7 @@ describe('SDK E2E Test', function () { step("Wallet C can register a derivative IP asset with multiple parent IP assets", async function () { const response = await expect( - registerDerivative("C", ipIdC, [ipIdA, ipIdB], [licenseTermsId1, licenseTermsId1], waitForTransaction) + registerDerivative("C", ipIdC, [ipIdA, ipIdB], [comRemixLicenseTermsId1, comRemixLicenseTermsId1], waitForTransaction) ).to.not.be.rejected; expect(response.txHash).to.be.a("string").and.not.empty; @@ -218,9 +204,8 @@ describe('SDK E2E Test', function () { describe("Register a derivative IP assets with multiple license tokens", async function () { step("Mint a NFT to Wallet A and get a tokenId (tokenIdA)", async function () { tokenIdA = await mintNFTWithRetry(privateKeyA); - if (tokenIdA === "") { - throw new Error("Unable to mint NFT"); - }; + checkMintResult(tokenIdA); + expect(tokenIdA).not.empty; }); @@ -235,9 +220,9 @@ describe('SDK E2E Test', function () { ipIdA = response.ipId; }); - step("Wallet A attach licenseTermsId1(commercial remix PIL) to ipIdA", async function () { + step("Wallet A attach comRemixLicenseTermsId1(commercial remix PIL) to ipIdA", async function () { const response = await expect( - attachLicenseTerms("A", ipIdA, licenseTermsId1, waitForTransaction) + attachLicenseTerms("A", ipIdA, comRemixLicenseTermsId1, waitForTransaction) ).to.not.be.rejected; expect(response.txHash).to.be.a("string").and.not.empty; @@ -245,7 +230,7 @@ describe('SDK E2E Test', function () { step("Wallet A mint a license token with the receiverAddress set as Wallet B, get a licenseId (licenseTokenIdA)", async function () { const response = await expect( - mintLicenseTokens("A", ipIdA, licenseTermsId1, 2, accountC.address, waitForTransaction) + mintLicenseTokens("A", ipIdA, comRemixLicenseTermsId1, 2, accountC.address, waitForTransaction) ).to.not.be.rejected; expect(response.txHash).to.be.a("string").and.not.empty; @@ -256,9 +241,8 @@ describe('SDK E2E Test', function () { step("Mint a NFT to WalletB, get a tokenId (tokenIdB)", async function () { tokenIdB = await mintNFTWithRetry(privateKeyB); - if (tokenIdB === "") { - throw new Error("Unable to mint NFT"); - } + checkMintResult(tokenIdB); + expect(tokenIdB).not.empty; }); @@ -273,9 +257,9 @@ describe('SDK E2E Test', function () { ipIdB = response.ipId; }); - step("Wallet B attach licenseTermsId1(commercial remix PIL) to ipIdB", async function () { + step("Wallet B attach comRemixLicenseTermsId1(commercial remix PIL) to ipIdB", async function () { const response = await expect( - attachLicenseTerms("B", ipIdB, licenseTermsId1, waitForTransaction) + attachLicenseTerms("B", ipIdB, comRemixLicenseTermsId1, waitForTransaction) ).to.not.be.rejected; expect(response.txHash).to.be.a("string").and.not.empty; @@ -283,7 +267,7 @@ describe('SDK E2E Test', function () { step("Wallet B mint a license token with the receiverAddress set as Wallet C, get a licenseTokenId (licenseTokenIdB)", async function () { const response = await expect( - mintLicenseTokens("B", ipIdB, licenseTermsId1, 2, accountC.address, waitForTransaction) + mintLicenseTokens("B", ipIdB, comRemixLicenseTermsId1, 2, accountC.address, waitForTransaction) ).to.not.be.rejected; expect(response.txHash).to.be.a("string").and.not.empty; @@ -294,9 +278,8 @@ describe('SDK E2E Test', function () { step("Mint a NFT to WalletC, get a tokenId (tokenIdC)", async function () { tokenIdC = await mintNFTWithRetry(privateKeyC); - if (tokenIdC === "") { - throw new Error("Unable to mint NFT"); - } + checkMintResult(tokenIdC); + expect(tokenIdC).not.empty; }); @@ -323,9 +306,8 @@ describe('SDK E2E Test', function () { describe("Register a derivative IP assets with multiple license tokens, the sender is not licensee", async function () { step("Mint a NFT to Wallet A and get a tokenId (tokenIdA)", async function () { tokenIdA = await mintNFTWithRetry(privateKeyA); - if (tokenIdA === "") { - throw new Error("Unable to mint NFT"); - }; + checkMintResult(tokenIdA); + expect(tokenIdA).not.empty; }); @@ -340,9 +322,9 @@ describe('SDK E2E Test', function () { ipIdA = response.ipId; }); - step("Wallet A attach licenseTermsId1(commercial remix PIL) to ipIdA", async function () { + step("Wallet A attach comRemixLicenseTermsId1(commercial remix PIL) to ipIdA", async function () { const response = await expect( - attachLicenseTerms("A", ipIdA, licenseTermsId1, waitForTransaction) + attachLicenseTerms("A", ipIdA, comRemixLicenseTermsId1, waitForTransaction) ).to.not.be.rejected; expect(response.txHash).to.be.a("string").and.not.empty; @@ -350,7 +332,7 @@ describe('SDK E2E Test', function () { step("Wallet A mint a license token with the receiverAddress set as Wallet B, get a licenseId (licenseTokenIdA)", async function () { const response = await expect( - mintLicenseTokens("A", ipIdA, licenseTermsId1, 2, accountB.address, waitForTransaction) + mintLicenseTokens("A", ipIdA, comRemixLicenseTermsId1, 2, accountB.address, waitForTransaction) ).to.not.be.rejected; expect(response.txHash).to.be.a("string").and.not.empty; @@ -361,9 +343,8 @@ describe('SDK E2E Test', function () { step("Mint a NFT to WalletB, get a tokenId (tokenIdB)", async function () { tokenIdB = await mintNFTWithRetry(privateKeyB); - if (tokenIdB === "") { - throw new Error("Unable to mint NFT"); - } + checkMintResult(tokenIdB); + expect(tokenIdB).not.empty; }); @@ -378,9 +359,9 @@ describe('SDK E2E Test', function () { ipIdB = response.ipId; }); - step("Wallet B attach licenseTermsId1(commercial remix PIL) to ipIdB", async function () { + step("Wallet B attach comRemixLicenseTermsId1(commercial remix PIL) to ipIdB", async function () { const response = await expect( - attachLicenseTerms("B", ipIdB, licenseTermsId1, waitForTransaction) + attachLicenseTerms("B", ipIdB, comRemixLicenseTermsId1, waitForTransaction) ).to.not.be.rejected; expect(response.txHash).to.be.a("string").and.not.empty; @@ -388,7 +369,7 @@ describe('SDK E2E Test', function () { step("Wallet B mint a license token with the receiverAddress set as Wallet C, get a licenseTokenId (licenseTokenIdB)", async function () { const response = await expect( - mintLicenseTokens("B", ipIdB, licenseTermsId1, 2, accountC.address, waitForTransaction) + mintLicenseTokens("B", ipIdB, comRemixLicenseTermsId1, 2, accountC.address, waitForTransaction) ).to.not.be.rejected; expect(response.txHash).to.be.a("string").and.not.empty; @@ -399,9 +380,8 @@ describe('SDK E2E Test', function () { step("Mint a NFT to WalletC, get a tokenId (tokenIdC)", async function () { tokenIdC = await mintNFTWithRetry(privateKeyC); - if (tokenIdC === "") { - throw new Error("Unable to mint NFT"); - } + checkMintResult(tokenIdC); + expect(tokenIdC).not.empty; }); @@ -427,9 +407,8 @@ describe('SDK E2E Test', function () { describe("Register multiple derivative IP assets with license token, registered amount larger than mint amount of license token", async function () { step("Mint a NFT to Wallet A and get a tokenId (tokenIdA)", async function () { tokenIdA = await mintNFTWithRetry(privateKeyA); - if (tokenIdA === "") { - throw new Error("Unable to mint NFT"); - } + checkMintResult(tokenIdA); + expect(tokenIdA).not.empty; }); @@ -444,9 +423,9 @@ describe('SDK E2E Test', function () { ipIdA = response.ipId; }); - step("Wallet A attach licenseTermsId1(commercial remix PIL) to ipIdA", async function () { + step("Wallet A attach comRemixLicenseTermsId1(commercial remix PIL) to ipIdA", async function () { const response = await expect( - attachLicenseTerms("A", ipIdA, licenseTermsId1, waitForTransaction) + attachLicenseTerms("A", ipIdA, comRemixLicenseTermsId1, waitForTransaction) ).to.not.be.rejected; expect(response.txHash).to.be.a("string").and.not.empty; @@ -454,7 +433,7 @@ describe('SDK E2E Test', function () { step("Wallet A mint a license token with ipIdA and get a licenseTokenId (licenseTokenIdA)", async function () { const response = await expect( - mintLicenseTokens("A", ipIdA, licenseTermsId1, 1, accountB.address, waitForTransaction) + mintLicenseTokens("A", ipIdA, comRemixLicenseTermsId1, 1, accountB.address, waitForTransaction) ).to.not.be.rejected; expect(response.txHash).to.be.a("string").and.not.empty; @@ -465,9 +444,8 @@ describe('SDK E2E Test', function () { step("Mint a NFT to WalletB and get a tokenId (tokenIdB)", async function () { tokenIdB = await mintNFTWithRetry(privateKeyB); - if (tokenIdB === "") { - throw new Error("Unable to mint NFT"); - } + checkMintResult(tokenIdB); + expect(tokenIdB).not.empty; }); @@ -492,9 +470,8 @@ describe('SDK E2E Test', function () { step("Mint a NFT to WalletB and get a tokenId (tokenIdB)", async function () { tokenIdC = await mintNFTWithRetry(privateKeyB); - if (tokenIdC === "") { - throw new Error("Unable to mint NFT"); - } + checkMintResult(tokenIdC); + expect(tokenIdC).not.empty; }); @@ -519,9 +496,8 @@ describe('SDK E2E Test', function () { describe("Register derivative IP asset with an IP that already has license", async function () { step("Mint a NFT to Wallet A and get a tokenId (tokenIdA)", async function () { tokenIdA = await mintNFTWithRetry(privateKeyA); - if (tokenIdA === "") { - throw new Error("Unable to mint NFT"); - } + checkMintResult(tokenIdA); + expect(tokenIdA).not.empty; }); @@ -536,9 +512,9 @@ describe('SDK E2E Test', function () { ipIdA = response.ipId; }); - step("Wallet A attach licenseTermsId1(commercial remix PIL) to ipIdA", async function () { + step("Wallet A attach comRemixLicenseTermsId1(commercial remix PIL) to ipIdA", async function () { const response = await expect( - attachLicenseTerms("A", ipIdA, licenseTermsId1, waitForTransaction) + attachLicenseTerms("A", ipIdA, comRemixLicenseTermsId1, waitForTransaction) ).to.not.be.rejected; expect(response.txHash).to.be.a("string").and.not.empty; @@ -546,7 +522,7 @@ describe('SDK E2E Test', function () { step("Wallet A mint a license token with ipIdA and get a licenseTokenId (licenseTokenIdA)", async function () { const response = await expect( - mintLicenseTokens("A", ipIdA, licenseTermsId1, 1, accountB.address, waitForTransaction) + mintLicenseTokens("A", ipIdA, comRemixLicenseTermsId1, 1, accountB.address, waitForTransaction) ).to.not.be.rejected; expect(response.txHash).to.be.a("string").and.not.empty; @@ -557,9 +533,8 @@ describe('SDK E2E Test', function () { step("Mint a NFT to WalletB and get a tokenId (tokenIdB)", async function () { tokenIdB = await mintNFTWithRetry(privateKeyB); - if (tokenIdB === "") { - throw new Error("Unable to mint NFT"); - } + checkMintResult(tokenIdB); + expect(tokenIdB).not.empty; }); @@ -574,9 +549,9 @@ describe('SDK E2E Test', function () { ipIdB = response.ipId; }); - step("Wallet B attach licenseTermsId1(commercial remix PIL) to ipIdA", async function () { + step("Wallet B attach comRemixLicenseTermsId1(commercial remix PIL) to ipIdA", async function () { const response = await expect( - attachLicenseTerms("B", ipIdB, licenseTermsId1, waitForTransaction) + attachLicenseTerms("B", ipIdB, comRemixLicenseTermsId1, waitForTransaction) ).to.not.be.rejected; expect(response.txHash).to.be.a("string").and.not.empty; @@ -584,7 +559,7 @@ describe('SDK E2E Test', function () { step("Wallet B mint a license token with ipIdB and get a licenseTokenId (licenseTokenIdB)", async function () { const response = await expect( - mintLicenseTokens("B", ipIdB, licenseTermsId1, 1, accountA.address, waitForTransaction) + mintLicenseTokens("B", ipIdB, comRemixLicenseTermsId1, 1, accountA.address, waitForTransaction) ).to.not.be.rejected; expect(response.txHash).to.be.a("string").and.not.empty; diff --git a/test/e2e/derivativeIP.comUsePIL.test.ts b/test/e2e/derivativeIP.comUsePIL.test.ts index 95f236b..0ddb835 100644 --- a/test/e2e/derivativeIP.comUsePIL.test.ts +++ b/test/e2e/derivativeIP.comUsePIL.test.ts @@ -1,6 +1,6 @@ -import { privateKeyA, privateKeyB, privateKeyC, accountA, accountB, accountC, nftContractAddress, mintingFeeTokenAddress } from '../../config/config' +import { privateKeyA, privateKeyB, privateKeyC, accountA, accountB, accountC, nftContractAddress } from '../../config/config' import { mintNFTWithRetry } from '../../utils/utils' -import { registerCommercialUsePIL, registerIpAsset, attachLicenseTerms, mintLicenseTokens, registerDerivative, registerDerivativeWithLicenseTokens } from '../../utils/sdkUtils' +import { registerIpAsset, attachLicenseTerms, mintLicenseTokens, registerDerivative, registerDerivativeWithLicenseTokens } from '../../utils/sdkUtils' import { expect } from 'chai' import chai from 'chai'; @@ -8,6 +8,7 @@ import chaiAsPromised from 'chai-as-promised'; chai.use(chaiAsPromised); import '../setup'; import { Hex } from 'viem'; +import { comUseLicenseTermsId1 } from '../setup'; let tokenIdA: string; let tokenIdB: string; @@ -15,7 +16,6 @@ let tokenIdC: string; let ipIdA: Hex; let ipIdB: Hex; let ipIdC: Hex; -let licenseTermsId1: string; let licenseTokenIdA: string; let licenseTokenIdB: string; @@ -23,14 +23,6 @@ const waitForTransaction: boolean = true; describe('SDK E2E Test', function () { describe("Register Derivative IP Asset with Commercial Use PIL", function () { - before("Register commercial use PIL", async function () { - const responsePolicy = await expect( - registerCommercialUsePIL("A", "1", mintingFeeTokenAddress, waitForTransaction) - ).to.not.be.rejected; - - licenseTermsId1 = responsePolicy.licenseTermsId; - }); - describe("[smoke]Register a derivative IP asset with/without license tokens", async function () { step("Mint a NFT to Wallet A and get a tokenId (tokenIdA)", async function () { tokenIdA = await mintNFTWithRetry(privateKeyA); @@ -51,9 +43,9 @@ describe('SDK E2E Test', function () { ipIdA = response.ipId; }); - step("Wallet A attach licenseTermsId1(commercial use PIL) to ipIdA", async function () { + step("Wallet A attach comUseLicenseTermsId1(commercial use PIL) to ipIdA", async function () { const response = await expect( - attachLicenseTerms("A", ipIdA, licenseTermsId1, waitForTransaction) + attachLicenseTerms("A", ipIdA, comUseLicenseTermsId1, waitForTransaction) ).to.not.be.rejected; expect(response.txHash).to.be.a("string").and.not.empty; @@ -61,7 +53,7 @@ describe('SDK E2E Test', function () { step("Wallet A mint a license token with the receiverAddress set as Wallet B, get a licenseTokenId (licenseTokenIdA)", async function () { const response = await expect( - mintLicenseTokens("A", ipIdA, licenseTermsId1, 2, accountB.address, waitForTransaction) + mintLicenseTokens("A", ipIdA, comUseLicenseTermsId1, 2, accountB.address, waitForTransaction) ).to.not.be.rejected; expect(response.txHash).to.be.a("string").and.not.empty; @@ -125,7 +117,7 @@ describe('SDK E2E Test', function () { step("Wallet C can register a derivative IP asset without licenseTokenId", async function () { const response = await expect( - registerDerivative("C", ipIdC, [ipIdA], [licenseTermsId1], waitForTransaction) + registerDerivative("C", ipIdC, [ipIdA], [comUseLicenseTermsId1], waitForTransaction) ).to.not.be.rejected; expect(response.txHash).to.be.a("string").and.not.empty; @@ -152,9 +144,9 @@ describe('SDK E2E Test', function () { ipIdA = response.ipId; }); - step("Wallet A attach licenseTermsId1(commercial use PIL) to ipIdA", async function () { + step("Wallet A attach comUseLicenseTermsId1(commercial use PIL) to ipIdA", async function () { const response = await expect( - attachLicenseTerms("A", ipIdA, licenseTermsId1, waitForTransaction) + attachLicenseTerms("A", ipIdA, comUseLicenseTermsId1, waitForTransaction) ).to.not.be.rejected; expect(response.txHash).to.be.a("string").and.not.empty; @@ -179,9 +171,9 @@ describe('SDK E2E Test', function () { ipIdB = response.ipId; }); - step("Wallet B attach licenseTermsId1(commercial use PIL) to ipIdA", async function () { + step("Wallet B attach comUseLicenseTermsId1(commercial use PIL) to ipIdA", async function () { const response = await expect( - attachLicenseTerms("B", ipIdB, licenseTermsId1, waitForTransaction) + attachLicenseTerms("B", ipIdB, comUseLicenseTermsId1, waitForTransaction) ).to.not.be.rejected; expect(response.txHash).to.be.a("string").and.not.empty; @@ -208,7 +200,7 @@ describe('SDK E2E Test', function () { step("Wallet C can register a derivative IP asset with multiple parent IP assets (ipIdA, ipIdB)", async function () { const response = await expect( - registerDerivative("C", ipIdC, [ipIdA, ipIdB], [licenseTermsId1, licenseTermsId1], waitForTransaction) + registerDerivative("C", ipIdC, [ipIdA, ipIdB], [comUseLicenseTermsId1, comUseLicenseTermsId1], waitForTransaction) ).to.not.be.rejected; expect(response.txHash).to.be.a("string").and.not.empty; @@ -235,9 +227,9 @@ describe('SDK E2E Test', function () { ipIdA = response.ipId; }); - step("Wallet A attach licenseTermsId1(commercial use PIL) to ipIdA", async function () { + step("Wallet A attach comUseLicenseTermsId1(commercial use PIL) to ipIdA", async function () { const response = await expect( - attachLicenseTerms("A", ipIdA, licenseTermsId1, waitForTransaction) + attachLicenseTerms("A", ipIdA, comUseLicenseTermsId1, waitForTransaction) ).to.not.be.rejected; expect(response.txHash).to.be.a("string").and.not.empty; @@ -245,7 +237,7 @@ describe('SDK E2E Test', function () { step("Wallet A mint a license token with the receiverAddress set as Wallet B, get a licenseId (licenseTokenIdA)", async function () { const response = await expect( - mintLicenseTokens("A", ipIdA, licenseTermsId1, 2, accountC.address, waitForTransaction) + mintLicenseTokens("A", ipIdA, comUseLicenseTermsId1, 2, accountC.address, waitForTransaction) ).to.not.be.rejected; expect(response.txHash).to.be.a("string").and.not.empty; @@ -273,9 +265,9 @@ describe('SDK E2E Test', function () { ipIdB = response.ipId; }); - step("Wallet B attach licenseTermsId1(commercial use PIL) to ipIdB", async function () { + step("Wallet B attach comUseLicenseTermsId1(commercial use PIL) to ipIdB", async function () { const response = await expect( - attachLicenseTerms("B", ipIdB, licenseTermsId1, waitForTransaction) + attachLicenseTerms("B", ipIdB, comUseLicenseTermsId1, waitForTransaction) ).to.not.be.rejected; expect(response.txHash).to.be.a("string").and.not.empty; @@ -283,7 +275,7 @@ describe('SDK E2E Test', function () { step("Wallet B mint a license token with the receiverAddress set as Wallet C, get a licenseTokenId (licenseTokenIdB)", async function () { const response = await expect( - mintLicenseTokens("B", ipIdB, licenseTermsId1, 2, accountC.address, waitForTransaction) + mintLicenseTokens("B", ipIdB, comUseLicenseTermsId1, 2, accountC.address, waitForTransaction) ).to.not.be.rejected; expect(response.txHash).to.be.a("string").and.not.empty; @@ -340,9 +332,9 @@ describe('SDK E2E Test', function () { ipIdA = response.ipId; }); - step("Wallet A attach licenseTermsId1(commercial use PIL) to ipIdA", async function () { + step("Wallet A attach comUseLicenseTermsId1(commercial use PIL) to ipIdA", async function () { const response = await expect( - attachLicenseTerms("A", ipIdA, licenseTermsId1, waitForTransaction) + attachLicenseTerms("A", ipIdA, comUseLicenseTermsId1, waitForTransaction) ).to.not.be.rejected; expect(response.txHash).to.be.a("string").and.not.empty; @@ -350,7 +342,7 @@ describe('SDK E2E Test', function () { step("Wallet A mint a license token with the receiverAddress set as Wallet B, get a licenseId (licenseTokenIdA)", async function () { const response = await expect( - mintLicenseTokens("A", ipIdA, licenseTermsId1, 2, accountB.address, waitForTransaction) + mintLicenseTokens("A", ipIdA, comUseLicenseTermsId1, 2, accountB.address, waitForTransaction) ).to.not.be.rejected; expect(response.txHash).to.be.a("string").and.not.empty; @@ -378,9 +370,9 @@ describe('SDK E2E Test', function () { ipIdB = response.ipId; }); - step("Wallet B attach licenseTermsId1(commercial use PIL) to ipIdB", async function () { + step("Wallet B attach comUseLicenseTermsId1(commercial use PIL) to ipIdB", async function () { const response = await expect( - attachLicenseTerms("B", ipIdB, licenseTermsId1, waitForTransaction) + attachLicenseTerms("B", ipIdB, comUseLicenseTermsId1, waitForTransaction) ).to.not.be.rejected; expect(response.txHash).to.be.a("string").and.not.empty; @@ -388,7 +380,7 @@ describe('SDK E2E Test', function () { step("Wallet B mint a license token with the receiverAddress set as Wallet C, get a licenseTokenId (licenseTokenIdB)", async function () { const response = await expect( - mintLicenseTokens("B", ipIdB, licenseTermsId1, 2, accountC.address, waitForTransaction) + mintLicenseTokens("B", ipIdB, comUseLicenseTermsId1, 2, accountC.address, waitForTransaction) ).to.not.be.rejected; expect(response.txHash).to.be.a("string").and.not.empty; @@ -444,9 +436,9 @@ describe('SDK E2E Test', function () { ipIdA = response.ipId; }); - step("Wallet A attach licenseTermsId1(commercial use PIL) to ipIdA", async function () { + step("Wallet A attach comUseLicenseTermsId1(commercial use PIL) to ipIdA", async function () { const response = await expect( - attachLicenseTerms("A", ipIdA, licenseTermsId1, waitForTransaction) + attachLicenseTerms("A", ipIdA, comUseLicenseTermsId1, waitForTransaction) ).to.not.be.rejected; expect(response.txHash).to.be.a("string").and.not.empty; @@ -454,7 +446,7 @@ describe('SDK E2E Test', function () { step("Wallet A mint a license token with ipIdA and get a licenseTokenId (licenseTokenIdA)", async function () { const response = await expect( - mintLicenseTokens("A", ipIdA, licenseTermsId1, 1, accountB.address, waitForTransaction) + mintLicenseTokens("A", ipIdA, comUseLicenseTermsId1, 1, accountB.address, waitForTransaction) ).to.not.be.rejected; expect(response.txHash).to.be.a("string").and.not.empty; @@ -536,9 +528,9 @@ describe('SDK E2E Test', function () { ipIdA = response.ipId; }); - step("Wallet A attach licenseTermsId1(commercial use PIL) to ipIdA", async function () { + step("Wallet A attach comUseLicenseTermsId1(commercial use PIL) to ipIdA", async function () { const response = await expect( - attachLicenseTerms("A", ipIdA, licenseTermsId1, waitForTransaction) + attachLicenseTerms("A", ipIdA, comUseLicenseTermsId1, waitForTransaction) ).to.not.be.rejected; expect(response.txHash).to.be.a("string").and.not.empty; @@ -546,7 +538,7 @@ describe('SDK E2E Test', function () { step("Wallet A mint a license token with ipIdA and get a licenseTokenId (licenseTokenIdA)", async function () { const response = await expect( - mintLicenseTokens("A", ipIdA, licenseTermsId1, 1, accountB.address, waitForTransaction) + mintLicenseTokens("A", ipIdA, comUseLicenseTermsId1, 1, accountB.address, waitForTransaction) ).to.not.be.rejected; expect(response.txHash).to.be.a("string").and.not.empty; @@ -574,9 +566,9 @@ describe('SDK E2E Test', function () { ipIdB = response.ipId; }); - step("Wallet B attach licenseTermsId1(commercial use PIL) to ipIdB", async function () { + step("Wallet B attach comUseLicenseTermsId1(commercial use PIL) to ipIdB", async function () { const response = await expect( - attachLicenseTerms("B", ipIdB, licenseTermsId1, waitForTransaction) + attachLicenseTerms("B", ipIdB, comUseLicenseTermsId1, waitForTransaction) ).to.not.be.rejected; expect(response.txHash).to.be.a("string").and.not.empty; @@ -584,7 +576,7 @@ describe('SDK E2E Test', function () { step("Wallet B mint a license token with ipIdB and get a licenseTokenId (licenseTokenIdB)", async function () { const response = await expect( - mintLicenseTokens("B", ipIdB, licenseTermsId1, 1, accountA.address, waitForTransaction) + mintLicenseTokens("B", ipIdB, comUseLicenseTermsId1, 1, accountA.address, waitForTransaction) ).to.not.be.rejected; expect(response.txHash).to.be.a("string").and.not.empty; diff --git a/test/e2e/derivativeIP.nonComPIL.test.ts b/test/e2e/derivativeIP.nonComPIL.test.ts index 5e9b639..58f0ec5 100644 --- a/test/e2e/derivativeIP.nonComPIL.test.ts +++ b/test/e2e/derivativeIP.nonComPIL.test.ts @@ -1,6 +1,6 @@ import { privateKeyA, privateKeyB, privateKeyC, accountA, accountB, accountC,nftContractAddress } from '../../config/config' import { mintNFTWithRetry } from '../../utils/utils' -import { registerNonComSocialRemixingPIL, registerIpAsset, attachLicenseTerms, mintLicenseTokens, registerDerivative, registerDerivativeWithLicenseTokens } from '../../utils/sdkUtils' +import { registerIpAsset, attachLicenseTerms, mintLicenseTokens, registerDerivative, registerDerivativeWithLicenseTokens } from '../../utils/sdkUtils' import { expect } from 'chai' import chai from 'chai'; @@ -8,6 +8,7 @@ import chaiAsPromised from 'chai-as-promised'; chai.use(chaiAsPromised); import '../setup'; import { Hex } from 'viem'; +import { nonComLicenseTermsId } from '../setup'; let tokenIdA: string; let tokenIdB: string; @@ -15,7 +16,6 @@ let tokenIdC: string; let ipIdA: Hex; let ipIdB: Hex; let ipIdC: Hex; -let licenseTermsId1: string; let licenseTokenIdA: string; let licenseTokenIdB: string; @@ -23,14 +23,6 @@ const waitForTransaction: boolean = true; describe('SDK E2E Test', function () { describe("Register Derivative IP Asset with Non-Commercial Social Remixing PIL", function () { - before("Register Non-Commercial Social Remixing PIL", async function () { - const responsePolicy = await expect( - registerNonComSocialRemixingPIL("A", waitForTransaction) - ).to.not.be.rejected; - - licenseTermsId1 = responsePolicy.licenseTermsId; - }); - describe("[smoke]Register a derivative IP asset with/without license tokens", async function () { step("Mint a NFT to Wallet A and get a tokenId (tokenIdA)", async function () { tokenIdA = await mintNFTWithRetry(privateKeyA); @@ -51,9 +43,9 @@ describe('SDK E2E Test', function () { ipIdA = response.ipId; }); - step("Wallet A attach licenseTermsId1(non-commercial social remixing PIL) to ipIdA", async function () { + step("Wallet A attach nonComLicenseTermsId(non-commercial social remixing PIL) to ipIdA", async function () { const response = await expect( - attachLicenseTerms("A", ipIdA, licenseTermsId1, waitForTransaction) + attachLicenseTerms("A", ipIdA, nonComLicenseTermsId, waitForTransaction) ).to.not.be.rejected; expect(response.txHash).to.be.a("string").and.not.empty; @@ -61,7 +53,7 @@ describe('SDK E2E Test', function () { step("Wallet A mint a license token with the receiverAddress set as Wallet B, get a licenseTokenId (licenseTokenIdA)", async function () { const response = await expect( - mintLicenseTokens("A", ipIdA, licenseTermsId1, 2, accountB.address, waitForTransaction) + mintLicenseTokens("A", ipIdA, nonComLicenseTermsId, 2, accountB.address, waitForTransaction) ).to.not.be.rejected; expect(response.txHash).to.be.a("string").and.not.empty; @@ -125,7 +117,7 @@ describe('SDK E2E Test', function () { step("Wallet C can register a derivative IP asset without licenseTokenId", async function () { const response = await expect( - registerDerivative("C", ipIdC, [ipIdA], [licenseTermsId1], waitForTransaction) + registerDerivative("C", ipIdC, [ipIdA], [nonComLicenseTermsId], waitForTransaction) ).to.not.be.rejected; expect(response.txHash).to.be.a("string").and.not.empty; @@ -152,9 +144,9 @@ describe('SDK E2E Test', function () { ipIdA = response.ipId; }); - step("Wallet A attach licenseTermsId1(non-commercial social remixing PIL) to ipIdA", async function () { + step("Wallet A attach nonComLicenseTermsId(non-commercial social remixing PIL) to ipIdA", async function () { const response = await expect( - attachLicenseTerms("A", ipIdA, licenseTermsId1, waitForTransaction) + attachLicenseTerms("A", ipIdA, nonComLicenseTermsId, waitForTransaction) ).to.not.be.rejected; expect(response.txHash).to.be.a("string").and.not.empty; @@ -179,9 +171,9 @@ describe('SDK E2E Test', function () { ipIdB = response.ipId; }); - step("Wallet B attach licenseTermsId1(non-commercial social remixing PIL) to ipIdA", async function () { + step("Wallet B attach nonComLicenseTermsId(non-commercial social remixing PIL) to ipIdA", async function () { const response = await expect( - attachLicenseTerms("B", ipIdB, licenseTermsId1, waitForTransaction) + attachLicenseTerms("B", ipIdB, nonComLicenseTermsId, waitForTransaction) ).to.not.be.rejected; expect(response.txHash).to.be.a("string").and.not.empty; @@ -208,7 +200,7 @@ describe('SDK E2E Test', function () { step("Wallet C can register a derivative IP asset with multiple parent IP assets", async function () { const response = await expect( - registerDerivative("C", ipIdC, [ipIdA, ipIdB], [licenseTermsId1, licenseTermsId1], waitForTransaction) + registerDerivative("C", ipIdC, [ipIdA, ipIdB], [nonComLicenseTermsId, nonComLicenseTermsId], waitForTransaction) ).to.not.be.rejected; expect(response.txHash).to.be.a("string").and.not.empty; @@ -235,9 +227,9 @@ describe('SDK E2E Test', function () { ipIdA = response.ipId; }); - step("Wallet A attach licenseTermsId1(non-commercial social remixing PIL) to ipIdA", async function () { + step("Wallet A attach nonComLicenseTermsId(non-commercial social remixing PIL) to ipIdA", async function () { const response = await expect( - attachLicenseTerms("A", ipIdA, licenseTermsId1, waitForTransaction) + attachLicenseTerms("A", ipIdA, nonComLicenseTermsId, waitForTransaction) ).to.not.be.rejected; expect(response.txHash).to.be.a("string").and.not.empty; @@ -245,7 +237,7 @@ describe('SDK E2E Test', function () { step("Wallet A mint a license token with the receiverAddress set as Wallet B, get a licenseId (licenseTokenIdA)", async function () { const response = await expect( - mintLicenseTokens("A", ipIdA, licenseTermsId1, 2, accountC.address, waitForTransaction) + mintLicenseTokens("A", ipIdA, nonComLicenseTermsId, 2, accountC.address, waitForTransaction) ).to.not.be.rejected; expect(response.txHash).to.be.a("string").and.not.empty; @@ -273,9 +265,9 @@ describe('SDK E2E Test', function () { ipIdB = response.ipId; }); - step("Wallet B attach licenseTermsId1(non-commercial social remixing PIL) to ipIdB", async function () { + step("Wallet B attach nonComLicenseTermsId(non-commercial social remixing PIL) to ipIdB", async function () { const response = await expect( - attachLicenseTerms("B", ipIdB, licenseTermsId1, waitForTransaction) + attachLicenseTerms("B", ipIdB, nonComLicenseTermsId, waitForTransaction) ).to.not.be.rejected; expect(response.txHash).to.be.a("string").and.not.empty; @@ -283,7 +275,7 @@ describe('SDK E2E Test', function () { step("Wallet B mint a license token with the receiverAddress set as Wallet C, get a licenseTokenId (licenseTokenIdB)", async function () { const response = await expect( - mintLicenseTokens("B", ipIdB, licenseTermsId1, 2, accountC.address, waitForTransaction) + mintLicenseTokens("B", ipIdB, nonComLicenseTermsId, 2, accountC.address, waitForTransaction) ).to.not.be.rejected; expect(response.txHash).to.be.a("string").and.not.empty; @@ -340,9 +332,9 @@ describe('SDK E2E Test', function () { ipIdA = response.ipId; }); - step("Wallet A attach licenseTermsId1(non-commercial social remixing PIL) to ipIdA", async function () { + step("Wallet A attach nonComLicenseTermsId(non-commercial social remixing PIL) to ipIdA", async function () { const response = await expect( - attachLicenseTerms("A", ipIdA, licenseTermsId1, waitForTransaction) + attachLicenseTerms("A", ipIdA, nonComLicenseTermsId, waitForTransaction) ).to.not.be.rejected; expect(response.txHash).to.be.a("string").and.not.empty; @@ -350,7 +342,7 @@ describe('SDK E2E Test', function () { step("Wallet A mint a license token with the receiverAddress set as Wallet B, get a licenseId (licenseTokenIdA)", async function () { const response = await expect( - mintLicenseTokens("A", ipIdA, licenseTermsId1, 2, accountB.address, waitForTransaction) + mintLicenseTokens("A", ipIdA, nonComLicenseTermsId, 2, accountB.address, waitForTransaction) ).to.not.be.rejected; expect(response.txHash).to.be.a("string").and.not.empty; @@ -378,9 +370,9 @@ describe('SDK E2E Test', function () { ipIdB = response.ipId; }); - step("Wallet B attach licenseTermsId1(non-commercial social remixing PIL) to ipIdB", async function () { + step("Wallet B attach nonComLicenseTermsId(non-commercial social remixing PIL) to ipIdB", async function () { const response = await expect( - attachLicenseTerms("B", ipIdB, licenseTermsId1, waitForTransaction) + attachLicenseTerms("B", ipIdB, nonComLicenseTermsId, waitForTransaction) ).to.not.be.rejected; expect(response.txHash).to.be.a("string").and.not.empty; @@ -388,7 +380,7 @@ describe('SDK E2E Test', function () { step("Wallet B mint a license token with the receiverAddress set as Wallet C, get a licenseTokenId (licenseTokenIdB)", async function () { const response = await expect( - mintLicenseTokens("B", ipIdB, licenseTermsId1, 2, accountC.address, waitForTransaction) + mintLicenseTokens("B", ipIdB, nonComLicenseTermsId, 2, accountC.address, waitForTransaction) ).to.not.be.rejected; expect(response.txHash).to.be.a("string").and.not.empty; @@ -444,9 +436,9 @@ describe('SDK E2E Test', function () { ipIdA = response.ipId; }); - step("Wallet A attach licenseTermsId1(non-commercial social remixing PIL) to ipIdA", async function () { + step("Wallet A attach nonComLicenseTermsId(non-commercial social remixing PIL) to ipIdA", async function () { const response = await expect( - attachLicenseTerms("A", ipIdA, licenseTermsId1, waitForTransaction) + attachLicenseTerms("A", ipIdA, nonComLicenseTermsId, waitForTransaction) ).to.not.be.rejected; expect(response.txHash).to.be.a("string").and.not.empty; @@ -454,7 +446,7 @@ describe('SDK E2E Test', function () { step("Wallet A mint a license token with ipIdA and get a licenseTokenId (licenseTokenIdA)", async function () { const response = await expect( - mintLicenseTokens("A", ipIdA, licenseTermsId1, 1, accountB.address, waitForTransaction) + mintLicenseTokens("A", ipIdA, nonComLicenseTermsId, 1, accountB.address, waitForTransaction) ).to.not.be.rejected; expect(response.txHash).to.be.a("string").and.not.empty; @@ -536,9 +528,9 @@ describe('SDK E2E Test', function () { ipIdA = response.ipId; }); - step("Wallet A attach licenseTermsId1(non-commercial social remixing PIL) to ipIdA", async function () { + step("Wallet A attach nonComLicenseTermsId(non-commercial social remixing PIL) to ipIdA", async function () { const response = await expect( - attachLicenseTerms("A", ipIdA, licenseTermsId1, waitForTransaction) + attachLicenseTerms("A", ipIdA, nonComLicenseTermsId, waitForTransaction) ).to.not.be.rejected; expect(response.txHash).to.be.a("string").and.not.empty; @@ -546,7 +538,7 @@ describe('SDK E2E Test', function () { step("Wallet A mint a license token with ipIdA and get a licenseTokenId (licenseTokenIdA)", async function () { const response = await expect( - mintLicenseTokens("A", ipIdA, licenseTermsId1, 1, accountB.address, waitForTransaction) + mintLicenseTokens("A", ipIdA, nonComLicenseTermsId, 1, accountB.address, waitForTransaction) ).to.not.be.rejected; expect(response.txHash).to.be.a("string").and.not.empty; @@ -574,9 +566,9 @@ describe('SDK E2E Test', function () { ipIdB = response.ipId; }); - step("Wallet B attach licenseTermsId1(non-commercial social remixing PIL) to ipIdA", async function () { + step("Wallet B attach nonComLicenseTermsId(non-commercial social remixing PIL) to ipIdA", async function () { const response = await expect( - attachLicenseTerms("B", ipIdB, licenseTermsId1, waitForTransaction) + attachLicenseTerms("B", ipIdB, nonComLicenseTermsId, waitForTransaction) ).to.not.be.rejected; expect(response.txHash).to.be.a("string").and.not.empty; @@ -584,7 +576,7 @@ describe('SDK E2E Test', function () { step("Wallet B mint a license token with ipIdB and get a licenseTokenId (licenseTokenIdB)", async function () { const response = await expect( - mintLicenseTokens("B", ipIdB, licenseTermsId1, 1, accountA.address, waitForTransaction) + mintLicenseTokens("B", ipIdB, nonComLicenseTermsId, 1, accountA.address, waitForTransaction) ).to.not.be.rejected; expect(response.txHash).to.be.a("string").and.not.empty; diff --git a/test/e2e/dispute.test.ts b/test/e2e/dispute.test.ts index 0d73137..742b612 100644 --- a/test/e2e/dispute.test.ts +++ b/test/e2e/dispute.test.ts @@ -1,56 +1,31 @@ -import { privateKeyA, privateKeyB, accountB, nftContractAddress, arbitrationPolicyAddress, mintingFeeTokenAddress } from '../../config/config'; -import { mintNFTWithRetry, checkMintResult, sleep } from '../../utils/utils'; -import { registerIpAsset, raiseDispute, registerNonComSocialRemixingPIL, attachLicenseTerms, registerCommercialUsePIL, registerCommercialRemixPIL, mintLicenseTokens, registerDerivativeWithLicenseTokens, payRoyaltyOnBehalf, collectRoyaltyTokens, royaltySnapshot, royaltyClaimableRevenue, royaltyClaimRevenue, registerDerivative } from '../../utils/sdkUtils'; +import { privateKeyA, privateKeyB, accountB, nftContractAddress, arbitrationPolicyAddress, mintingFeeTokenAddress, privateKeyC, accountA } from '../../config/config'; +import { mintNFTWithRetry, checkMintResult, setDisputeJudgement, sleep } from '../../utils/utils'; +import { registerIpAsset, raiseDispute, attachLicenseTerms, mintLicenseTokens, registerDerivativeWithLicenseTokens, payRoyaltyOnBehalf, collectRoyaltyTokens, royaltySnapshot, royaltyClaimableRevenue, royaltyClaimRevenue, registerDerivative, resolveDispute } from '../../utils/sdkUtils'; import { Hex } from 'viem'; import chai from 'chai'; import chaiAsPromised from 'chai-as-promised'; import { expect } from 'chai'; chai.use(chaiAsPromised); import '../setup'; +import { nonComLicenseTermsId, comUseLicenseTermsId1, comRemixLicenseTermsId2, mintingFee1, mintingFee2, commercialRevShare2 } from '../setup'; const waitForTransaction: boolean = true; -let tokenIdA: string; let ipIdA: Hex; let ipIdB: Hex; -let licenseTermsId1: string; -let licenseTermsId2: string; -let licenseTermsId3: string; +let ipIdC: Hex; +let disputeId1: string; +let disputeId2: string; +let disputeId3: string; +let licenseTokenId1: string; +let licenseTokenId2: string; let licenseTokenId3: string; -const mintingFee1: string = "60"; -const mintingFee2: string = "100"; -const commercialRevShare: number = 200; -describe("SDK Test", function () { +describe("SDK E2E Test", function () { describe("IP Asset is IN_DISPUTE", async function () { - before("Register license terms and IP assets, raise dispute", async function () { - const responseLicenseTerms1 = await expect( - registerNonComSocialRemixingPIL("A", waitForTransaction) - ).to.not.be.rejected; - - expect(responseLicenseTerms1.licenseTermsId).to.be.a("string").and.not.empty; - - licenseTermsId1 = responseLicenseTerms1.licenseTermsId; - - const responseLicenseTerms2 = await expect( - registerCommercialUsePIL("A", mintingFee1, mintingFeeTokenAddress, waitForTransaction) - ).to.not.be.rejected; - - expect(responseLicenseTerms2.licenseTermsId).to.be.a("string").and.not.empty; - - licenseTermsId2 = responseLicenseTerms2.licenseTermsId; - - const responseLicenseTerms3 = await expect( - registerCommercialRemixPIL("A", mintingFee2, commercialRevShare, mintingFeeTokenAddress, waitForTransaction) - ).to.not.be.rejected; - - expect(responseLicenseTerms3.licenseTermsId).to.be.a("string").and.not.empty; - - licenseTermsId3 = responseLicenseTerms3.licenseTermsId; - - tokenIdA = await mintNFTWithRetry(privateKeyA); + before("Register IP assets and raise dispute", async function () { + const tokenIdA = await mintNFTWithRetry(privateKeyA); checkMintResult(tokenIdA); - expect(tokenIdA).not.empty; const responseRegisterIpAsset = await expect( registerIpAsset("A", nftContractAddress, tokenIdA, waitForTransaction) @@ -61,6 +36,18 @@ describe("SDK Test", function () { ipIdA = responseRegisterIpAsset.ipId; + const tokenIdB = await mintNFTWithRetry(privateKeyB); + checkMintResult(tokenIdB); + + const response = await expect( + registerIpAsset("B", nftContractAddress, tokenIdB, waitForTransaction) + ).to.not.be.rejected; + + expect(response.txHash).to.be.a("string").and.not.empty; + expect(response.ipId).to.be.a("string").and.not.empty; + + ipIdB = response.ipId; + const responseRaiseDispute = await expect( raiseDispute("B", ipIdA, arbitrationPolicyAddress, "test", "PLAGIARISM", waitForTransaction) ).to.not.be.rejected; @@ -70,53 +57,53 @@ describe("SDK Test", function () { }); describe("Attach License Terms to IN_DISPUTE IP Asset", async function () { - it("Attach non-commerical social remixing PIL to an IN_DISPUTE IP asset", async function () { + it("Attach non-commerical social remixing PIL to IN_DISPUTE IP asset", async function () { const response = await expect( - attachLicenseTerms("A", ipIdA, licenseTermsId1, waitForTransaction) + attachLicenseTerms("A", ipIdA, nonComLicenseTermsId, waitForTransaction) ).to.not.be.rejected; expect(response.txHash).to.be.a("string").and.not.empty; }); - it("Attach commercial use PIL to an IN_DISPUTE IP asset", async function () { + it("Attach commercial use PIL to IN_DISPUTE IP asset", async function () { const response = await expect( - attachLicenseTerms("A", ipIdA, licenseTermsId2, waitForTransaction) + attachLicenseTerms("A", ipIdA, comUseLicenseTermsId1, waitForTransaction) ).to.not.be.rejected; expect(response.txHash).to.be.a("string").and.not.empty; }); - it("Attach commericial remix PIL to an IN_DISPUTE IP asset", async function () { + it("Attach commericial remix PIL to IN_DISPUTE IP asset", async function () { const response = await expect( - attachLicenseTerms("A", ipIdA, licenseTermsId3, waitForTransaction) + attachLicenseTerms("A", ipIdA, comRemixLicenseTermsId2, waitForTransaction) ).to.not.be.rejected; expect(response.txHash).to.be.a("string").and.not.empty; }); }); - describe("Mint License Tokens", async function () { - it("Mint license tokens with non-commerical social remixing PIL for an IN_DISPUTE IP asset", async function () { + describe("Mint License Tokens for IN_DISPUTE IP asset", async function () { + it("Mint license tokens with non-commerical social remixing PIL for IN_DISPUTE IP asset", async function () { const response = await expect( - mintLicenseTokens("A", ipIdA, licenseTermsId1, 2, accountB.address, waitForTransaction) + mintLicenseTokens("A", ipIdA, nonComLicenseTermsId, 2, accountB.address, waitForTransaction) ).to.not.be.rejected; expect(response.txHash).to.be.a("string").and.not.empty; expect(response.licenseTokenId).to.be.a("string").and.not.empty; }); - it("Mint license tokens with commercial use PIL for an IN_DISPUTE IP asset", async function () { + it("Mint license tokens with commercial use PIL for IN_DISPUTE IP asset", async function () { const response = await expect( - mintLicenseTokens("A", ipIdA, licenseTermsId2, 2, accountB.address, waitForTransaction) + mintLicenseTokens("A", ipIdA, comUseLicenseTermsId1, 2, accountB.address, waitForTransaction) ).to.not.be.rejected; expect(response.txHash).to.be.a("string").and.not.empty; expect(response.licenseTokenId).to.be.a("string").and.not.empty; }); - it("Mint license tokens with commericial remix PIL for an IN_DISPUTE IP asset", async function () { + it("Mint license tokens with commericial remix PIL for IN_DISPUTE IP asset", async function () { const response = await expect( - mintLicenseTokens("A", ipIdA, licenseTermsId3, 2, accountB.address, waitForTransaction) + mintLicenseTokens("A", ipIdA, comRemixLicenseTermsId2, 2, accountB.address, waitForTransaction) ).to.not.be.rejected; expect(response.txHash).to.be.a("string").and.not.empty; @@ -130,20 +117,6 @@ describe("SDK Test", function () { const payAmount: string = "100"; const revenueTokens: string = String(Number(payAmount) + Number(mintingFee1) * 2 + Number(mintingFee2) * 2); - before("Register IP Asset", async function () { - const tokenIdB = await mintNFTWithRetry(privateKeyB); - checkMintResult(tokenIdB); - - const response = await expect( - registerIpAsset("B", nftContractAddress, tokenIdB, waitForTransaction) - ).to.not.be.rejected; - - expect(response.txHash).to.be.a("string").and.not.empty; - expect(response.ipId).to.be.a("string").and.not.empty; - - ipIdB = response.ipId; - }) - step("Register derivative with license tokens attached commercial remix PIL, parent IP is an IN_DISPUTE IP asset", async function () { const response = await expect( registerDerivativeWithLicenseTokens("B", ipIdB, [licenseTokenId3], waitForTransaction) @@ -166,7 +139,7 @@ describe("SDK Test", function () { ).to.not.be.rejected; expect(response.txHash).to.be.a("string").and.not.empty; - expect(response.royaltyTokensCollected).to.be.a("string").and.be.equal(String(commercialRevShare)); + expect(response.royaltyTokensCollected).to.be.a("string").and.be.equal(String(commercialRevShare2)); }); step("Captue snapshot", async function () { @@ -215,7 +188,7 @@ describe("SDK Test", function () { step("Register derivative with non-commercial social remixing PIL, parent IP is an IN_DISPUTE IP asset", async function () { const response = await expect( - registerDerivative("B", ipIdB, [ipIdA], [licenseTermsId1], waitForTransaction) + registerDerivative("B", ipIdB, [ipIdA], [comRemixLicenseTermsId2], waitForTransaction) ).to.not.be.rejected; expect(response.txHash).to.be.a("string").and.not.empty; @@ -239,7 +212,7 @@ describe("SDK Test", function () { step("Register derivative with commercial use PIL, parent IP is an IN_DISPUTE IP asset", async function () { const response = await expect( - registerDerivative("B", ipIdB, [ipIdA], [licenseTermsId2], waitForTransaction) + registerDerivative("B", ipIdB, [ipIdA], [comUseLicenseTermsId1], waitForTransaction) ).to.not.be.rejected; expect(response.txHash).to.be.a("string").and.not.empty; @@ -259,11 +232,11 @@ describe("SDK Test", function () { expect(response.ipId).to.be.a("string").and.not.empty; ipIdB = response.ipId; - }) - + }); + step("Register derivative with commercial remix PIL, parent IP is an IN_DISPUTE IP asset", async function () { const response = await expect( - registerDerivative("B", ipIdB, [ipIdA], [licenseTermsId3], waitForTransaction) + registerDerivative("B", ipIdB, [ipIdA], [nonComLicenseTermsId], waitForTransaction) ).to.not.be.rejected; expect(response.txHash).to.be.a("string").and.not.empty; @@ -271,4 +244,451 @@ describe("SDK Test", function () { }); }); }); + + describe("IP Asset is DISPUTED", async function () { + before("Register IP assets and raise dispute", async function () { + const tokenIdA = await mintNFTWithRetry(privateKeyA); + checkMintResult(tokenIdA); + + const responseRegisterIpAsset = await expect( + registerIpAsset("A", nftContractAddress, tokenIdA, waitForTransaction) + ).to.not.be.rejected; + + expect(responseRegisterIpAsset.txHash).to.be.a("string").and.not.empty; + expect(responseRegisterIpAsset.ipId).to.be.a("string").and.not.empty; + + ipIdA = responseRegisterIpAsset.ipId; + + const tokenIdB = await mintNFTWithRetry(privateKeyB); + checkMintResult(tokenIdB); + + const response = await expect( + registerIpAsset("B", nftContractAddress, tokenIdB, waitForTransaction) + ).to.not.be.rejected; + + expect(response.txHash).to.be.a("string").and.not.empty; + expect(response.ipId).to.be.a("string").and.not.empty; + + ipIdB = response.ipId; + + const responseRaiseDispute = await expect( + raiseDispute("B", ipIdA, arbitrationPolicyAddress, "test", "PLAGIARISM", waitForTransaction) + ).to.not.be.rejected; + + expect(responseRaiseDispute.txHash).to.be.a("string").and.not.empty; + expect(responseRaiseDispute.disputeId).to.be.a("string").and.not.empty; + + disputeId1 = responseRaiseDispute.disputeId; + + await setDisputeJudgement(privateKeyC, disputeId1, true, "0x"); + }); + + describe("Attach License Terms to DISPUTED IP Asset", async function () { + it("Attach non-commerical social remixing PIL to a DISPUTED IP asset", async function () { + const response = await expect( + attachLicenseTerms("A", ipIdA, nonComLicenseTermsId, waitForTransaction) + ).to.be.rejectedWith("Failed to attach license terms: The contract function \"attachLicenseTerms\" reverted.", + "Error: LicensingModule__DisputedIpId()"); + }); + + it("Attach commercial use PIL to an IN_DISPUTE IP asset", async function () { + const response = await expect( + attachLicenseTerms("A", ipIdA, comUseLicenseTermsId1, waitForTransaction) + ).to.be.rejectedWith("Failed to attach license terms: The contract function \"attachLicenseTerms\" reverted.", + "Error: LicensingModule__DisputedIpId()"); + }); + + it("Attach commericial remix PIL to an IN_DISPUTE IP asset", async function () { + const response = await expect( + attachLicenseTerms("A", ipIdA, comRemixLicenseTermsId2, waitForTransaction) + ).to.be.rejectedWith("Failed to attach license terms: The contract function \"attachLicenseTerms\" reverted.", + "Error: LicensingModule__DisputedIpId()"); + }); + }); + + describe("Mint License Tokens for DISPUTED IP asset", async function () { + before("Attach license terms, raise dispute and set judgement", async function () { + const response1 = await expect( + attachLicenseTerms("B", ipIdB, nonComLicenseTermsId, waitForTransaction) + ).to.not.be.rejected; + + expect(response1.txHash).to.be.a("string").and.not.empty; + + const response2 = await expect( + attachLicenseTerms("B", ipIdB, comUseLicenseTermsId1, waitForTransaction) + ).to.not.be.rejected; + + expect(response2.txHash).to.be.a("string").and.not.empty; + + const response3 = await expect( + attachLicenseTerms("B", ipIdB, comRemixLicenseTermsId2, waitForTransaction) + ).to.not.be.rejected; + + expect(response3.txHash).to.be.a("string").and.not.empty; + + const responseRaiseDispute = await expect( + raiseDispute("A", ipIdB, arbitrationPolicyAddress, "test", "PLAGIARISM", waitForTransaction) + ).to.not.be.rejected; + + expect(responseRaiseDispute.txHash).to.be.a("string").and.not.empty; + expect(responseRaiseDispute.disputeId).to.be.a("string").and.not.empty; + + disputeId2 = responseRaiseDispute.disputeId; + + await setDisputeJudgement(privateKeyC, disputeId2, true, "0x"); + }); + + it("Mint license tokens with non-commerical social remixing PIL for a DISPUTED IP asset", async function () { + const response = await expect( + mintLicenseTokens("B", ipIdB, nonComLicenseTermsId, 2, accountB.address, waitForTransaction) + ).to.be.rejectedWith("Failed to mint license tokens: The contract function \"mintLicenseTokens\" reverted.", + "Error: LicensingModule__DisputedIpId()"); + }); + + it("Mint license tokens with commerical use PIL for a DISPUTED IP asset", async function () { + const response = await expect( + mintLicenseTokens("B", ipIdB, comUseLicenseTermsId1, 2, accountB.address, waitForTransaction) + ).to.be.rejectedWith("Failed to mint license tokens: The contract function \"mintLicenseTokens\" reverted.", + "Error: LicensingModule__DisputedIpId()"); + }); + + it("Mint license tokens with commericial remix PIL for a DISPUTED IP asset", async function () { + const response = await expect( + mintLicenseTokens("B", ipIdB, comRemixLicenseTermsId2, 2, accountB.address, waitForTransaction) + ).to.be.rejectedWith("Failed to mint license tokens: The contract function \"mintLicenseTokens\" reverted.", + "Error: LicensingModule__DisputedIpId()"); + }); + }); + + describe("Register Derivative IP Asset without License Tokens", async function () { + before("Register IP Asset", async function () { + const tokenIdC = await mintNFTWithRetry(privateKeyA); + checkMintResult(tokenIdC); + + const response = await expect( + registerIpAsset("A", nftContractAddress, tokenIdC, waitForTransaction) + ).to.not.be.rejected; + + expect(response.txHash).to.be.a("string").and.not.empty; + expect(response.ipId).to.be.a("string").and.not.empty; + + ipIdC = response.ipId; + }); + + describe("Non-commerical social remixing PIL", async function () { + // 0x76a26b62: LicenseRegistry__ParentIpTagged(address) + step("Register derivative with non-commercial social remixing PIL, parent IP is a DISPUTED IP asset", async function () { + const response = await expect( + registerDerivative("A", ipIdC, [ipIdB], [nonComLicenseTermsId], waitForTransaction) + ).to.be.rejectedWith("Failed to register derivative: The contract function \"registerDerivative\" reverted with the following signature:", "0x76a26b62"); + }); + + step("Register derivative with non-commercial social remixing PIL, derivative IP is a DISPUTED IP asset", async function () { + const responseAttachLicenseTerms = await expect( + attachLicenseTerms("A", ipIdC, nonComLicenseTermsId, waitForTransaction) + ).to.not.be.rejected; + + expect(responseAttachLicenseTerms.txHash).to.be.a("string").and.not.empty; + + const response = await expect( + registerDerivative("B", ipIdB, [ipIdC], [nonComLicenseTermsId], waitForTransaction) + ).to.be.rejectedWith("Failed to register derivative: The contract function \"registerDerivative\" reverted.", "Error: LicensingModule__DisputedIpId()"); + }); + }); + + describe("Commercial use PIL", async function () { + // 0x76a26b62: LicenseRegistry__ParentIpTagged(address) + step("Register derivative with commercial use PIL, parent IP is a DISPUTED IP asset", async function () { + const response = await expect( + registerDerivative("A", ipIdC, [ipIdB], [comUseLicenseTermsId1], waitForTransaction) + ).to.be.rejectedWith("Failed to register derivative: The contract function \"registerDerivative\" reverted with the following signature:", "0x76a26b62"); + }); + + step("Register derivative with non-commercial social remixing PIL, derivative IP is a DISPUTED IP asset", async function () { + const responseAttachLicenseTerms = await expect( + attachLicenseTerms("A", ipIdC, comUseLicenseTermsId1, waitForTransaction) + ).to.not.be.rejected; + + expect(responseAttachLicenseTerms.txHash).to.be.a("string").and.not.empty; + + const response = await expect( + registerDerivative("B", ipIdB, [ipIdC], [comUseLicenseTermsId1], waitForTransaction) + ).to.be.rejectedWith("Failed to register derivative: The contract function \"registerDerivative\" reverted.", "Error: LicensingModule__DisputedIpId()"); + }); + }); + + describe("Commercial remix PIL", async function () { + // 0x76a26b62: LicenseRegistry__ParentIpTagged(address) + step("Register derivative with commercial remix PIL, parent IP is a DISPUTED IP asset", async function () { + const response = await expect( + registerDerivative("A", ipIdC, [ipIdB], [comRemixLicenseTermsId2], waitForTransaction) + ).to.be.rejectedWith("Failed to register derivative: The contract function \"registerDerivative\" reverted with the following signature:", "0x76a26b62"); + }); + + step("Register derivative with non-commercial social remixing PIL, derivative IP is a DISPUTED IP asset", async function () { + const responseAttachLicenseTerms = await expect( + attachLicenseTerms("A", ipIdC, comRemixLicenseTermsId2, waitForTransaction) + ).to.not.be.rejected; + + expect(responseAttachLicenseTerms.txHash).to.be.a("string").and.not.empty; + + const response = await expect( + registerDerivative("B", ipIdB, [ipIdC], [comRemixLicenseTermsId2], waitForTransaction) + ).to.be.rejectedWith("Failed to register derivative: The contract function \"registerDerivative\" reverted.", "Error: LicensingModule__DisputedIpId()"); + }); + }); + }); + + describe("Register Derivative IP Asset with License Tokens", async function () { + before("Register IP Asset", async function () { + const responseResolveDispute = await expect( + resolveDispute("A", disputeId2, "0x0000", false) + ).to.not.be.rejected; + + expect(responseResolveDispute.txHash).to.be.a("string").and.not.empty; + + const responsemintLicenseTokens1 = await expect( + mintLicenseTokens("B", ipIdB, nonComLicenseTermsId, 2, accountA.address, true) + ).to.not.be.rejected; + + expect(responsemintLicenseTokens1.txHash).to.be.a("string").and.not.empty; + expect(responsemintLicenseTokens1.licenseTokenId).to.be.a("string").and.not.empty; + + licenseTokenId1 = responsemintLicenseTokens1.licenseTokenId; + + const responsemintLicenseTokens2 = await expect( + mintLicenseTokens("B", ipIdB, comUseLicenseTermsId1, 2, accountA.address, true) + ).to.not.be.rejected; + + expect(responsemintLicenseTokens2.txHash).to.be.a("string").and.not.empty; + expect(responsemintLicenseTokens2.licenseTokenId).to.be.a("string").and.not.empty; + + licenseTokenId2 = responsemintLicenseTokens2.licenseTokenId; + + const responsemintLicenseTokens3 = await expect( + mintLicenseTokens("B", ipIdB, comRemixLicenseTermsId2, 2, accountA.address, true) + ).to.not.be.rejected; + + expect(responsemintLicenseTokens3.txHash).to.be.a("string").and.not.empty; + expect(responsemintLicenseTokens3.licenseTokenId).to.be.a("string").and.not.empty; + + licenseTokenId3 = responsemintLicenseTokens3.licenseTokenId; + + const responseRaiseDispute = await expect( + raiseDispute("A", ipIdB, arbitrationPolicyAddress, "test", "PLAGIARISM", waitForTransaction) + ).to.not.be.rejected; + + expect(responseRaiseDispute.txHash).to.be.a("string").and.not.empty; + expect(responseRaiseDispute.disputeId).to.be.a("string").and.not.empty; + + disputeId2 = responseRaiseDispute.disputeId; + + await setDisputeJudgement(privateKeyC, disputeId2, true, "0x"); + + const tokenIdC = await mintNFTWithRetry(privateKeyA); + checkMintResult(tokenIdC); + + const response = await expect( + registerIpAsset("A", nftContractAddress, tokenIdC, waitForTransaction) + ).to.not.be.rejected; + + expect(response.txHash).to.be.a("string").and.not.empty; + expect(response.ipId).to.be.a("string").and.not.empty; + + ipIdC = response.ipId; + }); + + describe("Register derivative IP asset, parent IP is a DISPUTED IP asset, ", async function () { + // 0x39944339: LicenseToken__RevokedLicense(uint256) + step("Non-commerical social remixing PIL", async function () { + const response = await expect( + registerDerivativeWithLicenseTokens("A", ipIdC, [licenseTokenId1], waitForTransaction) + ).to.be.rejectedWith("Failed to register derivative with license tokens: The contract function \"registerDerivativeWithLicenseTokens\" reverted with the following signature:", "0x39944339"); + }); + + // 0x39944339: LicenseToken__RevokedLicense(uint256) + step("Commercial use PIL", async function () { + const response = await expect( + registerDerivativeWithLicenseTokens("A", ipIdC, [licenseTokenId2],waitForTransaction) + ).to.be.rejectedWith("Failed to register derivative with license tokens: The contract function \"registerDerivativeWithLicenseTokens\" reverted with the following signature:", "0x39944339"); + }); + + // 0x39944339: LicenseToken__RevokedLicense(uint256) + step("Register derivative with commercial remix PIL, parent IP is a DISPUTED IP asset", async function () { + const response = await expect( + registerDerivativeWithLicenseTokens("A", ipIdC, [licenseTokenId3],waitForTransaction) + ).to.be.rejectedWith("Failed to register derivative with license tokens: The contract function \"registerDerivativeWithLicenseTokens\" reverted with the following signature:", "0x39944339"); + }); + }); + + describe("Register derivative IP asset, derivative IP is a DISPUTED IP asset, ", async function () { + before("Resolve dispute for the parent IP, raise dispute for the derivative IP", async function () { + const responseResolveDispute = await expect( + resolveDispute("A", disputeId2, "0x0000", false) + ).to.not.be.rejected; + + expect(responseResolveDispute.txHash).to.be.a("string").and.not.empty; + + const responseRaiseDispute = await expect( + raiseDispute("B", ipIdC, arbitrationPolicyAddress, "test", "PLAGIARISM", waitForTransaction) + ).to.not.be.rejected; + + expect(responseRaiseDispute.txHash).to.be.a("string").and.not.empty; + expect(responseRaiseDispute.disputeId).to.be.a("string").and.not.empty; + + disputeId3 = responseRaiseDispute.disputeId; + + await setDisputeJudgement(privateKeyC, disputeId3, true, "0x"); + }) + + step("Non-commerical social remixing PIL", async function () { + const response = await expect( + registerDerivativeWithLicenseTokens("A", ipIdC, [licenseTokenId1], waitForTransaction) + ).to.be.rejectedWith("Failed to register derivative with license tokens: The contract function \"registerDerivativeWithLicenseTokens\" reverted.", "Error: LicensingModule__DisputedIpId()"); + }); + + step("Commerical use PIL", async function () { + const response = await expect( + registerDerivativeWithLicenseTokens("A", ipIdC, [licenseTokenId2], waitForTransaction) + ).to.be.rejectedWith("Failed to register derivative with license tokens: The contract function \"registerDerivativeWithLicenseTokens\" reverted.", "Error: LicensingModule__DisputedIpId()"); + }); + + step("Commerical remix PIL", async function () { + const response = await expect( + registerDerivativeWithLicenseTokens("A", ipIdC, [licenseTokenId3], waitForTransaction) + ).to.be.rejectedWith("Failed to register derivative with license tokens: The contract function \"registerDerivativeWithLicenseTokens\" reverted.", "Error: LicensingModule__DisputedIpId()"); + }); + }); + }); + + describe("Register Derivative IP Asset with License Tokens and Royalty Related Process", async function () { + let snapshotId1: string; + let snapshotId2: string; + const payAmount: string = "100"; + const revenueTokens: string = String(Number(payAmount) + Number(mintingFee1) * 2 + Number(mintingFee2) * 2); + + before("Resolve dispute for the derivative IP", async function () { + const responseResolveDispute = await expect( + resolveDispute("B", disputeId3, "0x0000", false) + ).to.not.be.rejected; + + expect(responseResolveDispute.txHash).to.be.a("string").and.not.empty; + }) + + step("Register derivative with license tokens attached commercial remix PIL", async function () { + const response = await expect( + registerDerivativeWithLicenseTokens("A", ipIdC, [licenseTokenId3], waitForTransaction) + ).to.not.be.rejected; + + expect(response.txHash).to.be.a("string").and.not.empty; + }); + + step("Raise dispute for the parent IP and set dispute judgement", async function () { + const responseRaiseDispute = await expect( + raiseDispute("A", ipIdB, arbitrationPolicyAddress, "test", "PLAGIARISM", waitForTransaction) + ).to.not.be.rejected; + + expect(responseRaiseDispute.txHash).to.be.a("string").and.not.empty; + expect(responseRaiseDispute.disputeId).to.be.a("string").and.not.empty; + + disputeId2 = responseRaiseDispute.disputeId; + + await setDisputeJudgement(privateKeyC, disputeId2, true, "0x"); + }); + + step("Pay royalty on behalf, parent IP is DISPUTED", async function () { + const response = await expect( + payRoyaltyOnBehalf("A", ipIdB, ipIdC, mintingFeeTokenAddress, payAmount, waitForTransaction) + ).to.be.rejectedWith("Failed to pay royalty on behalf: The contract function \"payRoyaltyOnBehalf\" reverted.", "Error: RoyaltyModule__IpIsTagged()"); + }); + + step("Pay royalty on behalf, derivative IP is DISPUTED", async function () { + const responseResolveDispute = await expect( + resolveDispute("A", disputeId2, "0x0000", false) + ).to.not.be.rejected; + + expect(responseResolveDispute.txHash).to.be.a("string").and.not.empty; + + const responseRaiseDispute = await expect( + raiseDispute("B", ipIdC, arbitrationPolicyAddress, "test", "PLAGIARISM", waitForTransaction) + ).to.not.be.rejected; + + expect(responseRaiseDispute.txHash).to.be.a("string").and.not.empty; + expect(responseRaiseDispute.disputeId).to.be.a("string").and.not.empty; + + disputeId3 = responseRaiseDispute.disputeId; + + await setDisputeJudgement(privateKeyC, disputeId3, true, "0x"); + + const response = await expect( + payRoyaltyOnBehalf("B", ipIdB, ipIdC, mintingFeeTokenAddress, payAmount, waitForTransaction) + ).to.be.rejectedWith("Failed to pay royalty on behalf: The contract function \"payRoyaltyOnBehalf\" reverted.", "Error: RoyaltyModule__IpIsTagged()"); + }); + + step("Pay royalty on behalf", async function () { + const responseResolveDispute = await expect( + resolveDispute("B", disputeId3, "0x0000", false) + ).to.not.be.rejected; + + expect(responseResolveDispute.txHash).to.be.a("string").and.not.empty; + + const response = await expect( + payRoyaltyOnBehalf("B", ipIdB, ipIdC, mintingFeeTokenAddress, payAmount, waitForTransaction) + ).to.not.be.rejected; + + expect(response.txHash).to.be.a("string").and.not.empty; + }); + + step("Raise dispute for the parent IP and set dispute judgement", async function () { + const responseRaiseDispute = await expect( + raiseDispute("A", ipIdB, arbitrationPolicyAddress, "test", "PLAGIARISM", waitForTransaction) + ).to.not.be.rejected; + + expect(responseRaiseDispute.txHash).to.be.a("string").and.not.empty; + expect(responseRaiseDispute.disputeId).to.be.a("string").and.not.empty; + + disputeId2 = responseRaiseDispute.disputeId; + + await setDisputeJudgement(privateKeyC, disputeId2, true, "0x"); + }); + + step("Collect royalty tokens", async function () { + const response = await expect( + collectRoyaltyTokens("B", ipIdB, ipIdC, waitForTransaction) + ).to.not.be.rejected; + + expect(response.txHash).to.be.a("string").and.not.empty; + expect(response.royaltyTokensCollected).to.be.a("string").and.be.equal(String(commercialRevShare2)); + }); + + step("Captue snapshot", async function () { + const response = await expect( + royaltySnapshot("B", ipIdB, waitForTransaction) + ).to.not.be.rejected; + + expect(response.txHash).to.be.a("string").and.not.empty; + + snapshotId1 = response.snapshotId; + }); + + // IP asset is disputed, the cliaimable revenue should be 0 + step("Check claimable revenue", async function () { + const response = await expect( + royaltyClaimableRevenue("B", ipIdB, ipIdB, snapshotId1, mintingFeeTokenAddress, waitForTransaction) + ).to.not.be.rejected; + + expect(response).to.be.a("string").and.be.equal("0"); + }); + + // IP asset is disputed, the cliaimable revenue should be 0 + step("Claim royalty tokens", async function () { + const response = await expect( + royaltyClaimRevenue("B", [snapshotId1], ipIdB, ipIdB, mintingFeeTokenAddress, waitForTransaction) + ).to.not.be.rejected; + + expect(response.txHash).to.be.a("string").and.not.empty; + expect(response.claimableToken).to.be.a("string").and.be.equal("0"); + }); + }); + }); }); \ No newline at end of file diff --git a/test/e2e/multiLIcenseTerms.test.ts b/test/e2e/multiLIcenseTerms.test.ts index 96c7915..eecd01f 100644 --- a/test/e2e/multiLIcenseTerms.test.ts +++ b/test/e2e/multiLIcenseTerms.test.ts @@ -1,6 +1,6 @@ -import { privateKeyA, privateKeyB, privateKeyC, nftContractAddress, mintingFeeTokenAddress } from '../../config/config' +import { privateKeyA, privateKeyB, nftContractAddress } from '../../config/config' import { mintNFTWithRetry } from '../../utils/utils' -import { registerNonComSocialRemixingPIL, registerCommercialUsePIL, registerCommercialRemixPIL, registerIpAsset, attachLicenseTerms, registerDerivative } from '../../utils/sdkUtils' +import { registerIpAsset, attachLicenseTerms, registerDerivative } from '../../utils/sdkUtils' import { expect } from 'chai' import '../setup'; @@ -9,63 +9,22 @@ import chaiAsPromised from 'chai-as-promised'; chai.use(chaiAsPromised); import '../setup'; import { Hex } from 'viem'; +import { nonComLicenseTermsId, comUseLicenseTermsId1, comUseLicenseTermsId2, comRemixLicenseTermsId1, comRemixLicenseTermsId2 } from '../setup'; let tokenIdA: string; let tokenIdB: string; let tokenIdC: string; -let tokenIdD: string; let ipIdA: Hex; let ipIdB: Hex; let ipIdC: Hex; -let ipIdD: Hex; -let licenseTermsId1: string; -let licenseTermsId2: string; -let licenseTermsId3: string; -let licenseTermsId4: string; -let licenseTermsId5: string; const waitForTransaction: boolean = true; describe('SDK E2E Test', function () { describe("Register Derivative IP Asset with multiple PILs", function () { - this.beforeAll("Register non-commercial social remixing, commercial use and commercial remix PILs", async function () { - const responseLicenseTerms1 = await expect( - registerCommercialUsePIL("A", "1", mintingFeeTokenAddress, waitForTransaction) - ).to.not.be.rejected; - - licenseTermsId1 = responseLicenseTerms1.licenseTermsId; - - const responseLicenseTerms2 = await expect( - registerCommercialUsePIL("A", "20", mintingFeeTokenAddress, waitForTransaction) - ).to.not.be.rejected; - - licenseTermsId2 = responseLicenseTerms2.licenseTermsId; - - const responseLicenseTerms3 = await expect( - registerCommercialRemixPIL("A", "60", 200, mintingFeeTokenAddress, waitForTransaction) - ).to.not.be.rejected; - - licenseTermsId3 = responseLicenseTerms3.licenseTermsId; - - const responseLicenseTerms4 = await expect( - registerCommercialRemixPIL("A", "16", 100, mintingFeeTokenAddress, waitForTransaction) - ).to.not.be.rejected; - - licenseTermsId4 = responseLicenseTerms4.licenseTermsId; - - const responseLicenseTerms5 = await expect( - registerNonComSocialRemixingPIL("A", waitForTransaction) - ).to.not.be.rejected; - - licenseTermsId5 = responseLicenseTerms5.licenseTermsId; - }); - describe("[smoke]Register derivative IP assets, parent IP asset with multiple commercial use PILs", async function () { step("Mint a NFT to Wallet A and get a tokenId (tokenIdA)", async function () { tokenIdA = await mintNFTWithRetry(privateKeyA); - if (tokenIdA === '') { - throw new Error('Unable to mint NFT'); - }; expect(tokenIdA).not.empty; }); @@ -80,17 +39,17 @@ describe('SDK E2E Test', function () { ipIdA = response.ipId; }); - step("Wallet A attach licenseTermsId1 (commercial use PIL) to ipIdA", async function () { + step("Wallet A attach comUseLicenseTermsId1 (commercial use PIL) to ipIdA", async function () { const response = await expect( - attachLicenseTerms("A", ipIdA, licenseTermsId1, waitForTransaction) + attachLicenseTerms("A", ipIdA, comUseLicenseTermsId1, waitForTransaction) ).to.not.be.rejected; expect(response.txHash).to.be.a("string").and.not.empty; }); - step("Wallet A attach licenseTermsId2 (commercial use PIL) to ipIdA", async function () { + step("Wallet A attach comUseLicenseTermsId2 (commercial use PIL) to ipIdA", async function () { const response = await expect( - attachLicenseTerms("A", ipIdA, licenseTermsId2, waitForTransaction) + attachLicenseTerms("A", ipIdA, comUseLicenseTermsId2, waitForTransaction) ).to.not.be.rejected; expect(response.txHash).to.be.a("string").and.not.empty; @@ -98,9 +57,6 @@ describe('SDK E2E Test', function () { step("Mint a NFT to Wallet B and get a tokenId (tokenIdB)", async function () { tokenIdB = await mintNFTWithRetry(privateKeyB); - if (tokenIdB === '') { - throw new Error('Unable to mint NFT'); - }; expect(tokenIdB).not.empty; }); @@ -115,9 +71,9 @@ describe('SDK E2E Test', function () { ipIdB = response.ipId; }); - step("Wallet B can use licenseTermsId1 to register ipIdB as ipIdA's derivative IP asset", async function () { + step("Wallet B can use comUseLicenseTermsId1 to register ipIdB as ipIdA's derivative IP asset", async function () { const response = await expect( - registerDerivative("B", ipIdB, [ipIdA], [licenseTermsId1], waitForTransaction) + registerDerivative("B", ipIdB, [ipIdA], [comUseLicenseTermsId1], waitForTransaction) ).to.not.be.rejected; expect(response.txHash).to.be.a("string").and.not.empty; @@ -125,9 +81,6 @@ describe('SDK E2E Test', function () { step("Mint a NFT to Wallet B and get a tokenId (tokenIdB)", async function () { tokenIdC = await mintNFTWithRetry(privateKeyB); - if (tokenIdB === '') { - throw new Error('Unable to mint NFT'); - }; expect(tokenIdC).not.empty; }); @@ -142,15 +95,15 @@ describe('SDK E2E Test', function () { ipIdC = response.ipId; }); - step("Wallet B can NOT use licenseTermsId3 to register ipIdC as ipIdA's derivative IP asset", async function () { + step("Wallet B can NOT use comRemixLicenseTermsId1 to register ipIdC as ipIdA's derivative IP asset", async function () { const response = await expect( - registerDerivative("B", ipIdC, [ipIdA], [licenseTermsId3], waitForTransaction) - ).to.be.rejectedWith("Failed to register derivative: License terms id " + licenseTermsId3 + " must be attached to the parent ipId " + ipIdA + " before registering derivative."); + registerDerivative("B", ipIdC, [ipIdA], [comRemixLicenseTermsId1], waitForTransaction) + ).to.be.rejectedWith("Failed to register derivative: License terms id " + comRemixLicenseTermsId1 + " must be attached to the parent ipId " + ipIdA + " before registering derivative."); }); - step("Wallet B can use licenseTermsId1 and licenseTermsId2 to register ipIdC as ipIdA's derivative IP asset", async function () { + step("Wallet B can use comUseLicenseTermsId1 and comUseLicenseTermsId2 to register ipIdC as ipIdA's derivative IP asset", async function () { const response = await expect( - registerDerivative("B", ipIdC, [ipIdA, ipIdA], [licenseTermsId1, licenseTermsId2], waitForTransaction) + registerDerivative("B", ipIdC, [ipIdA, ipIdA], [comUseLicenseTermsId1, comUseLicenseTermsId2], waitForTransaction) ).to.not.be.rejected; expect(response.txHash).to.be.a("string").and.not.empty; @@ -160,9 +113,6 @@ describe('SDK E2E Test', function () { describe("[smoke]Register derivative IP assets, parent IP asset with multiple commercial remix PILs", async function () { step("Mint a NFT to Wallet A and get a tokenId (tokenIdA)", async function () { tokenIdA = await mintNFTWithRetry(privateKeyA); - if (tokenIdA === '') { - throw new Error('Unable to mint NFT'); - }; expect(tokenIdA).not.empty; }); @@ -177,17 +127,17 @@ describe('SDK E2E Test', function () { ipIdA = response.ipId; }); - step("Wallet A attach licenseTermsId3(commercial remix PIL) to ipIdA", async function () { + step("Wallet A attach comRemixLicenseTermsId1(commercial remix PIL) to ipIdA", async function () { const response = await expect( - attachLicenseTerms("A", ipIdA, licenseTermsId3, waitForTransaction) + attachLicenseTerms("A", ipIdA, comRemixLicenseTermsId1, waitForTransaction) ).to.not.be.rejected; expect(response.txHash).to.be.a("string").and.not.empty; }); - step("Wallet A attach licenseTermsId4(commercial remix PIL) to ipIdA", async function () { + step("Wallet A attach comRemixLicenseTermsId2(commercial remix PIL) to ipIdA", async function () { const response = await expect( - attachLicenseTerms("A", ipIdA, licenseTermsId4, waitForTransaction) + attachLicenseTerms("A", ipIdA, comRemixLicenseTermsId2, waitForTransaction) ).to.not.be.rejected; expect(response.txHash).to.be.a("string").and.not.empty; @@ -195,9 +145,6 @@ describe('SDK E2E Test', function () { step("Mint a NFT to Wallet B and get a tokenId (tokenIdB)", async function () { tokenIdB = await mintNFTWithRetry(privateKeyB); - if (tokenIdB === '') { - throw new Error('Unable to mint NFT'); - }; expect(tokenIdB).not.empty; }); @@ -212,9 +159,9 @@ describe('SDK E2E Test', function () { ipIdB = response.ipId; }); - step("Wallet B can use licenseTermsId4 to register ipIdB as ipIdA's derivative IP asset", async function () { + step("Wallet B can use comRemixLicenseTermsId2 to register ipIdB as ipIdA's derivative IP asset", async function () { const response = await expect( - registerDerivative("B", ipIdB, [ipIdA], [licenseTermsId4], waitForTransaction) + registerDerivative("B", ipIdB, [ipIdA], [comRemixLicenseTermsId2], waitForTransaction) ).to.not.be.rejected; expect(response.txHash).to.be.a("string").and.not.empty; @@ -222,9 +169,6 @@ describe('SDK E2E Test', function () { step("Mint a NFT to Wallet B and get a tokenId (tokenIdB)", async function () { tokenIdC = await mintNFTWithRetry(privateKeyB); - if (tokenIdB === '') { - throw new Error('Unable to mint NFT'); - }; expect(tokenIdC).not.empty; }); @@ -239,15 +183,15 @@ describe('SDK E2E Test', function () { ipIdC = response.ipId; }); - step("Wallet B can NOT use licenseTermsId5 to register ipIdC as ipIdA's derivative IP asset", async function () { + step("Wallet B can NOT use nonComLicenseTermsId to register ipIdC as ipIdA's derivative IP asset", async function () { const response = await expect( - registerDerivative("B", ipIdC, [ipIdA], [licenseTermsId5], waitForTransaction) - ).to.be.rejectedWith("Failed to register derivative: License terms id " + licenseTermsId5 + " must be attached to the parent ipId " + ipIdA + " before registering derivative."); + registerDerivative("B", ipIdC, [ipIdA], [nonComLicenseTermsId], waitForTransaction) + ).to.be.rejectedWith("Failed to register derivative: License terms id " + nonComLicenseTermsId + " must be attached to the parent ipId " + ipIdA + " before registering derivative."); }); - step("Wallet B can use licenseTermsId3 and licenseTermsId4 to register ipIdC as ipIdA's derivative IP asset", async function () { + step("Wallet B can use comRemixLicenseTermsId1 and comRemixLicenseTermsId2 to register ipIdC as ipIdA's derivative IP asset", async function () { const response = await expect( - registerDerivative("B", ipIdC, [ipIdA, ipIdA], [licenseTermsId3, licenseTermsId4], waitForTransaction) + registerDerivative("B", ipIdC, [ipIdA, ipIdA], [comRemixLicenseTermsId1, comRemixLicenseTermsId2], waitForTransaction) ).to.not.be.rejected; expect(response.txHash).to.be.a("string").and.not.empty; @@ -257,9 +201,6 @@ describe('SDK E2E Test', function () { describe("Register a derivative IP asset, parent IP asset with multiple non-commericial and commercial PILs", async function () { step("Mint a NFT to Wallet A and get a tokenId (tokenIdA)", async function () { tokenIdA = await mintNFTWithRetry(privateKeyA); - if (tokenIdA === '') { - throw new Error('Unable to mint NFT'); - }; expect(tokenIdA).not.empty; }); @@ -274,25 +215,25 @@ describe('SDK E2E Test', function () { ipIdA = response.ipId; }); - step("Wallet A attach licenseTermsId1(commercial use PIL) to ipIdA", async function () { + step("Wallet A attach comUseLicenseTermsId1(commercial use PIL) to ipIdA", async function () { const response = await expect( - attachLicenseTerms("A", ipIdA, licenseTermsId1, waitForTransaction) + attachLicenseTerms("A", ipIdA, comUseLicenseTermsId1, waitForTransaction) ).to.not.be.rejected; expect(response.txHash).to.be.a("string").and.not.empty; }); - step("Wallet A attach licenseTermsId3(commercial remix PIL) to ipIdA", async function () { + step("Wallet A attach comRemixLicenseTermsId1(commercial remix PIL) to ipIdA", async function () { const response = await expect( - attachLicenseTerms("A", ipIdA, licenseTermsId3, waitForTransaction) + attachLicenseTerms("A", ipIdA, comRemixLicenseTermsId1, waitForTransaction) ).to.not.be.rejected; expect(response.txHash).to.be.a("string").and.not.empty; }); - step("Wallet A attach licenseTermsId5(non-commercial social remixing PIL) to ipIdA", async function () { + step("Wallet A attach nonComLicenseTermsId(non-commercial social remixing PIL) to ipIdA", async function () { const response = await expect( - attachLicenseTerms("A", ipIdA, licenseTermsId5, waitForTransaction) + attachLicenseTerms("A", ipIdA, nonComLicenseTermsId, waitForTransaction) ).to.not.be.rejected; expect(response.txHash).to.be.a("string").and.not.empty; @@ -300,9 +241,6 @@ describe('SDK E2E Test', function () { step("Mint a NFT to Wallet B and get a tokenId (tokenIdB)", async function () { tokenIdB = await mintNFTWithRetry(privateKeyB); - if (tokenIdB === '') { - throw new Error('Unable to mint NFT'); - }; expect(tokenIdB).not.empty; }); @@ -317,30 +255,30 @@ describe('SDK E2E Test', function () { ipIdB = response.ipId; }); - step("Wallet B can NOT use licenseTermsId1, licenseTermsId3 to register ipIdB as ipIdA's derivative IP asset", async function () { + step("Wallet B can NOT use comUseLicenseTermsId1, comRemixLicenseTermsId1 to register ipIdB as ipIdA's derivative IP asset", async function () { const response = await expect( - registerDerivative("B", ipIdB, [ipIdA, ipIdA], [licenseTermsId1, licenseTermsId3], waitForTransaction) + registerDerivative("B", ipIdB, [ipIdA, ipIdA], [comUseLicenseTermsId1, comRemixLicenseTermsId1], waitForTransaction) ).to.be.rejectedWith("Failed to register derivative: The contract function \"registerDerivative\" reverted.", "Error: LicensingModule__LicenseNotCompatibleForDerivative"); }); - step("Wallet B can NOT use licenseTermsId1, licenseTermsId5 to register ipIdB as ipIdA's derivative IP asset", async function () { + step("Wallet B can NOT use comUseLicenseTermsId1, nonComLicenseTermsId to register ipIdB as ipIdA's derivative IP asset", async function () { const response = await expect( - registerDerivative("B", ipIdB, [ipIdA, ipIdA], [licenseTermsId1, licenseTermsId5], waitForTransaction) + registerDerivative("B", ipIdB, [ipIdA, ipIdA], [comUseLicenseTermsId1, nonComLicenseTermsId], waitForTransaction) ).to.be.rejectedWith("Failed to register derivative: The contract function \"registerDerivative\" reverted.", "Error: LicensingModule__LicenseNotCompatibleForDerivative"); }); - step("Wallet B can NOT use licenseTermsId3, licenseTermsId5 to register ipIdB as ipIdA's derivative IP asset", async function () { + step("Wallet B can NOT use comRemixLicenseTermsId1, nonComLicenseTermsId to register ipIdB as ipIdA's derivative IP asset", async function () { const response = await expect( - registerDerivative("B", ipIdB, [ipIdA, ipIdA], [licenseTermsId3, licenseTermsId5], waitForTransaction) + registerDerivative("B", ipIdB, [ipIdA, ipIdA], [comRemixLicenseTermsId1, nonComLicenseTermsId], waitForTransaction) ).to.be.rejectedWith("Failed to register derivative: The contract function \"registerDerivative\" reverted.", "Error: LicensingModule__LicenseNotCompatibleForDerivative"); }); - step("Wallet B can NOT use licenseTermsId1, licenseTermsId3, licenseTermsId5 to register ipIdB as ipIdA's derivative IP asset", async function () { + step("Wallet B can NOT use comUseLicenseTermsId1, comRemixLicenseTermsId1, nonComLicenseTermsId to register ipIdB as ipIdA's derivative IP asset", async function () { const response = await expect( - registerDerivative("B", ipIdB, [ipIdA, ipIdA, ipIdA], [licenseTermsId1, licenseTermsId3, licenseTermsId5], waitForTransaction) + registerDerivative("B", ipIdB, [ipIdA, ipIdA, ipIdA], [comUseLicenseTermsId1, comRemixLicenseTermsId1, nonComLicenseTermsId], waitForTransaction) ).to.be.rejectedWith("Failed to register derivative: The contract function \"registerDerivative\" reverted.", "Error: LicensingModule__LicenseNotCompatibleForDerivative"); }); diff --git a/test/e2e/royalty.test.ts b/test/e2e/royalty.test.ts index 3871fd6..b312710 100644 --- a/test/e2e/royalty.test.ts +++ b/test/e2e/royalty.test.ts @@ -1,12 +1,13 @@ import { privateKeyA, privateKeyB, privateKeyC, nftContractAddress, mintingFeeTokenAddress } from '../../config/config' import { checkMintResult, mintNFTWithRetry, sleep } from '../../utils/utils' -import { registerIpAsset, attachLicenseTerms, registerDerivative, registerCommercialUsePIL, registerCommercialRemixPIL, payRoyaltyOnBehalf, royaltySnapshot, collectRoyaltyTokens, royaltyClaimableRevenue, royaltyClaimRevenue } from '../../utils/sdkUtils' +import { registerIpAsset, attachLicenseTerms, registerDerivative, payRoyaltyOnBehalf, royaltySnapshot, collectRoyaltyTokens, royaltyClaimableRevenue, royaltyClaimRevenue } from '../../utils/sdkUtils' import { expect } from 'chai' import chai from 'chai'; import chaiAsPromised from 'chai-as-promised'; chai.use(chaiAsPromised); import '../setup'; +import { comUseLicenseTermsId1, comRemixLicenseTermsId2, mintingFee1, mintingFee2, commercialRevShare2, comUseLicenseTermsId2, comRemixLicenseTermsId1, commercialRevShare1 } from '../setup'; import { Hex } from 'viem'; let tokenIdA: string; @@ -15,7 +16,6 @@ let tokenIdC: string; let ipIdA: Hex; let ipIdB: Hex; let ipIdC: Hex; -let licenseTermsId1: string; let snapshotId1: string; let snapshotId2: string; @@ -24,18 +24,9 @@ const waitForTransaction: boolean = true; describe('SDK E2E Test', function () { describe("Royalty", function () { describe("Commercial Use PIL - Claim Minting Fee", function () { - const mintingFee: string = "100"; - before("Register parent and derivative IP assets", async function () { - const responseLicenseTerm1 = await expect( - registerCommercialUsePIL("A", mintingFee, mintingFeeTokenAddress, waitForTransaction) - ).to.not.be.rejected; - - licenseTermsId1 = responseLicenseTerm1.licenseTermsId; - tokenIdA = await mintNFTWithRetry(privateKeyA); checkMintResult(tokenIdA); - expect(tokenIdA).not.empty; const responseRegisterIpAsset = await expect( registerIpAsset("A", nftContractAddress, tokenIdA, waitForTransaction) @@ -47,14 +38,13 @@ describe('SDK E2E Test', function () { ipIdA = responseRegisterIpAsset.ipId; const responseAttachLicenseTerms = await expect( - attachLicenseTerms("A", ipIdA, licenseTermsId1, waitForTransaction) + attachLicenseTerms("A", ipIdA, comUseLicenseTermsId1, waitForTransaction) ).to.not.be.rejected; expect(responseAttachLicenseTerms.txHash).to.be.a("string").and.not.empty; tokenIdB = await mintNFTWithRetry(privateKeyB); checkMintResult(tokenIdB); - expect(tokenIdB).not.empty; const responseregisterIpAssetB = await expect( registerIpAsset("B", nftContractAddress, tokenIdB, waitForTransaction) @@ -66,12 +56,19 @@ describe('SDK E2E Test', function () { ipIdB = responseregisterIpAssetB.ipId; const response = await expect( - registerDerivative("B", ipIdB, [ipIdA], [licenseTermsId1], waitForTransaction) + registerDerivative("B", ipIdB, [ipIdA], [comUseLicenseTermsId1], waitForTransaction) ).to.not.be.rejected; expect(response.txHash).to.be.a("string").and.not.empty; + }); - await sleep(20); + step("Collect royalty tokens", async function () { + const response = await expect( + collectRoyaltyTokens("B", ipIdA, ipIdB, waitForTransaction) + ).to.not.be.rejected; + + expect(response.txHash).to.be.a("string").and.not.empty; + expect(response.royaltyTokensCollected).to.be.a('string').and.equal("0"); }); step("Capture snapshotId", async function () { @@ -82,7 +79,7 @@ describe('SDK E2E Test', function () { expect(response.txHash).to.be.a("string").and.not.empty; expect(response.snapshotId).to.be.a("string").and.not.empty; - snapshotId1 = response.snapshotId; + snapshotId1 = String(response.snapshotId); }); step("Check claimable revenue", async function () { @@ -91,7 +88,7 @@ describe('SDK E2E Test', function () { ).to.not.be.rejected; expect(response).to.be.a("string").and.not.empty; - expect(response).to.be.equal(mintingFee); + expect(response).to.be.equal(mintingFee1); }); step("Claim minting fee", async function () { @@ -100,7 +97,7 @@ describe('SDK E2E Test', function () { ).to.not.be.rejected; expect(response.txHash).to.be.a("string").and.not.empty; - expect(response.claimableToken).to.be.equal(mintingFee); + expect(response.claimableToken).to.be.equal(mintingFee1); }); step("Check claimable revenue again", async function () { @@ -114,19 +111,11 @@ describe('SDK E2E Test', function () { }) describe('Commercial Use PIL - Claim Minting Fee and Pay on Behalf', async function () { - let mintingFee: string = "60"; let payAmount: string = "100"; - before("Register parent and derivative IP assets", async function () { - const responseLicenseTerms1 = await expect( - registerCommercialUsePIL("A", mintingFee, mintingFeeTokenAddress, waitForTransaction) - ).to.not.be.rejected; - - licenseTermsId1 = responseLicenseTerms1.licenseTermsId; - + before("Register parent and derivative IP assets", async function () { tokenIdA = await mintNFTWithRetry(privateKeyA); checkMintResult(tokenIdA); - expect(tokenIdA).not.empty; const responseRegisterIpAsset = await expect( registerIpAsset("A", nftContractAddress, tokenIdA, waitForTransaction) @@ -138,14 +127,13 @@ describe('SDK E2E Test', function () { ipIdA = responseRegisterIpAsset.ipId; const responseAttachLicenseTerms = await expect( - attachLicenseTerms("A", ipIdA, licenseTermsId1, waitForTransaction) + attachLicenseTerms("A", ipIdA, comUseLicenseTermsId2, waitForTransaction) ).to.not.be.rejected; expect(responseAttachLicenseTerms.txHash).to.be.a("string").and.not.empty; tokenIdB = await mintNFTWithRetry(privateKeyB); checkMintResult(tokenIdB); - expect(tokenIdB).not.empty; const responseregisterIpAssetB = await expect( registerIpAsset("B", nftContractAddress, tokenIdB, waitForTransaction) @@ -157,11 +145,10 @@ describe('SDK E2E Test', function () { ipIdB = responseregisterIpAssetB.ipId; const response = await expect( - registerDerivative("B", ipIdB, [ipIdA], [licenseTermsId1], waitForTransaction) + registerDerivative("B", ipIdB, [ipIdA], [comUseLicenseTermsId2], waitForTransaction) ).to.not.be.rejected; expect(response.txHash).to.be.a("string").and.not.empty; - await sleep(20); }); step("Collect royalty tokens", async function () { @@ -190,7 +177,7 @@ describe('SDK E2E Test', function () { ).to.not.be.rejected; expect(response).to.be.a("string").and.not.empty; - expect(response).to.be.equal(mintingFee); + expect(response).to.be.equal(mintingFee2); }); step("Pay royalty on behalf", async function () { @@ -199,7 +186,6 @@ describe('SDK E2E Test', function () { ).to.not.be.rejected; expect(response.txHash).to.be.a("string").and.not.empty; - await sleep(20); }); step("Capture snapshotId", async function () { @@ -223,7 +209,7 @@ describe('SDK E2E Test', function () { }); step("Claim revenue", async function () { - const claimableRevenue = String(Number(mintingFee) + Number(payAmount)); + const claimableRevenue = String(Number(mintingFee2) + Number(payAmount)); const response = await expect( royaltyClaimRevenue("A", [snapshotId1, snapshotId2], ipIdA, ipIdA, mintingFeeTokenAddress, waitForTransaction) ).to.not.be.rejected; @@ -251,19 +237,9 @@ describe('SDK E2E Test', function () { }); describe("Commercial Remix PIL - Claim Minting Fee", function () { - const mintingFee: string = "80"; - const commercialRevShare: number = 200; - - before("Register parent and derivative IP Assets", async function () { - const responsePolicy = await expect( - registerCommercialRemixPIL("A", mintingFee, commercialRevShare, mintingFeeTokenAddress, waitForTransaction) - ).to.not.be.rejected; - - licenseTermsId1 = responsePolicy.licenseTermsId; - + before("Register parent and derivative IP Assets", async function () { tokenIdA = await mintNFTWithRetry(privateKeyA); checkMintResult(tokenIdA); - expect(tokenIdA).not.empty; const responseRegisterIpAsset = await expect( registerIpAsset("A", nftContractAddress, tokenIdA, waitForTransaction) @@ -275,14 +251,13 @@ describe('SDK E2E Test', function () { ipIdA = responseRegisterIpAsset.ipId; const responseAttachLicenseTerms = await expect( - attachLicenseTerms("A", ipIdA, licenseTermsId1, waitForTransaction) + attachLicenseTerms("A", ipIdA, comRemixLicenseTermsId1, waitForTransaction) ).to.not.be.rejected; expect(responseAttachLicenseTerms.txHash).to.be.a("string").and.not.empty; tokenIdB = await mintNFTWithRetry(privateKeyB); checkMintResult(tokenIdB); - expect(tokenIdB).not.empty; const responseregisterIpAssetB = await expect( registerIpAsset("B", nftContractAddress, tokenIdB, waitForTransaction) @@ -294,11 +269,10 @@ describe('SDK E2E Test', function () { ipIdB = responseregisterIpAssetB.ipId; const response = await expect( - registerDerivative("B", ipIdB, [ipIdA], [licenseTermsId1], waitForTransaction) + registerDerivative("B", ipIdB, [ipIdA], [comRemixLicenseTermsId1], waitForTransaction) ).to.not.be.rejected; expect(response.txHash).to.be.a("string").and.not.empty; - await sleep(20); }); step("Collect royalty tokens", async function () { @@ -309,7 +283,7 @@ describe('SDK E2E Test', function () { expect(response.txHash).to.be.a("string").and.not.empty; expect(response.royaltyTokensCollected).to.be.a('string').and.not.empty; - expect(Number(response.royaltyTokensCollected)).to.be.equal(commercialRevShare); + expect(Number(response.royaltyTokensCollected)).to.be.equal(commercialRevShare1); }); step("Capture snapshotId", async function () { @@ -329,7 +303,7 @@ describe('SDK E2E Test', function () { ).to.not.be.rejected; expect(response).to.be.a("string").and.not.empty; - expect(response).to.be.equal(mintingFee); + expect(response).to.be.equal(mintingFee1); }); step("Claim revenue", async function () { @@ -338,7 +312,7 @@ describe('SDK E2E Test', function () { ).to.not.be.rejected; expect(response.txHash).to.be.a("string").and.not.empty; - expect(response.claimableToken).to.be.equal(mintingFee); + expect(response.claimableToken).to.be.equal(mintingFee1); }); step("Check claimable revenue again", async function () { @@ -352,19 +326,10 @@ describe('SDK E2E Test', function () { }) describe('Commercial Remix PIL - Claim Minting Fee and Pay on Behalf', async function () { - let mintingFee: string = "90"; let payAmount: string = "600"; - let commercialRevShare: number = 100; + const claimableRevenue = String(Number(mintingFee2) + Number(payAmount)); - const claimableRevenue = String(Number(mintingFee) + Number(payAmount)); - - before("Register parent and derivative IP assets", async function () { - const responsePolicy = await expect( - registerCommercialRemixPIL("A", mintingFee, commercialRevShare, mintingFeeTokenAddress, waitForTransaction) - ).to.not.be.rejected; - - licenseTermsId1 = responsePolicy.licenseTermsId; - + before("Register parent and derivative IP assets", async function () { tokenIdA = await mintNFTWithRetry(privateKeyA); checkMintResult(tokenIdA); expect(tokenIdA).not.empty; @@ -379,7 +344,7 @@ describe('SDK E2E Test', function () { ipIdA = responseRegisterIpAsset.ipId; const responseAttachLicenseTerms = await expect( - attachLicenseTerms("A", ipIdA, licenseTermsId1, waitForTransaction) + attachLicenseTerms("A", ipIdA, comRemixLicenseTermsId2, waitForTransaction) ).to.not.be.rejected; expect(responseAttachLicenseTerms.txHash).to.be.a("string").and.not.empty; @@ -398,11 +363,10 @@ describe('SDK E2E Test', function () { ipIdB = responseregisterIpAssetB.ipId; const responseB = await expect( - registerDerivative("B", ipIdB, [ipIdA], [licenseTermsId1], waitForTransaction) + registerDerivative("B", ipIdB, [ipIdA], [comRemixLicenseTermsId2], waitForTransaction) ).to.not.be.rejected; expect(responseB.txHash).to.be.a("string").and.not.empty; - await sleep(20); }); step("Collect royalty tokens", async function () { @@ -411,7 +375,7 @@ describe('SDK E2E Test', function () { ).to.not.be.rejected; expect(response.txHash).to.be.a("string").and.not.empty; - expect(response.royaltyTokensCollected).to.be.a('string').and.equal(String(commercialRevShare)); + expect(response.royaltyTokensCollected).to.be.a('string').and.equal(String(commercialRevShare2)); }); step("Capture snapshot", async function () { @@ -431,7 +395,7 @@ describe('SDK E2E Test', function () { ).to.not.be.rejected; expect(response).to.be.a("string").and.not.empty; - expect(response).to.be.equal(mintingFee); + expect(response).to.be.equal(mintingFee2); }); step("Pay royalty on behalf", async function () { @@ -441,7 +405,7 @@ describe('SDK E2E Test', function () { console.log(response); expect(response.txHash).to.be.a("string").and.not.empty; - await sleep(20); + }); step("Capture snapshot", async function () { @@ -491,19 +455,10 @@ describe('SDK E2E Test', function () { }); describe('Royalty - Derivative and Re-inherited IP Assets', async function () { - let mintingFee: string = "120"; let payAmount: string = "800"; - let commercialRevShare: number = 160; - - const claimableRevenue = String(Number(mintingFee) + Number(payAmount)); + const claimableRevenue = String(Number(mintingFee1) + Number(payAmount)); - before("Register parent and derivative IP assets", async function () { - const responsePolicy = await expect( - registerCommercialRemixPIL("A", mintingFee, commercialRevShare, mintingFeeTokenAddress, waitForTransaction) - ).to.not.be.rejected; - - licenseTermsId1 = responsePolicy.licenseTermsId; - + before("Register parent and derivative IP assets", async function () { tokenIdA = await mintNFTWithRetry(privateKeyA); checkMintResult(tokenIdA); expect(tokenIdA).not.empty; @@ -518,7 +473,7 @@ describe('SDK E2E Test', function () { ipIdA = responseRegisterIpAsset.ipId; const responseAttachLicenseTerms = await expect( - attachLicenseTerms("A", ipIdA, licenseTermsId1, waitForTransaction) + attachLicenseTerms("A", ipIdA, comRemixLicenseTermsId1, waitForTransaction) ).to.not.be.rejected; expect(responseAttachLicenseTerms.txHash).to.be.a("string").and.not.empty; @@ -537,14 +492,13 @@ describe('SDK E2E Test', function () { ipIdB = responseregisterIpAssetB.ipId; const responseB = await expect( - registerDerivative("B", ipIdB, [ipIdA], [licenseTermsId1], waitForTransaction) + registerDerivative("B", ipIdB, [ipIdA], [comRemixLicenseTermsId1], waitForTransaction) ).to.not.be.rejected; expect(responseB.txHash).to.be.a("string").and.not.empty; tokenIdC = await mintNFTWithRetry(privateKeyC); checkMintResult(tokenIdC); - expect(tokenIdC).not.empty; const responseregisterIpAssetC = await expect( registerIpAsset("C", nftContractAddress, tokenIdC, waitForTransaction) @@ -556,11 +510,10 @@ describe('SDK E2E Test', function () { ipIdC = responseregisterIpAssetC.ipId; const responseC = await expect( - registerDerivative("C", ipIdC, [ipIdB], [licenseTermsId1], waitForTransaction) + registerDerivative("C", ipIdC, [ipIdB], [comRemixLicenseTermsId1], waitForTransaction) ).to.not.be.rejected; expect(responseC.txHash).to.be.a("string").and.not.empty; - await sleep(20); }); step("Pay royalty on behalf", async function () { @@ -570,7 +523,6 @@ describe('SDK E2E Test', function () { console.log(response); expect(response.txHash).to.be.a("string").and.not.empty; - await sleep(20); }); step("Collect royalty tokens", async function () { @@ -579,7 +531,7 @@ describe('SDK E2E Test', function () { ).to.not.be.rejected; expect(response.txHash).to.be.a("string").and.not.empty; - expect(response.royaltyTokensCollected).to.be.a('string').and.equal(String(commercialRevShare)); + expect(response.royaltyTokensCollected).to.be.a('string').and.equal(String(commercialRevShare1)); }); step("Collect royalty tokens", async function () { @@ -588,7 +540,7 @@ describe('SDK E2E Test', function () { ).to.not.be.rejected; expect(response.txHash).to.be.a("string").and.not.empty; - expect(response.royaltyTokensCollected).to.be.a('string').and.equal(String(commercialRevShare)); + expect(response.royaltyTokensCollected).to.be.a('string').and.equal(String(commercialRevShare1)); }); step("Capture snapshot", async function () { @@ -608,7 +560,7 @@ describe('SDK E2E Test', function () { ).to.not.be.rejected; expect(response).to.be.a("string").and.not.empty; - expect(response).to.be.equal(mintingFee); + expect(response).to.be.equal(mintingFee1); }); step("Claim royalty tokens", async function () { @@ -617,7 +569,7 @@ describe('SDK E2E Test', function () { ).to.not.be.rejected; expect(response.txHash).to.be.a("string").and.not.empty; - expect(response.claimableToken).to.be.equal(mintingFee); + expect(response.claimableToken).to.be.equal(mintingFee1); }) step("Check claimable revenue again", async function () { diff --git a/test/e2e/setPermissions.test.ts b/test/e2e/setPermissions.test.ts index f3aa847..e9f221a 100644 --- a/test/e2e/setPermissions.test.ts +++ b/test/e2e/setPermissions.test.ts @@ -1,9 +1,10 @@ -import { privateKeyA, accountB, licensingModuleAddress, nftContractAddress, mintingFeeTokenAddress} from '../../config/config'; -import { mintNFTWithRetry } from '../../utils/utils'; -import { registerNonComSocialRemixingPIL, registerCommercialUsePIL, registerIpAsset, setPermission, attachLicenseTerms } from '../../utils/sdkUtils'; +import { privateKeyA, accountB, licensingModuleAddress, nftContractAddress} from '../../config/config'; +import { checkMintResult, mintNFTWithRetry } from '../../utils/utils'; +import { registerIpAsset, setPermission, attachLicenseTerms } from '../../utils/sdkUtils'; import { expect } from 'chai'; import { Hex } from 'viem'; import '../setup'; +import { nonComLicenseTermsId, comUseLicenseTermsId1 } from '../setup'; import chai from 'chai'; import chaiAsPromised from 'chai-as-promised'; @@ -13,31 +14,14 @@ let tokenIdA: string; let tokenIdB: string; let ipIdA: Hex; let ipIdB: Hex; -let licenseTermsId1: string; -let licenseTermsId2: string; const waitForTransaction: boolean = true; describe('SDK E2E Test', function () { describe("[smoke]Set Permissions", async function () { - this.beforeAll("Register 2 license terms and 2 IP assets", async function () { - const responselicenseTerms1 = await expect( - registerNonComSocialRemixingPIL("A", waitForTransaction) - ).to.not.be.rejected; - - licenseTermsId1 = responselicenseTerms1.licenseTermsId; - - const responselicenseTerms2 = await expect( - registerCommercialUsePIL("A", "100", mintingFeeTokenAddress, waitForTransaction) - ).to.not.be.rejected; - - licenseTermsId2 = responselicenseTerms2.licenseTermsId; - + this.beforeAll("Wallet A register 2 license terms and 2 IP assets", async function () { tokenIdA = await mintNFTWithRetry(privateKeyA); - if (tokenIdA === '') { - throw new Error('Unable to mint NFT'); - } - expect(tokenIdA).not.empty; + checkMintResult(tokenIdA); const responseRegisterIpA = await expect( registerIpAsset("A", nftContractAddress, tokenIdA, waitForTransaction) @@ -47,12 +31,9 @@ describe('SDK E2E Test', function () { expect(responseRegisterIpA.ipId).to.be.a("string").and.not.empty; ipIdA = responseRegisterIpA.ipId; - + tokenIdB = await mintNFTWithRetry(privateKeyA); - if (tokenIdB === '') { - throw new Error('Unable to mint NFT'); - } - expect(tokenIdB).not.empty; + checkMintResult(tokenIdB); const responseRegisterIpB = await expect( registerIpAsset("A", nftContractAddress, tokenIdB, waitForTransaction) @@ -63,8 +44,16 @@ describe('SDK E2E Test', function () { ipIdB = responseRegisterIpB.ipId; }) - + describe("Set permission - 1 ALLOW", async function (){ + // error 0xb3e96921: AccessController__PermissionDenied(address,address,address,bytes4) + step("Wallet B(non-owner) can NOT attach licenseTermsId1 to ipIdA", async function () { + const response = await expect( + attachLicenseTerms("B", ipIdA, nonComLicenseTermsId, waitForTransaction) + ).to.be.rejectedWith("Failed to attach license terms: The contract function \"attachLicenseTerms\" reverted with the following signature:", "0xb3e96921"); + }); + + // wallet B is granted permission - 1 ALLOW for ipIdA step("Wallet A set permission (permission id: 1) to allow Wallet B to call license Module for ipIdA", async function () { const response = await expect( setPermission("A", ipIdA, accountB.address, licensingModuleAddress, 1, waitForTransaction) @@ -76,20 +65,23 @@ describe('SDK E2E Test', function () { step("Wallet B can attach licenseTermsId1 to ipIdA", async function () { const response = await expect( - attachLicenseTerms("B", ipIdA, licenseTermsId1, waitForTransaction) + attachLicenseTerms("B", ipIdA, nonComLicenseTermsId, waitForTransaction) ).to.not.be.rejected; expect(response.txHash).to.be.a("string").and.not.empty; }); + // wallet B is not granted any permission for ipIdB + // error 0xb3e96921: AccessController__PermissionDenied(address,address,address,bytes4) step("Wallet B can NOT attach licenseTermsId1 to ipIdB", async function () { const response = await expect( - attachLicenseTerms("B", ipIdB, licenseTermsId1, waitForTransaction) + attachLicenseTerms("B", ipIdB, nonComLicenseTermsId, waitForTransaction) ).to.be.rejectedWith("Failed to attach license terms: The contract function \"attachLicenseTerms\" reverted with the following signature:", "0xb3e96921"); }); }); describe("Set permission - 2 DENY", async function (){ + // change wallet B's permission to 2 DENY for ipIdA step("Wallet A set permission (permission id: 2) to NOT allow Wallet B to call license Module for ipIdA", async function () { const response = await expect( setPermission("A", ipIdA, accountB.address, licensingModuleAddress, 2, waitForTransaction) @@ -99,14 +91,16 @@ describe('SDK E2E Test', function () { expect(response.success).to.be.true; }); + // error 0xb3e96921: AccessController__PermissionDenied(address,address,address,bytes4) step("Wallet B can NOT attach licenseTermsId1 to ipIdA", async function () { const response = await expect( - attachLicenseTerms("B", ipIdA, licenseTermsId2, waitForTransaction) + attachLicenseTerms("B", ipIdA, comUseLicenseTermsId1, waitForTransaction) ).to.be.rejectedWith("Failed to attach license terms: The contract function \"attachLicenseTerms\" reverted with the following signature:", "0xb3e96921"); }); }); describe("Set permission - 0 ABSTAIN", async function (){ + // wallet B is granted permission - 1 ALLOW for ipIdB step("Wallet A set permission (permission id: 1) to allow Wallet B to call license Module for ipIdB", async function () { const response = await expect( setPermission("A", ipIdB, accountB.address, licensingModuleAddress, 1, waitForTransaction) @@ -118,12 +112,13 @@ describe('SDK E2E Test', function () { step("Wallet B can attach licenseTermsId1 to ipIdB", async function () { const response = await expect( - attachLicenseTerms("B", ipIdB, licenseTermsId1, waitForTransaction) + attachLicenseTerms("B", ipIdB, nonComLicenseTermsId, waitForTransaction) ).to.not.be.rejected; expect(response.txHash).to.be.a("string").and.not.empty; }); + // change wallet B's permission to 0 ABSTAIN for ipIdB step("Wallet A set permission (permission id: 0) to NOT allow Wallet B to call license Module for ipIdB", async function () { const response = await expect( setPermission("A", ipIdB, accountB.address, licensingModuleAddress, 0, waitForTransaction) @@ -133,9 +128,10 @@ describe('SDK E2E Test', function () { expect(response.success).to.be.true; }); + // error 0xb3e96921: AccessController__PermissionDenied(address,address,address,bytes4) step("Wallet B can NOT attach licenseTermsId2 to ipIdB", async function () { const response = await expect( - attachLicenseTerms("B", ipIdB, licenseTermsId2, waitForTransaction) + attachLicenseTerms("B", ipIdB, comUseLicenseTermsId1, waitForTransaction) ).to.be.rejectedWith("Failed to attach license terms: The contract function \"attachLicenseTerms\" reverted with the following signature:", "0xb3e96921"); }); }); diff --git a/test/ipAsset/registerDerivative.test.ts b/test/ipAsset/registerDerivative.test.ts index c75a734..4537366 100644 --- a/test/ipAsset/registerDerivative.test.ts +++ b/test/ipAsset/registerDerivative.test.ts @@ -1,5 +1,5 @@ -import { nftContractAddress, privateKeyA, privateKeyB, mintingFeeTokenAddress } from '../../config/config'; -import { attachLicenseTerms, registerCommercialUsePIL, registerDerivative, registerIpAsset, registerNonComSocialRemixingPIL } from '../../utils/sdkUtils'; +import { privateKeyA, privateKeyB, nftContractAddress } from '../../config/config'; +import { attachLicenseTerms, registerDerivative, registerIpAsset } from '../../utils/sdkUtils'; import { checkMintResult, mintNFTWithRetry } from '../../utils/utils'; import { expect } from 'chai' import chai from 'chai'; @@ -7,27 +7,16 @@ import chaiAsPromised from 'chai-as-promised'; chai.use(chaiAsPromised); import '../setup'; import { Hex } from 'viem'; +import { nonComLicenseTermsId, comUseLicenseTermsId1 } from '../setup'; let tokenIdA: string; let tokenIdB: string; let ipIdA: Hex; let ipIdB: Hex; -let licenseTermsId1: string; -let licenseTermsId2: string; describe('SDK Test', function () { describe('Test ipAsset.registerDerivative Function', async function () { before("Register license terms, mint NFTs and register IP assets",async function () { - const licenseTerms1 = await expect( - registerNonComSocialRemixingPIL("A", true) - ).to.not.be.rejected; - licenseTermsId1 = licenseTerms1.licenseTermsId; - - const licenseTerms2 = await expect( - registerCommercialUsePIL("A", "0", mintingFeeTokenAddress, true) - ).to.not.be.rejected; - licenseTermsId2 = licenseTerms2.licenseTermsId; - tokenIdA = await mintNFTWithRetry(privateKeyA); checkMintResult(tokenIdA); expect(tokenIdA).not.empty; @@ -57,63 +46,63 @@ describe('SDK Test', function () { it("Register a derivative IP asset fail as no license terms attached", async function () { await expect( - registerDerivative("C", ipIdB, [ipIdA], [licenseTermsId1], true) - ).to.be.rejectedWith("Failed to register derivative: License terms id " + licenseTermsId1 + " must be attached to the parent ipId " + ipIdA + " before registering derivative."); + registerDerivative("C", ipIdB, [ipIdA], [nonComLicenseTermsId], true) + ).to.be.rejectedWith("Failed to register derivative: License terms id " + nonComLicenseTermsId + " must be attached to the parent ipId " + ipIdA + " before registering derivative."); }); it("Register a derivative IP asset fail as no license terms attached", async function () { const response = await expect( - attachLicenseTerms("A", ipIdA, licenseTermsId1, true) + attachLicenseTerms("A", ipIdA, nonComLicenseTermsId, true) ).to.not.be.rejected; expect(response.txHash).to.be.a("string").and.not.empty; await expect( - registerDerivative("C", ipIdB, [ipIdA], [licenseTermsId1], true) + registerDerivative("C", ipIdB, [ipIdA], [nonComLicenseTermsId], true) ).to.be.rejectedWith("Failed to register derivative: The contract function \"registerDerivative\" reverted with the following signature:", "0xb3e96921"); }); it("Register a derivative IP asset fail as undefined child ipId", async function () { let ipIdB: any; await expect( - registerDerivative("B", ipIdB, [ipIdA], [licenseTermsId1], true) + registerDerivative("B", ipIdB, [ipIdA], [nonComLicenseTermsId], true) ).to.be.rejectedWith("Failed to register derivative: Address \"undefined\" is invalid."); }); it("Register a derivative IP asset fail as invalid child ipId", async function () { await expect( - registerDerivative("B", "0x0000", [ipIdA], [licenseTermsId1], true) + registerDerivative("B", "0x0000", [ipIdA], [nonComLicenseTermsId], true) ).to.be.rejectedWith("Failed to register derivative: Address \"0x0000\" is invalid."); }); it("Register a derivative IP asset fail as non-existent child ipId", async function () { await expect( - registerDerivative("B", "0x485FCfC79Ce0A082Ab2a5e729D6e6255A540342a", [ipIdA], [licenseTermsId1], true) - ).to.be.rejectedWith("Failed to register derivative: Address \"0x485FCfC79Ce0A082Ab2a5e729D6e6255A540342a\" is invalid."); + registerDerivative("B", "0x485FCfC79Ce0A082Ab2a5e729D6e6255A540342a", [ipIdA], [nonComLicenseTermsId], true) + ).to.be.rejectedWith("Failed to register derivative: The child IP with id 0x485FCfC79Ce0A082Ab2a5e729D6e6255A540342a is not registered."); }); it("Register a derivative IP asset fail as undefined parent ipId", async function () { let ipIdA: any; await expect( - registerDerivative("B", ipIdB, [ipIdA], [licenseTermsId1], true) + registerDerivative("B", ipIdB, [ipIdA], [nonComLicenseTermsId], true) ).to.be.rejectedWith("Failed to register derivative: Address \"undefined\" is invalid."); }); it("Register a derivative IP asset fail as invalid parent ipId", async function () { await expect( - registerDerivative("B", ipIdB, ["0x0000"], [licenseTermsId1], true) + registerDerivative("B", ipIdB, ["0x0000"], [nonComLicenseTermsId], true) ).to.be.rejectedWith("Failed to register derivative: Address \"0x0000\" is invalid."); }); it("Register a derivative IP asset fail as non-existent parent ipId", async function () { await expect( - registerDerivative("B", ipIdB, ["0x485FCfC79Ce0A082Ab2a5e729D6e6255A540342a"], [licenseTermsId1], true) - ).to.be.rejectedWith("Failed to register derivative: Address \"0x485FCfC79Ce0A082Ab2a5e729D6e6255A540342a\" is invalid."); + registerDerivative("B", ipIdB, ["0x485FCfC79Ce0A082Ab2a5e729D6e6255A540342a"], [nonComLicenseTermsId], true) + ).to.be.rejectedWith("Failed to register derivative: The parent IP with id 0x485FCfC79Ce0A082Ab2a5e729D6e6255A540342a is not registered."); }); it("Register a derivative IP asset fail as undefined licenseTermsId", async function () { - let licenseTermsId1: any; + let nonComLicenseTermsId: any; await expect( - registerDerivative("B", ipIdB, [ipIdA], [licenseTermsId1], true) + registerDerivative("B", ipIdB, [ipIdA], [nonComLicenseTermsId], true) ).to.be.rejectedWith("Failed to register derivative: Cannot convert undefined to a BigInt"); }); @@ -131,26 +120,26 @@ describe('SDK Test', function () { it("Register a derivative IP asset fail as parent id and licenseTermsId not in pairs", async function () { const response= await expect( - attachLicenseTerms("A", ipIdA, licenseTermsId2, true) + attachLicenseTerms("A", ipIdA, comUseLicenseTermsId1, true) ).to.not.be.rejected; expect(response.txHash).to.be.a("string").and.not.empty; await expect( - registerDerivative("B", ipIdB, [ipIdA], [licenseTermsId1, licenseTermsId2], true) + registerDerivative("B", ipIdB, [ipIdA], [nonComLicenseTermsId, comUseLicenseTermsId1], true) ).to.be.rejectedWith("Failed to register derivative: Parent IP IDs and License terms IDs must be provided in pairs."); }); it("Register a derivative IP asset fail as LicenseNotCompatibleForDerivative", async function () { await expect( - registerDerivative("B", ipIdB, [ipIdA, ipIdA], [licenseTermsId1, licenseTermsId2], true) + registerDerivative("B", ipIdB, [ipIdA, ipIdA], [nonComLicenseTermsId, comUseLicenseTermsId1], true) ).to.be.rejectedWith("Failed to register derivative: The contract function \"registerDerivative\" reverted.", "Error: LicensingModule__LicenseNotCompatibleForDerivative(address childIpId)"); }); it("Register a derivative IP asset success", async function () { const response = await expect( - registerDerivative("B", ipIdB, [ipIdA], [licenseTermsId1], true) + registerDerivative("B", ipIdB, [ipIdA], [nonComLicenseTermsId], true) ).to.not.be.rejected; expect(response.txHash).to.be.a("string").and.not.empty; @@ -158,13 +147,13 @@ describe('SDK Test', function () { it("Register a derivative IP asset fail as DerivativeIpAlreadyHasLicense", async function () { await expect( - registerDerivative("B", ipIdB, [ipIdA], [licenseTermsId2], true) + registerDerivative("B", ipIdB, [ipIdA], [comUseLicenseTermsId1], true) ).to.be.rejectedWith("Failed to register derivative: The contract function \"registerDerivative\" reverted with the following signature:", "0x650aa4f5"); }); it("Register a derivative IP asset that is already registered with same parent ipId and licenseTermsId", async function () { const response = await expect( - registerDerivative("B", ipIdB, [ipIdA], [licenseTermsId1], true) + registerDerivative("B", ipIdB, [ipIdA], [nonComLicenseTermsId], true) ).to.be.rejectedWith("Failed to register derivative: The contract function \"registerDerivative\" reverted with the following signature:", "0x650aa4f5"); }); }); diff --git a/test/ipAsset/registerDerivativeWithLicenseTokens.test.ts b/test/ipAsset/registerDerivativeWithLicenseTokens.test.ts index 8a38955..9c6b597 100644 --- a/test/ipAsset/registerDerivativeWithLicenseTokens.test.ts +++ b/test/ipAsset/registerDerivativeWithLicenseTokens.test.ts @@ -1,11 +1,12 @@ -import { privateKeyA, privateKeyB, privateKeyC, accountB, accountC, nftContractAddress, mintingFeeTokenAddress } from '../../config/config'; -import { attachLicenseTerms, registerCommercialUsePIL, registerDerivativeWithLicenseTokens, registerIpAsset, registerNonComSocialRemixingPIL, mintLicenseTokens } from '../../utils/sdkUtils'; +import { privateKeyA, privateKeyB, privateKeyC, accountB, accountC, nftContractAddress } from '../../config/config'; +import { attachLicenseTerms, registerDerivativeWithLicenseTokens, registerIpAsset, mintLicenseTokens } from '../../utils/sdkUtils'; import { checkMintResult, mintNFTWithRetry } from '../../utils/utils'; import { expect } from 'chai' import chai from 'chai'; import chaiAsPromised from 'chai-as-promised'; chai.use(chaiAsPromised); import '../setup'; +import { nonComLicenseTermsId, comUseLicenseTermsId1, comUseLicenseTermsId2 } from '../setup'; import { Hex } from 'viem'; let tokenIdA: string; @@ -14,9 +15,6 @@ let tokenIdC: string; let ipIdA: Hex; let ipIdB: Hex; let ipIdC: Hex; -let licenseTermsId1: string; -let licenseTermsId2: string; -let licenseTermsId3: string; let licenseTokenIdA: string; let licenseTokenIdB: string; let licenseTokenIdC: string; @@ -25,21 +23,6 @@ let licenseTokenIdD: string; describe('SDK Test', function () { describe('Test ipAsset.registerDerivativeWithLicenseTokens Function', async function () { before("Register license terms, register IP assets and mint license tokens",async function () { - const licenseTerms1 = await expect( - registerNonComSocialRemixingPIL("A", true) - ).to.not.be.rejected; - licenseTermsId1 = licenseTerms1.licenseTermsId; - - const licenseTerms2 = await expect( - registerCommercialUsePIL("A", "0", mintingFeeTokenAddress, true) - ).to.not.be.rejected; - licenseTermsId2 = licenseTerms2.licenseTermsId; - - const licenseTerms3 = await expect( - registerCommercialUsePIL("A", "100", mintingFeeTokenAddress, true) - ).to.not.be.rejected; - licenseTermsId3 = licenseTerms3.licenseTermsId; - tokenIdA = await mintNFTWithRetry(privateKeyA); checkMintResult(tokenIdA); expect(tokenIdA).not.empty; @@ -80,13 +63,13 @@ describe('SDK Test', function () { ipIdC = responseRegisterIpC.ipId; const responseAttachLicenseTerms1 = await expect( - attachLicenseTerms("A", ipIdA, licenseTermsId1, true) + attachLicenseTerms("A", ipIdA, nonComLicenseTermsId, true) ).to.not.be.rejected; expect(responseAttachLicenseTerms1.txHash).to.be.a("string").and.not.empty; const responsemintLicenseTokenA = await expect( - mintLicenseTokens("A", ipIdA, licenseTermsId1, 2, accountB.address, true) + mintLicenseTokens("A", ipIdA, nonComLicenseTermsId, 2, accountB.address, true) ).to.not.be.rejected; expect(responsemintLicenseTokenA.txHash).to.be.a("string").and.not.empty; @@ -95,13 +78,13 @@ describe('SDK Test', function () { licenseTokenIdA = responsemintLicenseTokenA.licenseTokenId; const responseAttachLicenseTerms2 = await expect( - attachLicenseTerms("A", ipIdA, licenseTermsId2, true) + attachLicenseTerms("A", ipIdA, comUseLicenseTermsId1, true) ).to.not.be.rejected; expect(responseAttachLicenseTerms2.txHash).to.be.a("string").and.not.empty; const responsemintLicenseTokenB = await expect( - mintLicenseTokens("A", ipIdA, licenseTermsId2, 2, accountB.address, true) + mintLicenseTokens("A", ipIdA, comUseLicenseTermsId1, 2, accountB.address, true) ).to.not.be.rejected; expect(responsemintLicenseTokenB.txHash).to.be.a("string").and.not.empty; @@ -110,7 +93,7 @@ describe('SDK Test', function () { licenseTokenIdB = responsemintLicenseTokenB.licenseTokenId; const responsemintLicenseTokenC = await expect( - mintLicenseTokens("A", ipIdA, licenseTermsId2, 2, accountC.address, true) + mintLicenseTokens("A", ipIdA, comUseLicenseTermsId1, 2, accountC.address, true) ).to.not.be.rejected; expect(responsemintLicenseTokenC.txHash).to.be.a("string").and.not.empty; @@ -119,13 +102,13 @@ describe('SDK Test', function () { licenseTokenIdC = responsemintLicenseTokenC.licenseTokenId; const responseAttachLicenseTerms3 = await expect( - attachLicenseTerms("A", ipIdA, licenseTermsId3, true) + attachLicenseTerms("A", ipIdA, comUseLicenseTermsId2, true) ).to.not.be.rejected; expect(responseAttachLicenseTerms3.txHash).to.be.a("string").and.not.empty; const responsemintLicenseTokenD = await expect( - mintLicenseTokens("A", ipIdA, licenseTermsId3, 2, accountC.address, true) + mintLicenseTokens("A", ipIdA, comUseLicenseTermsId2, 2, accountC.address, true) ).to.not.be.rejected; expect(responsemintLicenseTokenD.txHash).to.be.a("string").and.not.empty; @@ -156,7 +139,7 @@ describe('SDK Test', function () { it("Register a derivative IP asset fail as non-existent child ipId", async function () { await expect( registerDerivativeWithLicenseTokens("B", "0x485FCfC79Ce0A082Ab2a5e729D6e6255A540342a", [licenseTokenIdA], true) - ).to.be.rejectedWith("Failed to register derivative with license tokens: Address \"0x485FCfC79Ce0A082Ab2a5e729D6e6255A540342a\" is invalid."); + ).to.be.rejectedWith("Failed to register derivative with license tokens: The child IP with id 0x485FCfC79Ce0A082Ab2a5e729D6e6255A540342a is not registered."); }); it("Register a derivative IP asset fail as undefined licenseTokenId", async function () { diff --git a/test/ipAsset/registerIpAsset.test.ts b/test/ipAsset/registerIpAsset.test.ts index d489e7f..a1d002d 100644 --- a/test/ipAsset/registerIpAsset.test.ts +++ b/test/ipAsset/registerIpAsset.test.ts @@ -1,4 +1,4 @@ -import { nftContractAddress, privateKeyA, privateKeyB, privateKeyC } from '../../config/config'; +import { privateKeyA, privateKeyB, privateKeyC, nftContractAddress } from '../../config/config'; import { registerIpAsset } from '../../utils/sdkUtils'; import { checkMintResult, mintNFTWithRetry } from '../../utils/utils'; import { expect } from 'chai' @@ -31,7 +31,7 @@ describe('SDK Test', function () { it("Register an IP asset fail as non-existent NFT contract address", async function () { await expect( registerIpAsset("A","0x7ee32b8B515dEE0Ba2F25f612A04a731eEc24F48", tokenIdA, true) - ).to.be.rejectedWith("Failed to register IP: Address \"0x7ee32b8B515dEE0Ba2F25f612A04a731eEc24F48\" is invalid."); + ).to.be.rejectedWith("Failed to register IP: The contract function \"register\" reverted.", "Error: IPAssetRegistry__UnsupportedIERC721(address contractAddress)"); }); it("Register an IP asset fail as invalid NFT contract address", async function () { diff --git a/test/license/attachLicenseTerms.test.ts b/test/license/attachLicenseTerms.test.ts index 58197a6..a00f7d4 100644 --- a/test/license/attachLicenseTerms.test.ts +++ b/test/license/attachLicenseTerms.test.ts @@ -1,4 +1,4 @@ -import { privateKeyA, privateKeyB, privateKeyC, nftContractAddress, mintingFeeTokenAddress } from '../../config/config'; +import { privateKeyA, privateKeyB, privateKeyC, nftContractAddress } from '../../config/config'; import { checkMintResult, mintNFTWithRetry } from '../../utils/utils'; import { Hex } from 'viem'; import chai from 'chai'; @@ -6,13 +6,9 @@ import chaiAsPromised from 'chai-as-promised'; import { expect } from 'chai'; chai.use(chaiAsPromised); import '../setup'; -import { registerNonComSocialRemixingPIL, registerCommercialUsePIL, registerCommercialRemixPIL,registerIpAsset, attachLicenseTerms, registerDerivative } from '../../utils/sdkUtils'; +import { registerIpAsset, attachLicenseTerms, registerDerivative } from '../../utils/sdkUtils'; +import { nonComLicenseTermsId, comUseLicenseTermsId1, comUseLicenseTermsId2, comRemixLicenseTermsId1 } from '../setup'; -let licenseTermsId1: string; -let licenseTermsId2: string; -let licenseTermsId3: string; -let licenseTermsId4: string; -let licenseTermsId5: string; let tokenIdA: string; let tokenIdB: string; let tokenIdC: string; @@ -25,36 +21,6 @@ const waitForTransaction: boolean = true; describe("SDK Test", function () { describe("Register PIL", async function () { before("Register license terms and IP assets", async function () { - const responseLicenseTerms1 = await expect( - registerCommercialUsePIL("A", "1", mintingFeeTokenAddress, waitForTransaction) - ).to.not.be.rejected; - - licenseTermsId1 = responseLicenseTerms1.licenseTermsId; - - const responseLicenseTerms2 = await expect( - registerCommercialUsePIL("A", "20", mintingFeeTokenAddress, waitForTransaction) - ).to.not.be.rejected; - - licenseTermsId2 = responseLicenseTerms2.licenseTermsId; - - const responseLicenseTerms3 = await expect( - registerCommercialRemixPIL("A", "60", 200, mintingFeeTokenAddress, waitForTransaction) - ).to.not.be.rejected; - - licenseTermsId3 = responseLicenseTerms3.licenseTermsId; - - const responseLicenseTerms4 = await expect( - registerCommercialRemixPIL("A", "16", 100, mintingFeeTokenAddress, waitForTransaction) - ).to.not.be.rejected; - - licenseTermsId4 = responseLicenseTerms4.licenseTermsId; - - const responseLicenseTerms5 = await expect( - registerNonComSocialRemixingPIL("A", waitForTransaction) - ).to.not.be.rejected; - - licenseTermsId5 = responseLicenseTerms5.licenseTermsId; - tokenIdA = await mintNFTWithRetry(privateKeyA); checkMintResult(tokenIdA); @@ -83,27 +49,27 @@ describe("SDK Test", function () { describe("Attach license terms - negative tests", async function () { it("Non-owner attach license terms", async function () { const response = await expect( - attachLicenseTerms("B", ipIdA, licenseTermsId1, true) + attachLicenseTerms("B", ipIdA, comUseLicenseTermsId1, true) ).to.be.rejectedWith("The contract function \"attachLicenseTerms\" reverted with the following signature:"); }); it("Attach license terms with ipId: undefined", async function () { let ipId: any; const response = await expect( - attachLicenseTerms("A", ipId, licenseTermsId1, true) + attachLicenseTerms("A", ipId, comUseLicenseTermsId1, true) ).to.be.rejectedWith("Address \"undefined\" is invalid."); }); it("Attach license terms with an invalid ipId", async function () { const response = await expect( - attachLicenseTerms("A", "0x0000", licenseTermsId1, true) + attachLicenseTerms("A", "0x0000", comUseLicenseTermsId1, true) ).to.not.be.rejectedWith("InvalidAddressError: Address \"0x0000\" is invalid."); }); it("Attach license terms with a non-existent ipId", async function () { const response = await expect( - attachLicenseTerms("A", "0xA36F2A4A02f5C215d1b3630f71A4Ff55B5492AAB", licenseTermsId1, true) - ).to.be.rejectedWith("Address \"0xA36F2A4A02f5C215d1b3630f71A4Ff55B5492AAB\" is invalid."); + attachLicenseTerms("A", "0xA36F2A4A02f5C215d1b3630f71A4Ff55B5492AAB", comUseLicenseTermsId1, true) + ).to.be.rejectedWith("Failed to attach license terms: The IP with id 0xA36F2A4A02f5C215d1b3630f71A4Ff55B5492AAB is not registered."); }); it("Attach license terms with licenseTermsId: undefined", async function () { @@ -130,27 +96,27 @@ describe("SDK Test", function () { it("Attach license terms with waitForTransaction: undefined", async function () { let waitForTransaction: any; const response = await expect( - attachLicenseTerms("A", ipIdA, licenseTermsId1, waitForTransaction) + attachLicenseTerms("A", ipIdA, comUseLicenseTermsId1, waitForTransaction) ).to.not.be.rejected; expect(response.txHash).to.be.a("string").and.not.empty; }); it("Attach license terms with waitForTransaction: true", async function () { const response = await expect( - attachLicenseTerms("B", ipIdB, licenseTermsId1, true) + attachLicenseTerms("B", ipIdB, comUseLicenseTermsId1, true) ).to.not.be.rejected; expect(response.txHash).to.be.a("string").and.not.empty; }); it("Attach license terms that is already attached to the IP Asset", async function () { const response = await expect( - attachLicenseTerms("A", ipIdA, licenseTermsId1, true) - ).to.be.rejectedWith("Failed to attach license terms: License terms id " + licenseTermsId1 + " is already attached to the IP with id " + ipIdA); + attachLicenseTerms("A", ipIdA, comUseLicenseTermsId1, true) + ).to.be.rejectedWith("Failed to attach license terms: License terms id " + comUseLicenseTermsId1 + " is already attached to the IP with id " + ipIdA); }); it("Attach license terms with waitForTransaction: false", async function () { const response = await expect( - attachLicenseTerms("A", ipIdC, licenseTermsId1, false) + attachLicenseTerms("A", ipIdC, comUseLicenseTermsId1, false) ).to.not.be.rejected; expect(response.txHash).to.be.a("string").and.not.empty; expect(response.ipId).to.not.be.exist; @@ -180,9 +146,9 @@ describe("SDK Test", function () { ipIdA = response.ipId; }) - step("Wallet A attach licenseTermsId1(commercial use PIL) to ipIdA", async function () { + step("Wallet A attach comUseLicenseTermsId1(commercial use PIL) to ipIdA", async function () { const response = await expect( - attachLicenseTerms("A", ipIdA, licenseTermsId1, waitForTransaction) + attachLicenseTerms("A", ipIdA, comUseLicenseTermsId1, waitForTransaction) ).to.not.be.rejected; expect(response.txHash).to.be.a("string").and.not.empty; @@ -199,9 +165,9 @@ describe("SDK Test", function () { ipIdB = response.ipId; }) - step("Wallet B register a derivative IP asset with ipIdA and licenseTermsId1", async function () { + step("Wallet B register a derivative IP asset with ipIdA and comUseLicenseTermsId1", async function () { const response = await expect( - registerDerivative("B", ipIdB, [ipIdA], [licenseTermsId1], waitForTransaction) + registerDerivative("B", ipIdB, [ipIdA], [comUseLicenseTermsId1], waitForTransaction) ).to.not.be.rejected; expect(response.txHash).to.be.a("string").and.not.empty; @@ -209,13 +175,13 @@ describe("SDK Test", function () { step("Derivative IP asset can NOT attach more license terms", async function () { const response = await expect( - attachLicenseTerms("B", ipIdB, licenseTermsId2, waitForTransaction) + attachLicenseTerms("B", ipIdB, comUseLicenseTermsId2, waitForTransaction) ).to.be.rejectedWith("Failed to attach license terms: The contract function \"attachLicenseTerms\" reverted with the following signature:", "0x1ae3058f"); }); step("Parent IP asset can attach more license terms(commercial PIL)", async function () { const response = await expect( - attachLicenseTerms("A", ipIdA, licenseTermsId3, waitForTransaction) + attachLicenseTerms("A", ipIdA, comUseLicenseTermsId2, waitForTransaction) ).to.not.be.rejected; expect(response.txHash).to.be.a("string").and.not.empty; @@ -223,7 +189,7 @@ describe("SDK Test", function () { step("Parent IP asset can attach more license terms(non-commercial PIL)", async function () { const response = await expect( - attachLicenseTerms("A", ipIdA, licenseTermsId5, waitForTransaction) + attachLicenseTerms("A", ipIdA, nonComLicenseTermsId, waitForTransaction) ).to.not.be.rejected; expect(response.txHash).to.be.a("string").and.not.empty; @@ -240,9 +206,9 @@ describe("SDK Test", function () { ipIdC = response.ipId; }) - step("Wallet C register a derivative IP asset with ipIdC and licenseTermsId1", async function () { + step("Wallet C register a derivative IP asset with ipIdC and comUseLicenseTermsId1", async function () { const response = await expect( - registerDerivative("C", ipIdC, [ipIdB], [licenseTermsId1], waitForTransaction) + registerDerivative("C", ipIdC, [ipIdB], [comUseLicenseTermsId1], waitForTransaction) ).to.not.be.rejected; expect(response.txHash).to.be.a("string").and.not.empty; @@ -250,13 +216,13 @@ describe("SDK Test", function () { step("Derivative IP asset (ipIdB) can NOT attach more license terms", async function () { const response = await expect( - attachLicenseTerms("B", ipIdB, licenseTermsId2, waitForTransaction) + attachLicenseTerms("B", ipIdB, comUseLicenseTermsId2, waitForTransaction) ).to.be.rejectedWith("Failed to attach license terms: The contract function \"attachLicenseTerms\" reverted with the following signature:", "0x1ae3058f"); }); step("Derivative IP asset (ipIdC) can NOT attach more license terms", async function () { const response = await expect( - attachLicenseTerms("C", ipIdC, licenseTermsId4, waitForTransaction) + attachLicenseTerms("C", ipIdC, comRemixLicenseTermsId1, waitForTransaction) ).to.be.rejectedWith("Failed to attach license terms: The contract function \"attachLicenseTerms\" reverted with the following signature:", "0x1ae3058f"); }); }); diff --git a/test/license/mintLicenseTokens.test.ts b/test/license/mintLicenseTokens.test.ts index 3cb0100..e7e5bf5 100644 --- a/test/license/mintLicenseTokens.test.ts +++ b/test/license/mintLicenseTokens.test.ts @@ -1,5 +1,5 @@ -import { privateKeyA, accountB, nftContractAddress, mintingFeeTokenAddress } from '../../config/config'; -import { attachLicenseTerms, mintLicenseTokens, registerCommercialRemixPIL, registerCommercialUsePIL, registerIpAsset, registerNonComSocialRemixingPIL } from '../../utils/sdkUtils'; +import { privateKeyA, accountB, nftContractAddress } from '../../config/config'; +import { attachLicenseTerms, mintLicenseTokens, registerIpAsset } from '../../utils/sdkUtils'; import { checkMintResult, mintNFTWithRetry } from '../../utils/utils'; import { expect } from 'chai'; import chai from 'chai'; @@ -7,12 +7,10 @@ import chaiAsPromised from 'chai-as-promised'; chai.use(chaiAsPromised); import '../setup'; import { Hex } from 'viem'; +import { nonComLicenseTermsId, comUseLicenseTermsId1, comRemixLicenseTermsId1 } from '../setup'; let tokenIdA: string; let tokenIdB: string; -let licenseTermsId1: "string"; -let licenseTermsId2: "string"; -let licenseTermsId3: "string"; let ipIdA: Hex; let ipIdB: Hex; @@ -27,27 +25,6 @@ describe('SDK Test', function () { tokenIdB = await mintNFTWithRetry(privateKeyA); checkMintResult(tokenIdB); - const responseLicenseTerms1 = await expect( - registerNonComSocialRemixingPIL("A", waitForTransaction) - ).to.not.be.rejected; - expect(responseLicenseTerms1.licenseTermsId).to.be.a("string").and.not.empty; - - licenseTermsId1 = responseLicenseTerms1.licenseTermsId; - - const responseLicenseTerms2 = await expect( - registerCommercialUsePIL("A", "100", mintingFeeTokenAddress, waitForTransaction) - ).to.not.be.rejected; - expect(responseLicenseTerms2.licenseTermsId).to.be.a("string").and.not.empty; - - licenseTermsId2 = responseLicenseTerms2.licenseTermsId; - - const responseLicenseTerms3 = await expect( - registerCommercialRemixPIL("A", "10", 100, mintingFeeTokenAddress, waitForTransaction) - ).to.not.be.rejected; - expect(responseLicenseTerms3.licenseTermsId).to.be.a("string").and.not.empty; - - licenseTermsId3 = responseLicenseTerms3.licenseTermsId; - const responseA = await expect( registerIpAsset("A", nftContractAddress, tokenIdA, waitForTransaction) ).to.not.be.rejected; @@ -58,7 +35,7 @@ describe('SDK Test', function () { ipIdA = responseA.ipId; const response = await expect( - attachLicenseTerms("A", ipIdA, licenseTermsId1, waitForTransaction) + attachLicenseTerms("A", ipIdA, nonComLicenseTermsId, waitForTransaction) ).to.not.be.rejected; expect(response.txHash).to.be.a("string").and.not.empty; @@ -77,26 +54,26 @@ describe('SDK Test', function () { it("Mint a license token fail as undefined ipId", async function () { let ipIdA: any; const response = await expect( - mintLicenseTokens("A", ipIdA, licenseTermsId1, 2, accountB.address, true) + mintLicenseTokens("A", ipIdA, nonComLicenseTermsId, 2, accountB.address, true) ).to.be.rejectedWith("Failed to mint license tokens: Address \"undefined\" is invalid."); }); it("Mint a license token fail as invalid ipId", async function () { const response = await expect( - mintLicenseTokens("A", "0x0000", licenseTermsId1, 2, accountB.address, true) + mintLicenseTokens("A", "0x0000", nonComLicenseTermsId, 2, accountB.address, true) ).to.be.rejectedWith("Failed to mint license tokens: Address \"0x0000\" is invalid."); }); it("Mint a license token fail as non-existent ipId", async function () { const response = await expect( - mintLicenseTokens("A", "0xA36F2A4A02f5C215d1b3630f71A4Ff55B5492AAB", licenseTermsId1, 2, accountB.address, true) - ).to.be.rejectedWith("Failed to mint license tokens: Address \"0xA36F2A4A02f5C215d1b3630f71A4Ff55B5492AAB\" is invalid."); + mintLicenseTokens("A", "0xA36F2A4A02f5C215d1b3630f71A4Ff55B5492AAB", nonComLicenseTermsId, 2, accountB.address, true) + ).to.be.rejectedWith("Failed to mint license tokens: The licensor IP with id 0xA36F2A4A02f5C215d1b3630f71A4Ff55B5492AAB is not registered."); }); it("Mint a license token fail as undefined licenseTermsId", async function () { - let licenseTermsId1: any; + let nonComLicenseTermsId: any; const response = await expect( - mintLicenseTokens("A", ipIdA, licenseTermsId1, 2, accountB.address, true) + mintLicenseTokens("A", ipIdA, nonComLicenseTermsId, 2, accountB.address, true) ).to.be.rejectedWith("Failed to mint license tokens: Cannot convert undefined to a BigInt"); }); @@ -115,33 +92,20 @@ describe('SDK Test', function () { it("Mint a license token fail as invalid amount value (-1)", async function () { let receiver: any; const response = await expect( - mintLicenseTokens("A", ipIdA, licenseTermsId1, -1, receiver, true) + mintLicenseTokens("A", ipIdA, nonComLicenseTermsId, -1, receiver, true) ).to.be.rejectedWith("Failed to mint license tokens: Number \"-1n\" is not in safe 256-bit unsigned integer range (0n to 115792089237316195423570985008687907853269984665640564039457584007913129639935n)"); }); - it("Mint a license token fail as invalid amount value", async function () { - let receiver: any; - const response = await expect( - mintLicenseTokens("A", ipIdA, licenseTermsId1, 9007199254740992, receiver, true) - ).to.be.rejectedWith("Failed to mint license tokens: Execution reverted for an unknown reason."); - }); - it("Mint a license token fail as invalid receiver address", async function () { const response = await expect( - mintLicenseTokens("A", ipIdA, licenseTermsId1, 2, "0x0000", true) + mintLicenseTokens("A", ipIdA, nonComLicenseTermsId, 2, "0x0000", true) ).to.be.rejectedWith("Failed to mint license tokens: Address \"0x0000\" is invalid."); }); - it("Mint a license token fail as non-existent receiver address", async function () { - const response = await expect( - mintLicenseTokens("A", ipIdA, licenseTermsId1, 2, "0x485FCfC79Ce0A082Ab2a5e729D6e6255A540342a", true) - ).to.be.rejectedWith("Failed to mint license tokens: Address \"0x485FCfC79Ce0A082Ab2a5e729D6e6255A540342a\" is invalid."); - }); - it("Mint a license token fail as not attached licenseTermsId", async function () { const response = await expect( - mintLicenseTokens("A", ipIdB, licenseTermsId1, 2, "0x485FCfC79Ce0A082Ab2a5e729D6e6255A540342a", true) - ).to.be.rejectedWith("Failed to mint license tokens: License terms id " + licenseTermsId1 + " is not attached to the IP with id " + ipIdB); + mintLicenseTokens("A", ipIdB, nonComLicenseTermsId, 2, "0x485FCfC79Ce0A082Ab2a5e729D6e6255A540342a", true) + ).to.be.rejectedWith("Failed to mint license tokens: License terms id " + nonComLicenseTermsId + " is not attached to the IP with id " + ipIdB); }); }); @@ -149,7 +113,7 @@ describe('SDK Test', function () { it("Mint a license token with undefined amount", async function () { let amount: any; const response = await expect( - mintLicenseTokens("A", ipIdA, licenseTermsId1, amount, accountB.address, true) + mintLicenseTokens("A", ipIdA, nonComLicenseTermsId, amount, accountB.address, true) ).to.not.be.rejected; expect(response.txHash).to.be.a("string").and.not.empty; @@ -158,7 +122,7 @@ describe('SDK Test', function () { it("Mint a license token with amount: 0", async function () { const response = await expect( - mintLicenseTokens("A", ipIdA, licenseTermsId1, 0, accountB.address, true) + mintLicenseTokens("A", ipIdA, nonComLicenseTermsId, 0, accountB.address, true) ).to.not.be.rejected; expect(response.txHash).to.be.a("string").and.not.empty; @@ -167,7 +131,7 @@ describe('SDK Test', function () { it("Mint a license token by non-owner", async function () { const response = await expect( - mintLicenseTokens("B", ipIdA, licenseTermsId1, 2, accountB.address, true) + mintLicenseTokens("B", ipIdA, nonComLicenseTermsId, 2, accountB.address, true) ).to.not.be.rejected; expect(response.txHash).to.be.a("string").and.not.empty; @@ -177,7 +141,7 @@ describe('SDK Test', function () { it("Mint a license token with undefined receiver address", async function () { let receiver: any; const response = await expect( - mintLicenseTokens("A", ipIdA, licenseTermsId1, 2, receiver, true) + mintLicenseTokens("A", ipIdA, nonComLicenseTermsId, 2, receiver, true) ).to.not.be.rejected; expect(response.txHash).to.be.a("string").and.not.empty; @@ -186,7 +150,7 @@ describe('SDK Test', function () { it("Mint a license token with waitForTransaction:true", async function () { const response = await expect( - mintLicenseTokens("A", ipIdA, licenseTermsId1, 2, accountB.address, true) + mintLicenseTokens("A", ipIdA, nonComLicenseTermsId, 2, accountB.address, true) ).to.not.be.rejected; expect(response.txHash).to.be.a("string").and.not.empty; @@ -195,7 +159,7 @@ describe('SDK Test', function () { it("Mint a license token with the same parameters before", async function () { const response = await expect( - mintLicenseTokens("A", ipIdA, licenseTermsId1, 2, accountB.address, true) + mintLicenseTokens("A", ipIdA, nonComLicenseTermsId, 2, accountB.address, true) ).to.not.be.rejected; expect(response.txHash).to.be.a("string").and.not.empty; @@ -205,7 +169,7 @@ describe('SDK Test', function () { it("Mint a license token with undefined waitForTransaction", async function () { let waitForTransaction: any; const response = await expect( - mintLicenseTokens("B", ipIdA, licenseTermsId1, 2, accountB.address, waitForTransaction) + mintLicenseTokens("B", ipIdA, nonComLicenseTermsId, 2, accountB.address, waitForTransaction) ).to.not.be.rejected; expect(response.txHash).to.be.a("string").and.not.empty; @@ -215,45 +179,45 @@ describe('SDK Test', function () { describe("Mint License Tokens - IP asset attached multiple license terms", async function () { before("Register 2 license terms and 2 IP assets", async function () { const responseAttachLicenseTerms1 = await expect( - attachLicenseTerms("A", ipIdB, licenseTermsId1, waitForTransaction) + attachLicenseTerms("A", ipIdB, nonComLicenseTermsId, waitForTransaction) ).to.not.be.rejected; expect(responseAttachLicenseTerms1.txHash).to.be.a("string").and.not.empty; const responseAttachLicenseTerms2 = await expect( - attachLicenseTerms("A", ipIdB, licenseTermsId2, waitForTransaction) + attachLicenseTerms("A", ipIdB, comUseLicenseTermsId1, waitForTransaction) ).to.not.be.rejected; expect(responseAttachLicenseTerms2.txHash).to.be.a("string").and.not.empty; const responseAttachLicenseTerms3 = await expect( - attachLicenseTerms("A", ipIdB, licenseTermsId3, waitForTransaction) + attachLicenseTerms("A", ipIdB, comRemixLicenseTermsId1, waitForTransaction) ).to.not.be.rejected; expect(responseAttachLicenseTerms3.txHash).to.be.a("string").and.not.empty; }) - it("Mint a license token with ipIdB and licenseTermsId1", async function () { + it("Mint a license token with ipIdB and nonComLicenseTermsId", async function () { const response = await expect( - mintLicenseTokens("A", ipIdB, licenseTermsId1, 2, accountB.address, true) + mintLicenseTokens("A", ipIdB, nonComLicenseTermsId, 2, accountB.address, true) ).to.not.be.rejected; expect(response.txHash).to.be.a("string").and.not.empty; expect(response.licenseTokenId).to.be.a("string").and.not.empty; }); - it("Mint a license token with ipIdB and licenseTermsId2", async function () { + it("Mint a license token with ipIdB and comUsenonComLicenseTermsId", async function () { const response = await expect( - mintLicenseTokens("A", ipIdB, licenseTermsId2, 2, accountB.address, true) + mintLicenseTokens("A", ipIdB, comUseLicenseTermsId1, 2, accountB.address, true) ).to.not.be.rejected; expect(response.txHash).to.be.a("string").and.not.empty; expect(response.licenseTokenId).to.be.a("string").and.not.empty; }); - it("Mint a license token with ipIdB and licenseTermsId3", async function () { + it("Mint a license token with ipIdB and comRemixnonComLicenseTermsId", async function () { const response = await expect( - mintLicenseTokens("A", ipIdB, licenseTermsId3, 2, accountB.address, false) + mintLicenseTokens("A", ipIdB, comRemixLicenseTermsId1, 2, accountB.address, false) ).to.not.be.rejected; expect(response.txHash).to.be.a("string").and.not.empty; diff --git a/test/license/registerPIL.test.ts b/test/license/registerPIL.test.ts index 42d9f56..e52b31f 100644 --- a/test/license/registerPIL.test.ts +++ b/test/license/registerPIL.test.ts @@ -37,7 +37,7 @@ describe("SDK Test", function () { let mintingFee: any; const response = await expect( registerCommercialUsePIL("A", mintingFee, mintingFeeTokenAddress, true) - ).to.be.rejectedWith("Failed to register commercial use PIL: Cannot convert undefined to a BigInt") + ).to.be.rejectedWith("Failed to register commercial use PIL: mintingFee currency are required for commercial use PIL.") }); it("Register Commercial Use PIL with an invalid mintingFee value (test)", async function () { @@ -56,13 +56,13 @@ describe("SDK Test", function () { let currency: any; const response = await expect( registerCommercialUsePIL("A", "0", currency, true) - ).to.be.rejectedWith("Failed to register commercial use PIL: Address \"undefined\" is invalid.") + ).to.be.rejectedWith("Failed to register commercial use PIL: mintingFee currency are required for commercial use PIL.") }); it("Register Commercial Use PIL with an invalid currency address", async function () { const response = await expect( registerCommercialUsePIL("A", "0", "0xA36F2A4A02f5C215d1b3630f71A4Ff55B5492AAB", true) - ).to.be.rejectedWith("Failed to register commercial use PIL: Address \"0xA36F2A4A02f5C215d1b3630f71A4Ff55B5492AAB\" is invalid.") + ).to.be.rejectedWith("Failed to register commercial use PIL: The contract function \"registerLicenseTerms\" reverted.", "Error: PILicenseTemplate__CurrencyTokenNotWhitelisted()") }); it("Register Commercial Use PIL with waitForTransaction: undefined", async function () { @@ -93,7 +93,7 @@ describe("SDK Test", function () { let mintingFee: any; const response = await expect( registerCommercialRemixPIL("A", mintingFee, 100, mintingFeeTokenAddress, true) - ).to.be.rejectedWith("Failed to register commercial remix PIL: Cannot convert undefined to a BigInt") + ).to.be.rejectedWith("Failed to register commercial remix PIL: mintingFee, currency and commercialRevShare are required for commercial remix PIL.") }); it("Register Commercial Remix PIL with an invalid mintingFee value (test)", async function () { @@ -112,7 +112,7 @@ describe("SDK Test", function () { let commercialRevShare: any; const response = await expect( registerCommercialRemixPIL("A", "0", commercialRevShare, mintingFeeTokenAddress, true) - ).to.be.rejectedWith("Failed to register commercial remix PIL: Cannot convert undefined to a BigInt") + ).to.be.rejectedWith("Failed to register commercial remix PIL: mintingFee, currency and commercialRevShare are required for commercial remix PIL.") }); it("Register Commercial Remix PIL with an invalid commercialRevShare value (-1)", async function () { @@ -125,13 +125,13 @@ describe("SDK Test", function () { let currency: any; const response = await expect( registerCommercialRemixPIL("A", "0", 0, currency, true) - ).to.be.rejectedWith("Failed to register commercial remix PIL: Address \"undefined\" is invalid.") + ).to.be.rejectedWith("Failed to register commercial remix PIL: mintingFee, currency and commercialRevShare are required for commercial remix PIL.") }); it("Register Commercial Remix PIL with an invalid currency address", async function () { const response = await expect( registerCommercialRemixPIL("A", "0", 0, "0xA36F2A4A02f5C215d1b3630f71A4Ff55B5492AAB", true) - ).to.be.rejectedWith("Failed to register commercial remix PIL: Address \"0xA36F2A4A02f5C215d1b3630f71A4Ff55B5492AAB\" is invalid.") + ).to.be.rejectedWith("Failed to register commercial remix PIL: The contract function \"registerLicenseTerms\" reverted.", "Error: PILicenseTemplate__CurrencyTokenNotWhitelisted()") }); it("Register Commercial Remix PIL with waitForTransaction: undefined", async function () { diff --git a/test/permission/permission.test.ts b/test/permission/permission.test.ts index e1819d0..8641656 100644 --- a/test/permission/permission.test.ts +++ b/test/permission/permission.test.ts @@ -1,6 +1,6 @@ import { nftContractAddress, privateKeyA, accountB, licensingModuleAddress } from '../../config/config'; import { registerIpAsset, setPermission } from '../../utils/sdkUtils'; -import { mintNFTWithRetry } from '../../utils/utils'; +import { checkMintResult, mintNFTWithRetry } from '../../utils/utils'; import { expect } from 'chai'; import { Hex } from 'viem'; import chai from 'chai'; @@ -15,10 +15,7 @@ describe('SDK Test', function () { describe('Test ipAsset.register Function', async function () { before("Mint NFT and Register IP Asset",async function () { tokenIdA = await mintNFTWithRetry(privateKeyA); - if(tokenIdA == ""){ - throw new Error('Unable to mint NFT'); - } - expect(tokenIdA).not.empty; + checkMintResult(tokenIdA); const response = await expect( registerIpAsset("A", nftContractAddress, tokenIdA, true) diff --git a/test/royalty/claimRevenue.test.ts b/test/royalty/claimRevenue.test.ts index 9d680cb..24d0966 100644 --- a/test/royalty/claimRevenue.test.ts +++ b/test/royalty/claimRevenue.test.ts @@ -1,32 +1,24 @@ import { privateKeyA, privateKeyB, nftContractAddress, mintingFeeTokenAddress } from '../../config/config'; import { mintNFTWithRetry, checkMintResult } from '../../utils/utils'; -import { registerIpAsset, attachLicenseTerms, registerDerivative, registerCommercialRemixPIL, royaltyClaimRevenue, royaltySnapshot, payRoyaltyOnBehalf } from '../../utils/sdkUtils'; +import { registerIpAsset, attachLicenseTerms, registerDerivative, royaltyClaimRevenue, royaltySnapshot } from '../../utils/sdkUtils'; import { Hex } from 'viem'; import chai from 'chai'; import chaiAsPromised from 'chai-as-promised'; import { expect } from 'chai'; chai.use(chaiAsPromised); import '../setup'; +import { comRemixLicenseTermsId1, mintingFee1 } from '../setup'; let tokenIdA: string; let tokenIdB: string; let ipIdA: Hex; let ipIdB: Hex; -let licenseTermsId1: string; let snapshotId1: string; -const mintingFee: string = "100"; -const commercialRevShare: number = 200; const waitForTransaction: boolean = true; describe("SDK Test", function () { describe("Test royalty.claimRevenue Function", async function () { before("Register parent and derivative IP assets, capture snapshot", async function () { - const responseLicenseTerm1 = await expect( - registerCommercialRemixPIL("A", mintingFee, commercialRevShare, mintingFeeTokenAddress, waitForTransaction) - ).to.not.be.rejected; - - licenseTermsId1 = responseLicenseTerm1.licenseTermsId; - tokenIdA = await mintNFTWithRetry(privateKeyA); checkMintResult(tokenIdA); @@ -40,7 +32,7 @@ describe("SDK Test", function () { ipIdA = responseRegisterIpAsset.ipId; const responseAttachLicenseTerms1 = await expect( - attachLicenseTerms("A", ipIdA, licenseTermsId1, waitForTransaction) + attachLicenseTerms("A", ipIdA, comRemixLicenseTermsId1, waitForTransaction) ).to.not.be.rejected; expect(responseAttachLicenseTerms1.txHash).to.be.a("string").and.not.empty; @@ -58,7 +50,7 @@ describe("SDK Test", function () { ipIdB = responseRegisterIpAssetB.ipId; const responseRegisterDerivative1 = await expect( - registerDerivative("B", ipIdB, [ipIdA], [licenseTermsId1], waitForTransaction) + registerDerivative("B", ipIdB, [ipIdA], [comRemixLicenseTermsId1], waitForTransaction) ).to.not.be.rejected; expect(responseRegisterDerivative1.txHash).to.be.a("string").and.not.empty; @@ -112,20 +104,23 @@ describe("SDK Test", function () { it("Claim revenue fail as non-existent royaltyVaultIpId", async function () { const response = await expect( royaltyClaimRevenue("A", [snapshotId1], "0xe967f54D03acc01CF624b54e0F24794a2f8f229b", ipIdA, mintingFeeTokenAddress, waitForTransaction) - ).to.be.rejectedWith("Failed to claim revenue: Address \"0xe967f54D03acc01CF624b54e0F24794a2f8f229b\" is invalid."); + ).to.be.rejectedWith("Failed to claim revenue: The royalty vault IP with id 0xE967F54d03aCC01Cf624b54E0f24794A2F8F229b is not registered."); }); - it("Claim revenue fail as undefined account address", async function () { + it("Claim revenue with undefined account address", async function () { let accountAddress: any; const response = await expect( royaltyClaimRevenue("A", [snapshotId1], ipIdA, accountAddress, mintingFeeTokenAddress, waitForTransaction) - ).to.be.rejectedWith("Failed to claim revenue: Failed to execute the IP Account transaction: Address \"undefined\" is invalid."); + ).to.not.be.rejected; + + expect(response.txHash).to.be.a("string").and.not.empty; + expect(response.claimableToken).to.be.a("string").and.equal("0"); }); it("Claim revenue fail as invalid account address", async function () { const response = await expect( royaltyClaimRevenue("A", [snapshotId1], ipIdA, "0x00000", mintingFeeTokenAddress, waitForTransaction) - ).to.be.rejectedWith("Failed to claim revenue: Failed to execute the IP Account transaction: Address \"0x00000\" is invalid."); + ).to.be.rejectedWith("Failed to claim revenue: Address \"0x00000\" is invalid."); }); it("Claim revenue fail as non-existent account address", async function () { @@ -160,7 +155,7 @@ describe("SDK Test", function () { ).to.not.be.rejected; expect(response.txHash).to.be.a("string").and.not.empty; - expect(response.claimableToken).to.be.a("string").and.equal(mintingFee); + expect(response.claimableToken).to.be.a("string").and.equal(mintingFee1); }); it("Claim revenue with waitForTransaction: false", async function () { diff --git a/test/royalty/claimableRevenue.test.ts b/test/royalty/claimableRevenue.test.ts index 8fc8cbb..828c130 100644 --- a/test/royalty/claimableRevenue.test.ts +++ b/test/royalty/claimableRevenue.test.ts @@ -1,32 +1,24 @@ import { privateKeyA, privateKeyB, nftContractAddress, mintingFeeTokenAddress } from '../../config/config'; import { mintNFTWithRetry, checkMintResult } from '../../utils/utils'; -import { registerIpAsset, attachLicenseTerms, registerDerivative, registerCommercialRemixPIL, royaltyClaimableRevenue, royaltySnapshot } from '../../utils/sdkUtils'; +import { registerIpAsset, attachLicenseTerms, registerDerivative, royaltyClaimableRevenue, royaltySnapshot } from '../../utils/sdkUtils'; import { Hex } from 'viem'; import chai from 'chai'; import chaiAsPromised from 'chai-as-promised'; import { expect } from 'chai'; chai.use(chaiAsPromised); import '../setup'; +import { comRemixLicenseTermsId1, mintingFee1 } from '../setup'; let tokenIdA: string; let tokenIdB: string; let ipIdA: Hex; let ipIdB: Hex; -let licenseTermsId1: string; let snapshotId1: string; -const mintingFee: string = "100"; -const commercialRevShare: number = 200; const waitForTransaction: boolean = true; describe("SDK Test", function () { describe("Test royalty.claimableRevenue Function", async function () { before("Register parent and derivative IP assets, capture snapshot", async function () { - const responseLicenseTerm1 = await expect( - registerCommercialRemixPIL("A", mintingFee, commercialRevShare, mintingFeeTokenAddress, waitForTransaction) - ).to.not.be.rejected; - - licenseTermsId1 = responseLicenseTerm1.licenseTermsId; - tokenIdA = await mintNFTWithRetry(privateKeyA); checkMintResult(tokenIdA); @@ -40,7 +32,7 @@ describe("SDK Test", function () { ipIdA = responseRegisterIpAsset.ipId; const responseAttachLicenseTerms1 = await expect( - attachLicenseTerms("A", ipIdA, licenseTermsId1, waitForTransaction) + attachLicenseTerms("A", ipIdA, comRemixLicenseTermsId1, waitForTransaction) ).to.not.be.rejected; expect(responseAttachLicenseTerms1.txHash).to.be.a("string").and.not.empty; @@ -58,7 +50,7 @@ describe("SDK Test", function () { ipIdB = responseRegisterIpAssetB.ipId; const responseRegisterDerivative1 = await expect( - registerDerivative("B", ipIdB, [ipIdA], [licenseTermsId1], waitForTransaction) + registerDerivative("B", ipIdB, [ipIdA], [comRemixLicenseTermsId1], waitForTransaction) ).to.not.be.rejected; expect(responseRegisterDerivative1.txHash).to.be.a("string").and.not.empty; @@ -92,7 +84,7 @@ describe("SDK Test", function () { it("Check claimable revenue fail as non-existent parentIpId", async function () { const response = await expect( royaltyClaimableRevenue("A", "0xe967f54D03acc01CF624b54e0F24794a2f8f229a", ipIdA, "1", mintingFeeTokenAddress, waitForTransaction) - ).to.be.rejectedWith("Failed to calculate claimable revenue: Address \"0xe967f54D03acc01CF624b54e0F24794a2f8f229a\" is invalid."); + ).to.be.rejectedWith("Failed to calculate claimable revenue: The royalty vault IP with id 0xe967F54d03ACc01CF624B54e0F24794A2f8f229a is not registered."); }); it("Check claimable revenue fail as undefined account address", async function () { @@ -108,12 +100,6 @@ describe("SDK Test", function () { ).to.be.rejectedWith("Failed to calculate claimable revenue: Address \"0x0000\" is invalid."); }); - it("Check claimable revenue fail as non-existent account address", async function () { - const response = await expect( - royaltyClaimableRevenue("A", ipIdA, "0xe967f54D03acc01CF624b54e0F24794a2f8f229a", "1", mintingFeeTokenAddress, waitForTransaction) - ).to.be.rejectedWith("Failed to calculate claimable revenue: Address \"0xe967f54D03acc01CF624b54e0F24794a2f8f229a\" is invalid."); - }); - it("Check claimable revenue fail as undefined snapshotId", async function () { let snapshotId: any; const response = await expect( @@ -160,19 +146,13 @@ describe("SDK Test", function () { ).to.be.rejectedWith("Failed to calculate claimable revenue: Address \"0x0000\" is invalid."); }); - it("Check claimable revenue fail as non-existent token address", async function () { - const response = await expect( - royaltyClaimableRevenue("A", ipIdA, ipIdA, snapshotId1, "0xe967f54D03acc01CF624b54e0F24794a2f8f229a", waitForTransaction) - ).to.be.rejectedWith("Failed to calculate claimable revenue: Address \"0xe967f54D03acc01CF624b54e0F24794a2f8f229a\" is invalid."); - }); - it("Check claimable revenue with waitForTransaction: undefined", async function () { let waitForTransaction: any; const response = await expect( royaltyClaimableRevenue("A", ipIdA, ipIdA, snapshotId1, mintingFeeTokenAddress, waitForTransaction) ).to.not.be.rejected; - expect(response).to.be.a("string").and.to.be.equal(mintingFee); + expect(response).to.be.a("string").and.to.be.equal(mintingFee1); }); it("Check claimable revenue with waitForTransaction: true", async function () { @@ -180,7 +160,7 @@ describe("SDK Test", function () { royaltyClaimableRevenue("A", ipIdA, ipIdA, snapshotId1, mintingFeeTokenAddress, true) ).to.not.be.rejected; - expect(response).to.be.a("string").and.to.be.equal(mintingFee); + expect(response).to.be.a("string").and.to.be.equal(mintingFee1); }); it("Check claimable revenue with waitForTransaction: false", async function () { @@ -188,7 +168,7 @@ describe("SDK Test", function () { royaltyClaimableRevenue("A", ipIdA, ipIdA, snapshotId1, mintingFeeTokenAddress, false) ).to.not.be.rejected; - expect(response).to.be.a("string").and.to.be.equal(mintingFee); + expect(response).to.be.a("string").and.to.be.equal(mintingFee1); }); it("Check claimable revenue by non-owner", async function () { @@ -196,7 +176,7 @@ describe("SDK Test", function () { royaltyClaimableRevenue("C", ipIdA, ipIdA, snapshotId1, mintingFeeTokenAddress, false) ).to.not.be.rejected; - expect(response).to.be.a("string").and.to.be.equal(mintingFee); + expect(response).to.be.a("string").and.to.be.equal(mintingFee1); }); }); }); diff --git a/test/royalty/collectRoyaltyTokens.test.ts b/test/royalty/collectRoyaltyTokens.test.ts index 3110937..d1f2a23 100644 --- a/test/royalty/collectRoyaltyTokens.test.ts +++ b/test/royalty/collectRoyaltyTokens.test.ts @@ -1,12 +1,13 @@ -import { privateKeyA, privateKeyB, privateKeyC, nftContractAddress, mintingFeeTokenAddress } from '../../config/config'; +import { privateKeyA, privateKeyB, privateKeyC, nftContractAddress } from '../../config/config'; import { mintNFTWithRetry, checkMintResult, sleep } from '../../utils/utils'; -import { registerIpAsset, attachLicenseTerms, registerDerivative, collectRoyaltyTokens, registerCommercialRemixPIL } from '../../utils/sdkUtils'; +import { registerIpAsset, attachLicenseTerms, registerDerivative, collectRoyaltyTokens } from '../../utils/sdkUtils'; import { Hex } from 'viem'; import chai from 'chai'; import chaiAsPromised from 'chai-as-promised'; import { expect } from 'chai'; chai.use(chaiAsPromised); import '../setup'; +import { comRemixLicenseTermsId1, comRemixLicenseTermsId2, commercialRevShare1, commercialRevShare2 } from '../setup'; const waitForTransaction: boolean = true; @@ -20,26 +21,10 @@ let ipIdB: Hex; let ipIdC: Hex; let ipIdD: Hex; let ipIdE: Hex; -let licenseTermsId1: string; -let licenseTermsId2: string; -const commercialRevShare1: number = 200; -const commercialRevShare2: number = 600; describe("SDK Test", function () { describe("Test royalty.collectRoyaltyTokens Function", async function () { before("Register parent and derivative IP assets", async function () { - const responseLicenseTerm1 = await expect( - registerCommercialRemixPIL("A", "100", commercialRevShare1, mintingFeeTokenAddress, waitForTransaction) - ).to.not.be.rejected; - - licenseTermsId1 = responseLicenseTerm1.licenseTermsId; - - const responseLicenseTerm2 = await expect( - registerCommercialRemixPIL("A", "100", commercialRevShare2, mintingFeeTokenAddress, waitForTransaction) - ).to.not.be.rejected; - - licenseTermsId2 = responseLicenseTerm2.licenseTermsId; - tokenIdA = await mintNFTWithRetry(privateKeyA); checkMintResult(tokenIdA); @@ -53,13 +38,13 @@ describe("SDK Test", function () { ipIdA = responseRegisterIpAsset.ipId; const responseAttachLicenseTerms1 = await expect( - attachLicenseTerms("A", ipIdA, licenseTermsId1, waitForTransaction) + attachLicenseTerms("A", ipIdA, comRemixLicenseTermsId1, waitForTransaction) ).to.not.be.rejected; expect(responseAttachLicenseTerms1.txHash).to.be.a("string").and.not.empty; const responseAttachLicenseTerms2 = await expect( - attachLicenseTerms("A", ipIdA, licenseTermsId2, waitForTransaction) + attachLicenseTerms("A", ipIdA, comRemixLicenseTermsId2, waitForTransaction) ).to.not.be.rejected; expect(responseAttachLicenseTerms2.txHash).to.be.a("string").and.not.empty; @@ -77,7 +62,7 @@ describe("SDK Test", function () { ipIdB = responseregisterIpAssetB.ipId; const responseRegisterDerivative1 = await expect( - registerDerivative("B", ipIdB, [ipIdA], [licenseTermsId1], waitForTransaction) + registerDerivative("B", ipIdB, [ipIdA], [comRemixLicenseTermsId1], waitForTransaction) ).to.not.be.rejected; expect(responseRegisterDerivative1.txHash).to.be.a("string").and.not.empty; @@ -110,7 +95,7 @@ describe("SDK Test", function () { it("Collect royalty tokens fail as non-existent parentIpId", async function () { const response = await expect( collectRoyaltyTokens("B", "0xe967f54D03acc01CF624b54e0F24794a2f8f229a", ipIdB, waitForTransaction) - ).to.be.rejectedWith("Failed to collect royalty tokens: Address \"0xe967f54D03acc01CF624b54e0F24794a2f8f229a\" is invalid."); + ).to.be.rejectedWith("Failed to collect royalty tokens: The parent IP with id 0xe967f54D03acc01CF624b54e0F24794a2f8f229a is not registered."); }); it("Collect royalty tokens fail as undefined royaltyVaultIpId", async function () { @@ -129,7 +114,7 @@ describe("SDK Test", function () { it("Collect royalty tokens fail as non-existent royaltyVaultIpId", async function () { const response = await expect( collectRoyaltyTokens("B", ipIdA, "0xe967f54D03acc01CF624b54e0F24794a2f8f229b", waitForTransaction) - ).to.be.rejectedWith("Failed to collect royalty tokens: Address \"0xe967f54D03acc01CF624b54e0F24794a2f8f229b\" is invalid."); + ).to.be.rejectedWith("Failed to collect royalty tokens: The royalty vault IP with id 0xE967F54d03aCC01Cf624b54E0f24794A2F8F229b is not registered."); }); it("Collect royalty tokens with waitForTransaction: true", async function () { @@ -159,7 +144,7 @@ describe("SDK Test", function () { ipIdC = responseregisterIpAssetC.ipId; const responseRegisterDerivative2 = await expect( - registerDerivative("C", ipIdC, [ipIdA], [licenseTermsId2], waitForTransaction) + registerDerivative("C", ipIdC, [ipIdA], [comRemixLicenseTermsId2], waitForTransaction) ).to.not.be.rejected; expect(responseRegisterDerivative2.txHash).to.be.a("string").and.not.empty; @@ -183,7 +168,7 @@ describe("SDK Test", function () { ipIdD = responseregisterIpAssetD.ipId; const responseRegisterDerivative3 = await expect( - registerDerivative("B", ipIdD, [ipIdA, ipIdA], [licenseTermsId1, licenseTermsId2], waitForTransaction) + registerDerivative("B", ipIdD, [ipIdA, ipIdA], [comRemixLicenseTermsId1, comRemixLicenseTermsId2], waitForTransaction) ).to.not.be.rejected; expect(responseRegisterDerivative3.txHash).to.be.a("string").and.not.empty; @@ -218,7 +203,7 @@ describe("SDK Test", function () { it("Collect royalty tokens with waitForTransaction: false", async function () { const responseRegisterDerivative4 = await expect( - registerDerivative("C", ipIdE, [ipIdC], [licenseTermsId2], waitForTransaction) + registerDerivative("C", ipIdE, [ipIdC], [comRemixLicenseTermsId2], waitForTransaction) ).to.not.be.rejected; expect(responseRegisterDerivative4.txHash).to.be.a("string").and.not.empty; diff --git a/test/royalty/payRoyaltyOnBehalf.test.ts b/test/royalty/payRoyaltyOnBehalf.test.ts index 8d701e3..0c9802d 100644 --- a/test/royalty/payRoyaltyOnBehalf.test.ts +++ b/test/royalty/payRoyaltyOnBehalf.test.ts @@ -1,12 +1,13 @@ import { privateKeyA, privateKeyB, privateKeyC, nftContractAddress, mintingFeeTokenAddress } from '../../config/config'; import { mintNFTWithRetry, checkMintResult, sleep } from '../../utils/utils'; -import { registerIpAsset, payRoyaltyOnBehalf, registerCommercialUsePIL, attachLicenseTerms, registerDerivative } from '../../utils/sdkUtils'; +import { registerIpAsset, payRoyaltyOnBehalf, attachLicenseTerms, registerDerivative } from '../../utils/sdkUtils'; import { Hex } from 'viem'; import chai from 'chai'; import chaiAsPromised from 'chai-as-promised'; import { expect } from 'chai'; chai.use(chaiAsPromised); import '../setup'; +import { comUseLicenseTermsId1 } from '../setup'; const waitForTransaction: boolean = true; @@ -16,20 +17,12 @@ let tokenIdC: string; let ipIdA: Hex; let ipIdB: Hex; let ipIdC: Hex; -let licenseTermsId1: string; describe("SDK Test", function () { describe("Test royalty.payRoyaltyOnBehalf Function", async function () { before("Register parent and derivative IP assets", async function () { - const responseLicenseTerm1 = await expect( - registerCommercialUsePIL("A", "100", mintingFeeTokenAddress, waitForTransaction) - ).to.not.be.rejected; - - licenseTermsId1 = responseLicenseTerm1.licenseTermsId; - tokenIdA = await mintNFTWithRetry(privateKeyA); checkMintResult(tokenIdA); - expect(tokenIdA).not.empty; const responseRegisterIpAsset = await expect( registerIpAsset("A", nftContractAddress, tokenIdA, waitForTransaction) @@ -41,14 +34,13 @@ describe("SDK Test", function () { ipIdA = responseRegisterIpAsset.ipId; const responseAttachLicenseTerms = await expect( - attachLicenseTerms("A", ipIdA, licenseTermsId1, waitForTransaction) + attachLicenseTerms("A", ipIdA, comUseLicenseTermsId1, waitForTransaction) ).to.not.be.rejected; expect(responseAttachLicenseTerms.txHash).to.be.a("string").and.not.empty; tokenIdB = await mintNFTWithRetry(privateKeyB); checkMintResult(tokenIdB); - expect(tokenIdB).not.empty; const responseregisterIpAssetB = await expect( registerIpAsset("B", nftContractAddress, tokenIdB, waitForTransaction) @@ -60,22 +52,19 @@ describe("SDK Test", function () { ipIdB = responseregisterIpAssetB.ipId; const response = await expect( - registerDerivative("B", ipIdB, [ipIdA], [licenseTermsId1], waitForTransaction) + registerDerivative("B", ipIdB, [ipIdA], [comUseLicenseTermsId1], waitForTransaction) ).to.not.be.rejected; expect(response.txHash).to.be.a("string").and.not.empty; tokenIdC = await mintNFTWithRetry(privateKeyC); checkMintResult(tokenIdC); - expect(tokenIdC).not.empty; const responseregisterIpAssetC = await expect( registerIpAsset("C", nftContractAddress, tokenIdB, waitForTransaction) ).to.not.be.rejected; ipIdC = responseregisterIpAssetC.ipId; - - await sleep(20); }); it("Pay royalty on behalf fail as undefined receiverIpId", async function () { @@ -94,7 +83,7 @@ describe("SDK Test", function () { it("Pay royalty on behalf fail as non-existent receiverIpId", async function () { const response = await expect( payRoyaltyOnBehalf("B", "0xe967f54D03acc01CF624b54e0F24794a2f8f229a", ipIdB, mintingFeeTokenAddress, "100", waitForTransaction) - ).to.be.rejectedWith("Failed to pay royalty on behalf: Address \"0xe967f54D03acc01CF624b54e0F24794a2f8f229a\" is invalid."); + ).to.be.rejectedWith("Failed to pay royalty on behalf: The receiver IP with id 0xe967f54D03acc01CF624b54e0F24794a2f8f229a is not registered."); }); it("Pay royalty on behalf fail as undefined payerIpId", async function () { @@ -113,7 +102,7 @@ describe("SDK Test", function () { it("Pay royalty on behalf fail as non-existent payerIpId", async function () { const response = await expect( payRoyaltyOnBehalf("B", ipIdA, "0xe967f54D03acc01CF624b54e0F24794a2f8f229b", mintingFeeTokenAddress, "100", waitForTransaction) - ).to.be.rejectedWith("Failed to pay royalty on behalf: Address \"0xe967f54D03acc01CF624b54e0F24794a2f8f229b\" is invalid."); + ).to.be.rejectedWith("Failed to pay royalty on behalf: The payer IP with id 0xe967f54D03acc01CF624b54e0F24794a2f8f229b is not registered."); }); it("Pay royalty on behalf fail as undefined token address", async function () { @@ -132,7 +121,7 @@ describe("SDK Test", function () { it("Pay royalty on behalf fail as non-existent token address", async function () { const response = await expect( payRoyaltyOnBehalf("B", ipIdA, ipIdB, "0xe967f54D03acc01CF624b54e0F24794a2f8f229c", "100", waitForTransaction) - ).to.be.rejectedWith("Failed to pay royalty on behalf: Address \"0xe967f54D03acc01CF624b54e0F24794a2f8f229c\" is invalid."); + ).to.be.rejectedWith("Failed to pay royalty on behalf: The contract function \"payRoyaltyOnBehalf\" reverted.", "Error: RoyaltyModule__NotWhitelistedRoyaltyToken()"); }); it("Pay royalty on behalf fail as undefined pay amount", async function () { diff --git a/test/royalty/snapshot.test.ts b/test/royalty/snapshot.test.ts index b82d933..8219421 100644 --- a/test/royalty/snapshot.test.ts +++ b/test/royalty/snapshot.test.ts @@ -1,12 +1,13 @@ -import { privateKeyA, privateKeyB,nftContractAddress, mintingFeeTokenAddress } from '../../config/config'; +import { privateKeyA, privateKeyB, nftContractAddress } from '../../config/config'; import { mintNFTWithRetry, checkMintResult, sleep } from '../../utils/utils'; -import { registerIpAsset, royaltySnapshot, registerCommercialUsePIL, attachLicenseTerms, registerDerivative } from '../../utils/sdkUtils'; +import { registerIpAsset, royaltySnapshot, attachLicenseTerms, registerDerivative } from '../../utils/sdkUtils'; import { Hex } from 'viem'; import chai from 'chai'; import chaiAsPromised from 'chai-as-promised'; import { expect } from 'chai'; chai.use(chaiAsPromised); import '../setup'; +import { comUseLicenseTermsId1 } from '../setup'; const waitForTransaction: boolean = true; @@ -16,20 +17,12 @@ let tokenIdC: string; let ipIdA: Hex; let ipIdB: Hex; let ipIdC: Hex; -let licenseTermsId1: string; describe("SDK Test", function () { describe("Test royalty.snapshot function", async function () { before("Register parent and derivative IP assets", async function () { - const responseLicenseTerm1 = await expect( - registerCommercialUsePIL("A", "100", mintingFeeTokenAddress, waitForTransaction) - ).to.not.be.rejected; - - licenseTermsId1 = responseLicenseTerm1.licenseTermsId; - tokenIdA = await mintNFTWithRetry(privateKeyA); checkMintResult(tokenIdA); - expect(tokenIdA).not.empty; const responseRegisterIpAsset = await expect( registerIpAsset("A", nftContractAddress, tokenIdA, waitForTransaction) @@ -41,14 +34,13 @@ describe("SDK Test", function () { ipIdA = responseRegisterIpAsset.ipId; const responseAttachLicenseTerms = await expect( - attachLicenseTerms("A", ipIdA, licenseTermsId1, waitForTransaction) + attachLicenseTerms("A", ipIdA, comUseLicenseTermsId1, waitForTransaction) ).to.not.be.rejected; expect(responseAttachLicenseTerms.txHash).to.be.a("string").and.not.empty; tokenIdB = await mintNFTWithRetry(privateKeyB); checkMintResult(tokenIdB); - expect(tokenIdB).not.empty; const responseregisterIpAssetB = await expect( registerIpAsset("B", nftContractAddress, tokenIdB, waitForTransaction) @@ -60,14 +52,13 @@ describe("SDK Test", function () { ipIdB = responseregisterIpAssetB.ipId; const response = await expect( - registerDerivative("B", ipIdB, [ipIdA], [licenseTermsId1], waitForTransaction) + registerDerivative("B", ipIdB, [ipIdA], [comUseLicenseTermsId1], waitForTransaction) ).to.not.be.rejected; expect(response.txHash).to.be.a("string").and.not.empty; tokenIdC = await mintNFTWithRetry(privateKeyA); checkMintResult(tokenIdA); - expect(tokenIdA).not.empty; const responseRegisterIpAssetC = await expect( registerIpAsset("A", nftContractAddress, tokenIdC, waitForTransaction) @@ -76,9 +67,7 @@ describe("SDK Test", function () { expect(responseRegisterIpAssetC.txHash).to.be.a("string").and.not.empty; expect(responseRegisterIpAssetC.ipId).to.be.a("string").and.not.empty; - ipIdC = responseRegisterIpAssetC.ipId; - - await sleep(20); + ipIdC = responseRegisterIpAssetC.ipId; }); it("Captue snapshot fail as undefined ipId", async function () { @@ -96,11 +85,11 @@ describe("SDK Test", function () { }); - it("Captue snapshot fail as invalid ipId", async function () { + it("Captue snapshot fail as non-existent ipId", async function () { let ipIdA: any; const response = await expect( royaltySnapshot("A", "0x7F51F6AC36B5d618545345baDbe22E40ed113e2a", waitForTransaction) - ).to.be.rejectedWith("Failed to snapshot: Address \"0x7F51F6AC36B5d618545345baDbe22E40ed113e2a\" is invalid."); + ).to.be.rejectedWith("Failed to snapshot: The royalty vault IP with id 0x7f51f6AC36B5D618545345badBe22e40eD113e2A is not registered."); }); it("Captue snapshot by non-owner", async function () { @@ -119,9 +108,9 @@ describe("SDK Test", function () { }); it("Captue snapshot with waitForTransaction: true", async function () { - await sleep(10); + await sleep(20); const response = await expect( - royaltySnapshot("C", ipIdA, true) + royaltySnapshot("C", ipIdB, true) ).to.not.be.rejected; expect(response.txHash).to.be.a("string").and.not.empty; @@ -130,7 +119,7 @@ describe("SDK Test", function () { it("Captue snapshot with waitForTransaction: false", async function () { const response = await expect( - royaltySnapshot("A", ipIdB, false) + royaltySnapshot("A", ipIdA, false) ).to.not.be.rejected; expect(response.txHash).to.be.a("string").and.not.empty; @@ -141,7 +130,7 @@ describe("SDK Test", function () { await sleep(10); let waitForTransaction: any; const response = await expect( - royaltySnapshot("C", ipIdA, waitForTransaction) + royaltySnapshot("C", ipIdB, waitForTransaction) ).to.not.be.rejected; expect(response.txHash).to.be.a("string").and.not.empty; diff --git a/test/setup.ts b/test/setup.ts index fe723be..9b6cd8e 100644 --- a/test/setup.ts +++ b/test/setup.ts @@ -1,7 +1,20 @@ import addContext = require("mochawesome/addContext"); import { captureConsoleLogs } from "../utils/utils"; +import { mintingFeeTokenAddress } from '../config/config'; +import { registerNonComSocialRemixingPIL, registerCommercialUsePIL, registerCommercialRemixPIL } from '../utils/sdkUtils'; +import { expect } from 'chai'; let consoleLogs: string[] = []; +let nonComLicenseTermsId: string; +let comUseLicenseTermsId1: string; +let comUseLicenseTermsId2: string; +let comRemixLicenseTermsId1: string; +let comRemixLicenseTermsId2: string; + +const mintingFee1: string = "100"; +const mintingFee2: string = "60"; +const commercialRevShare1: number = 100; +const commercialRevShare2: number = 200; beforeEach(function () { consoleLogs = captureConsoleLogs(consoleLogs); @@ -13,5 +26,60 @@ afterEach(function () { title: 'Test Result', value: consoleLogs[0], }); - } -}); \ No newline at end of file + }; +}); + +before("Register License Terms", async function () { + it("Register Non-Commercial Social Remixing License Terms", async function () { + const responseNonComLicenseTerms = await expect( + registerNonComSocialRemixingPIL("A", true) + ).to.not.be.rejected; + + expect(responseNonComLicenseTerms.licenseTermsId).to.be.a("string").and.not.empty; + nonComLicenseTermsId = responseNonComLicenseTerms.licenseTermsId; + }); + + it("Register Commercial Use License Terms", async function () { + const responseComUseLicenseTerms1 = await expect( + registerCommercialUsePIL("A", mintingFee1, mintingFeeTokenAddress, true) + ).to.not.be.rejected; + + expect(responseComUseLicenseTerms1.licenseTermsId).to.be.a("string").and.not.empty; + + comUseLicenseTermsId1 = responseComUseLicenseTerms1.licenseTermsId; + + const responseComUseLicenseTerms2 = await expect( + registerCommercialUsePIL("A", mintingFee2, mintingFeeTokenAddress, true) + ).to.not.be.rejected; + + comUseLicenseTermsId2 = responseComUseLicenseTerms2.licenseTermsId; + }); + + it("Register Commercial Remix License Terms", async function () { + const responseComRemixLicenseTerms1 = await expect( + registerCommercialRemixPIL("A", mintingFee1, commercialRevShare1, mintingFeeTokenAddress, true) + ).to.not.be.rejected; + + expect(responseComRemixLicenseTerms1.licenseTermsId).to.be.a("string").and.not.empty; + + comRemixLicenseTermsId1 = responseComRemixLicenseTerms1.licenseTermsId; + + const responseComRemixLicenseTerms2 = await expect( + registerCommercialRemixPIL("A", mintingFee2, commercialRevShare2, mintingFeeTokenAddress, true) + ).to.not.be.rejected; + + comRemixLicenseTermsId2 = responseComRemixLicenseTerms2.licenseTermsId; + }); +}); + +export { + nonComLicenseTermsId, + comUseLicenseTermsId1, + comUseLicenseTermsId2, + comRemixLicenseTermsId1, + comRemixLicenseTermsId2, + mintingFee1, + mintingFee2, + commercialRevShare1, + commercialRevShare2 +}; diff --git a/utils/utils.ts b/utils/utils.ts index 1bd1b8c..0e9cbda 100644 --- a/utils/utils.ts +++ b/utils/utils.ts @@ -2,7 +2,7 @@ import { Hex, http, Address, createWalletClient, createPublicClient, Chain } fro import { privateKeyToAccount } from 'viem/accounts' import { sepolia } from 'viem/chains'; import fs from 'fs'; -import { chainStringToViemChain, nftContractAddress, rpcProviderUrl, royaltyPolicyLAPAddress, royaltyApproveAddress } from "../config/config"; +import { chainStringToViemChain, nftContractAddress, rpcProviderUrl, royaltyPolicyLAPAddress, royaltyApproveAddress, disputeModuleAddress } from "../config/config"; const TEST_ENV = process.env.TEST_ENV as string | undefined; @@ -204,6 +204,48 @@ export async function mintAmount(WALLET_PRIVATE_KEY: Hex, amount: number){ }); }; +export async function setDisputeJudgement(WALLET_PRIVATE_KEY: Hex, disputeId: string, decision: boolean, data: Hex) { + try { + const account = privateKeyToAccount(WALLET_PRIVATE_KEY as Address); + const baseConfig = { + chain: chainId, + transport: http(rpcProviderUrl) + }; + const walletClient = createWalletClient({ + ...baseConfig, + account + }); + const publicClient = createPublicClient(baseConfig); + const contractAbi = { + inputs: [ + { internalType: "uint256", name: "disputeId", type: "uint256" }, + { internalType: "bool", name: "decision", type: "bool" }, + { internalType: "bytes", name: "data", type: "bytes" } + ], + name: 'setDisputeJudgement', + outputs: [], + stateMutability: 'nonpayable', + type: 'function', + }; + + const requestArgs = { + address: disputeModuleAddress, + functionName: 'setDisputeJudgement', + args: [BigInt(disputeId), decision, data], + abi: [contractAbi], + account: account + }; + + await publicClient.simulateContract(requestArgs); + const hash = await walletClient.writeContract(requestArgs); + await publicClient.waitForTransactionReceipt({ + hash: hash + }); + } catch (error) { + console.error(error); + } +}; + export async function getLatestTokenId(): Promise { const contractAddress = nftContractAddress; let latestTokenId: number | undefined;