Skip to content

Commit

Permalink
add ipasset unit test case
Browse files Browse the repository at this point in the history
  • Loading branch information
jhd2best committed Aug 1, 2024
1 parent 307e331 commit 6c516c2
Showing 1 changed file with 184 additions and 0 deletions.
184 changes: 184 additions & 0 deletions packages/core-sdk/test/unit/resources/ipAsset.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,41 @@ describe("Test IpAssetClient", () => {
expect(response.ipId).equals("0xd142822Dc1674154EaF4DDF38bbF7EF8f0D8ECe4");
});

it("should return encoded tx data when register a IP given correct args, encodedTxDataOnly is true and metadata", async () => {
sinon
.stub(ipAssetClient.ipAssetRegistryClient, "ipId")
.resolves("0xd142822Dc1674154EaF4DDF38bbF7EF8f0D8ECe4");
sinon.stub(ipAssetClient.ipAssetRegistryClient, "isRegistered").resolves(false);
sinon
.stub(ipAssetClient.spgClient, "registerIp")
.resolves("0x129f7dd802200f096221dd89d5b086e4bd3ad6eafb378a0c75e3b04fc375f997");
sinon.stub(ipAssetClient.ipAssetRegistryClient, "parseTxIpRegisteredEvent").returns([
{
ipId: "0xd142822Dc1674154EaF4DDF38bbF7EF8f0D8ECe4",
chainId: 0n,
tokenContract: "0x1daAE3197Bc469Cb97B917aa460a12dD95c6627c",
tokenId: 0n,
name: "",
uri: "",
registrationDate: 0n,
},
]);
const response = await ipAssetClient.register({
nftContract: "0x1daAE3197Bc469Cb97B917aa460a12dD95c6627c",
tokenId: "3",
metadata: {
metadataURI: "",
metadataHash: zeroHash,
nftMetadataHash: zeroHash,
},
txOptions: {
encodedTxDataOnly: true,
},
});

expect(response.encodedTxData!.data).to.be.a("string").and.not.empty;
});

it("should throw error when request fails", async () => {
sinon
.stub(ipAssetClient.ipAssetRegistryClient, "ipId")
Expand Down Expand Up @@ -347,6 +382,34 @@ describe("Test IpAssetClient", () => {
"0x129f7dd802200f096221dd89d5b086e4bd3ad6eafb378a0c75e3b04fc375f997",
);
});

it("should return encoded tx data when registerDerivative given correct childIpId, parentIpId, licenseTermsIds and encodedTxDataOnly of true ", async () => {
sinon
.stub(ipAssetClient.ipAssetRegistryClient, "isRegistered")
.onCall(0)
.resolves(true)
.onCall(1)
.resolves(true);
sinon
.stub(ipAssetClient.licenseRegistryReadOnlyClient, "hasIpAttachedLicenseTerms")
.resolves(true);
sinon
.stub(ipAssetClient.licensingModuleClient, "registerDerivative")
.resolves("0x129f7dd802200f096221dd89d5b086e4bd3ad6eafb378a0c75e3b04fc375f997");

const res = await ipAssetClient.registerDerivative({
childIpId: "0x1daAE3197Bc469Cb97B917aa460a12dD95c6627c",
parentIpIds: ["0xd142822Dc1674154EaF4DDF38bbF7EF8f0D8ECe4"],
licenseTermsIds: ["1"],
licenseTemplate: "0x1daAE3197Bc469Cb97B917aa460a12dD95c6627c",
txOptions: {
encodedTxDataOnly: true,
},
});

expect(res.encodedTxData!.data).to.be.a("string").and.not.empty;
});

});

describe("Test ipAssetClient.registerDerivativeWithLicenseTokens", async () => {
Expand Down Expand Up @@ -436,6 +499,32 @@ describe("Test IpAssetClient", () => {
"0x129f7dd802200f096221dd89d5b086e4bd3ad6eafb378a0c75e3b04fc375f997",
);
});

it("should return encoded tx data when registerDerivativeWithLicenseTokens given correct args and encodedTxDataOnly of true", async () => {
sinon
.stub(ipAssetClient.ipAssetRegistryClient, "isRegistered")
.onCall(0)
.resolves(true)
.onCall(1)
.resolves(true);
sinon
.stub(ipAssetClient.licenseTokenReadOnlyClient, "ownerOf")
.resolves("0x73fcb515cee99e4991465ef586cfe2b072ebb512");
sinon
.stub(ipAssetClient.licensingModuleClient, "registerDerivativeWithLicenseTokens")
.resolves("0x129f7dd802200f096221dd89d5b086e4bd3ad6eafb378a0c75e3b04fc375f997");

const res = await ipAssetClient.registerDerivativeWithLicenseTokens({
childIpId: "0xd142822Dc1674154EaF4DDF38bbF7EF8f0D8ECe4",
licenseTokenIds: ["1"],
txOptions: {
encodedTxDataOnly: true,
},
});

expect(res.encodedTxData!.data).to.be.a("string").and.not.empty;
});

});

