Skip to content

Commit

Permalink
feat(store): add HelloStore event to TS event definitions (#1724)
Browse files Browse the repository at this point in the history
  • Loading branch information
holic authored Oct 10, 2023
1 parent 63ea7c3 commit 143a6ea
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 8 deletions.
23 changes: 23 additions & 0 deletions packages/store/ts/storeEvents.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { describe, expect, it } from "vitest";
import { parseAbiItem, AbiEvent } from "abitype";
import IStoreAbi from "../out/IStore.sol/IStore.abi.json";
import { helloStoreEvent } from "./storeEvents";

function normalizeAbiEvent(event: AbiEvent) {
return {
type: event.type,
name: event.name,
inputs: event.inputs.map((input) => ({
type: input.type,
name: input.name,
...(input.indexed ? { indexed: true } : null),
})),
} as const;
}

describe("Store events", () => {
it("should match the HelloStore event ABI", () => {
const forgeAbiItem = IStoreAbi.find((item) => item.type === "event" && item.name === "HelloStore") as AbiEvent;
expect(normalizeAbiEvent(parseAbiItem(helloStoreEvent))).toMatchObject(normalizeAbiEvent(forgeAbiItem));
});
});
22 changes: 18 additions & 4 deletions packages/store/ts/storeEvents.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,20 @@
export const helloStoreEvent = "event HelloStore(bytes32 indexed storeVersion)";

export const storeSetRecordEvent =
"event Store_SetRecord(bytes32 indexed tableId, bytes32[] keyTuple, bytes staticData, bytes32 encodedLengths, bytes dynamicData)";

export const storeSpliceStaticDataEvent =
"event Store_SpliceStaticData(bytes32 indexed tableId, bytes32[] keyTuple, uint48 start, bytes data)";

export const storeSpliceDynamicDataEvent =
"event Store_SpliceDynamicData(bytes32 indexed tableId, bytes32[] keyTuple, uint48 start, uint40 deleteCount, bytes32 encodedLengths, bytes data)";

export const storeDeleteRecordEvent = "event Store_DeleteRecord(bytes32 indexed tableId, bytes32[] keyTuple)";

// Store protocol events
export const storeEvents = [
"event Store_SetRecord(bytes32 indexed tableId, bytes32[] keyTuple, bytes staticData, bytes32 encodedLengths, bytes dynamicData)",
"event Store_SpliceStaticData(bytes32 indexed tableId, bytes32[] keyTuple, uint48 start, bytes data)",
"event Store_SpliceDynamicData(bytes32 indexed tableId, bytes32[] keyTuple, uint48 start, uint40 deleteCount, bytes32 encodedLengths, bytes data)",
"event Store_DeleteRecord(bytes32 indexed tableId, bytes32[] keyTuple)",
storeSetRecordEvent,
storeSpliceStaticDataEvent,
storeSpliceDynamicDataEvent,
storeDeleteRecordEvent,
] as const;
6 changes: 2 additions & 4 deletions packages/store/ts/storeEventsAbi.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,9 @@ describe("storeEventsAbi", () => {
it("should match the store ABI", () => {
const eventsDefined = normalizeAbiEvents(storeEventsAbi);
const eventsFromAbi = normalizeAbiEvents(
IStoreAbi.filter((item) => item.type === "event").filter(
(item) => item.name !== "HelloStore"
) as readonly AbiEvent[]
IStoreAbi.filter((item) => item.type === "event" && item.name !== "HelloStore") as readonly AbiEvent[]
);

expect(JSON.stringify(eventsDefined)).toEqual(JSON.stringify(eventsFromAbi));
expect(eventsDefined).toMatchObject(eventsFromAbi);
});
});

0 comments on commit 143a6ea

Please sign in to comment.