Skip to content

Commit

Permalink
makes getIsToken spec return false if spec is not parseable
Browse files Browse the repository at this point in the history
  • Loading branch information
aristidesstaffieri committed Oct 22, 2024
1 parent bff822e commit f044814
Show file tree
Hide file tree
Showing 6 changed files with 709 additions and 689 deletions.
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

0 comments on commit f044814

Please sign in to comment.