From aa09bc766341a5a7990732f72009befb97b2ae97 Mon Sep 17 00:00:00 2001 From: Jacqueline Zhang <131138188+jacqueline-57b@users.noreply.github.com> Date: Fri, 28 Jun 2024 09:49:09 +0800 Subject: [PATCH] Add sdk tests (#6) * update tests * add tests for permissions module * update * add tests for permissions module --- .../createBatchPermissionSignature.test.ts | 217 ++++++++++++++++++ .../createSetPermissionSignature.test.ts | 132 +++++++++++ test/permission/setAllPermissions.test.ts | 118 ++++++++++ test/permission/setBatchPermissions.test.ts | 195 ++++++++++++++++ ...rmission.test.ts => setPermission.test.ts} | 12 +- 5 files changed, 668 insertions(+), 6 deletions(-) create mode 100644 test/permission/createBatchPermissionSignature.test.ts create mode 100644 test/permission/createSetPermissionSignature.test.ts create mode 100644 test/permission/setAllPermissions.test.ts create mode 100644 test/permission/setBatchPermissions.test.ts rename test/permission/{permission.test.ts => setPermission.test.ts} (91%) diff --git a/test/permission/createBatchPermissionSignature.test.ts b/test/permission/createBatchPermissionSignature.test.ts new file mode 100644 index 0000000..cc38aab --- /dev/null +++ b/test/permission/createBatchPermissionSignature.test.ts @@ -0,0 +1,217 @@ +import { nftContractAddress, privateKeyA, licensingModuleAddress, accountA, disputeModuleAddress, accountC, accountB } from '../../config/config'; +import { createBatchPermissionSignature, registerIpAsset } from '../../utils/sdkUtils'; +import { checkMintResult, mintNFTWithRetry } from '../../utils/utils'; +import { expect } from 'chai'; +import { Address } from 'viem'; +import chai from 'chai'; +import chaiAsPromised from 'chai-as-promised'; +chai.use(chaiAsPromised); +import '../setup'; +import { AccessPermission } from '@story-protocol/core-sdk'; + +let tokenIdA: string; +let ipIdA: Address; +let permissions: any; + +describe('SDK Test', function () { + describe('Test permission.createBatchPermissionSignature Function', async function () { + before("Mint NFT and Register IP Asset",async function () { + tokenIdA = await mintNFTWithRetry(privateKeyA); + checkMintResult(tokenIdA); + + const response = await expect( + registerIpAsset("A", nftContractAddress, tokenIdA, true) + ).to.not.be.rejected + + expect(response.txHash).to.be.a("string").and.not.empty; + expect(response.ipId).to.be.a("string").and.not.empty; + + ipIdA = response.ipId + + permissions = [ + { + ipId: ipIdA, + signer: accountB.address as Address, + to: licensingModuleAddress, + permission: AccessPermission.DENY, + func: "function setAll(address,string,bytes32,bytes32)", + }, + { + ipId: ipIdA, + signer: accountC.address as Address, + to: disputeModuleAddress, + permission: AccessPermission.DENY, + func: "function setAll(address,string,bytes32,bytes32)", + } + ] + }); + + it("Non-owner create batch permission signature", async function () { + const response = await expect( + createBatchPermissionSignature("B", ipIdA, permissions, true) + ).to.be.rejectedWith(`Failed to create batch permission signature: The contract function "executeWithSig" reverted with the following signature:`, + `0xb3e96921`); + }); + + it("Create batch permission signature with an empty ipId", async function () { + let testIpId: any; + + const response = await expect( + createBatchPermissionSignature("A", testIpId, permissions, true) + ).to.be.rejectedWith(`Failed to create batch permission signature: The contract function "executeWithSig" reverted.`, + `Error: IPAccount__InvalidSignature()`); + }); + + it("Create batch permission signature with a non-existent ipId", async function () { + const response = await expect( + createBatchPermissionSignature("A", "0x1954631f55AC9a79CC4ec57103D23A9b2e8aDBfa", permissions, true) + ).to.be.rejectedWith(`Failed to create batch permission signature: Address "0x1954631f55AC9a79CC4ec57103D23A9b2e8aDBfa" is invalid.`); + }); + + it("Create batch permission signature with an invalid ipId", async function () { + const response = await expect( + createBatchPermissionSignature("A", "0x0000", permissions, true) + ).to.be.rejectedWith(`Failed to create batch permission signature: Address "0x0000" is invalid.`); + }); + + it("Create batch permission signature with an empty IP id", async function () { + let testIpId: any; + permissions[0].ipId = testIpId; + permissions[1].ipId = testIpId; + + const response = await expect( + createBatchPermissionSignature("A", ipIdA, permissions, true) + ).to.be.rejectedWith(`Failed to create batch permission signature: ipId address is invalid: undefined, Address must be a hex value of 20 bytes (40 hex characters) and match its checksum counterpart.`); + }); + + it("Create batch permission signature with a non-existent IP id", async function () { + permissions[0].ipId = "0x1954631f55AC9a79CC4ec57103D23A9b2e8aDBfa"; + permissions[1].ipId = "0x1954631f55AC9a79CC4ec57103D23A9b2e8aDBfa"; + + const response = await expect( + createBatchPermissionSignature("A", ipIdA, permissions, true) + ).to.be.rejectedWith(`Failed to create batch permission signature: IP id with 0x1954631f55AC9a79CC4ec57103D23A9b2e8aDBfa is not registered.`); + }); + + it("Create batch permission signature with an invalid IP id", async function () { + permissions[0].ipId = "0x00000"; + permissions[1].ipId = "0x00000"; + + const response = await expect( + createBatchPermissionSignature("A", ipIdA, permissions, true) + ).to.be.rejectedWith(`Failed to create batch permission signature: ipId address is invalid: 0x00000, Address must be a hex value of 20 bytes (40 hex characters) and match its checksum counterpart.`); + }); + + it("Create batch permission signature with an empty signer address", async function () { + let accountAddress:any; + permissions[0].ipId = ipIdA; + permissions[1].ipId = ipIdA; + permissions[0].signer = accountAddress; + permissions[1].signer = accountAddress; + + const response = await expect( + createBatchPermissionSignature("A", ipIdA, permissions, true) + ).to.be.rejectedWith(`Failed to create batch permission signature: Address "undefined" is invalid.`); + }); + + it("Create batch permission signature with an invalid signer address", async function () { + permissions[0].signer = "0x00000"; + permissions[1].signer = "0x00000"; + + const response = await expect( + createBatchPermissionSignature("A", ipIdA, permissions, true) + ).to.be.rejectedWith(`Failed to create batch permission signature: Address "0x00000" is invalid.`); + }); + + it("Create batch permission signature with an emty license module address", async function () { + let testLicenseAddress: any; + permissions[0].signer = accountA.address; + permissions[1].signer = accountB.address; + permissions[0].to = testLicenseAddress; + permissions[1].to = testLicenseAddress; + + const response = await expect( + createBatchPermissionSignature("A", ipIdA, permissions, true) + ).to.be.rejectedWith(`Failed to create batch permission signature: Address "undefined" is invalid.`); + }); + + it("Create batch permission signature with an invalid license module address", async function () { + permissions[0].to = "0x0000"; + permissions[1].to = "0x0000"; + + const response = await expect( + createBatchPermissionSignature("A", ipIdA, permissions, true) + ).to.be.rejectedWith(`Failed to create batch permission signature: Address "0x0000" is invalid.`); + }); + + it("Create batch permission signature with an invalid permission id (-1)", async function () { + permissions[0].to = licensingModuleAddress; + permissions[1].to = disputeModuleAddress; + permissions[0].permission = -1; + permissions[1].permission = -1; + + const response = await expect( + createBatchPermissionSignature("A", ipIdA, permissions, true) + ).to.be.rejectedWith(`Failed to create batch permission signature: Number "-1" is not in safe 256-bit unsigned integer range`); + }); + + it("Create batch permission signature with an invalid permission id (4)", async function () { + permissions[0].permission = 4; + permissions[1].permission = 4; + + const response = await expect( + createBatchPermissionSignature("A", ipIdA, permissions, true) + ).to.be.rejectedWith(`Failed to create batch permission signature: The contract function "executeWithSig" reverted with the following signature:`, + `0x07e5a971`); + }); + + it("Create batch permission (permission id: 1) signature", async function () { + permissions[0].permission = AccessPermission.ALLOW; + permissions[1].permission = AccessPermission.ALLOW; + + const response = await expect( + createBatchPermissionSignature("A", ipIdA, permissions, true) + ).to.not.be.rejected; + + expect(response.txHash).to.be.a("string").and.not.empty; + expect(response.success).to.be.true + }); + + it("Create batch permission (permission id: 1) signature again", async function () { + permissions[0].permission = AccessPermission.ALLOW; + permissions[1].permission = AccessPermission.ALLOW; + + const response = await expect( + createBatchPermissionSignature("A", ipIdA,permissions, true) + ).to.not.be.rejected; + + expect(response.txHash).to.be.a("string").and.not.empty; + expect(response.success).to.be.true + }); + + it("Create batch permission (permission id: 2) signature", async function () { + permissions[0].permission = AccessPermission.DENY; + permissions[1].permission = AccessPermission.DENY; + + const response = await expect( + createBatchPermissionSignature("A", ipIdA, permissions, true) + ).to.not.be.rejected; + + expect(response.txHash).to.be.a("string").and.not.empty; + expect(response.success).to.be.true + }); + + it("Create batch permission (permission id: 0) signature", async function () { + permissions[0].permission = AccessPermission.ABSTAIN; + permissions[1].permission = AccessPermission.ABSTAIN; + + const response = await expect( + createBatchPermissionSignature("A", ipIdA, permissions, true) + ).to.not.be.rejected; + + expect(response.txHash).to.be.a("string").and.not.empty; + expect(response.success).to.be.true + }); + }); +}); + diff --git a/test/permission/createSetPermissionSignature.test.ts b/test/permission/createSetPermissionSignature.test.ts new file mode 100644 index 0000000..9f93f7e --- /dev/null +++ b/test/permission/createSetPermissionSignature.test.ts @@ -0,0 +1,132 @@ +import { nftContractAddress, privateKeyA, accountB, licensingModuleAddress, accountA } from '../../config/config'; +import { createSetPermissionSignature, registerIpAsset } from '../../utils/sdkUtils'; +import { checkMintResult, mintNFTWithRetry } from '../../utils/utils'; +import { expect } from 'chai'; +import { Address } from 'viem'; +import chai from 'chai'; +import chaiAsPromised from 'chai-as-promised'; +chai.use(chaiAsPromised); +import '../setup'; + +let tokenIdA: string; +let ipIdA: Address; +const func = "function setAll(address,string,bytes32,bytes32)" + +describe('SDK Test', function () { + describe('Test permission.createSetPermissionSignature Function', async function () { + before("Mint NFT and Register IP Asset",async function () { + tokenIdA = await mintNFTWithRetry(privateKeyA); + checkMintResult(tokenIdA); + + const response = await expect( + registerIpAsset("A", nftContractAddress, tokenIdA, true) + ).to.not.be.rejected + + expect(response.txHash).to.be.a("string").and.not.empty; + expect(response.ipId).to.be.a("string").and.not.empty; + + ipIdA = response.ipId + }); + + it("Non-owner create set permission signature", async function () { + const response = await expect( + createSetPermissionSignature("B", ipIdA, accountB.address, licensingModuleAddress, 1, func, 6000n, true) + ).to.be.rejectedWith(`Failed to create set permission signature: The contract function "executeWithSig" reverted with the following signature:`, + `0xb3e96921`); + }); + + it("Create set permission signature with an empty IP id", async function () { + let testIpId:any; + const response = await expect( + createSetPermissionSignature("A", testIpId, accountA.address, licensingModuleAddress, 1, func, 6000n, true) + ).to.be.rejectedWith(`Failed to create set permission signature: ipId address is invalid: undefined, Address must be a hex value of 20 bytes (40 hex characters) and match its checksum counterpart.`); + }); + + it("Create set permission signature with a non-existent IP id", async function () { + const response = await expect( + createSetPermissionSignature("B", "0x1954631f55AC9a79CC4ec57103D23A9b2e8aDBfa", accountB.address, licensingModuleAddress, 1, func, 6000n, true) + ).to.be.rejectedWith(`Failed to create set permission signature: IP id with 0x1954631f55AC9a79CC4ec57103D23A9b2e8aDBfa is not registered.`); + }); + + it("Create set permission signature with an invalid IP id", async function () { + const response = await expect( + createSetPermissionSignature("A", "0x00000", accountA.address, licensingModuleAddress, 1, func, 6000n, true) + ).to.be.rejectedWith(`Failed to create set permission signature: ipId address is invalid: 0x00000, Address must be a hex value of 20 bytes (40 hex characters) and match its checksum counterpart.`); + }); + + it("Create set permission signature with an empty signer address", async function () { + let accountAddress:any; + const response = await expect( + createSetPermissionSignature("A", ipIdA, accountAddress, licensingModuleAddress, 1, func, 6000n, true) + ).to.be.rejectedWith(`Failed to create set permission signature: request.signer address is invalid: undefined, Address must be a hex value of 20 bytes (40 hex characters) and match its checksum counterpart.`); + }); + + it("Create set permission signature with an invalid signer address", async function () { + const response = await expect( + createSetPermissionSignature("A", ipIdA, "0x00000", licensingModuleAddress, 1, func, 6000n, true) + ).to.be.rejectedWith(`Failed to create set permission signature: request.signer address is invalid: 0x00000, Address must be a hex value of 20 bytes (40 hex characters) and match its checksum counterpart.`); + }); + + it("Create set permission signature with incorrect owner address", async function () { + const response = await expect( + createSetPermissionSignature("A", ipIdA, accountB.address, licensingModuleAddress, 4, func, 6000n, true) + ).to.be.rejectedWith(`Failed to create set permission signature: The contract function "executeWithSig" reverted.`, + `Error: IPAccount__InvalidSignature()`); + }); + + it("Create set permission signature with an emty license module address", async function () { + let testLicenseAddress: any; + const response = await expect( + createSetPermissionSignature("A", ipIdA, accountA.address, testLicenseAddress, 1, func, 6000n, true) + ).to.be.rejectedWith(`Failed to create set permission signature: request.to address is invalid: undefined, Address must be a hex value of 20 bytes (40 hex characters) and match its checksum counterpart.`); + }); + + it("Create set permission signature with an invalid license module address", async function () { + const response = await expect( + createSetPermissionSignature("A", ipIdA, accountA.address, "0x0000", 1, func, 6000n, true) + ).to.be.rejectedWith(`Failed to create set permission signature: request.to address is invalid: 0x0000, Address must be a hex value of 20 bytes (40 hex characters) and match its checksum counterpart.`); + }); + + it("Create set permission signature with an invalid permission id (-1)", async function () { + const response = await expect( + createSetPermissionSignature("A", ipIdA, accountA.address, licensingModuleAddress, -1, func, 6000n, true) + ).to.be.rejectedWith(`Failed to create set permission signature: Number "-1" is not in safe 256-bit unsigned integer range`); + }); + + it("Create set permission (permission id: 1) signature", async function () { + const response = await expect( + createSetPermissionSignature("A", ipIdA, accountA.address, licensingModuleAddress, 1, func, 6000n, true) + ).to.not.be.rejected; + + expect(response.txHash).to.be.a("string").and.not.empty; + expect(response.success).to.be.true + }); + + it("Create set permission (permission id: 1) signature again", async function () { + const response = await expect( + createSetPermissionSignature("A", ipIdA, accountA.address, licensingModuleAddress, 1, func, 6000n, true) + ).to.not.be.rejected; + + expect(response.txHash).to.be.a("string").and.not.empty; + expect(response.success).to.be.true + }); + + it("Create set permission (permission id: 2) signature", async function () { + const response = await expect( + createSetPermissionSignature("A", ipIdA, accountA.address, licensingModuleAddress, 2, func, 6000n, true) + ).to.not.be.rejected; + + expect(response.txHash).to.be.a("string").and.not.empty; + expect(response.success).to.be.true + }); + + it("Create set permission (permission id: 0) signature", async function () { + const response = await expect( + createSetPermissionSignature("A", ipIdA, accountA.address, licensingModuleAddress, 0, func, 6000n, true) + ).to.not.be.rejected; + + expect(response.txHash).to.be.a("string").and.not.empty; + expect(response.success).to.be.true + }); + }); +}); diff --git a/test/permission/setAllPermissions.test.ts b/test/permission/setAllPermissions.test.ts new file mode 100644 index 0000000..ab0025d --- /dev/null +++ b/test/permission/setAllPermissions.test.ts @@ -0,0 +1,118 @@ +import { nftContractAddress, privateKeyA, accountB } from '../../config/config'; +import { registerIpAsset, setAllPermissions } from '../../utils/sdkUtils'; +import { checkMintResult, mintNFTWithRetry } from '../../utils/utils'; +import { expect } from 'chai'; +import { Address } from 'viem'; +import chai from 'chai'; +import chaiAsPromised from 'chai-as-promised'; +chai.use(chaiAsPromised); +import '../setup'; + +let tokenIdA: string; +let ipIdA: Address; + +describe('SDK Test', function () { + describe('Test permission.setAllPermissions Function', async function () { + before("Mint NFT and Register IP Asset",async function () { + tokenIdA = await mintNFTWithRetry(privateKeyA); + checkMintResult(tokenIdA); + + const response = await expect( + registerIpAsset("A", nftContractAddress, tokenIdA, true) + ).to.not.be.rejected + + expect(response.txHash).to.be.a("string").and.not.empty; + expect(response.ipId).to.be.a("string").and.not.empty; + + ipIdA = response.ipId + }); + + it("Non-owner set all permission", async function () { + const response = await expect( + setAllPermissions("B", ipIdA, accountB.address, 1, true) + ).to.be.rejectedWith(`Failed to set all permissions: The contract function "setAllPermissions" reverted.`, + `Error: AccessController__CallerIsNotIPAccountOrOwner()`); + }); + + it("Set all permission with an empty IP id", async function () { + let testIpId:any; + const response = await expect( + setAllPermissions("A", testIpId, accountB.address, 1, true) + ).to.be.rejectedWith(`Failed to set all permissions: ipId address is invalid: undefined, Address must be a hex value of 20 bytes (40 hex characters) and match its checksum counterpart.`); + }); + + it("Set all permission with a non-existent IP id", async function () { + const response = await expect( + setAllPermissions("B", "0x1954631f55AC9a79CC4ec57103D23A9b2e8aDBfa", accountB.address, 1, true) + ).to.be.rejectedWith(`Failed to set all permissions: IP id with 0x1954631f55AC9a79CC4ec57103D23A9b2e8aDBfa is not registered.`); + }); + + it("Set all permission with an invalid IP id", async function () { + const response = await expect( + setAllPermissions("A", "0x00000", accountB.address, 1, true) + ).to.be.rejectedWith(`Failed to set all permissions: ipId address is invalid: 0x00000, Address must be a hex value of 20 bytes (40 hex characters) and match its checksum counterpart.`); + }); + + it("Set all permission with an empty signer address", async function () { + let accountAddress:any; + const response = await expect( + setAllPermissions("A", ipIdA, accountAddress, 1, true) + ).to.be.rejectedWith(`Failed to set all permissions: Address "undefined" is invalid.`); + }); + + it("Set all permission with an invalid signer address", async function () { + const response = await expect( + setAllPermissions("A", ipIdA, "0x00000", 1, true) + ).to.be.rejectedWith(`Failed to set all permissions: Address "0x00000" is invalid.`); + }); + + it("Set all permission with an invalid permission id (-1)", async function () { + const response = await expect( + setAllPermissions("A", ipIdA, accountB.address, -1, true) + ).to.be.rejectedWith(`Failed to set all permissions: Number "-1" is not in safe 256-bit unsigned integer range`); + }); + + it("Set all permission with an invalid permission id (4)", async function () { + const response = await expect( + setAllPermissions("A", ipIdA, accountB.address, 4, true) + ).to.be.rejectedWith(`Failed to set all permissions: The contract function "setAllPermissions" reverted.`, + `Error: AccessController__PermissionIsNotValid()`); + }); + + it("Set all permission (permission id: 1) to wallet B", async function () { + const response = await expect( + setAllPermissions("A", ipIdA, accountB.address, 1, true) + ).to.not.be.rejected; + + expect(response.txHash).to.be.a("string").and.not.empty; + expect(response.success).to.be.true + }); + + it("Set all permission (permission id: 1) that is already set 1 to wallet B", async function () { + const response = await expect( + setAllPermissions("A", ipIdA, accountB.address, 1, true) + ).to.not.be.rejected; + + expect(response.txHash).to.be.a("string").and.not.empty; + expect(response.success).to.be.true + }); + + it("Set all permission (permission id: 2) to wallet B", async function () { + const response = await expect( + setAllPermissions("A", ipIdA, accountB.address, 2, true) + ).to.not.be.rejected; + + expect(response.txHash).to.be.a("string").and.not.empty; + expect(response.success).to.be.true + }); + + it("Set all permission (permission id: 0) to wallet B", async function () { + const response = await expect( + setAllPermissions("A", ipIdA, accountB.address, 0, true) + ).to.not.be.rejected; + + expect(response.txHash).to.be.a("string").and.not.empty; + expect(response.success).to.be.true + }); + }); +}); diff --git a/test/permission/setBatchPermissions.test.ts b/test/permission/setBatchPermissions.test.ts new file mode 100644 index 0000000..a259ba2 --- /dev/null +++ b/test/permission/setBatchPermissions.test.ts @@ -0,0 +1,195 @@ +import { nftContractAddress, privateKeyA, licensingModuleAddress, accountA, disputeModuleAddress, accountC, accountB } from '../../config/config'; +import { registerIpAsset, setBatchPermissions } from '../../utils/sdkUtils'; +import { checkMintResult, mintNFTWithRetry } from '../../utils/utils'; +import { expect } from 'chai'; +import { Address } from 'viem'; +import chai from 'chai'; +import chaiAsPromised from 'chai-as-promised'; +chai.use(chaiAsPromised); +import '../setup'; +import { AccessPermission } from '@story-protocol/core-sdk'; + +let tokenIdA: string; +let ipIdA: Address; +let permissions: any; + +describe('SDK Test', function () { + describe('Test permission.setPermissions Function', async function () { + before("Mint NFT and Register IP Asset",async function () { + tokenIdA = await mintNFTWithRetry(privateKeyA); + checkMintResult(tokenIdA); + + const response = await expect( + registerIpAsset("A", nftContractAddress, tokenIdA, true) + ).to.not.be.rejected + + expect(response.txHash).to.be.a("string").and.not.empty; + expect(response.ipId).to.be.a("string").and.not.empty; + + ipIdA = response.ipId + + permissions = [ + { + ipId: ipIdA, + signer: accountA.address as Address, + to: licensingModuleAddress, + permission: AccessPermission.DENY, + func: "function setAll(address,string,bytes32,bytes32)", + }, + { + ipId: ipIdA, + signer: accountC.address as Address, + to: disputeModuleAddress, + permission: AccessPermission.DENY, + func: "function setAll(address,string,bytes32,bytes32)", + } + ] + }); + + it("Non-owner set batch permissions", async function () { + const response = await expect( + setBatchPermissions("B", permissions, true) + ).to.be.rejectedWith(`Failed to set batch permissions: The contract function "setBatchPermissions" reverted.`, + `Error: AccessController__CallerIsNotIPAccountOrOwner()`); + }); + + it("Set batch permission with an empty IP id", async function () { + let testIpId: any; + permissions[0].ipId = testIpId; + permissions[1].ipId = testIpId; + + const response = await expect( + setBatchPermissions("A", permissions, true) + ).to.be.rejectedWith(`Failed to set batch permissions: ipId address is invalid: undefined, Address must be a hex value of 20 bytes (40 hex characters) and match its checksum counterpart.`); + }); + + it("Set batch permissions with a non-existent IP id", async function () { + permissions[0].ipId = "0x1954631f55AC9a79CC4ec57103D23A9b2e8aDBfa"; + permissions[1].ipId = "0x1954631f55AC9a79CC4ec57103D23A9b2e8aDBfa"; + + const response = await expect( + setBatchPermissions("A", permissions, true) + ).to.be.rejectedWith(`Failed to set batch permissions: IP id with 0x1954631f55AC9a79CC4ec57103D23A9b2e8aDBfa is not registered.`); + }); + + it("Set batch permissions with an invalid IP id", async function () { + permissions[0].ipId = "0x00000"; + permissions[1].ipId = "0x00000"; + + const response = await expect( + setBatchPermissions("A", permissions, true) + ).to.be.rejectedWith(`Failed to set batch permissions: ipId address is invalid: 0x00000, Address must be a hex value of 20 bytes (40 hex characters) and match its checksum counterpart.`); + }); + + it("Set batch permissions with an empty signer address", async function () { + let accountAddress:any; + permissions[0].ipId = ipIdA; + permissions[1].ipId = ipIdA; + permissions[0].signer = accountAddress; + permissions[1].signer = accountAddress; + + const response = await expect( + setBatchPermissions("A", permissions, true) + ).to.be.rejectedWith(`Failed to set batch permissions: Address "undefined" is invalid.`); + }); + + it("Set batch permissions with an invalid signer address", async function () { + permissions[0].signer = "0x00000"; + permissions[1].signer = "0x00000"; + + const response = await expect( + setBatchPermissions("A", permissions, true) + ).to.be.rejectedWith(`Failed to set batch permissions: Address "0x00000" is invalid.`); + }); + + it("Set batch permissions with an emty license module address", async function () { + let testLicenseAddress: any; + permissions[0].signer = accountA.address; + permissions[1].signer = accountB.address; + permissions[0].to = testLicenseAddress; + permissions[1].to = testLicenseAddress; + + const response = await expect( + setBatchPermissions("A", permissions, true) + ).to.be.rejectedWith(`Failed to set batch permissions: Address "undefined" is invalid.`); + }); + + it("Set batch permissions with an invalid license module address", async function () { + permissions[0].to = "0x0000"; + permissions[1].to = "0x0000"; + + const response = await expect( + setBatchPermissions("A", permissions, true) + ).to.be.rejectedWith(`Failed to set batch permissions: Address "0x0000" is invalid.`); + }); + + it("Set batch permissions with an invalid permission id (-1)", async function () { + permissions[0].to = licensingModuleAddress; + permissions[1].to = disputeModuleAddress; + permissions[0].permission = -1; + permissions[1].permission = -1; + + const response = await expect( + setBatchPermissions("A", permissions, true) + ).to.be.rejectedWith(`Failed to set batch permissions: Number "-1" is not in safe 256-bit unsigned integer range`); + }); + + it("Set permission with an invalid permission id (4)", async function () { + permissions[0].permission = 4; + permissions[1].permission = 4; + + const response = await expect( + setBatchPermissions("A", permissions, true) + ).to.be.rejectedWith(`Failed to set batch permissions: The contract function "setBatchPermissions" reverted.`, + `Error: AccessController__PermissionIsNotValid()`); + }); + + it("Set permission (permission id: 1) to wallet B", async function () { + permissions[0].permission = AccessPermission.ALLOW; + permissions[1].permission = AccessPermission.ALLOW; + + const response = await expect( + setBatchPermissions("A", permissions, true) + ).to.not.be.rejected; + + expect(response.txHash).to.be.a("string").and.not.empty; + expect(response.success).to.be.true + }); + + it("Set permission (permission id: 1) that is already set 1 to wallet B", async function () { + permissions[0].permission = AccessPermission.ALLOW; + permissions[1].permission = AccessPermission.ALLOW; + + const response = await expect( + setBatchPermissions("A", permissions, true) + ).to.not.be.rejected; + + expect(response.txHash).to.be.a("string").and.not.empty; + expect(response.success).to.be.true + }); + + it("Set permission (permission id: 2) to wallet B", async function () { + permissions[0].permission = AccessPermission.DENY; + permissions[1].permission = AccessPermission.DENY; + + const response = await expect( + setBatchPermissions("A", permissions, true) + ).to.not.be.rejected; + + expect(response.txHash).to.be.a("string").and.not.empty; + expect(response.success).to.be.true + }); + + it("Set permission (permission id: 0) to wallet B", async function () { + permissions[0].permission = AccessPermission.ABSTAIN; + permissions[1].permission = AccessPermission.ABSTAIN; + + const response = await expect( + setBatchPermissions("A", permissions, true) + ).to.not.be.rejected; + + expect(response.txHash).to.be.a("string").and.not.empty; + expect(response.success).to.be.true + }); + }); +}); diff --git a/test/permission/permission.test.ts b/test/permission/setPermission.test.ts similarity index 91% rename from test/permission/permission.test.ts rename to test/permission/setPermission.test.ts index 4bd5dec..9d67a9a 100644 --- a/test/permission/permission.test.ts +++ b/test/permission/setPermission.test.ts @@ -12,7 +12,7 @@ let tokenIdA: string; let ipIdA: Address; describe('SDK Test', function () { - describe('Test ipAsset.register Function', async function () { + describe('Test permission.setPermissions Function', async function () { before("Mint NFT and Register IP Asset",async function () { tokenIdA = await mintNFTWithRetry(privateKeyA); checkMintResult(tokenIdA); @@ -57,32 +57,32 @@ describe('SDK Test', function () { let accountAddress:any; const response = await expect( setPermission("A", ipIdA, accountAddress, licensingModuleAddress, 1, true) - ).to.be.rejectedWith("Failed to set permissions: Address \"undefined\" is invalid."); + ).to.be.rejectedWith(`Failed to set permissions: Address "undefined" is invalid.`); }); it("Set permission with an invalid signer address", async function () { const response = await expect( setPermission("A", ipIdA, "0x00000", licensingModuleAddress, 1, true) - ).to.be.rejectedWith("Failed to set permissions: Address \"0x00000\" is invalid."); + ).to.be.rejectedWith(`Failed to set permissions: Address "0x00000" is invalid.`); }); it("Set permission with an emty license module address", async function () { let testLicenseAddress: any; const response = await expect( setPermission("A", ipIdA, accountB.address, testLicenseAddress, 1, true) - ).to.be.rejectedWith("Failed to set permissions: Address \"undefined\" is invalid."); + ).to.be.rejectedWith(`Failed to set permissions: Address "undefined" is invalid.`); }); it("Set permission with an invalid license module address", async function () { const response = await expect( setPermission("A", ipIdA, accountB.address, "0x0000", 1, true) - ).to.be.rejectedWith("Failed to set permissions: Address \"0x0000\" is invalid."); + ).to.be.rejectedWith(`Failed to set permissions: Address "0x0000" is invalid.`); }); it("Set permission with an invalid permission id (-1)", async function () { const response = await expect( setPermission("A", ipIdA, accountB.address, licensingModuleAddress, -1, true) - ).to.be.rejectedWith("Failed to set permissions: Number \"-1\" is not in safe 256-bit unsigned integer range"); + ).to.be.rejectedWith(`Failed to set permissions: Number "-1" is not in safe 256-bit unsigned integer range`); }); it("Set permission with an invalid permission id (4)", async function () {