Skip to content

Commit

Permalink
format calls to be human readable
Browse files Browse the repository at this point in the history
  • Loading branch information
holic committed Oct 17, 2024
1 parent 3c08075 commit e3a717e
Showing 1 changed file with 11 additions and 20 deletions.
31 changes: 11 additions & 20 deletions packages/store/ts/storeSimulator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
decodeFunctionData,
decodeFunctionResult,
encodeFunctionData,
getAbiItem,
keccak256,
pad,
size,
Expand All @@ -20,6 +21,7 @@ import {
} from "viem";
import storeSimulatorArtifact from "../out/StoreSimulator.sol/StoreSimulator.json";
import { readContract, simulateContract } from "viem/actions";
import { formatAbiItemWithArgs } from "viem/utils";

const storeSimulator = stringToHex("StoreSimulator", { size: 20 });
const alice = stringToHex("Alice", { size: 20 });
Expand Down Expand Up @@ -102,27 +104,16 @@ describe("storeSimulator", async () => {
expect(result).toMatchInlineSnapshot(`null`);

// TODO: replace calls with just store events
expect(calls.map((data) => decodeFunctionData({ abi: worldAbi, data }))).toMatchInlineSnapshot(`

const formattedCalls = calls.map((data) => {
const { args, functionName } = decodeFunctionData({ abi: worldAbi, data });
const abiItem = getAbiItem({ abi: worldAbi, name: functionName, args });
return formatAbiItemWithArgs({ abiItem, args } as never);
});
expect(formattedCalls).toMatchInlineSnapshot(`
[
{
"args": [
5,
5,
],
"functionName": "move",
},
{
"args": [
"0x74620000000000000000000000000000506f736974696f6e0000000000000000",
[
"0x0000000000000000000000002fb283b95c5f9b601f151a91cf72fb5fa53713d7",
],
"0x0000000500000005",
"0x0000000000000000000000000000000000000000000000000000000000000000",
"0x",
],
"functionName": "setRecord",
},
"move(5, 5)",
"setRecord(0x74620000000000000000000000000000506f736974696f6e0000000000000000, ["0x000000000000000000000000d710dcd524f7ee4886e50c67940e98e994efc88c"], 0x0000000500000005, 0x0000000000000000000000000000000000000000000000000000000000000000, 0x)",
]
`);
});
Expand Down

0 comments on commit e3a717e

Please sign in to comment.