describe("Test ipAssetClient.createIpAssetWithPilTerms", async () => {
Expand Down Expand Up @@ -481,6 +570,7 @@ describe("Test IpAssetClient", () => {

expect(result.txHash).to.equal(hash);
});

it("should return ipId, tokenId, licenseTermsId,txHash when createIpAssetWithPilTerms given correct args and waitForTransaction of true", async () => {
const hash = "0x129f7dd802200f096221dd89d5b086e4bd3ad6eafb378a0c75e3b04fc375f997";
sinon.stub(ipAssetClient.spgClient, "mintAndRegisterIpAndAttachPilTerms").resolves(hash);
Expand Down Expand Up @@ -519,6 +609,26 @@ describe("Test IpAssetClient", () => {
expect(result.licenseTermsId).to.equal(0n);
expect(result.tokenId).to.equal(1n);
});

it("should return encoded tx data when createIpAssetWithPilTerms given correct args and encodedTxDataOnly is true", async () => {
const hash = "0x129f7dd802200f096221dd89d5b086e4bd3ad6eafb378a0c75e3b04fc375f997";
sinon.stub(ipAssetClient.spgClient, "mintAndRegisterIpAndAttachPilTerms").resolves(hash);
const result = await ipAssetClient.mintAndRegisterIpAssetWithPilTerms({
nftContract: "0x1daAE3197Bc469Cb97B917aa460a12dD95c6627c",
pilType: 0,
recipient: "0x73fcb515cee99e4991465ef586cfe2b072ebb512",
metadata: {
metadataURI: "",
metadataHash: toHex(0, { size: 32 }),
},
txOptions: {
encodedTxDataOnly: true
}
});

expect(result.encodedTxData!.data).to.be.a("string").and.not.empty;
});

});

describe("Test ipAssetClient.registerDerivativeIp", async () => {
Expand Down Expand Up @@ -695,6 +805,49 @@ describe("Test IpAssetClient", () => {
);
expect(res.ipId).equal("0x1daAE3197Bc469Cb97B917aa460a12dD95c6627c");
});

it("should return encoded tx data when registerDerivativeIp given correct args and encodedTxDataOnly of true", async () => {
sinon
.stub(ipAssetClient.ipAssetRegistryClient, "ipId")
.resolves("0x1daAE3197Bc469Cb97B917aa460a12dD95c6627c");
sinon.stub(ipAssetClient.ipAssetRegistryClient, "isRegistered").resolves(false);
sinon
.stub(ipAssetClient.licenseRegistryReadOnlyClient, "hasIpAttachedLicenseTerms")
.resolves(true);
sinon
.stub(ipAssetClient.spgClient, "registerIpAndMakeDerivative")
.resolves("0x129f7dd802200f096221dd89d5b086e4bd3ad6eafb378a0c75e3b04fc375f997");
sinon.stub(ipAssetClient.ipAssetRegistryClient, "parseTxIpRegisteredEvent").returns([
{
ipId: "0x1daAE3197Bc469Cb97B917aa460a12dD95c6627c",
chainId: 0n,
tokenContract: "0x1daAE3197Bc469Cb97B917aa460a12dD95c6627c",
tokenId: 1n,
name: "",
uri: "",
registrationDate: 0n,
},
]);

const res = await ipAssetClient.registerDerivativeIp({
nftContract: "0x1daAE3197Bc469Cb97B917aa460a12dD95c6627c",
tokenId: "3",
derivData: {
parentIpIds: ["0xd142822Dc1674154EaF4DDF38bbF7EF8f0D8ECe4"],
licenseTermsIds: ["1"],
licenseTemplate: "0x1daAE3197Bc469Cb97B917aa460a12dD95c6627c",
},
metadata: {
metadataURI: "https://",
nftMetadataHash: toHex("nftMetadata", { size: 32 }),
},
txOptions: {
encodedTxDataOnly: true,
},
});

expect(res.encodedTxData!.data).to.be.a("string").and.not.empty;
});
});

describe("Test ipAssetClient.registerIpAndAttachPilTerms", async () => {
Expand Down Expand Up @@ -807,5 +960,36 @@ describe("Test IpAssetClient", () => {
expect(result.txHash).to.equal(hash);
expect(result.ipId).to.equal("0x1daAE3197Bc469Cb97B917aa460a12dD95c6627c");
});

it("should return encoded tx data when registerIpAndAttachPilTerms given correct args and encodedTxDataOnly of true", async () => {
const hash = "0x129f7dd802200f096221dd89d5b086e4bd3ad6eafb378a0c75e3b04fc375f997";
sinon
.stub(ipAssetClient.ipAssetRegistryClient, "ipId")
.resolves("0x1daAE3197Bc469Cb97B917aa460a12dD95c6627c");
sinon.stub(ipAssetClient.ipAssetRegistryClient, "isRegistered").resolves(false);

sinon.stub(ipAssetClient.spgClient, "registerIpAndAttachPilTerms").resolves(hash);
sinon.stub(ipAssetClient.licensingModuleClient, "parseTxLicenseTermsAttachedEvent").returns([
{
ipId: "0x1daAE3197Bc469Cb97B917aa460a12dD95c6627c",
caller: "0x73fcb515cee99e4991465ef586cfe2b072ebb512",
licenseTemplate: "0x1daAE3197Bc469Cb97B917aa460a12dD95c6627c",
licenseTermsId: 0n,
},
]);
const result = await ipAssetClient.registerIpAndAttachPilTerms({
nftContract: "0x1daAE3197Bc469Cb97B917aa460a12dD95c662ac",
tokenId: "3",
metadata: {
metadataURI: "https://",
},
pilType: 0,
txOptions: {
encodedTxDataOnly: true,
},
});

expect(result.encodedTxData!.data).to.be.a("string").and.not.empty;
});
});
});

0 comments on commit 6c516c2

Please sign in to comment.