Skip to content

Commit

Permalink
update test config
Browse files Browse the repository at this point in the history
  • Loading branch information
tyitang committed Dec 3, 2024
1 parent 9bb8451 commit 7d101a5
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 71 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: 20_000,
timeout: 60_000,
reporter: "mochawesome",
},
etherscan: {
Expand Down
8 changes: 4 additions & 4 deletions test/hardhat/e2e/ipa/ipa.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { mintNFT } from "../utils/nftHelper"
import hre from "hardhat";
import { MockERC721 } from "../constants";

describe.only("IP Asset", function () {
describe("IP Asset", function () {
let signers:any;

this.beforeAll("Get Signers", async function () {
Expand All @@ -13,7 +13,7 @@ describe.only("IP Asset", function () {
})

it("NFT owner register IP Asset with an NFT token", async function () {
const tokenId = await mintNFT(signers[0].address);
const tokenId = await mintNFT(signers[0]);
const connectedRegistry = this.ipAssetRegistry.connect(signers[0]);

const ipId = await expect(
Expand All @@ -31,7 +31,7 @@ describe.only("IP Asset", function () {
});

it("Non-NFT owner register IP asset with an NFT token", async function () {
const tokenId = await mintNFT(signers[0].address);
const tokenId = await mintNFT(signers[0]);
const connectedRegistry = this.ipAssetRegistry.connect(signers[1]);

const ipId = await expect(
Expand All @@ -49,7 +49,7 @@ describe.only("IP Asset", function () {
});

it("Register IP asset, the caller doesn’t have enough IP token", async function () {
const tokenId = await mintNFT(signers[0].address);
const tokenId = await mintNFT(signers[0]);

// generate random wallet
const randomWallet = hre.ethers.Wallet.createRandom();
Expand Down
76 changes: 23 additions & 53 deletions test/hardhat/e2e/setup.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import hre from "hardhat";
import { network } from "hardhat";
import { GroupingModule, IPAssetRegistry, LicenseRegistry, LicenseToken, LicensingModule, PILicenseTemplate, RoyaltyPolicyLAP, MockERC20, RoyaltyPolicyLRP, AccessController } from "./constants";
import { expect } from "chai";
import { terms } from "./licenseTermsTemplate";

before(async function () {
Expand All @@ -22,58 +21,29 @@ before(async function () {
this.chainId = networkConfig.chainId;
console.log("chainId: ", this.chainId);

it("Register non-commercial PIL license terms", async function () {
console.log(`================= Register non-commercial PIL license terms =================`);
const tx = await expect(
this.licenseTemplate.registerLicenseTerms(terms)
).to.not.be.rejectedWith(Error);
await tx.wait();

console.log("Transaction hash: ", tx.hash);
expect(tx.hash).not.to.be.empty.and.to.be.a("HexString");

this.nonCommericialLicenseId = await this.licenseTemplate.getLicenseTermsId(terms);
console.log("Non-commercial licenseTermsId: ", this.nonCommericialLicenseId);
});
console.log(`================= Register non-commercial PIL license terms =================`);
await this.licenseTemplate.registerLicenseTerms(terms);
this.nonCommericialLicenseId = await this.licenseTemplate.getLicenseTermsId(terms);
console.log("Non-commercial licenseTermsId: ", this.nonCommericialLicenseId);

it("Register commercial use PIL license terms", async function () {
console.log(`================= Register commercial-use PIL license terms =================`);
const testTerms = terms;
testTerms.royaltyPolicy = RoyaltyPolicyLAP;
testTerms.defaultMintingFee = 10;
testTerms.commercialUse = true;
testTerms.currency = MockERC20;

const tx = await expect(
this.licenseTemplate.registerLicenseTerms(testTerms)
).to.not.be.rejectedWith(Error);
await tx.wait();

console.log("Transaction hash: ", tx.hash);
expect(tx.hash).not.to.be.empty.and.to.be.a("HexString");

this.commericialUseLicenseId = await this.licenseTemplate.getLicenseTermsId(testTerms);
console.log("Commercial-use licenseTermsId: ", this.commericialUseLicenseId);
});

it("Register commercial remix PIL license terms", async function () {
console.log(`================= Register commercial-remix PIL license terms =================`);
const testTerms = terms;
testTerms.royaltyPolicy = RoyaltyPolicyLRP;
testTerms.defaultMintingFee = 80;
testTerms.commercialUse = true;
testTerms.commercialRevShare = 100;
testTerms.currency = MockERC20;

const tx = await expect(
this.licenseTemplate.registerLicenseTerms(testTerms)
).to.not.be.rejectedWith(Error);
await tx.wait();

console.log("Transaction hash: ", tx.hash);
expect(tx.hash).not.to.be.empty.and.to.be.a("HexString");
console.log(`================= Register commercial-use PIL license terms =================`);
let testTerms = terms;
testTerms.royaltyPolicy = RoyaltyPolicyLAP;
testTerms.defaultMintingFee = 30;
testTerms.commercialUse = true;
testTerms.currency = MockERC20;
await this.licenseTemplate.registerLicenseTerms(testTerms);
this.commericialUseLicenseId = await this.licenseTemplate.getLicenseTermsId(testTerms);
console.log("Commercial-use licenseTermsId: ", this.commericialUseLicenseId);

this.commericialRemixLicenseId = await this.licenseTemplate.getLicenseTermsId(testTerms);
console.log("Commercial-remix licenseTermsId: ", this.commericialRemixLicenseId);
});
console.log(`================= Register commercial-remix PIL license terms =================`);
testTerms = terms;
testTerms.royaltyPolicy = RoyaltyPolicyLRP;
testTerms.defaultMintingFee = 80;
testTerms.commercialUse = true;
testTerms.commercialRevShare = 100;
testTerms.currency = MockERC20;
await this.licenseTemplate.registerLicenseTerms(testTerms);
this.commericialRemixLicenseId = await this.licenseTemplate.getLicenseTermsId(testTerms);
console.log("Commercial-remix licenseTermsId: ", this.commericialRemixLicenseId);
});
13 changes: 7 additions & 6 deletions test/hardhat/e2e/utils/mintNFTAndRegisterIPA.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,18 @@ import hre from "hardhat";
import { network } from "hardhat";
import { HexString } from "ethers/lib.commonjs/utils/data";

export async function mintNFTAndRegisterIPA(mintNFTSigner: any, registerIPASigner: any): Promise<{ tokenId: number; ipId: HexString }> {
const ipAssetRegistry = await hre.ethers.getContractAt("IPAssetRegistry", IPAssetRegistry);
export async function mintNFTAndRegisterIPA(mintNFTSigner?: any, registerIPASigner?: any): Promise<{ tokenId: number; ipId: HexString }> {
const networkConfig = network.config;
const chainId = networkConfig.chainId;

const tokenId = await mintNFT(mintNFTSigner.address);
const connectedRegistry = ipAssetRegistry.connect(registerIPASigner);
const tokenId = await mintNFT(mintNFTSigner);

const signer = registerIPASigner || (await hre.ethers.getSigners())[0];
const ipAssetRegistry = await hre.ethers.getContractAt("IPAssetRegistry", IPAssetRegistry, signer);

// Register the IP Asset
const ipId = await expect(
connectedRegistry.register(chainId, MockERC721, tokenId)
ipAssetRegistry.register(chainId, MockERC721, tokenId)
).not.to.be.rejectedWith(Error).then((tx) => tx.wait()).then((receipt) => receipt.logs[2].args[0]);

console.log("ipId:", ipId);
Expand All @@ -25,7 +26,7 @@ export async function mintNFTAndRegisterIPA(mintNFTSigner: any, registerIPASigne

// Check if the IP Asset is registered
const isRegistered = await expect(
connectedRegistry.isRegistered(ipId)
ipAssetRegistry.isRegistered(ipId)
).not.to.be.rejectedWith(Error);

expect(isRegistered).to.equal(true);
Expand Down
12 changes: 5 additions & 7 deletions test/hardhat/e2e/utils/nftHelper.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import hre from "hardhat"
import { MockERC721 } from "../constants";
import { ethers } from "ethers";


export async function mintNFT(walletAddress?: string): Promise<number> {
export async function mintNFT(singer?: ethers.Wallet): Promise<number> {
let tokenId: any
const contractAbi = [
{
Expand All @@ -14,12 +15,9 @@ export async function mintNFT(walletAddress?: string): Promise<number> {
},
]

const nftContract = await hre.ethers.getContractAt(contractAbi, MockERC721);

const [owner] = await hre.ethers.getSigners();
const address = walletAddress || owner.address

const tx = await nftContract.mint(address)
const caller = singer || (await hre.ethers.getSigners())[0]
const nftContract = await hre.ethers.getContractAt(contractAbi, MockERC721, caller);
const tx = await nftContract.mint(caller.address)
const receipt = await tx.wait()

const logs = receipt.logs
Expand Down

0 comments on commit 7d101a5

Please sign in to comment.