Skip to content

Commit

Permalink
add waitTx and export types (#63)
Browse files Browse the repository at this point in the history
* add waitTx and export types

* remove protocol-core
  • Loading branch information
DonFungible authored Feb 12, 2024
1 parent a95af61 commit 893d4eb
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 9 deletions.
21 changes: 21 additions & 0 deletions packages/core-sdk/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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";
9 changes: 9 additions & 0 deletions packages/core-sdk/src/resources/tagging.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
SetTagRequest,
SetTagResponse,
} from "../types/resources/tagging";
import { waitTx } from "../utils/utils";

export class TaggingClient {
private readonly wallet: WalletClient;
Expand All @@ -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");
Expand All @@ -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");
Expand Down
2 changes: 1 addition & 1 deletion packages/core-sdk/src/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export async function waitTx(
pollingInterval?: number;
timeout?: number;
},
) {
): Promise<void> {
await client.waitForTransactionReceipt({
hash: txHash,
...params,
Expand Down
2 changes: 1 addition & 1 deletion packages/core-sdk/test/integration/dispute.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions packages/core-sdk/test/integration/tagging.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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({
Expand Down
2 changes: 1 addition & 1 deletion packages/core-sdk/test/unit/resources/dispute.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
Expand Down
8 changes: 4 additions & 4 deletions packages/core-sdk/test/unit/resources/tagging.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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(
Expand All @@ -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(
Expand Down

0 comments on commit 893d4eb

Please sign in to comment.