diff --git a/packages/core-sdk/package.json b/packages/core-sdk/package.json index 3c03849f..7f4ca9da 100644 --- a/packages/core-sdk/package.json +++ b/packages/core-sdk/package.json @@ -17,9 +17,9 @@ ], "scripts": { "build": "pnpm run fix && preconstruct build", - "test": "pnpm run test:unit", - "test:unit": "TS_NODE_PROJECT='./tsconfig.test.json' c8 --all --src ./src mocha -r ts-node/register './test/unit/utils/ipfs.test.ts'", - "test:integration": "TS_NODE_PROJECT='./tsconfig.test.json' mocha -r ts-node/register './test/integration/**/dispute.test.ts' --timeout 240000", + "test": "pnpm run test:unit && pnpm run test:integration", + "test:unit": "TS_NODE_PROJECT='./tsconfig.test.json' c8 --all --src ./src mocha -r ts-node/register './test/unit/**/*.test.ts'", + "test:integration": "TS_NODE_PROJECT='./tsconfig.test.json' mocha -r ts-node/register './test/integration/**/*.test.ts' --timeout 240000", "fix": "pnpm run format:fix && pnpm run lint:fix", "format": "prettier --check .", "format:fix": "prettier --write .", diff --git a/packages/core-sdk/src/index.ts b/packages/core-sdk/src/index.ts index d4d08a15..4598ec25 100644 --- a/packages/core-sdk/src/index.ts +++ b/packages/core-sdk/src/index.ts @@ -127,3 +127,4 @@ export type { } from "./abi/generated"; export { getPermissionSignature } from "./utils/sign"; +export { convertCIDtoHashIPFS, convertHashIPFStoCID } from "./utils/ipfs"; diff --git a/packages/core-sdk/src/resources/dispute.ts b/packages/core-sdk/src/resources/dispute.ts index bddb2096..58fa1321 100644 --- a/packages/core-sdk/src/resources/dispute.ts +++ b/packages/core-sdk/src/resources/dispute.ts @@ -41,7 +41,9 @@ export class DisputeClient { const req = { targetIpId: getAddress(request.targetIpId, "request.targetIpId"), targetTag: stringToHex(request.targetTag, { size: 32 }), - data: request.data || "0x", + data: + request.data || + "0x00000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000278d0000000000000000000000000091f6f05b08c16769d3c85867548615d270c42fc700000000000000000000000000000000000000000000000000000000000000004153534552545f54525554480000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000a7465737420636c61696d00000000000000000000000000000000000000000000", disputeEvidenceHash: request.disputeEvidenceHash, }; diff --git a/packages/core-sdk/src/types/resources/dispute.ts b/packages/core-sdk/src/types/resources/dispute.ts index cd88b601..a5ef17bf 100644 --- a/packages/core-sdk/src/types/resources/dispute.ts +++ b/packages/core-sdk/src/types/resources/dispute.ts @@ -7,7 +7,7 @@ export type RaiseDisputeRequest = { targetIpId: Address; disputeEvidenceHash: Hex; targetTag: string; - data?: Address; + data?: Hex; txOptions?: TxOptions; }; diff --git a/packages/core-sdk/src/utils/ipfs.ts b/packages/core-sdk/src/utils/ipfs.ts index ccce053d..a60d3124 100644 --- a/packages/core-sdk/src/utils/ipfs.ts +++ b/packages/core-sdk/src/utils/ipfs.ts @@ -1,5 +1,6 @@ import { CID } from "multiformats/cid"; import bs58 from "bs58"; +import { base58btc } from "multiformats/bases/base58"; const v0Prefix = "1220"; export const convertCIDtoHashIPFS = (cid: string): string => { @@ -12,3 +13,14 @@ export const convertCIDtoHashIPFS = (cid: string): string => { .join(""); return "0x" + base16CID.slice(v0Prefix.length); }; + +export const convertHashIPFStoCID = (hash: string, version: "v0" | "v1" = "v0"): string => { + const base16CID = v0Prefix + hash.slice(2); + const bytes = new Uint8Array(base16CID.match(/.{1,2}/g)!.map((byte) => parseInt(byte, 16))); + const base58CID = bs58.encode(Buffer.from(bytes)); + if (version === "v0") { + return base58CID; + } else { + return CID.parse(base58CID, base58btc).toV1().toString(); + } +}; diff --git a/packages/core-sdk/test/integration/dispute.test.ts b/packages/core-sdk/test/integration/dispute.test.ts index 8db52300..b08a67f8 100644 --- a/packages/core-sdk/test/integration/dispute.test.ts +++ b/packages/core-sdk/test/integration/dispute.test.ts @@ -48,8 +48,8 @@ describe("Dispute Functions", () => { expect(response.txHash).to.be.a("string").and.not.empty; expect(response.disputeId).to.be.a("bigint"); }); - - it("should not throw error when cancel a dispute", async () => { + //In the current arbitration policy it is not possible to cancel disputes, so skip this test + it.skip("should not throw error when cancel a dispute", async () => { const cancelDispute: CancelDisputeRequest = { disputeId: disputeId, txOptions: { diff --git a/packages/core-sdk/test/integration/utils/util.ts b/packages/core-sdk/test/integration/utils/util.ts index f6c7a68e..f6d4459b 100644 --- a/packages/core-sdk/test/integration/utils/util.ts +++ b/packages/core-sdk/test/integration/utils/util.ts @@ -7,14 +7,13 @@ import { licenseTokenAddress, spgnftBeaconAddress, } from "../../../src/abi/generated"; -export const RPC = "https://story-testnet.aura.network"; +export const RPC = + " https://convincing-dark-feather.story-testnet.quiknode.pro/de18afeed566629cd009ba30eca51d6a9f7fb980/"; export const iliadChainId = 1513; export const mockERC721 = "0x322813fd9a801c5507c9de605d63cea4f2ce6c44"; -export const licenseToken = - licenseTokenAddress[Number(iliadChainId) as keyof typeof licenseTokenAddress]; -export const spgNftBeacon = - spgnftBeaconAddress[Number(iliadChainId) as keyof typeof spgnftBeaconAddress]; +export const licenseToken = licenseTokenAddress[iliadChainId]; +export const spgNftBeacon = spgnftBeaconAddress[iliadChainId]; const baseConfig = { chain: chainStringToViemChain("iliad"), diff --git a/packages/core-sdk/test/unit/utils/ipfs.test.ts b/packages/core-sdk/test/unit/utils/ipfs.test.ts index 3d9b1d37..d49862ff 100644 --- a/packages/core-sdk/test/unit/utils/ipfs.test.ts +++ b/packages/core-sdk/test/unit/utils/ipfs.test.ts @@ -1,5 +1,5 @@ import { expect } from "chai"; -import { convertCIDtoHashIPFS } from "../../../src/utils/ipfs"; +import { convertCIDtoHashIPFS, convertHashIPFStoCID } from "../../../src/utils/ipfs"; describe("IPFS", () => { it("should return hash when call convertCIDtoHashIPFS given CID with v0", async () => { const result = convertCIDtoHashIPFS("QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR"); @@ -13,4 +13,20 @@ describe("IPFS", () => { console.log(result); expect(result).to.equal("0xe3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"); }); + + it("should return CID when call convertHashIPFStoCID given hash with v0", async () => { + const result = convertHashIPFStoCID( + "0xc3c4733ec8affd06cf9e9ff50ffc6bcd2ec85a6170004bb709669c31de94391a", + "v0", + ); + expect(result).to.equal("QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR"); + }); + + it("should return CID when call convertHashIPFStoCID given hash with v1", async () => { + const result = convertHashIPFStoCID( + "0xe3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", + "v1", + ); + expect(result).to.equal("bafybeihdwdcefgh4dqkjv67uzcmw7ojee6xedzdetojuzjevtenxquvyku"); + }); }); diff --git a/packages/react-sdk/test/integration/utils/util.ts b/packages/react-sdk/test/integration/utils/util.ts index eeb80166..ed365285 100644 --- a/packages/react-sdk/test/integration/utils/util.ts +++ b/packages/react-sdk/test/integration/utils/util.ts @@ -46,9 +46,7 @@ export const walletClient = createWalletClient({ account: privateKeyToAccount(process.env.WALLET_PRIVATE_KEY as Hex), }); -export const getTokenId = async ( - nftContract?: Address -): Promise => { +export const getTokenId = async (): Promise => { const { request } = await publicClient.simulateContract({ abi: [ {