diff --git a/packages/store-sync/src/stash/createStorageAdapter.test.ts b/packages/store-sync/src/stash/createStorageAdapter.test.ts new file mode 100644 index 00000000000..08a1b007ead --- /dev/null +++ b/packages/store-sync/src/stash/createStorageAdapter.test.ts @@ -0,0 +1,95 @@ +import { beforeAll, describe, expect, it } from "vitest"; +import { storeEventsAbi } from "@latticexyz/store"; +import { createStorageAdapter } from "./createStorageAdapter"; +import { config, deployMockGame } from "../../test/mockGame"; +import { fetchAndStoreLogs } from "../fetchAndStoreLogs"; +import { testClient } from "../../test/common"; +import { getBlockNumber } from "viem/actions"; +import { Address } from "viem"; +import { createStash } from "@latticexyz/stash/internal"; + +describe("createStorageAdapter", async () => { + // eslint-disable-next-line @typescript-eslint/no-unused-vars + let worldAddress: Address; + beforeAll(async () => { + worldAddress = await deployMockGame(); + }); + + it("sets component values from logs", async () => { + const stash = createStash(config); + const storageAdapter = createStorageAdapter({ config, stash }); + + console.log("fetching blocks"); + // eslint-disable-next-line @typescript-eslint/no-unused-vars + for await (const block of fetchAndStoreLogs({ + storageAdapter, + publicClient: testClient, + events: storeEventsAbi, + fromBlock: 0n, + toBlock: await getBlockNumber(testClient), + })) { + // console.log("got block", block.blockNumber); + } + + expect(stash.get().records).toMatchInlineSnapshot(` + { + "": { + "Health": { + "0x078cf0753dd50f7C56F20B3Ae02719EA199BE2eb": { + "health": 0n, + "player": "0x078cf0753dd50f7C56F20B3Ae02719EA199BE2eb", + }, + "0x1D96F2f6BeF1202E4Ce1Ff6Dad0c2CB002861d3e": { + "health": 5n, + "player": "0x1D96F2f6BeF1202E4Ce1Ff6Dad0c2CB002861d3e", + }, + "0x328809Bc894f92807417D2dAD6b7C998c1aFdac6": { + "health": 5n, + "player": "0x328809Bc894f92807417D2dAD6b7C998c1aFdac6", + }, + }, + "Inventory": {}, + "Position": { + "0x078cf0753dd50f7C56F20B3Ae02719EA199BE2eb": { + "player": "0x078cf0753dd50f7C56F20B3Ae02719EA199BE2eb", + "x": 3, + "y": 5, + }, + "0x1D96F2f6BeF1202E4Ce1Ff6Dad0c2CB002861d3e": { + "player": "0x1D96F2f6BeF1202E4Ce1Ff6Dad0c2CB002861d3e", + "x": 1, + "y": -1, + }, + "0x328809Bc894f92807417D2dAD6b7C998c1aFdac6": { + "player": "0x328809Bc894f92807417D2dAD6b7C998c1aFdac6", + "x": 3, + "y": 5, + }, + "0xdBa86119a787422C593ceF119E40887f396024E2": { + "player": "0xdBa86119a787422C593ceF119E40887f396024E2", + "x": 100, + "y": 100, + }, + }, + "Score": {}, + "Terrain": { + "3|5": { + "terrainType": 2, + "x": 3, + "y": 5, + }, + }, + "Winner": {}, + }, + } + `); + + expect(stash.getRecord({ table: config.tables.Terrain, key: { x: 3, y: 5 } })).toMatchInlineSnapshot(` + { + "terrainType": 2, + "x": 3, + "y": 5, + } + `); + }); +}); diff --git a/packages/store-sync/src/stash/createStorageAdapter.ts b/packages/store-sync/src/stash/createStorageAdapter.ts index 984e15a07cc..310ff067654 100644 --- a/packages/store-sync/src/stash/createStorageAdapter.ts +++ b/packages/store-sync/src/stash/createStorageAdapter.ts @@ -14,7 +14,7 @@ import { size } from "viem"; export type CreateStorageAdapterOptions = { config: config; - stash: CreateStoreResult; + stash: CreateStoreResult; }; const emptyValueArgs = { diff --git a/packages/world/ts/config/v2/output.ts b/packages/world/ts/config/v2/output.ts index 77e5ec2af11..175fc2acdcb 100644 --- a/packages/world/ts/config/v2/output.ts +++ b/packages/world/ts/config/v2/output.ts @@ -4,11 +4,6 @@ import { DynamicResolution, ValueWithType } from "./dynamicResolution"; import { Hex } from "viem"; export type Module = { - /** - * The name of the module - * @deprecated - */ - readonly name: string; /** Should this module be installed as a root module? */ readonly root: boolean; /** Arguments to be passed to the module's install method */ diff --git a/packages/world/ts/config/v2/world.ts b/packages/world/ts/config/v2/world.ts index 92743fd2d54..424fab84007 100644 --- a/packages/world/ts/config/v2/world.ts +++ b/packages/world/ts/config/v2/world.ts @@ -74,6 +74,8 @@ export type resolveNamespaceMode = "namespaces" extends keyof input >; }; +type resolveModules = { [key in keyof input]: mergeIfUndefined }; + export type resolveWorld = resolveNamespaceMode & Omit, "multipleNamespaces" | "namespace" | "namespaces" | "tables"> & { readonly tables: flattenNamespacedTables>; @@ -88,7 +90,7 @@ export type resolveWorld = resolveNamespaceMode & readonly excludeSystems: "excludeSystems" extends keyof input ? input["excludeSystems"] : CONFIG_DEFAULTS["excludeSystems"]; - readonly modules: "modules" extends keyof input ? input["modules"] : CONFIG_DEFAULTS["modules"]; + readonly modules: "modules" extends keyof input ? resolveModules : CONFIG_DEFAULTS["modules"]; readonly codegen: show>; readonly deploy: show>; };