From 893d4ebae310883585b99df8b791c2d7d5648cf5 Mon Sep 17 00:00:00 2001 From: Don <100505855+DonFungible@users.noreply.github.com> Date: Sun, 11 Feb 2024 23:55:59 -0500 Subject: [PATCH] add waitTx and export types (#63) * add waitTx and export types * remove protocol-core --- packages/core-sdk/src/index.ts | 21 +++++++++++++++++++ packages/core-sdk/src/resources/tagging.ts | 9 ++++++++ packages/core-sdk/src/utils/utils.ts | 2 +- .../core-sdk/test/integration/dispute.test.ts | 2 +- .../core-sdk/test/integration/tagging.test.ts | 4 ++-- .../test/unit/resources/dispute.test.ts | 2 +- .../test/unit/resources/tagging.test.ts | 8 +++---- 7 files changed, 39 insertions(+), 9 deletions(-) diff --git a/packages/core-sdk/src/index.ts b/packages/core-sdk/src/index.ts index d115e981..35b81b13 100644 --- a/packages/core-sdk/src/index.ts +++ b/packages/core-sdk/src/index.ts @@ -6,6 +6,8 @@ export { IPAssetClient } from "./resources/ipAsset"; export { PermissionClient } from "./resources/permission"; export { LicenseClient } from "./resources/license"; export { PolicyClient } from "./resources/policy"; +export { TaggingClient } from "./resources/tagging"; +export { DisputeClient } from "./resources/dispute"; export type { StoryConfig } from "./types/config"; export type { Hex, TypedData } from "./types/common"; @@ -32,3 +34,22 @@ export type { } from "./types/resources/policy"; export type { setPermissionsRequest, setPermissionsResponse } from "./types/resources/permission"; + +export type { + SetTagRequest, + SetTagResponse, + RemoveTagRequest, + RemoveTagResponse, +} from "./types/resources/tagging"; + +export type { + Dispute, + RaiseDisputeRequest, + RaiseDisputeResponse, + SetDisputeJudgementRequest, + SetDisputeJudgementResponse, + CancelDisputeRequest, + CancelDisputeResponse, + ResolveDisputeRequest, + ResolveDisputeResponse, +} from "./types/resources/dispute"; diff --git a/packages/core-sdk/src/resources/tagging.ts b/packages/core-sdk/src/resources/tagging.ts index 6a32a14c..295db67f 100644 --- a/packages/core-sdk/src/resources/tagging.ts +++ b/packages/core-sdk/src/resources/tagging.ts @@ -8,6 +8,7 @@ import { SetTagRequest, SetTagResponse, } from "../types/resources/tagging"; +import { waitTx } from "../utils/utils"; export class TaggingClient { private readonly wallet: WalletClient; @@ -28,6 +29,10 @@ export class TaggingClient { const txHash = await this.wallet.writeContract(call); + if (request.txOptions?.waitForTransaction) { + await waitTx(this.rpcClient, txHash); + } + return { txHash: txHash }; } catch (error) { handleError(error, "Failed to set tag"); @@ -44,6 +49,10 @@ export class TaggingClient { const txHash = await this.wallet.writeContract(call); + if (request.txOptions?.waitForTransaction) { + await waitTx(this.rpcClient, txHash); + } + return { txHash: txHash }; } catch (error) { handleError(error, "Failed to remove tag"); diff --git a/packages/core-sdk/src/utils/utils.ts b/packages/core-sdk/src/utils/utils.ts index 16ac40a4..810daf84 100644 --- a/packages/core-sdk/src/utils/utils.ts +++ b/packages/core-sdk/src/utils/utils.ts @@ -71,7 +71,7 @@ export async function waitTx( pollingInterval?: number; timeout?: number; }, -) { +): Promise { await client.waitForTransactionReceipt({ hash: txHash, ...params, diff --git a/packages/core-sdk/test/integration/dispute.test.ts b/packages/core-sdk/test/integration/dispute.test.ts index d52a121a..bf4c9c9c 100644 --- a/packages/core-sdk/test/integration/dispute.test.ts +++ b/packages/core-sdk/test/integration/dispute.test.ts @@ -21,7 +21,7 @@ describe("Dispute Functions", () => { client = StoryClient.newClient(config); }); - describe("[Write Functions] Should be able to", async function () { + describe("Should be able to", async function () { it.skip("raise a dispute", async () => { const raiseDisputeRequest: RaiseDisputeRequest = { targetIpId: "0xcd3a91675b990f27eb544b85cdb6844573b66a43", diff --git a/packages/core-sdk/test/integration/tagging.test.ts b/packages/core-sdk/test/integration/tagging.test.ts index 5d61ec8a..e9633d39 100644 --- a/packages/core-sdk/test/integration/tagging.test.ts +++ b/packages/core-sdk/test/integration/tagging.test.ts @@ -3,7 +3,7 @@ import { StoryClient, StoryConfig } from "../../src"; import { Hex, http } from "viem"; import { privateKeyToAccount } from "viem/accounts"; -describe("Tagging Functions", () => { +describe("Tagging Functions (integration tests)", () => { let client: StoryClient; let senderAddress: string; @@ -18,7 +18,7 @@ describe("Tagging Functions", () => { client = StoryClient.newClient(config); }); - describe("[Write Functions] SDK should be able to", async function () { + describe("Should be able to", async function () { it("set tag and wait for transaction", async () => { const response = await expect( client.tagging.setTag({ diff --git a/packages/core-sdk/test/unit/resources/dispute.test.ts b/packages/core-sdk/test/unit/resources/dispute.test.ts index 2f4bc174..7559e98b 100644 --- a/packages/core-sdk/test/unit/resources/dispute.test.ts +++ b/packages/core-sdk/test/unit/resources/dispute.test.ts @@ -29,7 +29,7 @@ describe("Test DisputeClient", function () { sinon.restore(); }); - describe("[Write Functions] Should be able to", async function () { + describe("Should be able to", async function () { it.skip("raise a dispute", async () => { rpcMock.readContract = sinon.stub().resolves(AddressZero); rpcMock.simulateContract = sinon.stub().resolves({ request: null }); diff --git a/packages/core-sdk/test/unit/resources/tagging.test.ts b/packages/core-sdk/test/unit/resources/tagging.test.ts index 8fe5cc71..6aae9c8c 100644 --- a/packages/core-sdk/test/unit/resources/tagging.test.ts +++ b/packages/core-sdk/test/unit/resources/tagging.test.ts @@ -9,7 +9,7 @@ import { AddressZero } from "../../../src"; chai.use(chaiAsPromised); -describe("Test TaggingClient", function () { +describe("Test TaggingClient (unit tests)", function () { let taggingClient: TaggingClient; let rpcMock: PublicClient; let walletMock: WalletClient; @@ -24,11 +24,11 @@ describe("Test TaggingClient", function () { sinon.restore(); }); - describe("[Write functions] Should be able to", async function () { + describe("Should be able to", async function () { it("set tag and wait for transaction", async () => { const mockTxHash = "0xeef10fc5170f669b86c4cd0444882a96087221325f8bf2f55d6188633aa7be7c"; - rpcMock.readContract = sinon.stub().resolves(AddressZero); rpcMock.simulateContract = sinon.stub().resolves({ request: null }); + rpcMock.waitForTransactionReceipt = sinon.stub().resolves(); walletMock.writeContract = sinon.stub().resolves(mockTxHash); const response = await expect( @@ -48,10 +48,10 @@ describe("Test TaggingClient", function () { it("remove tag", async () => { const tagString = "bad-tag69"; const ipId = "0xabCc2421F927c128B9F5a94B612F4541C8E624B6"; - const mockSetTxHash = "0xset123"; const mockRemoveTxHash = "0xremove123"; rpcMock.simulateContract = sinon.stub().resolves({ request: null }); + rpcMock.waitForTransactionReceipt = sinon.stub().resolves(); walletMock.writeContract = sinon.stub().resolves(mockRemoveTxHash); const response = await expect(