From 2e288aa740852d618df561efde259792c8399963 Mon Sep 17 00:00:00 2001 From: Kevin Ingersoll Date: Wed, 28 Feb 2024 14:37:04 +0000 Subject: [PATCH] Revert "refactor(store,world-modules): clean up error names/locations" (#2337) --- .changeset/empty-camels-suffer.md | 11 -- docs/pages/store/reference/misc.mdx | 154 ++++++++---------- docs/pages/store/reference/store-hook.mdx | 10 ++ docs/pages/store/reference/store.mdx | 10 -- packages/store/src/FieldLayout.sol | 38 ++--- packages/store/src/IStoreHook.sol | 3 + packages/store/src/PackedCounter.sol | 4 +- packages/store/src/Schema.sol | 30 ++-- packages/store/src/Slice.sol | 4 +- packages/store/src/StoreHook.sol | 1 - packages/store/src/errors.sol | 3 - packages/store/test/FieldLayout.t.sol | 16 +- packages/store/test/Schema.t.sol | 14 +- packages/store/test/StoreCore.t.sol | 8 +- .../src/modules/erc20-puppet/ERC20Module.sol | 4 +- .../modules/erc721-puppet/ERC721Module.sol | 4 +- .../src/modules/puppet/Puppet.sol | 4 +- .../src/modules/puppet/PuppetMaster.sol | 4 +- 18 files changed, 153 insertions(+), 169 deletions(-) delete mode 100644 .changeset/empty-camels-suffer.md diff --git a/.changeset/empty-camels-suffer.md b/.changeset/empty-camels-suffer.md deleted file mode 100644 index d325411093..0000000000 --- a/.changeset/empty-camels-suffer.md +++ /dev/null @@ -1,11 +0,0 @@ ---- -"@latticexyz/store": major -"@latticexyz/world-modules": minor ---- - -Moved custom errors out of libraries and interfaces to the file level. In most cases, these errors are contained inside the same file as the library that uses them. - -Some have also been renamed: - -- `FieldLayoutLib_*` errors to `FieldLayout_*` -- `SchemaLib_*` errors to `Schema_*` diff --git a/docs/pages/store/reference/misc.mdx b/docs/pages/store/reference/misc.mdx index f766d269a0..78e1f5d689 100644 --- a/docs/pages/store/reference/misc.mdx +++ b/docs/pages/store/reference/misc.mdx @@ -269,62 +269,6 @@ function slice32(bytes memory data, uint256 start) internal pure returns (bytes3 | -------- | --------- | -------------------------------------------------------------------------- | | `output` | `bytes32` | The extracted bytes32 value from the specified position in the bytes blob. | -## FieldLayout_Empty - -[Git Source](https://github.com/latticexyz/mud/blob/main/packages/store/src/FieldLayout.sol) - -```solidity -error FieldLayout_Empty(); -``` - -## FieldLayout_InvalidStaticDataLength - -[Git Source](https://github.com/latticexyz/mud/blob/main/packages/store/src/FieldLayout.sol) - -```solidity -error FieldLayout_InvalidStaticDataLength(uint256 staticDataLength, uint256 computedStaticDataLength); -``` - -## FieldLayout_StaticLengthDoesNotFitInAWord - -[Git Source](https://github.com/latticexyz/mud/blob/main/packages/store/src/FieldLayout.sol) - -```solidity -error FieldLayout_StaticLengthDoesNotFitInAWord(uint256 index); -``` - -## FieldLayout_StaticLengthIsNotZero - -[Git Source](https://github.com/latticexyz/mud/blob/main/packages/store/src/FieldLayout.sol) - -```solidity -error FieldLayout_StaticLengthIsNotZero(uint256 index); -``` - -## FieldLayout_StaticLengthIsZero - -[Git Source](https://github.com/latticexyz/mud/blob/main/packages/store/src/FieldLayout.sol) - -```solidity -error FieldLayout_StaticLengthIsZero(uint256 index); -``` - -## FieldLayout_TooManyDynamicFields - -[Git Source](https://github.com/latticexyz/mud/blob/main/packages/store/src/FieldLayout.sol) - -```solidity -error FieldLayout_TooManyDynamicFields(uint256 numFields, uint256 maxFields); -``` - -## FieldLayout_TooManyFields - -[Git Source](https://github.com/latticexyz/mud/blob/main/packages/store/src/FieldLayout.sol) - -```solidity -error FieldLayout_TooManyFields(uint256 numFields, uint256 maxFields); -``` - ## FieldLayoutInstance [Git Source](https://github.com/latticexyz/mud/blob/main/packages/store/src/FieldLayout.sol) @@ -526,6 +470,50 @@ function encode(uint256[] memory _staticFieldLengths, uint256 numDynamicFields) | -------- | ------------- | ------------------------------------------------------------ | | `` | `FieldLayout` | A FieldLayout structure containing the encoded field layout. | +### Errors + +#### FieldLayoutLib_TooManyFields + +```solidity +error FieldLayoutLib_TooManyFields(uint256 numFields, uint256 maxFields); +``` + +#### FieldLayoutLib_TooManyDynamicFields + +```solidity +error FieldLayoutLib_TooManyDynamicFields(uint256 numFields, uint256 maxFields); +``` + +#### FieldLayoutLib_Empty + +```solidity +error FieldLayoutLib_Empty(); +``` + +#### FieldLayoutLib_InvalidStaticDataLength + +```solidity +error FieldLayoutLib_InvalidStaticDataLength(uint256 staticDataLength, uint256 computedStaticDataLength); +``` + +#### FieldLayoutLib_StaticLengthIsZero + +```solidity +error FieldLayoutLib_StaticLengthIsZero(uint256 index); +``` + +#### FieldLayoutLib_StaticLengthIsNotZero + +```solidity +error FieldLayoutLib_StaticLengthIsNotZero(uint256 index); +``` + +#### FieldLayoutLib_StaticLengthDoesNotFitInAWord + +```solidity +error FieldLayoutLib_StaticLengthDoesNotFitInAWord(uint256 index); +``` + ## FieldLayout [Git Source](https://github.com/latticexyz/mud/blob/main/packages/store/src/FieldLayout.sol) @@ -811,26 +799,6 @@ type and a name_ type ResourceId is bytes32; ``` -## Schema_InvalidLength - -[Git Source](https://github.com/latticexyz/mud/blob/main/packages/store/src/Schema.sol) - -_Error raised when the provided schema has an invalid length._ - -```solidity -error Schema_InvalidLength(uint256 length); -``` - -## Schema_StaticTypeAfterDynamicType - -[Git Source](https://github.com/latticexyz/mud/blob/main/packages/store/src/Schema.sol) - -_Error raised when a static type is placed after a dynamic type in a schema._ - -```solidity -error Schema_StaticTypeAfterDynamicType(); -``` - ## SchemaInstance [Git Source](https://github.com/latticexyz/mud/blob/main/packages/store/src/Schema.sol) @@ -1023,6 +991,24 @@ function encode(SchemaType[] memory schemas) internal pure returns (Schema); | -------- | -------- | ------------------- | | `` | `Schema` | The encoded Schema. | +### Errors + +#### SchemaLib_InvalidLength + +_Error raised when the provided schema has an invalid length._ + +```solidity +error SchemaLib_InvalidLength(uint256 length); +``` + +#### SchemaLib_StaticTypeAfterDynamicType + +_Error raised when a static type is placed after a dynamic type in a schema._ + +```solidity +error SchemaLib_StaticTypeAfterDynamicType(); +``` + ## Schema [Git Source](https://github.com/latticexyz/mud/blob/main/packages/store/src/Schema.sol) @@ -1037,14 +1023,6 @@ _Defines and handles the encoding/decoding of Schemas which describe the layout type Schema is bytes32; ``` -## Slice_OutOfBounds - -[Git Source](https://github.com/latticexyz/mud/blob/main/packages/store/src/Slice.sol) - -```solidity -error Slice_OutOfBounds(bytes data, uint256 start, uint256 end); -``` - ## SliceInstance [Git Source](https://github.com/latticexyz/mud/blob/main/packages/store/src/Slice.sol) @@ -1214,6 +1192,14 @@ function getSubslice(bytes memory data, uint256 start, uint256 end) internal pur | -------- | ------- | ------------------------------------- | | `` | `Slice` | A new Slice representing the subslice | +### Errors + +#### Slice_OutOfBounds + +```solidity +error Slice_OutOfBounds(bytes data, uint256 start, uint256 end); +``` + ## Slice [Git Source](https://github.com/latticexyz/mud/blob/main/packages/store/src/Slice.sol) diff --git a/docs/pages/store/reference/store-hook.mdx b/docs/pages/store/reference/store-hook.mdx index 48023b2030..ab8b0f4583 100644 --- a/docs/pages/store/reference/store-hook.mdx +++ b/docs/pages/store/reference/store-hook.mdx @@ -205,3 +205,13 @@ function onAfterDeleteRecord(ResourceId tableId, bytes32[] memory keyTuple, Fiel | `tableId` | `ResourceId` | The ID of the table where the record was deleted. | | `keyTuple` | `bytes32[]` | An array representing the composite key for the record. | | `fieldLayout` | `FieldLayout` | The layout of the field, see FieldLayout.sol. | + +### Errors + +#### StoreHook_NotImplemented + +Error emitted when a function is not implemented. + +```solidity +error StoreHook_NotImplemented(); +``` diff --git a/docs/pages/store/reference/store.mdx b/docs/pages/store/reference/store.mdx index 0f7dd3a263..4053966495 100644 --- a/docs/pages/store/reference/store.mdx +++ b/docs/pages/store/reference/store.mdx @@ -96,16 +96,6 @@ event Store_DeleteRecord(ResourceId indexed tableId, bytes32[] keyTuple); | `tableId` | `ResourceId` | The ID of the table where the record is deleted. | | `keyTuple` | `bytes32[]` | An array representing the composite key for the record. | -## StoreHook_NotImplemented - -[Git Source](https://github.com/latticexyz/mud/blob/main/packages/store/src/errors.sol) - -Error emitted when a function is not implemented. - -```solidity -error StoreHook_NotImplemented(); -``` - ## Store_IndexOutOfBounds [Git Source](https://github.com/latticexyz/mud/blob/main/packages/store/src/errors.sol) diff --git a/packages/store/src/FieldLayout.sol b/packages/store/src/FieldLayout.sol index e673da1c79..6db7af9bd3 100644 --- a/packages/store/src/FieldLayout.sol +++ b/packages/store/src/FieldLayout.sol @@ -18,14 +18,6 @@ type FieldLayout is bytes32; // When importing FieldLayout, attach FieldLayoutInstance to it using FieldLayoutInstance for FieldLayout global; -error FieldLayout_TooManyFields(uint256 numFields, uint256 maxFields); -error FieldLayout_TooManyDynamicFields(uint256 numFields, uint256 maxFields); -error FieldLayout_Empty(); -error FieldLayout_InvalidStaticDataLength(uint256 staticDataLength, uint256 computedStaticDataLength); -error FieldLayout_StaticLengthIsZero(uint256 index); -error FieldLayout_StaticLengthIsNotZero(uint256 index); -error FieldLayout_StaticLengthDoesNotFitInAWord(uint256 index); - /** * @title FieldLayoutLib * @dev A library for handling field layout encoding into a single bytes32. @@ -33,6 +25,14 @@ error FieldLayout_StaticLengthDoesNotFitInAWord(uint256 index); * various constraints regarding the length and size of the fields. */ library FieldLayoutLib { + error FieldLayoutLib_TooManyFields(uint256 numFields, uint256 maxFields); + error FieldLayoutLib_TooManyDynamicFields(uint256 numFields, uint256 maxFields); + error FieldLayoutLib_Empty(); + error FieldLayoutLib_InvalidStaticDataLength(uint256 staticDataLength, uint256 computedStaticDataLength); + error FieldLayoutLib_StaticLengthIsZero(uint256 index); + error FieldLayoutLib_StaticLengthIsNotZero(uint256 index); + error FieldLayoutLib_StaticLengthDoesNotFitInAWord(uint256 index); + /** * @notice Encodes the given field layout into a single bytes32. * @dev Ensures various constraints on the length and size of the fields. @@ -45,17 +45,17 @@ library FieldLayoutLib { uint256 fieldLayout; uint256 totalLength; uint256 totalFields = _staticFieldLengths.length + numDynamicFields; - if (totalFields > MAX_TOTAL_FIELDS) revert FieldLayout_TooManyFields(totalFields, MAX_TOTAL_FIELDS); + if (totalFields > MAX_TOTAL_FIELDS) revert FieldLayoutLib_TooManyFields(totalFields, MAX_TOTAL_FIELDS); if (numDynamicFields > MAX_DYNAMIC_FIELDS) - revert FieldLayout_TooManyDynamicFields(numDynamicFields, MAX_DYNAMIC_FIELDS); + revert FieldLayoutLib_TooManyDynamicFields(numDynamicFields, MAX_DYNAMIC_FIELDS); // Compute the total static length and store the field lengths in the encoded fieldLayout for (uint256 i; i < _staticFieldLengths.length; ) { uint256 staticByteLength = _staticFieldLengths[i]; if (staticByteLength == 0) { - revert FieldLayout_StaticLengthIsZero(i); + revert FieldLayoutLib_StaticLengthIsZero(i); } else if (staticByteLength > WORD_SIZE) { - revert FieldLayout_StaticLengthDoesNotFitInAWord(i); + revert FieldLayoutLib_StaticLengthDoesNotFitInAWord(i); } unchecked { @@ -153,18 +153,18 @@ library FieldLayoutInstance { */ function validate(FieldLayout fieldLayout) internal pure { if (fieldLayout.isEmpty()) { - revert FieldLayout_Empty(); + revert FieldLayoutLib.FieldLayoutLib_Empty(); } uint256 _numDynamicFields = fieldLayout.numDynamicFields(); if (_numDynamicFields > MAX_DYNAMIC_FIELDS) { - revert FieldLayout_TooManyDynamicFields(_numDynamicFields, MAX_DYNAMIC_FIELDS); + revert FieldLayoutLib.FieldLayoutLib_TooManyDynamicFields(_numDynamicFields, MAX_DYNAMIC_FIELDS); } uint256 _numStaticFields = fieldLayout.numStaticFields(); uint256 _numTotalFields = _numStaticFields + _numDynamicFields; if (_numTotalFields > MAX_TOTAL_FIELDS) { - revert FieldLayout_TooManyFields(_numTotalFields, MAX_TOTAL_FIELDS); + revert FieldLayoutLib.FieldLayoutLib_TooManyFields(_numTotalFields, MAX_TOTAL_FIELDS); } // Static lengths must be valid @@ -172,9 +172,9 @@ library FieldLayoutInstance { for (uint256 i; i < _numStaticFields; ) { uint256 staticByteLength = fieldLayout.atIndex(i); if (staticByteLength == 0) { - revert FieldLayout_StaticLengthIsZero(i); + revert FieldLayoutLib.FieldLayoutLib_StaticLengthIsZero(i); } else if (staticByteLength > WORD_SIZE) { - revert FieldLayout_StaticLengthDoesNotFitInAWord(i); + revert FieldLayoutLib.FieldLayoutLib_StaticLengthDoesNotFitInAWord(i); } _staticDataLength += staticByteLength; unchecked { @@ -183,13 +183,13 @@ library FieldLayoutInstance { } // Static length sums must match if (_staticDataLength != fieldLayout.staticDataLength()) { - revert FieldLayout_InvalidStaticDataLength(fieldLayout.staticDataLength(), _staticDataLength); + revert FieldLayoutLib.FieldLayoutLib_InvalidStaticDataLength(fieldLayout.staticDataLength(), _staticDataLength); } // Unused fields must be zero for (uint256 i = _numStaticFields; i < MAX_TOTAL_FIELDS; i++) { uint256 staticByteLength = fieldLayout.atIndex(i); if (staticByteLength != 0) { - revert FieldLayout_StaticLengthIsNotZero(i); + revert FieldLayoutLib.FieldLayoutLib_StaticLengthIsNotZero(i); } } } diff --git a/packages/store/src/IStoreHook.sol b/packages/store/src/IStoreHook.sol index 41a7adbc26..cea4825d48 100644 --- a/packages/store/src/IStoreHook.sol +++ b/packages/store/src/IStoreHook.sol @@ -7,6 +7,9 @@ import { PackedCounter } from "./PackedCounter.sol"; import { ResourceId } from "./ResourceId.sol"; interface IStoreHook is IERC165 { + /// @notice Error emitted when a function is not implemented. + error StoreHook_NotImplemented(); + /** * @notice Called before setting a record in the store. * @param tableId The ID of the table where the record is to be set. diff --git a/packages/store/src/PackedCounter.sol b/packages/store/src/PackedCounter.sol index 1927b8a3d1..e1dcd58120 100644 --- a/packages/store/src/PackedCounter.sol +++ b/packages/store/src/PackedCounter.sol @@ -26,8 +26,6 @@ uint256 constant VAL_BITS = 5 * BYTE_TO_BITS; // Maximum value of a 5-byte section uint256 constant MAX_VAL = type(uint40).max; -error PackedCounter_InvalidLength(uint256 length); - /** * @title PackedCounter Library * @notice Static functions for handling PackedCounter type. @@ -138,6 +136,8 @@ library PackedCounterLib { * @dev Offers decoding, extracting, and setting functionalities for a PackedCounter. */ library PackedCounterInstance { + error PackedCounter_InvalidLength(uint256 length); + /** * @notice Decode the accumulated counter from a PackedCounter. * @dev Extracts the right-most 7 bytes of a PackedCounter. diff --git a/packages/store/src/Schema.sol b/packages/store/src/Schema.sol index 79a1e61e63..87171de1a3 100644 --- a/packages/store/src/Schema.sol +++ b/packages/store/src/Schema.sol @@ -17,23 +17,23 @@ type Schema is bytes32; using SchemaInstance for Schema global; -/// @dev Error raised when the provided schema has an invalid length. -error Schema_InvalidLength(uint256 length); - -/// @dev Error raised when a static type is placed after a dynamic type in a schema. -error Schema_StaticTypeAfterDynamicType(); - /** * @dev Static utility functions for handling Schemas. */ library SchemaLib { + /// @dev Error raised when the provided schema has an invalid length. + error SchemaLib_InvalidLength(uint256 length); + + /// @dev Error raised when a static type is placed after a dynamic type in a schema. + error SchemaLib_StaticTypeAfterDynamicType(); + /** * @notice Encodes a given schema into a single bytes32. * @param schemas The list of SchemaTypes that constitute the schema. * @return The encoded Schema. */ function encode(SchemaType[] memory schemas) internal pure returns (Schema) { - if (schemas.length > MAX_TOTAL_FIELDS) revert Schema_InvalidLength(schemas.length); + if (schemas.length > MAX_TOTAL_FIELDS) revert SchemaLib_InvalidLength(schemas.length); uint256 schema; uint256 totalLength; uint256 dynamicFields; @@ -51,7 +51,7 @@ library SchemaLib { } } else if (dynamicFields > 0) { // Revert if we have seen a dynamic field before, but now we see a static field - revert Schema_StaticTypeAfterDynamicType(); + revert SchemaLib_StaticTypeAfterDynamicType(); } unchecked { @@ -65,7 +65,7 @@ library SchemaLib { } // Require MAX_DYNAMIC_FIELDS - if (dynamicFields > MAX_DYNAMIC_FIELDS) revert Schema_InvalidLength(dynamicFields); + if (dynamicFields > MAX_DYNAMIC_FIELDS) revert SchemaLib_InvalidLength(dynamicFields); // Get the static field count uint256 staticFields; @@ -157,23 +157,23 @@ library SchemaInstance { */ function validate(Schema schema, bool allowEmpty) internal pure { // Schema must not be empty - if (!allowEmpty && schema.isEmpty()) revert Schema_InvalidLength(0); + if (!allowEmpty && schema.isEmpty()) revert SchemaLib.SchemaLib_InvalidLength(0); // Schema must have no more than MAX_DYNAMIC_FIELDS uint256 _numDynamicFields = schema.numDynamicFields(); - if (_numDynamicFields > MAX_DYNAMIC_FIELDS) revert Schema_InvalidLength(_numDynamicFields); + if (_numDynamicFields > MAX_DYNAMIC_FIELDS) revert SchemaLib.SchemaLib_InvalidLength(_numDynamicFields); uint256 _numStaticFields = schema.numStaticFields(); // Schema must not have more than MAX_TOTAL_FIELDS in total uint256 _numTotalFields = _numStaticFields + _numDynamicFields; - if (_numTotalFields > MAX_TOTAL_FIELDS) revert Schema_InvalidLength(_numTotalFields); + if (_numTotalFields > MAX_TOTAL_FIELDS) revert SchemaLib.SchemaLib_InvalidLength(_numTotalFields); // No dynamic field can be before a dynamic field uint256 _staticDataLength; for (uint256 i; i < _numStaticFields; ) { uint256 staticByteLength = schema.atIndex(i).getStaticByteLength(); if (staticByteLength == 0) { - revert Schema_StaticTypeAfterDynamicType(); + revert SchemaLib.SchemaLib_StaticTypeAfterDynamicType(); } _staticDataLength += staticByteLength; unchecked { @@ -183,14 +183,14 @@ library SchemaInstance { // Static length sums must match if (_staticDataLength != schema.staticDataLength()) { - revert Schema_InvalidLength(schema.staticDataLength()); + revert SchemaLib.SchemaLib_InvalidLength(schema.staticDataLength()); } // No static field can be after a dynamic field for (uint256 i = _numStaticFields; i < _numTotalFields; ) { uint256 staticByteLength = schema.atIndex(i).getStaticByteLength(); if (staticByteLength > 0) { - revert Schema_StaticTypeAfterDynamicType(); + revert SchemaLib.SchemaLib_StaticTypeAfterDynamicType(); } unchecked { i++; diff --git a/packages/store/src/Slice.sol b/packages/store/src/Slice.sol index 3f2d0598ec..cce6cab687 100644 --- a/packages/store/src/Slice.sol +++ b/packages/store/src/Slice.sol @@ -13,12 +13,12 @@ type Slice is uint256; using SliceInstance for Slice global; using DecodeSlice for Slice global; -error Slice_OutOfBounds(bytes data, uint256 start, uint256 end); - /** * @title Static functions for Slice */ library SliceLib { + error Slice_OutOfBounds(bytes data, uint256 start, uint256 end); + uint256 constant MASK_LEN = uint256(type(uint128).max); /** diff --git a/packages/store/src/StoreHook.sol b/packages/store/src/StoreHook.sol index 48f0e54562..7463af8880 100644 --- a/packages/store/src/StoreHook.sol +++ b/packages/store/src/StoreHook.sol @@ -6,7 +6,6 @@ import { IERC165 } from "./IERC165.sol"; import { PackedCounter } from "./PackedCounter.sol"; import { FieldLayout } from "./FieldLayout.sol"; import { ResourceId } from "./ResourceId.sol"; -import { StoreHook_NotImplemented } from "./errors.sol"; /** * @title Store Hook Contract diff --git a/packages/store/src/errors.sol b/packages/store/src/errors.sol index d4f1d0e4af..66ab6e5307 100644 --- a/packages/store/src/errors.sol +++ b/packages/store/src/errors.sol @@ -17,6 +17,3 @@ error Store_InvalidValueSchemaLength(uint256 expected, uint256 received); error Store_InvalidValueSchemaStaticLength(uint256 expected, uint256 received); error Store_InvalidValueSchemaDynamicLength(uint256 expected, uint256 received); error Store_InvalidSplice(uint40 startWithinField, uint40 deleteCount, uint40 fieldLength); - -/// @notice Error emitted when a function is not implemented. -error StoreHook_NotImplemented(); diff --git a/packages/store/test/FieldLayout.t.sol b/packages/store/test/FieldLayout.t.sol index 45320b4243..915d96618f 100644 --- a/packages/store/test/FieldLayout.t.sol +++ b/packages/store/test/FieldLayout.t.sol @@ -3,7 +3,7 @@ pragma solidity >=0.8.24; import { Test, console } from "forge-std/Test.sol"; import { GasReporter } from "@latticexyz/gas-report/src/GasReporter.sol"; -import "../src/FieldLayout.sol"; +import { FieldLayout, FieldLayoutLib } from "../src/FieldLayout.sol"; import { FieldLayoutEncodeHelper } from "./FieldLayoutEncodeHelper.sol"; import { MAX_TOTAL_FIELDS, MAX_DYNAMIC_FIELDS } from "../src/constants.sol"; @@ -36,12 +36,12 @@ contract FieldLayoutTest is Test, GasReporter { } function testInvalidFieldLayoutStaticTypeIsZero() public { - vm.expectRevert(abi.encodeWithSelector(FieldLayout_StaticLengthIsZero.selector, 1)); + vm.expectRevert(abi.encodeWithSelector(FieldLayoutLib.FieldLayoutLib_StaticLengthIsZero.selector, 1)); FieldLayoutEncodeHelper.encode(1, 0, 1); } function testInvalidFieldLayoutStaticTypeDoesNotFitInAWord() public { - vm.expectRevert(abi.encodeWithSelector(FieldLayout_StaticLengthDoesNotFitInAWord.selector, 1)); + vm.expectRevert(abi.encodeWithSelector(FieldLayoutLib.FieldLayoutLib_StaticLengthDoesNotFitInAWord.selector, 1)); FieldLayoutEncodeHelper.encode(1, 33, 1); } @@ -96,7 +96,11 @@ contract FieldLayoutTest is Test, GasReporter { fieldLayout[15] = 32; fieldLayout[16] = 32; vm.expectRevert( - abi.encodeWithSelector(FieldLayout_TooManyFields.selector, fieldLayout.length + dynamicFields, MAX_TOTAL_FIELDS) + abi.encodeWithSelector( + FieldLayoutLib.FieldLayoutLib_TooManyFields.selector, + fieldLayout.length + dynamicFields, + MAX_TOTAL_FIELDS + ) ); FieldLayoutLib.encode(fieldLayout, dynamicFields); } @@ -113,7 +117,7 @@ contract FieldLayoutTest is Test, GasReporter { uint256 dynamicFields = 6; vm.expectRevert( abi.encodeWithSelector( - FieldLayout_TooManyDynamicFields.selector, + FieldLayoutLib.FieldLayoutLib_TooManyDynamicFields.selector, fieldLayout.length + dynamicFields, MAX_DYNAMIC_FIELDS ) @@ -198,7 +202,7 @@ contract FieldLayoutTest is Test, GasReporter { vm.expectRevert( abi.encodeWithSelector( - FieldLayout_TooManyDynamicFields.selector, + FieldLayoutLib.FieldLayoutLib_TooManyDynamicFields.selector, encodedFieldLayout.numDynamicFields(), MAX_DYNAMIC_FIELDS ) diff --git a/packages/store/test/Schema.t.sol b/packages/store/test/Schema.t.sol index 2d57642fd0..3762448b0c 100644 --- a/packages/store/test/Schema.t.sol +++ b/packages/store/test/Schema.t.sol @@ -4,7 +4,7 @@ pragma solidity >=0.8.24; import { Test, console } from "forge-std/Test.sol"; import { GasReporter } from "@latticexyz/gas-report/src/GasReporter.sol"; import { SchemaType } from "@latticexyz/schema-type/src/solidity/SchemaType.sol"; -import "../src/Schema.sol"; +import { Schema, SchemaLib } from "../src/Schema.sol"; import { SchemaEncodeHelper } from "./SchemaEncodeHelper.sol"; import { WORD_LAST_INDEX, BYTE_TO_BITS, LayoutOffsets } from "../src/constants.sol"; @@ -89,7 +89,7 @@ contract SchemaTest is Test, GasReporter { } function testInvalidSchemaStaticAfterDynamic() public { - vm.expectRevert(abi.encodeWithSelector(Schema_StaticTypeAfterDynamicType.selector)); + vm.expectRevert(abi.encodeWithSelector(SchemaLib.SchemaLib_StaticTypeAfterDynamicType.selector)); SchemaEncodeHelper.encode(SchemaType.UINT8, SchemaType.UINT32_ARRAY, SchemaType.UINT16); } @@ -159,7 +159,7 @@ contract SchemaTest is Test, GasReporter { schema[26] = SchemaType.UINT32_ARRAY; schema[27] = SchemaType.UINT32_ARRAY; schema[28] = SchemaType.UINT32_ARRAY; - vm.expectRevert(abi.encodeWithSelector(Schema_InvalidLength.selector, schema.length)); + vm.expectRevert(abi.encodeWithSelector(SchemaLib.SchemaLib_InvalidLength.selector, schema.length)); SchemaLib.encode(schema); } @@ -183,7 +183,7 @@ contract SchemaTest is Test, GasReporter { schema[3] = SchemaType.UINT32_ARRAY; schema[4] = SchemaType.UINT32_ARRAY; schema[5] = SchemaType.UINT32_ARRAY; - vm.expectRevert(abi.encodeWithSelector(Schema_InvalidLength.selector, schema.length)); + vm.expectRevert(abi.encodeWithSelector(SchemaLib.SchemaLib_InvalidLength.selector, schema.length)); SchemaLib.encode(schema); } @@ -295,7 +295,9 @@ contract SchemaTest is Test, GasReporter { function testValidateInvalidLength() public { Schema encodedSchema = Schema.wrap(keccak256("some invalid schema")); - vm.expectRevert(abi.encodeWithSelector(Schema_InvalidLength.selector, encodedSchema.numDynamicFields())); + vm.expectRevert( + abi.encodeWithSelector(SchemaLib.SchemaLib_InvalidLength.selector, encodedSchema.numDynamicFields()) + ); encodedSchema.validate({ allowEmpty: false }); } @@ -332,7 +334,7 @@ contract SchemaTest is Test, GasReporter { schema[27] = SchemaType.UINT32_ARRAY; Schema encodedSchema = encodeUnsafe(schema); - vm.expectRevert(Schema_StaticTypeAfterDynamicType.selector); + vm.expectRevert(SchemaLib.SchemaLib_StaticTypeAfterDynamicType.selector); encodedSchema.validate({ allowEmpty: false }); } diff --git a/packages/store/test/StoreCore.t.sol b/packages/store/test/StoreCore.t.sol index 4928b334d3..72e5ffe46b 100644 --- a/packages/store/test/StoreCore.t.sol +++ b/packages/store/test/StoreCore.t.sol @@ -7,7 +7,7 @@ import { StoreCore, StoreCoreInternal } from "../src/StoreCore.sol"; import { Bytes } from "../src/Bytes.sol"; import { SliceLib } from "../src/Slice.sol"; import { EncodeArray } from "../src/tightcoder/EncodeArray.sol"; -import { FieldLayout, FieldLayoutLib, FieldLayout_TooManyDynamicFields } from "../src/FieldLayout.sol"; +import { FieldLayout, FieldLayoutLib } from "../src/FieldLayout.sol"; import { Schema } from "../src/Schema.sol"; import { PackedCounter, PackedCounterLib } from "../src/PackedCounter.sol"; import { StoreMock } from "../test/StoreMock.sol"; @@ -129,7 +129,11 @@ contract StoreCoreTest is Test, StoreMock { FieldLayout invalidFieldLayout = FieldLayout.wrap(keccak256("random bytes as value field layout")); vm.expectRevert( - abi.encodeWithSelector(FieldLayout_TooManyDynamicFields.selector, invalidFieldLayout.numDynamicFields(), 5) + abi.encodeWithSelector( + FieldLayoutLib.FieldLayoutLib_TooManyDynamicFields.selector, + invalidFieldLayout.numDynamicFields(), + 5 + ) ); IStore(this).registerTable( tableId, diff --git a/packages/world-modules/src/modules/erc20-puppet/ERC20Module.sol b/packages/world-modules/src/modules/erc20-puppet/ERC20Module.sol index 73c894d9cd..3fce7e97cd 100644 --- a/packages/world-modules/src/modules/erc20-puppet/ERC20Module.sol +++ b/packages/world-modules/src/modules/erc20-puppet/ERC20Module.sol @@ -20,9 +20,9 @@ import { ERC20Registry } from "./tables/ERC20Registry.sol"; import { Allowances } from "./tables/Allowances.sol"; import { ERC20Metadata, ERC20MetadataData } from "./tables/ERC20Metadata.sol"; -error ERC20Module_InvalidNamespace(bytes14 namespace); - contract ERC20Module is Module { + error ERC20Module_InvalidNamespace(bytes14 namespace); + address immutable registrationLibrary = address(new ERC20ModuleRegistrationLibrary()); function install(bytes memory encodedArgs) public { diff --git a/packages/world-modules/src/modules/erc721-puppet/ERC721Module.sol b/packages/world-modules/src/modules/erc721-puppet/ERC721Module.sol index 6961d4e376..78e7c5ef91 100644 --- a/packages/world-modules/src/modules/erc721-puppet/ERC721Module.sol +++ b/packages/world-modules/src/modules/erc721-puppet/ERC721Module.sol @@ -24,9 +24,9 @@ import { TokenURI } from "./tables/TokenURI.sol"; import { ERC721Registry } from "./tables/ERC721Registry.sol"; import { ERC721Metadata, ERC721MetadataData } from "./tables/ERC721Metadata.sol"; -error ERC721Module_InvalidNamespace(bytes14 namespace); - contract ERC721Module is Module { + error ERC721Module_InvalidNamespace(bytes14 namespace); + address immutable registrationLibrary = address(new ERC721ModuleRegistrationLibrary()); function install(bytes memory encodedArgs) public { diff --git a/packages/world-modules/src/modules/puppet/Puppet.sol b/packages/world-modules/src/modules/puppet/Puppet.sol index 492d4d9ab5..2ae3f68c7d 100644 --- a/packages/world-modules/src/modules/puppet/Puppet.sol +++ b/packages/world-modules/src/modules/puppet/Puppet.sol @@ -6,9 +6,9 @@ import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; import { IBaseWorld } from "@latticexyz/world/src/codegen/interfaces/IBaseWorld.sol"; import { Systems } from "@latticexyz/world/src/codegen/tables/Systems.sol"; -error Puppet_AccessDenied(address caller); - contract Puppet { + error Puppet_AccessDenied(address caller); + IBaseWorld public immutable world; ResourceId public immutable systemId; diff --git a/packages/world-modules/src/modules/puppet/PuppetMaster.sol b/packages/world-modules/src/modules/puppet/PuppetMaster.sol index 7cda2adf98..c001a24799 100644 --- a/packages/world-modules/src/modules/puppet/PuppetMaster.sol +++ b/packages/world-modules/src/modules/puppet/PuppetMaster.sol @@ -7,9 +7,9 @@ import { PuppetRegistry } from "./tables/PuppetRegistry.sol"; import { PUPPET_TABLE_ID } from "./constants.sol"; import { Puppet } from "./Puppet.sol"; -error PuppetMaster_NoPuppet(address systemAddress, ResourceId systemId); - contract PuppetMaster { + error PuppetMaster_NoPuppet(address systemAddress, ResourceId systemId); + function puppet() internal view returns (Puppet) { ResourceId systemId = SystemRegistry.getSystemId(address(this)); address puppetAddress = PuppetRegistry.get(PUPPET_TABLE_ID, systemId);