Skip to content

Commit

Permalink
fix unit test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
allenchuang authored and edisonz0718 committed Jan 27, 2024
1 parent 35ff734 commit bea3b48
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 33 deletions.
61 changes: 31 additions & 30 deletions packages/core-sdk/src/resources/ipAsset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ export class IPAssetClient extends IPAssetReadOnlyClient {
...IPAccountRegistryConfig,
eventName: "IPAccountRegistered",
});
console.log({ targetLog });
return { txHash: txHash, ipAccountId: targetLog?.args.account.toString() };
} else {
return { txHash: txHash };
Expand All @@ -101,37 +102,37 @@ export class IPAssetClient extends IPAssetReadOnlyClient {
}

// TODO: move to License resource
public async createPolicy(request: addPolicyRequest): Promise<addPolicyResponse> {
try {
const { request: call } = await this.rpcClient.simulateContract({
...LicenseRegistryConfig,
functionName: "addPolicy",
args: [
{
frameworkId: parseToBigInt(request.frameworkId),
mintingParamValues: request.mintingParamValues.map((add) => getAddress(add)),
activationParamValues: request.activationParamValues.map((add) => getAddress(add)),
needsActivation: request.needsActivation,
linkParentParamValues: request.linkParentParamValues.map((add) => getAddress(add)),
},
], // TODO: add args
});
// public async createPolicy(request: addPolicyRequest): Promise<addPolicyResponse> {
// try {
// const { request: call } = await this.rpcClient.simulateContract({
// ...LicenseRegistryConfig,
// functionName: "addPolicy",
// args: [
// {
// frameworkId: parseToBigInt(request.frameworkId),
// mintingParamValues: request.mintingParamValues.map((add) => getAddress(add)),
// activationParamValues: request.activationParamValues.map((add) => getAddress(add)),
// needsActivation: request.needsActivation,
// linkParentParamValues: request.linkParentParamValues.map((add) => getAddress(add)),
// },
// ], // TODO: add args
// });

const txHash = await this.wallet.writeContract(call);
// TODO: need an emitted event
// if (request.txOptions?.waitForTransaction) {
// const targetLog = await waitTxAndFilterLog(this.rpcClient, txHash, {
// ...IPAccountRegistryConfig,
// eventName: "IPAccountRegistered",
// });
// return { txHash: txHash, policyId: targetLog?.args.account.toString() };
// } else {
return { txHash: txHash };
// }
} catch (error) {
handleError(error, "Failed to register derivative IP");
}
}
// const txHash = await this.wallet.writeContract(call);
// // TODO: need an emitted event
// // if (request.txOptions?.waitForTransaction) {
// // const targetLog = await waitTxAndFilterLog(this.rpcClient, txHash, {
// // ...IPAccountRegistryConfig,
// // eventName: "IPAccountRegistered",
// // });
// // return { txHash: txHash, policyId: targetLog?.args.account.toString() };
// // } else {
// return { txHash: txHash };
// // }
// } catch (error) {
// handleError(error, "Failed to register derivative IP");
// }
// }

// TODO: move to License resource
// public async addPolicyToIp(request: addPolicyToIpRequest): Promise<addPolicyToIpResponse> {
Expand Down
6 changes: 3 additions & 3 deletions packages/core-sdk/test/unit/resources/ipAsset.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ describe("Test IpAssetClient", function () {
expect(res.txHash).equal(txHash);
});

it.skip("should not throw error when creating a root IP and wait for transaction confirmed", async function () {
it("should not throw error when creating a root IP and wait for transaction confirmed", async function () {
const txHash = "0x129f7dd802200f096221dd89d5b086e4bd3ad6eafb378a0c75e3b04fc375f997";
rpcMock.readContract = sinon.stub().resolves(AddressZero);
rpcMock.simulateContract = sinon.stub().resolves({ request: null });
Expand Down Expand Up @@ -96,7 +96,7 @@ describe("Test IpAssetClient", function () {
tokenContractAddress: "0x1daAE3197Bc469Cb97B917aa460a12dD95c6627c",
tokenId: "3",
txOptions: {
waitForTransaction: false,
waitForTransaction: true,
},
});
expect(response.txHash).equal(txHash);
Expand Down Expand Up @@ -159,7 +159,7 @@ describe("Test IpAssetClient", function () {
expect(res.txHash).equal(txHash);
});

it.skip("should not throw error when creating a derivative IP and wait for transaction confirmed", async function () {
it("should not throw error when creating a derivative IP and wait for transaction confirmed", async function () {
const txHash = "0x129f7dd802200f096221dd89d5b086e4bd3ad6eafb378a0c75e3b04fc375f997";
rpcMock.readContract = sinon.stub().resolves(AddressZero);
rpcMock.simulateContract = sinon.stub().resolves({ request: null });
Expand Down

0 comments on commit bea3b48

Please sign in to comment.