diff --git a/.changeset/curly-numbers-talk.md b/.changeset/curly-numbers-talk.md new file mode 100644 index 0000000000..928e66945f --- /dev/null +++ b/.changeset/curly-numbers-talk.md @@ -0,0 +1,6 @@ +--- +"@latticexyz/store": patch +"@latticexyz/world": patch +--- + +Moved the test tables out of the main config in `world` and `store` and into their own separate config. diff --git a/packages/store/gas-report.json b/packages/store/gas-report.json index 9463ca8072..a1d1ad39b1 100644 --- a/packages/store/gas-report.json +++ b/packages/store/gas-report.json @@ -59,6 +59,24 @@ "name": "create bytes32 from bytes memory with offset 16", "gasUsed": 36 }, + { + "file": "test/Callbacks.t.sol", + "test": "testSetAndGet", + "name": "Callbacks: set field", + "gasUsed": 56241 + }, + { + "file": "test/Callbacks.t.sol", + "test": "testSetAndGet", + "name": "Callbacks: get field (warm)", + "gasUsed": 2842 + }, + { + "file": "test/Callbacks.t.sol", + "test": "testSetAndGet", + "name": "Callbacks: push 1 element", + "gasUsed": 32499 + }, { "file": "test/FieldLayout.t.sol", "test": "testEncodeDecodeFieldLayout", @@ -960,137 +978,119 @@ "gasUsed": 108 }, { - "file": "test/StoreSwitch.t.sol", - "test": "testDelegatecall", - "name": "get Store address", - "gasUsed": 2170 - }, - { - "file": "test/StoreSwitch.t.sol", - "test": "testNoDelegatecall", - "name": "get Store address", - "gasUsed": 2173 - }, - { - "file": "test/tables/Callbacks.t.sol", - "test": "testSetAndGet", - "name": "Callbacks: set field", - "gasUsed": 56241 - }, - { - "file": "test/tables/Callbacks.t.sol", - "test": "testSetAndGet", - "name": "Callbacks: get field (warm)", - "gasUsed": 2842 - }, - { - "file": "test/tables/Callbacks.t.sol", - "test": "testSetAndGet", - "name": "Callbacks: push 1 element", - "gasUsed": 32499 - }, - { - "file": "test/tables/StoreHooks.t.sol", + "file": "test/StoreHooks.t.sol", "test": "testOneSlot", "name": "StoreHooks: set field with one elements (cold)", "gasUsed": 58247 }, { - "file": "test/tables/StoreHooks.t.sol", + "file": "test/StoreHooks.t.sol", "test": "testTable", "name": "StoreHooks: set field (cold)", "gasUsed": 58247 }, { - "file": "test/tables/StoreHooks.t.sol", + "file": "test/StoreHooks.t.sol", "test": "testTable", "name": "StoreHooks: get field (warm)", "gasUsed": 2844 }, { - "file": "test/tables/StoreHooks.t.sol", + "file": "test/StoreHooks.t.sol", "test": "testTable", "name": "StoreHooks: push 1 element (cold)", "gasUsed": 12597 }, { - "file": "test/tables/StoreHooks.t.sol", + "file": "test/StoreHooks.t.sol", "test": "testTable", "name": "StoreHooks: pop 1 element (warm)", "gasUsed": 9931 }, { - "file": "test/tables/StoreHooks.t.sol", + "file": "test/StoreHooks.t.sol", "test": "testTable", "name": "StoreHooks: push 1 element (warm)", "gasUsed": 10614 }, { - "file": "test/tables/StoreHooks.t.sol", + "file": "test/StoreHooks.t.sol", "test": "testTable", "name": "StoreHooks: update 1 element (warm)", "gasUsed": 29840 }, { - "file": "test/tables/StoreHooks.t.sol", + "file": "test/StoreHooks.t.sol", "test": "testTable", "name": "StoreHooks: delete record (warm)", "gasUsed": 10410 }, { - "file": "test/tables/StoreHooks.t.sol", + "file": "test/StoreHooks.t.sol", "test": "testTable", "name": "StoreHooks: set field (warm)", "gasUsed": 30392 }, { - "file": "test/tables/StoreHooks.t.sol", + "file": "test/StoreHooks.t.sol", "test": "testThreeSlots", "name": "StoreHooks: set field with three elements (cold)", "gasUsed": 80935 }, { - "file": "test/tables/StoreHooks.t.sol", + "file": "test/StoreHooks.t.sol", "test": "testTwoSlots", "name": "StoreHooks: set field with two elements (cold)", "gasUsed": 80847 }, { - "file": "test/tables/StoreHooksColdLoad.t.sol", + "file": "test/StoreHooksColdLoad.t.sol", "test": "testDelete", "name": "StoreHooks: delete record (cold)", "gasUsed": 19268 }, { - "file": "test/tables/StoreHooksColdLoad.t.sol", + "file": "test/StoreHooksColdLoad.t.sol", "test": "testGet", "name": "StoreHooks: get field (cold)", "gasUsed": 8841 }, { - "file": "test/tables/StoreHooksColdLoad.t.sol", + "file": "test/StoreHooksColdLoad.t.sol", "test": "testGetItem", "name": "StoreHooks: get 1 element (cold)", "gasUsed": 8486 }, { - "file": "test/tables/StoreHooksColdLoad.t.sol", + "file": "test/StoreHooksColdLoad.t.sol", "test": "testLength", "name": "StoreHooks: get length (cold)", "gasUsed": 5394 }, { - "file": "test/tables/StoreHooksColdLoad.t.sol", + "file": "test/StoreHooksColdLoad.t.sol", "test": "testPop", "name": "StoreHooks: pop 1 element (cold)", "gasUsed": 18366 }, { - "file": "test/tables/StoreHooksColdLoad.t.sol", + "file": "test/StoreHooksColdLoad.t.sol", "test": "testUpdate", "name": "StoreHooks: update 1 element (cold)", "gasUsed": 20295 }, + { + "file": "test/StoreSwitch.t.sol", + "test": "testDelegatecall", + "name": "get Store address", + "gasUsed": 2170 + }, + { + "file": "test/StoreSwitch.t.sol", + "test": "testNoDelegatecall", + "name": "get Store address", + "gasUsed": 2173 + }, { "file": "test/tightcoder/DecodeSlice.t.sol", "test": "testToArrayUint32", diff --git a/packages/store/mud.config.ts b/packages/store/mud.config.ts index f825dd5c8f..3609c876e3 100644 --- a/packages/store/mud.config.ts +++ b/packages/store/mud.config.ts @@ -3,9 +3,6 @@ import { mudConfig } from "./ts/register"; export default mudConfig({ storeImportPath: "../../", namespace: "mudstore", - enums: { - ExampleEnum: ["None", "First", "Second", "Third"], - }, userTypes: { ResourceId: { filePath: "./src/ResourceId.sol", internalType: "bytes32" }, FieldLayout: { filePath: "./src/FieldLayout.sol", internalType: "bytes32" }, @@ -50,32 +47,5 @@ export default mudConfig({ }, tableIdArgument: true, }, - // TODO: move these test tables to a separate mud config - Callbacks: "bytes24[]", - Mixed: { - valueSchema: { - u32: "uint32", - u128: "uint128", - a32: "uint32[]", - s: "string", - }, - }, - Vector2: { - valueSchema: { - x: "uint32", - y: "uint32", - }, - }, - KeyEncoding: { - keySchema: { - k1: "uint256", - k2: "int32", - k3: "bytes16", - k4: "address", - k5: "bool", - k6: "ExampleEnum", - }, - valueSchema: "bool", - }, }, }); diff --git a/packages/store/package.json b/packages/store/package.json index d2fe260e43..6db4928cd3 100644 --- a/packages/store/package.json +++ b/packages/store/package.json @@ -38,12 +38,12 @@ "build:abi": "forge build --skip test script", "build:abi-ts": "abi-ts && prettier --write '**/*.abi.json.d.ts'", "build:js": "tsup", - "build:mud": "tsx ./ts/scripts/tablegen.ts", + "build:mud": "tsx ./ts/scripts/tablegen.ts && tsx ./ts/scripts/generate-test-tables.ts", "build:tightcoder": "tsx ./ts/scripts/generate-tightcoder.ts", "clean": "pnpm run clean:abi && pnpm run clean:js && pnpm run clean:mud", "clean:abi": "forge clean", "clean:js": "rimraf dist", - "clean:mud": "rimraf src/codegen", + "clean:mud": "rimraf src/codegen && rimraf test/codegen", "dev": "tsup --watch", "gas-report": "gas-report --save gas-report.json", "lint": "solhint --config ./.solhint.json 'src/**/*.sol'", diff --git a/packages/store/src/codegen/index.sol b/packages/store/src/codegen/index.sol index 6c2596d938..0f6948556f 100644 --- a/packages/store/src/codegen/index.sol +++ b/packages/store/src/codegen/index.sol @@ -7,7 +7,3 @@ import { StoreHooks, StoreHooksTableId } from "./tables/StoreHooks.sol"; import { Tables, TablesData, TablesTableId } from "./tables/Tables.sol"; import { ResourceIds, ResourceIdsTableId } from "./tables/ResourceIds.sol"; import { Hooks } from "./tables/Hooks.sol"; -import { Callbacks, CallbacksTableId } from "./tables/Callbacks.sol"; -import { Mixed, MixedData, MixedTableId } from "./tables/Mixed.sol"; -import { Vector2, Vector2Data, Vector2TableId } from "./tables/Vector2.sol"; -import { KeyEncoding, KeyEncodingTableId } from "./tables/KeyEncoding.sol"; diff --git a/packages/store/test/tables/Callbacks.t.sol b/packages/store/test/Callbacks.t.sol similarity index 90% rename from packages/store/test/tables/Callbacks.t.sol rename to packages/store/test/Callbacks.t.sol index 5f38d69481..3dc7b7344d 100644 --- a/packages/store/test/tables/Callbacks.t.sol +++ b/packages/store/test/Callbacks.t.sol @@ -3,8 +3,8 @@ pragma solidity >=0.8.21; import { Test } from "forge-std/Test.sol"; import { GasReporter } from "@latticexyz/gas-report/src/GasReporter.sol"; -import { StoreMock } from "../../test/StoreMock.sol"; -import { Callbacks } from "../../src/codegen/index.sol"; +import { Callbacks } from "./codegen/tables/Callbacks.sol"; +import { StoreMock } from "./StoreMock.sol"; contract CallbacksTest is Test, GasReporter, StoreMock { function testSetAndGet() public { diff --git a/packages/store/test/Gas.t.sol b/packages/store/test/Gas.t.sol index da555ceb8a..442c0a0c69 100644 --- a/packages/store/test/Gas.t.sol +++ b/packages/store/test/Gas.t.sol @@ -7,7 +7,8 @@ import { Bytes } from "../src/Bytes.sol"; import { SliceLib } from "../src/Slice.sol"; import { Storage } from "../src/Storage.sol"; import { PackedCounter } from "../src/PackedCounter.sol"; -import { Mixed, MixedData } from "../src/codegen/index.sol"; + +import { Mixed, MixedData } from "./codegen/index.sol"; contract SomeContract { function doSomethingWithBytes(bytes memory data) public {} diff --git a/packages/store/test/KeyEncoding.t.sol b/packages/store/test/KeyEncoding.t.sol index 81cda12052..d2870e52c4 100644 --- a/packages/store/test/KeyEncoding.t.sol +++ b/packages/store/test/KeyEncoding.t.sol @@ -3,13 +3,14 @@ pragma solidity >=0.8.21; import { Test } from "forge-std/Test.sol"; import { GasReporter } from "@latticexyz/gas-report/src/GasReporter.sol"; -import { KeyEncoding, KeyEncodingTableId } from "../src/codegen/index.sol"; -import { ExampleEnum } from "../src/codegen/common.sol"; import { StoreCore } from "../src/StoreCore.sol"; -import { StoreMock } from "../test/StoreMock.sol"; import { FieldLayout } from "../src/FieldLayout.sol"; import { Schema } from "../src/Schema.sol"; +import { StoreMock } from "./StoreMock.sol"; +import { KeyEncoding, KeyEncodingTableId } from "./codegen/index.sol"; +import { ExampleEnum } from "./codegen/common.sol"; + contract KeyEncodingTest is Test, GasReporter, StoreMock { function testRegisterAndGetFieldLayout() public { startGasReport("register KeyEncoding table"); diff --git a/packages/store/test/Mixed.t.sol b/packages/store/test/Mixed.t.sol index c9a0ba7249..3b5b1c6302 100644 --- a/packages/store/test/Mixed.t.sol +++ b/packages/store/test/Mixed.t.sol @@ -3,13 +3,14 @@ pragma solidity >=0.8.21; import { Test } from "forge-std/Test.sol"; import { GasReporter } from "@latticexyz/gas-report/src/GasReporter.sol"; -import { Mixed, MixedData, MixedTableId } from "../src/codegen/index.sol"; import { StoreCore } from "../src/StoreCore.sol"; import { StoreMock } from "../test/StoreMock.sol"; import { FieldLayout } from "../src/FieldLayout.sol"; import { Schema } from "../src/Schema.sol"; import { PackedCounter } from "../src/PackedCounter.sol"; +import { Mixed, MixedData, MixedTableId } from "./codegen/index.sol"; + contract MixedTest is Test, GasReporter, StoreMock { MixedData private testMixed; diff --git a/packages/store/test/tables/StoreHooks.t.sol b/packages/store/test/StoreHooks.t.sol similarity index 95% rename from packages/store/test/tables/StoreHooks.t.sol rename to packages/store/test/StoreHooks.t.sol index 78cdd70f70..cd85475d39 100644 --- a/packages/store/test/tables/StoreHooks.t.sol +++ b/packages/store/test/StoreHooks.t.sol @@ -3,9 +3,9 @@ pragma solidity >=0.8.21; import { Test } from "forge-std/Test.sol"; import { GasReporter } from "@latticexyz/gas-report/src/GasReporter.sol"; -import { ResourceId } from "../../src/ResourceId.sol"; -import { StoreHooks } from "../../src/codegen/index.sol"; -import { StoreMock } from "../StoreMock.sol"; +import { ResourceId } from "../src/ResourceId.sol"; +import { StoreHooks } from "../src/codegen/tables/StoreHooks.sol"; +import { StoreMock } from "./StoreMock.sol"; contract StoreHooksTest is Test, GasReporter, StoreMock { function testTable() public { diff --git a/packages/store/test/tables/StoreHooksColdLoad.t.sol b/packages/store/test/StoreHooksColdLoad.t.sol similarity index 93% rename from packages/store/test/tables/StoreHooksColdLoad.t.sol rename to packages/store/test/StoreHooksColdLoad.t.sol index 3a9ca2e686..99dabe827a 100644 --- a/packages/store/test/tables/StoreHooksColdLoad.t.sol +++ b/packages/store/test/StoreHooksColdLoad.t.sol @@ -3,9 +3,9 @@ pragma solidity >=0.8.21; import { Test } from "forge-std/Test.sol"; import { GasReporter } from "@latticexyz/gas-report/src/GasReporter.sol"; -import { ResourceId } from "../../src/ResourceId.sol"; -import { StoreMock } from "../../test/StoreMock.sol"; -import { StoreHooks } from "../../src/codegen/index.sol"; +import { ResourceId } from "../src/ResourceId.sol"; +import { StoreHooks } from "../src/codegen/tables/StoreHooks.sol"; +import { StoreMock } from "./StoreMock.sol"; contract StoreHooksColdLoadTest is Test, GasReporter, StoreMock { bytes21[] hooks; diff --git a/packages/store/test/Vector2.t.sol b/packages/store/test/Vector2.t.sol index a20bee36b9..b2d9ff89c6 100644 --- a/packages/store/test/Vector2.t.sol +++ b/packages/store/test/Vector2.t.sol @@ -3,12 +3,13 @@ pragma solidity >=0.8.21; import { Test } from "forge-std/Test.sol"; import { GasReporter } from "@latticexyz/gas-report/src/GasReporter.sol"; -import { Vector2, Vector2Data, Vector2TableId } from "../src/codegen/index.sol"; import { StoreCore } from "../src/StoreCore.sol"; import { StoreMock } from "../test/StoreMock.sol"; import { FieldLayout } from "../src/FieldLayout.sol"; import { Schema } from "../src/Schema.sol"; +import { Vector2, Vector2Data, Vector2TableId } from "./codegen/index.sol"; + contract Vector2Test is Test, GasReporter, StoreMock { function testRegisterAndGetFieldLayout() public { startGasReport("register Vector2 field layout"); diff --git a/packages/store/src/codegen/common.sol b/packages/store/test/codegen/common.sol similarity index 100% rename from packages/store/src/codegen/common.sol rename to packages/store/test/codegen/common.sol diff --git a/packages/store/test/codegen/index.sol b/packages/store/test/codegen/index.sol new file mode 100644 index 0000000000..f6004e70d5 --- /dev/null +++ b/packages/store/test/codegen/index.sol @@ -0,0 +1,9 @@ +// SPDX-License-Identifier: MIT +pragma solidity >=0.8.21; + +/* Autogenerated file. Do not edit manually. */ + +import { Callbacks, CallbacksTableId } from "./tables/Callbacks.sol"; +import { Mixed, MixedData, MixedTableId } from "./tables/Mixed.sol"; +import { Vector2, Vector2Data, Vector2TableId } from "./tables/Vector2.sol"; +import { KeyEncoding, KeyEncodingTableId } from "./tables/KeyEncoding.sol"; diff --git a/packages/store/src/codegen/tables/Callbacks.sol b/packages/store/test/codegen/tables/Callbacks.sol similarity index 96% rename from packages/store/src/codegen/tables/Callbacks.sol rename to packages/store/test/codegen/tables/Callbacks.sol index 78cf4c6bf3..2b1a92138e 100644 --- a/packages/store/src/codegen/tables/Callbacks.sol +++ b/packages/store/test/codegen/tables/Callbacks.sol @@ -7,18 +7,18 @@ pragma solidity >=0.8.21; import { SchemaType } from "@latticexyz/schema-type/src/solidity/SchemaType.sol"; // Import store internals -import { IStore } from "../../IStore.sol"; -import { StoreSwitch } from "../../StoreSwitch.sol"; -import { StoreCore } from "../../StoreCore.sol"; -import { Bytes } from "../../Bytes.sol"; -import { Memory } from "../../Memory.sol"; -import { SliceLib } from "../../Slice.sol"; -import { EncodeArray } from "../../tightcoder/EncodeArray.sol"; -import { FieldLayout, FieldLayoutLib } from "../../FieldLayout.sol"; -import { Schema, SchemaLib } from "../../Schema.sol"; -import { PackedCounter, PackedCounterLib } from "../../PackedCounter.sol"; -import { ResourceId } from "../../ResourceId.sol"; -import { RESOURCE_TABLE, RESOURCE_OFFCHAIN_TABLE } from "../../storeResourceTypes.sol"; +import { IStore } from "../../../src/IStore.sol"; +import { StoreSwitch } from "../../../src/StoreSwitch.sol"; +import { StoreCore } from "../../../src/StoreCore.sol"; +import { Bytes } from "../../../src/Bytes.sol"; +import { Memory } from "../../../src/Memory.sol"; +import { SliceLib } from "../../../src/Slice.sol"; +import { EncodeArray } from "../../../src/tightcoder/EncodeArray.sol"; +import { FieldLayout, FieldLayoutLib } from "../../../src/FieldLayout.sol"; +import { Schema, SchemaLib } from "../../../src/Schema.sol"; +import { PackedCounter, PackedCounterLib } from "../../../src/PackedCounter.sol"; +import { ResourceId } from "../../../src/ResourceId.sol"; +import { RESOURCE_TABLE, RESOURCE_OFFCHAIN_TABLE } from "../../../src/storeResourceTypes.sol"; ResourceId constant _tableId = ResourceId.wrap( bytes32(abi.encodePacked(RESOURCE_TABLE, bytes14("mudstore"), bytes16("Callbacks"))) diff --git a/packages/store/src/codegen/tables/KeyEncoding.sol b/packages/store/test/codegen/tables/KeyEncoding.sol similarity index 94% rename from packages/store/src/codegen/tables/KeyEncoding.sol rename to packages/store/test/codegen/tables/KeyEncoding.sol index 4beef6264b..0cc39e05ac 100644 --- a/packages/store/src/codegen/tables/KeyEncoding.sol +++ b/packages/store/test/codegen/tables/KeyEncoding.sol @@ -7,18 +7,18 @@ pragma solidity >=0.8.21; import { SchemaType } from "@latticexyz/schema-type/src/solidity/SchemaType.sol"; // Import store internals -import { IStore } from "../../IStore.sol"; -import { StoreSwitch } from "../../StoreSwitch.sol"; -import { StoreCore } from "../../StoreCore.sol"; -import { Bytes } from "../../Bytes.sol"; -import { Memory } from "../../Memory.sol"; -import { SliceLib } from "../../Slice.sol"; -import { EncodeArray } from "../../tightcoder/EncodeArray.sol"; -import { FieldLayout, FieldLayoutLib } from "../../FieldLayout.sol"; -import { Schema, SchemaLib } from "../../Schema.sol"; -import { PackedCounter, PackedCounterLib } from "../../PackedCounter.sol"; -import { ResourceId } from "../../ResourceId.sol"; -import { RESOURCE_TABLE, RESOURCE_OFFCHAIN_TABLE } from "../../storeResourceTypes.sol"; +import { IStore } from "../../../src/IStore.sol"; +import { StoreSwitch } from "../../../src/StoreSwitch.sol"; +import { StoreCore } from "../../../src/StoreCore.sol"; +import { Bytes } from "../../../src/Bytes.sol"; +import { Memory } from "../../../src/Memory.sol"; +import { SliceLib } from "../../../src/Slice.sol"; +import { EncodeArray } from "../../../src/tightcoder/EncodeArray.sol"; +import { FieldLayout, FieldLayoutLib } from "../../../src/FieldLayout.sol"; +import { Schema, SchemaLib } from "../../../src/Schema.sol"; +import { PackedCounter, PackedCounterLib } from "../../../src/PackedCounter.sol"; +import { ResourceId } from "../../../src/ResourceId.sol"; +import { RESOURCE_TABLE, RESOURCE_OFFCHAIN_TABLE } from "../../../src/storeResourceTypes.sol"; // Import user types import { ExampleEnum } from "./../common.sol"; diff --git a/packages/store/src/codegen/tables/Mixed.sol b/packages/store/test/codegen/tables/Mixed.sol similarity index 97% rename from packages/store/src/codegen/tables/Mixed.sol rename to packages/store/test/codegen/tables/Mixed.sol index 603baed3bd..f25111b8ab 100644 --- a/packages/store/src/codegen/tables/Mixed.sol +++ b/packages/store/test/codegen/tables/Mixed.sol @@ -7,18 +7,18 @@ pragma solidity >=0.8.21; import { SchemaType } from "@latticexyz/schema-type/src/solidity/SchemaType.sol"; // Import store internals -import { IStore } from "../../IStore.sol"; -import { StoreSwitch } from "../../StoreSwitch.sol"; -import { StoreCore } from "../../StoreCore.sol"; -import { Bytes } from "../../Bytes.sol"; -import { Memory } from "../../Memory.sol"; -import { SliceLib } from "../../Slice.sol"; -import { EncodeArray } from "../../tightcoder/EncodeArray.sol"; -import { FieldLayout, FieldLayoutLib } from "../../FieldLayout.sol"; -import { Schema, SchemaLib } from "../../Schema.sol"; -import { PackedCounter, PackedCounterLib } from "../../PackedCounter.sol"; -import { ResourceId } from "../../ResourceId.sol"; -import { RESOURCE_TABLE, RESOURCE_OFFCHAIN_TABLE } from "../../storeResourceTypes.sol"; +import { IStore } from "../../../src/IStore.sol"; +import { StoreSwitch } from "../../../src/StoreSwitch.sol"; +import { StoreCore } from "../../../src/StoreCore.sol"; +import { Bytes } from "../../../src/Bytes.sol"; +import { Memory } from "../../../src/Memory.sol"; +import { SliceLib } from "../../../src/Slice.sol"; +import { EncodeArray } from "../../../src/tightcoder/EncodeArray.sol"; +import { FieldLayout, FieldLayoutLib } from "../../../src/FieldLayout.sol"; +import { Schema, SchemaLib } from "../../../src/Schema.sol"; +import { PackedCounter, PackedCounterLib } from "../../../src/PackedCounter.sol"; +import { ResourceId } from "../../../src/ResourceId.sol"; +import { RESOURCE_TABLE, RESOURCE_OFFCHAIN_TABLE } from "../../../src/storeResourceTypes.sol"; ResourceId constant _tableId = ResourceId.wrap( bytes32(abi.encodePacked(RESOURCE_TABLE, bytes14("mudstore"), bytes16("Mixed"))) diff --git a/packages/store/src/codegen/tables/Vector2.sol b/packages/store/test/codegen/tables/Vector2.sol similarity index 93% rename from packages/store/src/codegen/tables/Vector2.sol rename to packages/store/test/codegen/tables/Vector2.sol index 2a394dce5d..506d02ab62 100644 --- a/packages/store/src/codegen/tables/Vector2.sol +++ b/packages/store/test/codegen/tables/Vector2.sol @@ -7,18 +7,18 @@ pragma solidity >=0.8.21; import { SchemaType } from "@latticexyz/schema-type/src/solidity/SchemaType.sol"; // Import store internals -import { IStore } from "../../IStore.sol"; -import { StoreSwitch } from "../../StoreSwitch.sol"; -import { StoreCore } from "../../StoreCore.sol"; -import { Bytes } from "../../Bytes.sol"; -import { Memory } from "../../Memory.sol"; -import { SliceLib } from "../../Slice.sol"; -import { EncodeArray } from "../../tightcoder/EncodeArray.sol"; -import { FieldLayout, FieldLayoutLib } from "../../FieldLayout.sol"; -import { Schema, SchemaLib } from "../../Schema.sol"; -import { PackedCounter, PackedCounterLib } from "../../PackedCounter.sol"; -import { ResourceId } from "../../ResourceId.sol"; -import { RESOURCE_TABLE, RESOURCE_OFFCHAIN_TABLE } from "../../storeResourceTypes.sol"; +import { IStore } from "../../../src/IStore.sol"; +import { StoreSwitch } from "../../../src/StoreSwitch.sol"; +import { StoreCore } from "../../../src/StoreCore.sol"; +import { Bytes } from "../../../src/Bytes.sol"; +import { Memory } from "../../../src/Memory.sol"; +import { SliceLib } from "../../../src/Slice.sol"; +import { EncodeArray } from "../../../src/tightcoder/EncodeArray.sol"; +import { FieldLayout, FieldLayoutLib } from "../../../src/FieldLayout.sol"; +import { Schema, SchemaLib } from "../../../src/Schema.sol"; +import { PackedCounter, PackedCounterLib } from "../../../src/PackedCounter.sol"; +import { ResourceId } from "../../../src/ResourceId.sol"; +import { RESOURCE_TABLE, RESOURCE_OFFCHAIN_TABLE } from "../../../src/storeResourceTypes.sol"; ResourceId constant _tableId = ResourceId.wrap( bytes32(abi.encodePacked(RESOURCE_TABLE, bytes14("mudstore"), bytes16("Vector2"))) diff --git a/packages/store/test/common.sol b/packages/store/test/common.sol new file mode 100644 index 0000000000..4f6c334a8e --- /dev/null +++ b/packages/store/test/common.sol @@ -0,0 +1,10 @@ +// SPDX-License-Identifier: MIT +pragma solidity >=0.8.21; + +/* Autogenerated file. Do not edit manually. */ +enum ExampleEnum { + None, + First, + Second, + Third +} diff --git a/packages/store/ts/scripts/generate-test-tables.ts b/packages/store/ts/scripts/generate-test-tables.ts new file mode 100644 index 0000000000..24ee4ae192 --- /dev/null +++ b/packages/store/ts/scripts/generate-test-tables.ts @@ -0,0 +1,46 @@ +import path from "path"; +import { getRemappings, getSrcDirectory } from "@latticexyz/common/foundry"; +import { tablegen } from "../codegen"; +import { mudConfig } from "../register"; + +const config = mudConfig({ + storeImportPath: "../../../src/", + namespace: "mudstore", + codegenDirectory: "../test/codegen", + enums: { + ExampleEnum: ["None", "First", "Second", "Third"], + }, + tables: { + Callbacks: "bytes24[]", + Mixed: { + valueSchema: { + u32: "uint32", + u128: "uint128", + a32: "uint32[]", + s: "string", + }, + }, + Vector2: { + valueSchema: { + x: "uint32", + y: "uint32", + }, + }, + KeyEncoding: { + keySchema: { + k1: "uint256", + k2: "int32", + k3: "bytes16", + k4: "address", + k5: "bool", + k6: "ExampleEnum", + }, + valueSchema: "bool", + }, + }, +}); + +const srcDir = await getSrcDirectory(); +const remappings = await getRemappings(); + +await tablegen(config, path.join(srcDir, config.codegenDirectory), remappings); diff --git a/packages/world/mud.config.ts b/packages/world/mud.config.ts index 7150cc36ea..16ca928d50 100644 --- a/packages/world/mud.config.ts +++ b/packages/world/mud.config.ts @@ -8,11 +8,6 @@ export default mudConfig({ ResourceId: { filePath: "@latticexyz/store/src/ResourceId.sol", internalType: "bytes32" }, }, tables: { - /************************************************************************ - * - * CORE TABLES - * - ************************************************************************/ NamespaceOwner: { keySchema: { namespaceId: "ResourceId", @@ -56,11 +51,6 @@ export default mudConfig({ delegationControlId: "ResourceId", }, }, - /************************************************************************ - * - * CORE MODULE TABLES - * - ************************************************************************/ Balances: { keySchema: { namespaceId: "ResourceId", @@ -112,33 +102,6 @@ export default mudConfig({ }, offchainOnly: true, }, - /************************************************************************ - * - * TEST TABLES - * - ************************************************************************/ - Bool: { - directory: "../test/tables", - keySchema: {}, - valueSchema: { - value: "bool", - }, - tableIdArgument: true, - }, - TwoFields: { - directory: "../test/tables", - keySchema: {}, - valueSchema: { - value1: "bool", - value2: "bool", - }, - tableIdArgument: true, - }, - AddressArray: { - directory: "../test/tables", - valueSchema: "address[]", - tableIdArgument: true, - }, }, excludeSystems: [ // Worldgen currently does not support systems inheriting logic diff --git a/packages/world/package.json b/packages/world/package.json index 2a725cd877..643fe05f66 100644 --- a/packages/world/package.json +++ b/packages/world/package.json @@ -34,11 +34,11 @@ "build:abi": "forge build --skip test script", "build:abi-ts": "abi-ts && prettier --write '**/*.abi.json.d.ts'", "build:js": "tsup", - "build:mud": "tsx ./ts/scripts/tablegen.ts && tsx ./ts/scripts/worldgen.ts", + "build:mud": "tsx ./ts/scripts/tablegen.ts && tsx ./ts/scripts/worldgen.ts && tsx ./ts/scripts/generate-test-tables.ts", "clean": "pnpm run clean:abi && pnpm run clean:js && pnpm run clean:mud", "clean:abi": "forge clean", "clean:js": "rimraf dist", - "clean:mud": "rimraf src/codegen", + "clean:mud": "rimraf src/codegen && rimraf test/codegen", "dev": "tsup --watch", "gas-report": "gas-report --save gas-report.json", "lint": "solhint --config ./.solhint.json 'src/**/*.sol'", diff --git a/packages/world/src/codegen/index.sol b/packages/world/src/codegen/index.sol index 72d7aa53e2..472f3049c3 100644 --- a/packages/world/src/codegen/index.sol +++ b/packages/world/src/codegen/index.sol @@ -14,6 +14,3 @@ import { SystemRegistry, SystemRegistryTableId } from "./tables/SystemRegistry.s import { SystemHooks, SystemHooksTableId } from "./tables/SystemHooks.sol"; import { FunctionSelectors, FunctionSelectorsTableId } from "./tables/FunctionSelectors.sol"; import { FunctionSignatures, FunctionSignaturesTableId } from "./tables/FunctionSignatures.sol"; -import { Bool } from "./../test/tables/Bool.sol"; -import { TwoFields, TwoFieldsData } from "./../test/tables/TwoFields.sol"; -import { AddressArray } from "./../test/tables/AddressArray.sol"; diff --git a/packages/world/test/World.t.sol b/packages/world/test/World.t.sol index 68cd479fd3..70c34d2fff 100644 --- a/packages/world/test/World.t.sol +++ b/packages/world/test/World.t.sol @@ -46,9 +46,9 @@ import { IBaseWorld } from "../src/codegen/interfaces/IBaseWorld.sol"; import { IWorldErrors } from "../src/interfaces/IWorldErrors.sol"; import { ISystemHook, SYSTEM_HOOK_INTERFACE_ID } from "../src/interfaces/ISystemHook.sol"; -import { Bool } from "./tables/Bool.sol"; -import { TwoFields, TwoFieldsData } from "./tables/TwoFields.sol"; -import { AddressArray } from "./tables/AddressArray.sol"; +import { Bool } from "./codegen/tables/Bool.sol"; +import { TwoFields, TwoFieldsData } from "./codegen/tables/TwoFields.sol"; +import { AddressArray } from "./codegen/tables/AddressArray.sol"; import { DelegationControlMock } from "./DelegationControlMock.sol"; interface IWorldTestSystem { diff --git a/packages/world/test/WorldDynamicUpdate.t.sol b/packages/world/test/WorldDynamicUpdate.t.sol index cd61c61506..5d7f930481 100644 --- a/packages/world/test/WorldDynamicUpdate.t.sol +++ b/packages/world/test/WorldDynamicUpdate.t.sol @@ -19,7 +19,7 @@ import { World } from "../src/World.sol"; import { ResourceId, WorldResourceIdLib, WorldResourceIdInstance } from "../src/WorldResourceId.sol"; import { RESOURCE_TABLE } from "../src/worldResourceTypes.sol"; -import { AddressArray } from "./tables/AddressArray.sol"; +import { AddressArray } from "./codegen/tables/AddressArray.sol"; import { CoreModule } from "../src/modules/core/CoreModule.sol"; diff --git a/packages/world/test/codegen/index.sol b/packages/world/test/codegen/index.sol new file mode 100644 index 0000000000..1c657e060b --- /dev/null +++ b/packages/world/test/codegen/index.sol @@ -0,0 +1,8 @@ +// SPDX-License-Identifier: MIT +pragma solidity >=0.8.21; + +/* Autogenerated file. Do not edit manually. */ + +import { Bool } from "./tables/Bool.sol"; +import { TwoFields, TwoFieldsData } from "./tables/TwoFields.sol"; +import { AddressArray } from "./tables/AddressArray.sol"; diff --git a/packages/world/test/tables/AddressArray.sol b/packages/world/test/codegen/tables/AddressArray.sol similarity index 100% rename from packages/world/test/tables/AddressArray.sol rename to packages/world/test/codegen/tables/AddressArray.sol diff --git a/packages/world/test/tables/Bool.sol b/packages/world/test/codegen/tables/Bool.sol similarity index 100% rename from packages/world/test/tables/Bool.sol rename to packages/world/test/codegen/tables/Bool.sol diff --git a/packages/world/test/tables/TwoFields.sol b/packages/world/test/codegen/tables/TwoFields.sol similarity index 100% rename from packages/world/test/tables/TwoFields.sol rename to packages/world/test/codegen/tables/TwoFields.sol diff --git a/packages/world/ts/scripts/generate-test-tables.ts b/packages/world/ts/scripts/generate-test-tables.ts new file mode 100644 index 0000000000..1ae80c1ede --- /dev/null +++ b/packages/world/ts/scripts/generate-test-tables.ts @@ -0,0 +1,33 @@ +import path from "path"; +import { getRemappings, getSrcDirectory } from "@latticexyz/common/foundry"; +import { tablegen } from "@latticexyz/store/codegen"; +import { mudConfig } from "../register"; + +const config = mudConfig({ + codegenDirectory: "../test/codegen", + tables: { + Bool: { + keySchema: {}, + valueSchema: { + value: "bool", + }, + tableIdArgument: true, + }, + TwoFields: { + keySchema: {}, + valueSchema: { + value1: "bool", + value2: "bool", + }, + tableIdArgument: true, + }, + AddressArray: { + valueSchema: "address[]", + tableIdArgument: true, + }, + }, +}); +const srcDir = await getSrcDirectory(); +const remappings = await getRemappings(); + +await tablegen(config, path.join(srcDir, config.codegenDirectory), remappings);