Skip to content

Commit

Permalink
add grouping IPA tests (storyprotocol#335)
Browse files Browse the repository at this point in the history
  • Loading branch information
tyitang authored Dec 10, 2024
1 parent 9cc03d2 commit 320e5c1
Show file tree
Hide file tree
Showing 5 changed files with 182 additions and 7 deletions.
2 changes: 1 addition & 1 deletion hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ const config: HardhatUserConfig = {
coinmarketcap: COINMARKETCAP_API_KEY,
},
mocha: {
timeout: 60_000,
timeout: 120_000,
reporter: "mochawesome",
},
etherscan: {
Expand Down
135 changes: 130 additions & 5 deletions test/hardhat/e2e/grouping/group.ipa.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,148 @@

import "../setup"
import { expect } from "chai"
import { EvenSplitGroupPool } from "../constants"
import { EvenSplitGroupPool, PILicenseTemplate, RoyaltyPolicyLRP } from "../constants"
import { mintNFTAndRegisterIPA, mintNFTAndRegisterIPAWithLicenseTerms } from "../utils/mintNFTAndRegisterIPA";
import { LicensingConfig, registerPILTerms } from "../utils/licenseHelper";

describe("Group IPA", function () {
describe("Register Group IPA", function () {
it("Register Group IPA with whitelisted group pool", async function () {

const groupId = await expect(
this.groupingModule.registerGroup(EvenSplitGroupPool)
).not.to.be.rejectedWith(Error).then((tx) => tx.wait()).then((receipt) => receipt.logs[5].args[0]);

console.log("groupId", groupId)
expect(groupId).to.be.properHex(40);

const isRegisteredGroup = await this.ipAssetRegistry.isRegisteredGroup(groupId);
expect(isRegisteredGroup).to.be.true;
});

it("Register Group IPA with non-whitelisted group pool", async function () {
const nonWhitelistedGroupPool = "0xC384B56fD62d6679Cd62A2fE0dA3fe4560f33300"
const nonWhitelistedGroupPool = this.user1.address;
await expect(
this.groupingModule.registerGroup(nonWhitelistedGroupPool)
).to.be.rejectedWith(Error)
).to.be.revertedWithCustomError(this.errors, "GroupIPAssetRegistry__GroupRewardPoolNotRegistered");
});
});

describe("Add/Remove IP from Group IPA", function () {
let groupId: any;
let commRemixTermsId: any;

before(async function () {
groupId = await expect(
this.groupingModule.registerGroup(EvenSplitGroupPool)
).not.to.be.rejectedWith(Error).then((tx) => tx.wait()).then((receipt) => receipt.logs[5].args[0]);
console.log("groupId", groupId);

commRemixTermsId = await registerPILTerms(true, 0, 10 * 10 ** 6, RoyaltyPolicyLRP);
await expect(
this.licensingModule.attachLicenseTerms(groupId, PILicenseTemplate, commRemixTermsId)
).not.to.be.rejectedWith(Error).then((tx) => tx.wait());
});

it("Add/Remove an IP to the group", async function () {
// Register IP
const { ipId } = await mintNFTAndRegisterIPAWithLicenseTerms(commRemixTermsId);
await expect(
this.licensingModule.setLicensingConfig(ipId, PILicenseTemplate, commRemixTermsId, LicensingConfig)
).not.to.be.rejectedWith(Error).then((tx) => tx.wait());

// Add IP to the group
await expect(
this.groupingModule.addIp(groupId, [ipId])
).not.to.be.rejectedWith(Error).then((tx) => tx.wait());

let containsIp = await this.ipAssetRegistry.containsIp(groupId, ipId);
expect(containsIp).to.be.true;

// Remove IP from the group
await expect(
this.groupingModule.removeIp(groupId, [ipId])
).not.to.be.rejectedWith(Error).then((tx) => tx.wait());

containsIp = await this.ipAssetRegistry.containsIp(groupId, ipId);
expect(containsIp).to.be.false;
});

it("Add/Remove multiple IPs to the group", async function () {
// Register IPs
const {ipId: ipId1} = await mintNFTAndRegisterIPAWithLicenseTerms(commRemixTermsId);
await expect(
this.licensingModule.setLicensingConfig(ipId1, PILicenseTemplate, commRemixTermsId, LicensingConfig)
).not.to.be.rejectedWith(Error).then((tx) => tx.wait());
const {ipId: ipId2} = await mintNFTAndRegisterIPAWithLicenseTerms(commRemixTermsId, this.user1, this.user1);
await expect(
this.licensingModule.connect(this.user1).setLicensingConfig(ipId2, PILicenseTemplate, commRemixTermsId, LicensingConfig)
).not.to.be.rejectedWith(Error).then((tx) => tx.wait());

// Add multiple IPs to the group
await expect(
this.groupingModule.addIp(groupId, [ipId1, ipId2])
).not.to.be.rejectedWith(Error).then((tx) => tx.wait());

let containsIp1 = await this.ipAssetRegistry.containsIp(groupId, ipId1);
expect(containsIp1).to.be.true;
let containsIp2 = await this.ipAssetRegistry.containsIp(groupId, ipId2);
expect(containsIp2).to.be.true;

// Remove multiple IPs from the group
await expect(
this.groupingModule.removeIp(groupId, [ipId1, ipId2])
).not.to.be.rejectedWith(Error).then((tx) => tx.wait());

containsIp1 = await this.ipAssetRegistry.containsIp(groupId, ipId1);
expect(containsIp1).to.be.false;
containsIp2 = await this.ipAssetRegistry.containsIp(groupId, ipId2);
expect(containsIp2).to.be.false;
});

it("Non-owner add IP to the group", async function () {
const { ipId } = await mintNFTAndRegisterIPAWithLicenseTerms(commRemixTermsId);
await expect(
this.licensingModule.setLicensingConfig(ipId, PILicenseTemplate, commRemixTermsId, LicensingConfig)
).not.to.be.rejectedWith(Error).then((tx) => tx.wait());
await expect(
this.groupingModule.connect(this.user1).addIp(groupId, [ipId])
).to.be.revertedWithCustomError(this.errors, "AccessController__PermissionDenied");;

const containsIp = await this.ipAssetRegistry.containsIp(groupId, ipId);
expect(containsIp).to.be.false;
});

it("Non-owner remove IP from the group", async function () {
const { ipId } = await mintNFTAndRegisterIPAWithLicenseTerms(commRemixTermsId);
await expect(
this.licensingModule.setLicensingConfig(ipId, PILicenseTemplate, commRemixTermsId, LicensingConfig)
).not.to.be.rejectedWith(Error).then((tx) => tx.wait());
await expect(
this.groupingModule.addIp(groupId, [ipId])
).not.to.be.rejectedWith(Error).then((tx) => tx.wait());
let containsIp = await this.ipAssetRegistry.containsIp(groupId, ipId);
expect(containsIp).to.be.true;

// Remove IP from the group
await expect(
this.groupingModule.connect(this.user1).removeIp(groupId, [ipId])
).to.be.revertedWithCustomError(this.errors, "AccessController__PermissionDenied");
containsIp = await this.ipAssetRegistry.containsIp(groupId, ipId);
expect(containsIp).to.be.true;
});

it("Add IP with none/different license term to the group", async function () {
const { ipId } = await mintNFTAndRegisterIPA();
// IP has no license term attached
await expect(
this.groupingModule.addIp(groupId, [ipId])
).to.be.revertedWithCustomError(this.errors, "LicenseRegistry__IpHasNoGroupLicenseTerms");

// IP has different license term attached
await expect(
this.licensingModule.attachLicenseTerms(ipId, PILicenseTemplate, this.commericialUseLicenseId)
).not.to.be.rejectedWith(Error).then((tx) => tx.wait());
await expect(
this.groupingModule.addIp(groupId, [ipId])
).to.be.revertedWithCustomError(this.errors, "LicenseRegistry__IpHasNoGroupLicenseTerms");
});
});
1 change: 1 addition & 0 deletions test/hardhat/e2e/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ before(async function () {
this.groupingModule = await hre.ethers.getContractAt("GroupingModule", GroupingModule);
this.licenseTemplate = await hre.ethers.getContractAt("PILicenseTemplate", PILicenseTemplate);
this.accessController = await hre.ethers.getContractAt("AccessController", AccessController);
this.errors = await hre.ethers.getContractFactory("Errors");

console.log(`================= Load Users =================`);
[this.owner, this.user1] = await hre.ethers.getSigners();
Expand Down
39 changes: 39 additions & 0 deletions test/hardhat/e2e/utils/licenseHelper.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// Purpose: Helper functions for licensing config and registering PIL terms functions

import hre from "hardhat";
import { EvenSplitGroupPool, MockERC20, PILicenseTemplate } from "../constants";
import { terms } from "../licenseTermsTemplate";

export const LicensingConfig = ({
isSet: true,
mintingFee: 20,
licensingHook: hre.ethers.ZeroAddress,
hookData: "0x",
commercialRevShare: 10 * 10 ** 6,
disabled: false,
expectMinimumGroupRewardShare: 0,
expectGroupRewardPool: EvenSplitGroupPool,
});

export async function registerPILTerms(
commercialUse: boolean = false,
mintingFee: number = 0,
commercialRevShare: number = 0,
royaltyPolicy: string = hre.ethers.ZeroAddress,
currencyToken: string = MockERC20): Promise<number> {

const licenseTemplate = await hre.ethers.getContractAt("PILicenseTemplate", PILicenseTemplate);

const testTerms = terms;
testTerms.royaltyPolicy = royaltyPolicy;
testTerms.defaultMintingFee = mintingFee;
testTerms.commercialUse = commercialUse;
testTerms.commercialRevShare = commercialRevShare;
testTerms.currency = currencyToken;

await licenseTemplate.registerLicenseTerms(testTerms).then((tx) => tx.wait());
const licenseTermsId = await licenseTemplate.getLicenseTermsId(testTerms);
console.log("licenseTermsId", licenseTermsId);

return licenseTermsId;
}
12 changes: 11 additions & 1 deletion test/hardhat/e2e/utils/mintNFTAndRegisterIPA.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import "../setup";
import { mintNFT } from "./nftHelper";
import { MockERC721, IPAssetRegistry } from "../constants";
import { MockERC721, IPAssetRegistry, LicensingModule, PILicenseTemplate } from "../constants";
import { expect } from "chai";
import hre from "hardhat";
import { network } from "hardhat";
Expand Down Expand Up @@ -37,3 +37,13 @@ export async function mintNFTAndRegisterIPA(mintNFTSigner?: any, registerIPASign
return { tokenId, ipId };
};

export async function mintNFTAndRegisterIPAWithLicenseTerms(licenseTermsId: any, mintNFTSigner?: any, registerIPASigner?: any): Promise<{ tokenId: number; ipId: HexString }> {
const { tokenId, ipId } = await mintNFTAndRegisterIPA(mintNFTSigner, registerIPASigner);

const licensingModule = await hre.ethers.getContractAt("LicensingModule", LicensingModule, registerIPASigner);
await expect(
licensingModule.attachLicenseTerms(ipId, PILicenseTemplate, licenseTermsId)
).not.to.be.rejectedWith(Error).then((tx) => tx.wait());

return { tokenId, ipId };
};

0 comments on commit 320e5c1

Please sign in to comment.