Skip to content

Commit

Permalink
More Tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bh2smith committed Nov 12, 2024
1 parent 19efa7a commit b739238
Showing 1 changed file with 30 additions and 17 deletions.
47 changes: 30 additions & 17 deletions tests/unit/types.guards.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,21 @@ const validEIP1559Transaction: TransactionSerializable = {
chainId: 1,
maxFeePerGas: 1n,
};
describe("Type Guards", () => {
it("isSignMethod", async () => {
expect(isSignMethod("poop")).toBe(false);

const commonInvalidCases = [
null,
undefined,
{},
{ to: "invalid-address" },
{ value: "not-a-bigint" },
{ chainId: "not-a-number" },
"random string",
123,
[],
];

describe("SignMethod", () => {
it("returns true for all valid SignMethods", async () => {
[
"eth_sign",
"personal_sign",
Expand All @@ -24,7 +36,14 @@ describe("Type Guards", () => {
].map((item) => expect(isSignMethod(item)).toBe(true));
});

it("isEIP712TypedData", async () => {
it("returns false for invalid data inputs", async () => {
["poop", undefined, false, 1, {}].map((item) =>
expect(isSignMethod(item)).toBe(false)
);
});
});
describe("isEIP712TypedData", () => {
it("returns true for valid EIP712TypedData", async () => {
const message = {
from: {
name: "Cow",
Expand Down Expand Up @@ -64,6 +83,12 @@ describe("Type Guards", () => {
} as const;
expect(isEIP712TypedData(typedData)).toBe(true);
});

it("returns false for invalid data inputs", async () => {
commonInvalidCases.map((item) =>
expect(isEIP712TypedData(item)).toBe(false)
);
});
});

describe("isTransactionSerializable", () => {
Expand All @@ -72,19 +97,7 @@ describe("isTransactionSerializable", () => {
});

it("should return false for invalid transaction data", () => {
const invalidCases = [
null,
undefined,
{},
{ to: "invalid-address" },
{ value: "not-a-bigint" },
{ chainId: "not-a-number" },
"random string",
123,
[],
];

invalidCases.forEach((testCase) => {
commonInvalidCases.forEach((testCase) => {
expect(isTransactionSerializable(testCase)).toBe(false);
});
});
Expand Down

0 comments on commit b739238

Please sign in to comment.