diff --git a/.changeset/empty-camels-suffer.md b/.changeset/empty-camels-suffer.md new file mode 100644 index 0000000000..d325411093 --- /dev/null +++ b/.changeset/empty-camels-suffer.md @@ -0,0 +1,11 @@ +--- +"@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 78e1f5d689..f766d269a0 100644 --- a/docs/pages/store/reference/misc.mdx +++ b/docs/pages/store/reference/misc.mdx @@ -269,6 +269,62 @@ 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) @@ -470,50 +526,6 @@ 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) @@ -799,6 +811,26 @@ 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) @@ -991,24 +1023,6 @@ 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) @@ -1023,6 +1037,14 @@ _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) @@ -1192,14 +1214,6 @@ 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 ab8b0f4583..48023b2030 100644 --- a/docs/pages/store/reference/store-hook.mdx +++ b/docs/pages/store/reference/store-hook.mdx @@ -205,13 +205,3 @@ 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 4053966495..0f7dd3a263 100644 --- a/docs/pages/store/reference/store.mdx +++ b/docs/pages/store/reference/store.mdx @@ -96,6 +96,16 @@ 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 6db7af9bd3..e673da1c79 100644 --- a/packages/store/src/FieldLayout.sol +++ b/packages/store/src/FieldLayout.sol @@ -18,6 +18,14 @@ 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. @@ -25,14 +33,6 @@ using FieldLayoutInstance for FieldLayout global; * 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 FieldLayoutLib_TooManyFields(totalFields, MAX_TOTAL_FIELDS); + if (totalFields > MAX_TOTAL_FIELDS) revert FieldLayout_TooManyFields(totalFields, MAX_TOTAL_FIELDS); if (numDynamicFields > MAX_DYNAMIC_FIELDS) - revert FieldLayoutLib_TooManyDynamicFields(numDynamicFields, MAX_DYNAMIC_FIELDS); + revert FieldLayout_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 FieldLayoutLib_StaticLengthIsZero(i); + revert FieldLayout_StaticLengthIsZero(i); } else if (staticByteLength > WORD_SIZE) { - revert FieldLayoutLib_StaticLengthDoesNotFitInAWord(i); + revert FieldLayout_StaticLengthDoesNotFitInAWord(i); } unchecked { @@ -153,18 +153,18 @@ library FieldLayoutInstance { */ function validate(FieldLayout fieldLayout) internal pure { if (fieldLayout.isEmpty()) { - revert FieldLayoutLib.FieldLayoutLib_Empty(); + revert FieldLayout_Empty(); } uint256 _numDynamicFields = fieldLayout.numDynamicFields(); if (_numDynamicFields > MAX_DYNAMIC_FIELDS) { - revert FieldLayoutLib.FieldLayoutLib_TooManyDynamicFields(_numDynamicFields, MAX_DYNAMIC_FIELDS); + revert FieldLayout_TooManyDynamicFields(_numDynamicFields, MAX_DYNAMIC_FIELDS); } uint256 _numStaticFields = fieldLayout.numStaticFields(); uint256 _numTotalFields = _numStaticFields + _numDynamicFields; if (_numTotalFields > MAX_TOTAL_FIELDS) { - revert FieldLayoutLib.FieldLayoutLib_TooManyFields(_numTotalFields, MAX_TOTAL_FIELDS); + revert FieldLayout_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 FieldLayoutLib.FieldLayoutLib_StaticLengthIsZero(i); + revert FieldLayout_StaticLengthIsZero(i); } else if (staticByteLength > WORD_SIZE) { - revert FieldLayoutLib.FieldLayoutLib_StaticLengthDoesNotFitInAWord(i); + revert FieldLayout_StaticLengthDoesNotFitInAWord(i); } _staticDataLength += staticByteLength; unchecked { @@ -183,13 +183,13 @@ library FieldLayoutInstance { } // Static length sums must match if (_staticDataLength != fieldLayout.staticDataLength()) { - revert FieldLayoutLib.FieldLayoutLib_InvalidStaticDataLength(fieldLayout.staticDataLength(), _staticDataLength); + revert FieldLayout_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 FieldLayoutLib.FieldLayoutLib_StaticLengthIsNotZero(i); + revert FieldLayout_StaticLengthIsNotZero(i); } } } diff --git a/packages/store/src/IStoreHook.sol b/packages/store/src/IStoreHook.sol index cea4825d48..41a7adbc26 100644 --- a/packages/store/src/IStoreHook.sol +++ b/packages/store/src/IStoreHook.sol @@ -7,9 +7,6 @@ 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 e1dcd58120..1927b8a3d1 100644 --- a/packages/store/src/PackedCounter.sol +++ b/packages/store/src/PackedCounter.sol @@ -26,6 +26,8 @@ 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. @@ -136,8 +138,6 @@ 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 87171de1a3..79a1e61e63 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 SchemaLib_InvalidLength(schemas.length); + if (schemas.length > MAX_TOTAL_FIELDS) revert Schema_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 SchemaLib_StaticTypeAfterDynamicType(); + revert Schema_StaticTypeAfterDynamicType(); } unchecked { @@ -65,7 +65,7 @@ library SchemaLib { } // Require MAX_DYNAMIC_FIELDS - if (dynamicFields > MAX_DYNAMIC_FIELDS) revert SchemaLib_InvalidLength(dynamicFields); + if (dynamicFields > MAX_DYNAMIC_FIELDS) revert Schema_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 SchemaLib.SchemaLib_InvalidLength(0); + if (!allowEmpty && schema.isEmpty()) revert Schema_InvalidLength(0); // Schema must have no more than MAX_DYNAMIC_FIELDS uint256 _numDynamicFields = schema.numDynamicFields(); - if (_numDynamicFields > MAX_DYNAMIC_FIELDS) revert SchemaLib.SchemaLib_InvalidLength(_numDynamicFields); + if (_numDynamicFields > MAX_DYNAMIC_FIELDS) revert Schema_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 SchemaLib.SchemaLib_InvalidLength(_numTotalFields); + if (_numTotalFields > MAX_TOTAL_FIELDS) revert Schema_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 SchemaLib.SchemaLib_StaticTypeAfterDynamicType(); + revert Schema_StaticTypeAfterDynamicType(); } _staticDataLength += staticByteLength; unchecked { @@ -183,14 +183,14 @@ library SchemaInstance { // Static length sums must match if (_staticDataLength != schema.staticDataLength()) { - revert SchemaLib.SchemaLib_InvalidLength(schema.staticDataLength()); + revert Schema_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 SchemaLib.SchemaLib_StaticTypeAfterDynamicType(); + revert Schema_StaticTypeAfterDynamicType(); } unchecked { i++; diff --git a/packages/store/src/Slice.sol b/packages/store/src/Slice.sol index cce6cab687..3f2d0598ec 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 7463af8880..48f0e54562 100644 --- a/packages/store/src/StoreHook.sol +++ b/packages/store/src/StoreHook.sol @@ -6,6 +6,7 @@ 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 66ab6e5307..d4f1d0e4af 100644 --- a/packages/store/src/errors.sol +++ b/packages/store/src/errors.sol @@ -17,3 +17,6 @@ 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 915d96618f..45320b4243 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 { FieldLayout, FieldLayoutLib } from "../src/FieldLayout.sol"; +import "../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(FieldLayoutLib.FieldLayoutLib_StaticLengthIsZero.selector, 1)); + vm.expectRevert(abi.encodeWithSelector(FieldLayout_StaticLengthIsZero.selector, 1)); FieldLayoutEncodeHelper.encode(1, 0, 1); } function testInvalidFieldLayoutStaticTypeDoesNotFitInAWord() public { - vm.expectRevert(abi.encodeWithSelector(FieldLayoutLib.FieldLayoutLib_StaticLengthDoesNotFitInAWord.selector, 1)); + vm.expectRevert(abi.encodeWithSelector(FieldLayout_StaticLengthDoesNotFitInAWord.selector, 1)); FieldLayoutEncodeHelper.encode(1, 33, 1); } @@ -96,11 +96,7 @@ contract FieldLayoutTest is Test, GasReporter { fieldLayout[15] = 32; fieldLayout[16] = 32; vm.expectRevert( - abi.encodeWithSelector( - FieldLayoutLib.FieldLayoutLib_TooManyFields.selector, - fieldLayout.length + dynamicFields, - MAX_TOTAL_FIELDS - ) + abi.encodeWithSelector(FieldLayout_TooManyFields.selector, fieldLayout.length + dynamicFields, MAX_TOTAL_FIELDS) ); FieldLayoutLib.encode(fieldLayout, dynamicFields); } @@ -117,7 +113,7 @@ contract FieldLayoutTest is Test, GasReporter { uint256 dynamicFields = 6; vm.expectRevert( abi.encodeWithSelector( - FieldLayoutLib.FieldLayoutLib_TooManyDynamicFields.selector, + FieldLayout_TooManyDynamicFields.selector, fieldLayout.length + dynamicFields, MAX_DYNAMIC_FIELDS ) @@ -202,7 +198,7 @@ contract FieldLayoutTest is Test, GasReporter { vm.expectRevert( abi.encodeWithSelector( - FieldLayoutLib.FieldLayoutLib_TooManyDynamicFields.selector, + FieldLayout_TooManyDynamicFields.selector, encodedFieldLayout.numDynamicFields(), MAX_DYNAMIC_FIELDS ) diff --git a/packages/store/test/Schema.t.sol b/packages/store/test/Schema.t.sol index 3762448b0c..2d57642fd0 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 { Schema, SchemaLib } from "../src/Schema.sol"; +import "../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(SchemaLib.SchemaLib_StaticTypeAfterDynamicType.selector)); + vm.expectRevert(abi.encodeWithSelector(Schema_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(SchemaLib.SchemaLib_InvalidLength.selector, schema.length)); + vm.expectRevert(abi.encodeWithSelector(Schema_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(SchemaLib.SchemaLib_InvalidLength.selector, schema.length)); + vm.expectRevert(abi.encodeWithSelector(Schema_InvalidLength.selector, schema.length)); SchemaLib.encode(schema); } @@ -295,9 +295,7 @@ contract SchemaTest is Test, GasReporter { function testValidateInvalidLength() public { Schema encodedSchema = Schema.wrap(keccak256("some invalid schema")); - vm.expectRevert( - abi.encodeWithSelector(SchemaLib.SchemaLib_InvalidLength.selector, encodedSchema.numDynamicFields()) - ); + vm.expectRevert(abi.encodeWithSelector(Schema_InvalidLength.selector, encodedSchema.numDynamicFields())); encodedSchema.validate({ allowEmpty: false }); } @@ -334,7 +332,7 @@ contract SchemaTest is Test, GasReporter { schema[27] = SchemaType.UINT32_ARRAY; Schema encodedSchema = encodeUnsafe(schema); - vm.expectRevert(SchemaLib.SchemaLib_StaticTypeAfterDynamicType.selector); + vm.expectRevert(Schema_StaticTypeAfterDynamicType.selector); encodedSchema.validate({ allowEmpty: false }); } diff --git a/packages/store/test/StoreCore.t.sol b/packages/store/test/StoreCore.t.sol index f2687ef941..2aa63add03 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 } from "../src/FieldLayout.sol"; +import { FieldLayout, FieldLayoutLib, FieldLayout_TooManyDynamicFields } from "../src/FieldLayout.sol"; import { Schema } from "../src/Schema.sol"; import { PackedCounter, PackedCounterLib } from "../src/PackedCounter.sol"; import { StoreMock } from "../test/StoreMock.sol"; @@ -129,11 +129,7 @@ contract StoreCoreTest is Test, StoreMock { FieldLayout invalidFieldLayout = FieldLayout.wrap(keccak256("random bytes as value field layout")); vm.expectRevert( - abi.encodeWithSelector( - FieldLayoutLib.FieldLayoutLib_TooManyDynamicFields.selector, - invalidFieldLayout.numDynamicFields(), - 5 - ) + abi.encodeWithSelector(FieldLayout_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 3fce7e97cd..73c894d9cd 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"; -contract ERC20Module is Module { - error ERC20Module_InvalidNamespace(bytes14 namespace); +error ERC20Module_InvalidNamespace(bytes14 namespace); +contract ERC20Module is Module { 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 78e7c5ef91..6961d4e376 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"; -contract ERC721Module is Module { - error ERC721Module_InvalidNamespace(bytes14 namespace); +error ERC721Module_InvalidNamespace(bytes14 namespace); +contract ERC721Module is Module { 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 2ae3f68c7d..492d4d9ab5 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"; -contract Puppet { - error Puppet_AccessDenied(address caller); +error Puppet_AccessDenied(address caller); +contract Puppet { 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 c001a24799..7cda2adf98 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"; -contract PuppetMaster { - error PuppetMaster_NoPuppet(address systemAddress, ResourceId systemId); +error PuppetMaster_NoPuppet(address systemAddress, ResourceId systemId); +contract PuppetMaster { function puppet() internal view returns (Puppet) { ResourceId systemId = SystemRegistry.getSystemId(address(this)); address puppetAddress = PuppetRegistry.get(PUPPET_TABLE_ID, systemId);