Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update royalty.test.ts #372

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
370 changes: 116 additions & 254 deletions test/hardhat/e2e/grouping/group.ipa.test.ts
Original file line number Diff line number Diff line change
@@ -1,265 +1,127 @@
// Test: Group IP Asset

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

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 = this.user1.address;
await expect(
this.groupingModule.registerGroup(nonWhitelistedGroupPool)
).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;
const registerGroupAndLicense = async function () {
const groupId = await this.groupingModule
.registerGroup(EvenSplitGroupPool)
.then((tx) => tx.wait())
.then((receipt) => receipt.logs[5].args[0]);
expect(groupId).to.be.properHex(40);

const commRemixTermsId = await registerPILTerms(true, 0, 10e6, RoyaltyPolicyLRP);
await this.licensingModule.attachLicenseTerms(groupId, PILicenseTemplate, commRemixTermsId).then((tx) => tx.wait());
return { groupId, commRemixTermsId };
};

describe("Group IP Asset Tests", function () {
describe("Register Group IPA", function () {
it("with whitelisted pool", async function () {
const groupId = await this.groupingModule
.registerGroup(EvenSplitGroupPool)
.then((tx) => tx.wait())
.then((receipt) => receipt.logs[5].args[0]);
expect(await this.ipAssetRegistry.isRegisteredGroup(groupId)).to.be.true;
});

it("with non-whitelisted pool", async function () {
await expect(this.groupingModule.registerGroup(this.user1.address)).to.be.revertedWithCustomError(
this.errors,
"GroupIPAssetRegistry__GroupRewardPoolNotRegistered"
);
});
});

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");
});
});

describe("Group is locked due to registered derivative", function () {
let groupId: any;
let commRemixTermsId: any;
let ipId1: any;
let ipId2: 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());

// Register IP
console.log("============ Register IP1 ============");
({ ipId: ipId1 } = await mintNFTAndRegisterIPAWithLicenseTerms(commRemixTermsId, this.user1, this.user1));
await expect(
this.licensingModule.connect(this.user1).setLicensingConfig(ipId1, PILicenseTemplate, commRemixTermsId, LicensingConfig)
).not.to.be.rejectedWith(Error).then((tx) => tx.wait());

// Add IP to the group
console.log("============ Add Ips to group ============");
await expect(
this.groupingModule.addIp(groupId, [ipId1])
).not.to.be.rejectedWith(Error).then((tx) => tx.wait());
expect(
await this.evenSplitGroupPool.getTotalIps(groupId)
).to.be.equal(1);

// Register derivative IP
console.log("============ Register IP2 ============");
({ ipId: ipId2 } = await mintNFTAndRegisterIPA(this.user2, this.user2));
await expect(
this.licensingModule.connect(this.user2).registerDerivative(ipId2, [groupId], [commRemixTermsId], PILicenseTemplate, "0x", 0, 100e6)
).not.to.be.rejectedWith(Error).then((tx) => tx.wait());
});

it("Add Ip to locked 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])
).to.be.revertedWithCustomError(this.errors, "GroupingModule__GroupFrozenDueToHasDerivativeIps");
});

it("Remove Ip from locked group", async function () {
await expect(
this.groupingModule.removeIp(groupId, [ipId1])
).to.be.revertedWithCustomError(this.errors, "GroupingModule__GroupFrozenDueToHasDerivativeIps");
});
});

describe("Group is locked due to minted license token", function () {
let groupId: any;
let commRemixTermsId: any;
let ipId1: 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());

// Register IP
console.log("============ Register IP1 ============");
({ ipId: ipId1 } = await mintNFTAndRegisterIPAWithLicenseTerms(commRemixTermsId, this.user1, this.user1));
await expect(
this.licensingModule.connect(this.user1).setLicensingConfig(ipId1, PILicenseTemplate, commRemixTermsId, LicensingConfig)
).not.to.be.rejectedWith(Error).then((tx) => tx.wait());

// Add IP to the group
console.log("============ Add Ips to group ============");
await expect(
this.groupingModule.addIp(groupId, [ipId1])
).not.to.be.rejectedWith(Error).then((tx) => tx.wait());
expect(
await this.evenSplitGroupPool.getTotalIps(groupId)
).to.be.equal(1);

// Mint license token
console.log("============ Group mint license token ============");
await expect(
this.licensingModule.mintLicenseTokens(groupId, PILicenseTemplate, commRemixTermsId, 1, this.owner.address, "0x", 0)
).not.to.be.rejectedWith(Error).then((tx) => tx.wait());
});

