Skip to content

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
vanruch committed Mar 27, 2024
1 parent dea4d85 commit 05afc70
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 18 deletions.
2 changes: 1 addition & 1 deletion evm/evm-codec/src/abi-components/function.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { slotsCount } from "../utils";
import { Src } from "../src";
import assert from "node:assert";

type FunctionReturn<T> = T extends Codec<infer U>
type FunctionReturn<T> = T extends Codec<any, infer U>
? U
: T extends Struct
? StructTypes<T>
Expand Down
8 changes: 4 additions & 4 deletions evm/evm-codec/test/array.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
string,
uint256,
} from "../src";
import { AbiParameter, encodeAbiParameters } from "viem";
import { AbiParameter, encodeAbiParameters, Hex } from "viem";

function compareTypes(sink: Sink, types: AbiParameter[], values: any[]) {
expect(sink.toString()).toEqual(encodeAbiParameters(types, values));
Expand Down Expand Up @@ -102,9 +102,9 @@ describe("dynamic size array", () => {
[["ggg", "hhh", "iii"]],
];
const data2 = [[1n, 2n, 3n], [], [4n]];
const data3 = [
[Buffer.from("1234", "hex"), Buffer.from("5678", "hex")],
[Buffer.from("dead", "hex"), Buffer.from("beef", "hex")],
const data3: Hex[][] = [
["0x1234", "0x5678"],
["0xdead", "0xbeef"],
];
arr1.encode(sink, data1);
address.encode(sink, "0x1234567890123456789012345678901234567890");
Expand Down
4 changes: 2 additions & 2 deletions evm/evm-codec/test/event.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ describe("Event", () => {
),
});
expect(decoded).toEqual({
a: Buffer.from(topics[1].slice(2), "hex"),
a: topics[1],
b: "hello",
c: Buffer.from([0x12, 0x34]),
c: "0x1234",
d: { _0: 100n, _1: "world" },
e: true,
});
Expand Down
4 changes: 2 additions & 2 deletions evm/evm-codec/test/function.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,12 @@ describe("Function", () => {
bar: [1n, 2n, 3n],
str: {
foo: 123n,
bar: Buffer.from([0x12, 0x34, 0x56, 0x78]),
bar: "0x12345678" as const,
},
},
arg4: {
foo: 100n,
bar: Buffer.from([0x12, 0x34, 0x56, 0x78]),
bar: "0x12345678" as const,
},
};
const viemArgs = [
Expand Down
8 changes: 3 additions & 5 deletions evm/evm-codec/test/src.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,9 @@ describe("src", () => {
const src = new Src(encoded);
expect(src.u8()).toBe(69);
expect(src.string()).toBe(str1);
expect(src.staticBytes(7)).toStrictEqual(
Buffer.from(bytes7.slice(2), "hex")
);
expect(src.staticBytes(7)).toStrictEqual(bytes7);
expect(src.i128()).toBe(-21312312452243312424534213123123123123n);
expect(src.bytes()).toStrictEqual(bytes1);
expect(src.bytes()).toStrictEqual("0x" + bytes1.toString("hex"));
expect(src.address()).toBe(address);
expect(src.string()).toBe(str2);
});
Expand Down Expand Up @@ -132,6 +130,6 @@ describe("src", () => {
"hex"
);
const src = new Src(encoded);
expect(src.bytes()).toStrictEqual(buffer);
expect(src.bytes()).toStrictEqual("0x" + buffer.toString("hex"));
});
});
4 changes: 2 additions & 2 deletions evm/evm-codec/test/struct.bench.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { bench, describe } from "vitest";
import { address, array, Codec, Sink, Src, struct, uint256 } from "../src";
import { decodeAbiParameters, encodeAbiParameters } from "viem";
import { decodeAbiParameters, encodeAbiParameters, Hex } from "viem";
import { ethers } from "ethers";

const hugeArray = Array.from({ length: 1000 }, (_, i) => BigInt(i));
Expand All @@ -11,7 +11,7 @@ class InlinedStructCodec<
b: bigint;
c: {
d: bigint[];
e: string;
e: Hex;
};
}
> implements Codec<S>
Expand Down
4 changes: 2 additions & 2 deletions evm/evm-codec/test/struct.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ describe("StructCodec", () => {
bar: [1n, 2n, 3n],
str: {
foo: 123n,
bar: Uint8Array.from([0x12, 0x34, 0x56, 0x78]),
bar: "0x12345678" as const,
},
});
compareTypes(
Expand Down Expand Up @@ -177,7 +177,7 @@ describe("StructCodec", () => {
bar: [1n, 2n, 3n],
str: {
foo: 123n,
bar: Buffer.from([0x12, 0x34, 0x56, 0x78]),
bar: "0x12345678",
},
});
});
Expand Down

0 comments on commit 05afc70

Please sign in to comment.