Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEATURE] makes getIsToken spec return false if spec is not parseable #163

Merged
merged 1 commit into from
Oct 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 22 additions & 8 deletions src/helper/soroban-rpc/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import { xdr } from "stellar-sdk";

import { base64regex } from "../test-helper";
import {
getLedgerKeyContractCode,
getLedgerKeyWasmId,
isTokenSpec,
parseWasmXdr,
} from ".";
import { base64regex, testLogger } from "../test-helper";
import * as networkHelpers from "./network";
import { getIsTokenSpec, isTokenSpec } from "./token";

const { getLedgerKeyContractCode, getLedgerKeyWasmId, parseWasmXdr } =
networkHelpers;

describe("Soroban RPC helpers", () => {
const CONTRACT_ID =
Expand All @@ -26,7 +25,7 @@ describe("Soroban RPC helpers", () => {
});
it("will throw when it fails to get ledger key", () => {
expect(() =>
getLedgerKeyContractCode("not contract ID", "TESTNET")
getLedgerKeyContractCode("not contract ID", "TESTNET"),
).toThrowError();
});
});
Expand Down Expand Up @@ -66,4 +65,19 @@ describe("Soroban RPC helpers", () => {
expect(isSep41).toBeFalsy();
});
});

describe("getIsTokenSpec", () => {
afterAll(() => {
jest.resetModules();
});
it("will return false when the spec cannot be parsed", async () => {
jest.spyOn(networkHelpers, "getContractSpec").mockImplementation(() => {
return Promise.resolve({ result: { notDefinitions: {} }, error: null });
});

const isSep41 = await getIsTokenSpec("contractId", "TESTNET", testLogger);

expect(isSep41).toBeFalsy();
});
});
});
Loading