it("Add Ip to locked 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])
).to.be.revertedWithCustomError(this.errors, "GroupingModule__GroupFrozenDueToAlreadyMintLicenseTokens");
describe("IP Management in Groups", function () {
let groupId, commRemixTermsId;
before(async function () {
({ groupId, commRemixTermsId } = await registerGroupAndLicense.call(this));
});

it("Add and remove a single IP", async function () {
const { ipId } = await mintNFTAndRegisterIPAWithLicenseTerms(commRemixTermsId);
await this.groupingModule.addIp(groupId, [ipId]).then((tx) => tx.wait());
expect(await this.ipAssetRegistry.containsIp(groupId, ipId)).to.be.true;

await this.groupingModule.removeIp(groupId, [ipId]).then((tx) => tx.wait());
expect(await this.ipAssetRegistry.containsIp(groupId, ipId)).to.be.false;
});

it("Add and remove multiple IPs", async function () {
const { ipId: ip1 } = await mintNFTAndRegisterIPAWithLicenseTerms(commRemixTermsId);
const { ipId: ip2 } = await mintNFTAndRegisterIPAWithLicenseTerms(commRemixTermsId, this.user1);
await this.groupingModule.addIp(groupId, [ip1, ip2]).then((tx) => tx.wait());
expect(await this.ipAssetRegistry.containsIp(groupId, ip1)).to.be.true;
expect(await this.ipAssetRegistry.containsIp(groupId, ip2)).to.be.true;

await this.groupingModule.removeIp(groupId, [ip1, ip2]).then((tx) => tx.wait());
expect(await this.ipAssetRegistry.containsIp(groupId, ip1)).to.be.false;
expect(await this.ipAssetRegistry.containsIp(groupId, ip2)).to.be.false;
});

it("Non-owner actions", async function () {
const { ipId } = await mintNFTAndRegisterIPAWithLicenseTerms(commRemixTermsId);
await expect(this.groupingModule.connect(this.user1).addIp(groupId, [ipId])).to.be.revertedWithCustomError(
this.errors,
"AccessController__PermissionDenied"
);
await expect(this.groupingModule.connect(this.user1).removeIp(groupId, [ipId])).to.be.revertedWithCustomError(
this.errors,
"AccessController__PermissionDenied"
);
});

it("Add IP with mismatched license", async function () {
const { ipId } = await mintNFTAndRegisterIPA();
await expect(this.groupingModule.addIp(groupId, [ipId])).to.be.revertedWithCustomError(
this.errors,
"LicenseRegistry__IpHasNoGroupLicenseTerms"
);
});
});

it("Remove Ip from locked group", async function () {
await expect(
this.groupingModule.removeIp(groupId, [ipId1])
).to.be.revertedWithCustomError(this.errors, "GroupingModule__GroupFrozenDueToAlreadyMintLicenseTokens");
describe("Locked Groups", function () {
let groupId, commRemixTermsId, ipId1, ipId2;

before(async function () {
({ groupId, commRemixTermsId } = await registerGroupAndLicense.call(this));
({ ipId: ipId1 } = await mintNFTAndRegisterIPAWithLicenseTerms(commRemixTermsId));
await this.groupingModule.addIp(groupId, [ipId1]).then((tx) => tx.wait());
({ ipId: ipId2 } = await mintNFTAndRegisterIPA(this.user2));
await this.licensingModule
.registerDerivative(ipId2, [groupId], [commRemixTermsId], PILicenseTemplate, "0x", 0, 100e6)
.then((tx) => tx.wait());
});

it("Handle group frozen due to derivative", async function () {
const { ipId } = await mintNFTAndRegisterIPAWithLicenseTerms(commRemixTermsId);
await expect(this.groupingModule.addIp(groupId, [ipId])).to.be.revertedWithCustomError(
this.errors,
"GroupingModule__GroupFrozenDueToHasDerivativeIps"
);
await expect(this.groupingModule.removeIp(groupId, [ipId1])).to.be.revertedWithCustomError(
this.errors,
"GroupingModule__GroupFrozenDueToHasDerivativeIps"
);
});

it("Handle group frozen due to minted license", async function () {
await this.licensingModule
.mintLicenseTokens(groupId, PILicenseTemplate, commRemixTermsId, 1, this.owner.address, "0x", 0)
.then((tx) => tx.wait());
const { ipId } = await mintNFTAndRegisterIPAWithLicenseTerms(commRemixTermsId);
await expect(this.groupingModule.addIp(groupId, [ipId])).to.be.revertedWithCustomError(
this.errors,
"GroupingModule__GroupFrozenDueToAlreadyMintLicenseTokens"
);
await expect(this.groupingModule.removeIp(groupId, [ipId1])).to.be.revertedWithCustomError(
this.errors,
"GroupingModule__GroupFrozenDueToAlreadyMintLicenseTokens"
);
});
});
});
Loading