From 6f6e8a147094f01585840c66ef41f2db36f3f2b1 Mon Sep 17 00:00:00 2001 From: alvrs Date: Thu, 21 Sep 2023 22:52:46 +0100 Subject: [PATCH 01/12] module errors --- packages/world/src/interfaces/IModule.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/world/src/interfaces/IModule.sol b/packages/world/src/interfaces/IModule.sol index e94fcbfdfa..f67e27f7d5 100644 --- a/packages/world/src/interfaces/IModule.sol +++ b/packages/world/src/interfaces/IModule.sol @@ -10,7 +10,7 @@ bytes4 constant MODULE_INTERFACE_ID = IModule.getName.selector ^ ERC165_INTERFACE_ID; interface IModule is IERC165 { - error RootInstallModeNotSupported(); + error RootInstallNotSupported(); error NonRootInstallNotSupported(); /** From 365b85176fc5bd731f18346fa0b9a9688dfa682a Mon Sep 17 00:00:00 2001 From: alvrs Date: Thu, 21 Sep 2023 22:56:54 +0100 Subject: [PATCH 02/12] store errors --- packages/store/src/IStoreErrors.sol | 23 +++++++++--------- packages/store/src/StoreCore.sol | 36 ++++++++++++++--------------- packages/store/test/StoreCore.t.sol | 26 ++++++++------------- packages/world/test/World.t.sol | 6 ++--- 4 files changed, 41 insertions(+), 50 deletions(-) diff --git a/packages/store/src/IStoreErrors.sol b/packages/store/src/IStoreErrors.sol index 239d064035..e75591d41f 100644 --- a/packages/store/src/IStoreErrors.sol +++ b/packages/store/src/IStoreErrors.sol @@ -5,17 +5,16 @@ import { ResourceId } from "./ResourceId.sol"; interface IStoreErrors { // Errors include a stringified version of the tableId for easier debugging if cleartext tableIds are used - error StoreCore_TableAlreadyExists(ResourceId tableId, string tableIdString); - error StoreCore_TableNotFound(ResourceId tableId, string tableIdString); - error StoreCore_InvalidResourceType(bytes2 expected, ResourceId resourceId, string resourceIdString); + error Store_TableAlreadyExists(ResourceId tableId, string tableIdString); + error Store_TableNotFound(ResourceId tableId, string tableIdString); + error Store_InvalidResourceType(bytes2 expected, ResourceId resourceId, string resourceIdString); - error StoreCore_NotImplemented(); - error StoreCore_NotDynamicField(); - error StoreCore_InvalidStaticDataLength(uint256 expected, uint256 received); - error StoreCore_InvalidDynamicDataLength(uint256 expected, uint256 received); - error StoreCore_InvalidKeyNamesLength(uint256 expected, uint256 received); - error StoreCore_InvalidFieldNamesLength(uint256 expected, uint256 received); - error StoreCore_InvalidValueSchemaLength(uint256 expected, uint256 received); - error StoreCore_DataIndexOverflow(uint256 length, uint256 received); - error StoreCore_InvalidSplice(uint40 startWithinField, uint40 deleteCount, uint40 fieldLength); + error Store_NotDynamicField(); + error Store_InvalidStaticDataLength(uint256 expected, uint256 received); + error Store_InvalidDynamicDataLength(uint256 expected, uint256 received); + error Store_InvalidKeyNamesLength(uint256 expected, uint256 received); + error Store_InvalidFieldNamesLength(uint256 expected, uint256 received); + error Store_InvalidValueSchemaLength(uint256 expected, uint256 received); + error Store_DataIndexOverflow(uint256 length, uint256 received); + error Store_InvalidSplice(uint40 startWithinField, uint40 deleteCount, uint40 fieldLength); } diff --git a/packages/store/src/StoreCore.sol b/packages/store/src/StoreCore.sol index 4db4bb6d1a..c87059a9aa 100644 --- a/packages/store/src/StoreCore.sol +++ b/packages/store/src/StoreCore.sol @@ -88,7 +88,7 @@ library StoreCore { function getFieldLayout(ResourceId tableId) internal view returns (FieldLayout fieldLayout) { fieldLayout = FieldLayout.wrap(Tables._getFieldLayout(ResourceId.unwrap(tableId))); if (fieldLayout.isEmpty()) { - revert IStoreErrors.StoreCore_TableNotFound(tableId, string(abi.encodePacked(tableId))); + revert IStoreErrors.Store_TableNotFound(tableId, string(abi.encodePacked(tableId))); } } @@ -99,7 +99,7 @@ library StoreCore { keySchema = Schema.wrap(Tables._getKeySchema(ResourceId.unwrap(tableId))); // key schemas can be empty for singleton tables, so we can't depend on key schema for table check if (!ResourceIds._getExists(ResourceId.unwrap(tableId))) { - revert IStoreErrors.StoreCore_TableNotFound(tableId, string(abi.encodePacked(tableId))); + revert IStoreErrors.Store_TableNotFound(tableId, string(abi.encodePacked(tableId))); } } @@ -109,7 +109,7 @@ library StoreCore { function getValueSchema(ResourceId tableId) internal view returns (Schema valueSchema) { valueSchema = Schema.wrap(Tables._getValueSchema(ResourceId.unwrap(tableId))); if (valueSchema.isEmpty()) { - revert IStoreErrors.StoreCore_TableNotFound(tableId, string(abi.encodePacked(tableId))); + revert IStoreErrors.Store_TableNotFound(tableId, string(abi.encodePacked(tableId))); } } @@ -126,7 +126,7 @@ library StoreCore { ) internal { // Verify the table ID is of type RESOURCE_TABLE if (tableId.getType() != RESOURCE_TABLE && tableId.getType() != RESOURCE_OFFCHAIN_TABLE) { - revert IStoreErrors.StoreCore_InvalidResourceType(RESOURCE_TABLE, tableId, string(abi.encodePacked(tableId))); + revert IStoreErrors.Store_InvalidResourceType(RESOURCE_TABLE, tableId, string(abi.encodePacked(tableId))); } // Verify the field layout is valid @@ -138,22 +138,22 @@ library StoreCore { // Verify the number of key names matches the number of key schema types if (keyNames.length != keySchema.numFields()) { - revert IStoreErrors.StoreCore_InvalidKeyNamesLength(keySchema.numFields(), keyNames.length); + revert IStoreErrors.Store_InvalidKeyNamesLength(keySchema.numFields(), keyNames.length); } // Verify the number of value names if (fieldNames.length != fieldLayout.numFields()) { - revert IStoreErrors.StoreCore_InvalidFieldNamesLength(fieldLayout.numFields(), fieldNames.length); + revert IStoreErrors.Store_InvalidFieldNamesLength(fieldLayout.numFields(), fieldNames.length); } // Verify the number of value schema types if (valueSchema.numFields() != fieldLayout.numFields()) { - revert IStoreErrors.StoreCore_InvalidValueSchemaLength(fieldLayout.numFields(), valueSchema.numFields()); + revert IStoreErrors.Store_InvalidValueSchemaLength(fieldLayout.numFields(), valueSchema.numFields()); } // Verify there is no resource with this ID yet if (ResourceIds._getExists(ResourceId.unwrap(tableId))) { - revert IStoreErrors.StoreCore_TableAlreadyExists(tableId, string(abi.encodePacked(tableId))); + revert IStoreErrors.Store_TableAlreadyExists(tableId, string(abi.encodePacked(tableId))); } // Register the table metadata @@ -182,7 +182,7 @@ library StoreCore { function registerStoreHook(ResourceId tableId, IStoreHook hookAddress, uint8 enabledHooksBitmap) internal { // Hooks are only supported for tables, not for offchain tables if (tableId.getType() != RESOURCE_TABLE) { - revert IStoreErrors.StoreCore_InvalidResourceType(RESOURCE_TABLE, tableId, string(abi.encodePacked(tableId))); + revert IStoreErrors.Store_InvalidResourceType(RESOURCE_TABLE, tableId, string(abi.encodePacked(tableId))); } StoreHooks.push(ResourceId.unwrap(tableId), Hook.unwrap(HookLib.encode(address(hookAddress), enabledHooksBitmap))); @@ -476,7 +476,7 @@ library StoreCore { FieldLayout fieldLayout ) internal { if (fieldIndex < fieldLayout.numStaticFields()) { - revert IStoreErrors.StoreCore_NotDynamicField(); + revert IStoreErrors.Store_NotDynamicField(); } StoreCoreInternal._pushToDynamicField(tableId, keyTuple, fieldLayout, fieldIndex, dataToPush); @@ -493,7 +493,7 @@ library StoreCore { FieldLayout fieldLayout ) internal { if (fieldIndex < fieldLayout.numStaticFields()) { - revert IStoreErrors.StoreCore_NotDynamicField(); + revert IStoreErrors.Store_NotDynamicField(); } StoreCoreInternal._popFromDynamicField(tableId, keyTuple, fieldLayout, fieldIndex, byteLengthToPop); @@ -511,13 +511,13 @@ library StoreCore { FieldLayout fieldLayout ) internal { if (fieldIndex < fieldLayout.numStaticFields()) { - revert IStoreErrors.StoreCore_NotDynamicField(); + revert IStoreErrors.Store_NotDynamicField(); } // index must be checked because it could be arbitrarily large // (but dataToSet.length can be unchecked - it won't overflow into another slot due to gas costs and hashed slots) if (startByteIndex > type(uint40).max) { - revert IStoreErrors.StoreCore_DataIndexOverflow(type(uint40).max, startByteIndex); + revert IStoreErrors.Store_DataIndexOverflow(type(uint40).max, startByteIndex); } StoreCoreInternal._setDynamicFieldItem(tableId, keyTuple, fieldLayout, fieldIndex, startByteIndex, dataToSet); @@ -651,7 +651,7 @@ library StoreCore { ) internal view returns (bytes memory) { uint8 numStaticFields = uint8(fieldLayout.numStaticFields()); if (fieldIndex < fieldLayout.numStaticFields()) { - revert IStoreErrors.StoreCore_NotDynamicField(); + revert IStoreErrors.Store_NotDynamicField(); } // Get the length and storage location of the dynamic field @@ -687,7 +687,7 @@ library StoreCoreInternal { // Splicing dynamic data is not supported for offchain tables, because it // requires reading the previous encoded lengths from storage if (tableId.getType() != RESOURCE_TABLE) { - revert IStoreErrors.StoreCore_InvalidResourceType(RESOURCE_TABLE, tableId, string(abi.encodePacked(tableId))); + revert IStoreErrors.Store_InvalidResourceType(RESOURCE_TABLE, tableId, string(abi.encodePacked(tableId))); } uint256 previousFieldLength = previousEncodedLengths.atIndex(dynamicFieldIndex); @@ -696,7 +696,7 @@ library StoreCoreInternal { // If the total length of the field is changed, the data has to be appended/removed at the end of the field. // Otherwise offchain indexers would shift the data after inserted data, while onchain the data is truncated at the end. if (previousFieldLength != updatedFieldLength && startWithinField + deleteCount != previousFieldLength) { - revert IStoreErrors.StoreCore_InvalidSplice(startWithinField, deleteCount, uint40(previousFieldLength)); + revert IStoreErrors.Store_InvalidSplice(startWithinField, deleteCount, uint40(previousFieldLength)); } // Compute start index for the splice @@ -894,10 +894,10 @@ library StoreCoreInternal { bytes memory dynamicData ) internal pure { if (fieldLayout.staticDataLength() != staticData.length) { - revert IStoreErrors.StoreCore_InvalidStaticDataLength(fieldLayout.staticDataLength(), staticData.length); + revert IStoreErrors.Store_InvalidStaticDataLength(fieldLayout.staticDataLength(), staticData.length); } if (encodedLengths.total() != dynamicData.length) { - revert IStoreErrors.StoreCore_InvalidDynamicDataLength(encodedLengths.total(), dynamicData.length); + revert IStoreErrors.Store_InvalidDynamicDataLength(encodedLengths.total(), dynamicData.length); } } diff --git a/packages/store/test/StoreCore.t.sol b/packages/store/test/StoreCore.t.sol index f72f690876..f429d92739 100644 --- a/packages/store/test/StoreCore.t.sol +++ b/packages/store/test/StoreCore.t.sol @@ -105,7 +105,7 @@ contract StoreCoreTest is Test, StoreMock { // Expect a revert when registering a table that already exists vm.expectRevert( abi.encodeWithSelector( - IStoreErrors.StoreCore_TableAlreadyExists.selector, + IStoreErrors.Store_TableAlreadyExists.selector, ResourceId.unwrap(tableId), string(bytes.concat(ResourceId.unwrap(tableId))) ) @@ -142,7 +142,7 @@ contract StoreCoreTest is Test, StoreMock { vm.expectRevert( abi.encodeWithSelector( - IStoreErrors.StoreCore_InvalidResourceType.selector, + IStoreErrors.Store_InvalidResourceType.selector, RESOURCE_TABLE, invalidTableId, string(abi.encodePacked(invalidTableId)) @@ -182,7 +182,7 @@ contract StoreCoreTest is Test, StoreMock { vm.expectRevert( abi.encodeWithSelector( - IStoreErrors.StoreCore_TableNotFound.selector, + IStoreErrors.Store_TableNotFound.selector, tableId2, string(abi.encodePacked(ResourceId.unwrap(tableId2))) ) @@ -190,20 +190,12 @@ contract StoreCoreTest is Test, StoreMock { IStore(this).getFieldLayout(tableId2); vm.expectRevert( - abi.encodeWithSelector( - IStoreErrors.StoreCore_TableNotFound.selector, - tableId2, - string(abi.encodePacked(tableId2)) - ) + abi.encodeWithSelector(IStoreErrors.Store_TableNotFound.selector, tableId2, string(abi.encodePacked(tableId2))) ); IStore(this).getValueSchema(tableId2); vm.expectRevert( - abi.encodeWithSelector( - IStoreErrors.StoreCore_TableNotFound.selector, - tableId2, - string(abi.encodePacked(tableId2)) - ) + abi.encodeWithSelector(IStoreErrors.Store_TableNotFound.selector, tableId2, string(abi.encodePacked(tableId2))) ); IStore(this).getKeySchema(tableId2); } @@ -223,11 +215,11 @@ contract StoreCoreTest is Test, StoreMock { string[] memory oneName = new string[](1); // Register table with invalid key names - vm.expectRevert(abi.encodeWithSelector(IStoreErrors.StoreCore_InvalidKeyNamesLength.selector, 4, 1)); + vm.expectRevert(abi.encodeWithSelector(IStoreErrors.Store_InvalidKeyNamesLength.selector, 4, 1)); IStore(this).registerTable(tableId, fieldLayout, keySchema, valueSchema, oneName, oneName); // Register table with invalid value names - vm.expectRevert(abi.encodeWithSelector(IStoreErrors.StoreCore_InvalidFieldNamesLength.selector, 1, 4)); + vm.expectRevert(abi.encodeWithSelector(IStoreErrors.Store_InvalidFieldNamesLength.selector, 1, 4)); IStore(this).registerTable(tableId, fieldLayout, keySchema, valueSchema, fourNames, fourNames); } @@ -333,7 +325,7 @@ contract StoreCoreTest is Test, StoreMock { keyTuple[0] = "some key"; // This should fail because the data is not 6 bytes long - vm.expectRevert(abi.encodeWithSelector(IStoreErrors.StoreCore_InvalidStaticDataLength.selector, 6, 4)); + vm.expectRevert(abi.encodeWithSelector(IStoreErrors.Store_InvalidStaticDataLength.selector, 6, 4)); IStore(this).setRecord(tableId, keyTuple, staticData, PackedCounter.wrap(bytes32(0)), new bytes(0), fieldLayout); } @@ -1051,7 +1043,7 @@ contract StoreCoreTest is Test, StoreMock { // startByteIndex must not overflow vm.expectRevert( - abi.encodeWithSelector(IStoreErrors.StoreCore_DataIndexOverflow.selector, type(uint40).max, type(uint56).max) + abi.encodeWithSelector(IStoreErrors.Store_DataIndexOverflow.selector, type(uint40).max, type(uint56).max) ); IStore(this).updateInField(data.tableId, data.keyTuple, 2, type(uint56).max, data.thirdDataForUpdate, fieldLayout); } diff --git a/packages/world/test/World.t.sol b/packages/world/test/World.t.sol index 451d3861dd..5cb7b44cfb 100644 --- a/packages/world/test/World.t.sol +++ b/packages/world/test/World.t.sol @@ -435,7 +435,7 @@ contract WorldTest is Test, GasReporter { // Expect an error when registering an existing table vm.expectRevert( abi.encodeWithSelector( - IStoreErrors.StoreCore_TableAlreadyExists.selector, + IStoreErrors.Store_TableAlreadyExists.selector, tableId, string(bytes.concat(ResourceId.unwrap(tableId))) ) @@ -646,7 +646,7 @@ contract WorldTest is Test, GasReporter { // Expect an error when trying to register a table at the same ID vm.expectRevert( abi.encodeWithSelector( - IStoreErrors.StoreCore_InvalidResourceType.selector, + IStoreErrors.Store_InvalidResourceType.selector, RESOURCE_TABLE, systemId, string(abi.encodePacked(systemId)) @@ -664,7 +664,7 @@ contract WorldTest is Test, GasReporter { // Expect an error when trying to register a new table at an existing table ID vm.expectRevert( abi.encodeWithSelector( - IStoreErrors.StoreCore_TableAlreadyExists.selector, + IStoreErrors.Store_TableAlreadyExists.selector, ResourceId.unwrap(tableId), string(bytes.concat(ResourceId.unwrap(tableId))) ) From e3645e6c6250b4b1ca60633f345d2a13d3ca7910 Mon Sep 17 00:00:00 2001 From: alvrs Date: Thu, 21 Sep 2023 23:02:37 +0100 Subject: [PATCH 03/12] world errors --- packages/world/src/AccessControl.sol | 8 +-- packages/world/src/SystemCall.sol | 2 +- packages/world/src/World.sol | 8 +-- .../world/src/interfaces/IWorldErrors.sol | 26 +++---- .../implementations/BalanceTransferSystem.sol | 6 +- .../StoreRegistrationSystem.sol | 2 +- .../WorldRegistrationSystem.sol | 14 ++-- packages/world/src/requireInterface.sol | 4 +- packages/world/test/AccessControl.t.sol | 2 +- .../test/StandardDelegationsModule.t.sol | 8 +-- packages/world/test/UniqueEntityModule.t.sol | 2 +- packages/world/test/World.t.sol | 72 +++++++++++-------- packages/world/test/WorldBalance.t.sol | 22 +++--- packages/world/test/WorldDynamicUpdate.t.sol | 8 +-- 14 files changed, 101 insertions(+), 83 deletions(-) diff --git a/packages/world/src/AccessControl.sol b/packages/world/src/AccessControl.sol index cb8284f321..2b57c5f581 100644 --- a/packages/world/src/AccessControl.sol +++ b/packages/world/src/AccessControl.sol @@ -21,22 +21,22 @@ library AccessControl { /** * Check for access at the given namespace or name. - * Reverts with AccessDenied if the caller has no access. + * Reverts with World_AccessDenied if the caller has no access. */ function requireAccess(ResourceId resourceId, address caller) internal view { // Check if the given caller has access to the given namespace or name if (!hasAccess(resourceId, caller)) { - revert IWorldErrors.AccessDenied(resourceId.toString(), caller); + revert IWorldErrors.World_AccessDenied(resourceId.toString(), caller); } } /** * Check for ownership of the namespace of the given resource ID. - * Reverts with AccessDenied if the check fails. + * Reverts with World_AccessDenied if the check fails. */ function requireOwner(ResourceId resourceId, address caller) internal view { if (NamespaceOwner._get(ResourceId.unwrap(resourceId.getNamespaceId())) != caller) { - revert IWorldErrors.AccessDenied(resourceId.toString(), caller); + revert IWorldErrors.World_AccessDenied(resourceId.toString(), caller); } } } diff --git a/packages/world/src/SystemCall.sol b/packages/world/src/SystemCall.sol index 50446dd14c..0a241c86eb 100644 --- a/packages/world/src/SystemCall.sol +++ b/packages/world/src/SystemCall.sol @@ -36,7 +36,7 @@ library SystemCall { (address systemAddress, bool publicAccess) = Systems._get(ResourceId.unwrap(systemId)); // Check if the system exists - if (systemAddress == address(0)) revert IWorldErrors.ResourceNotFound(systemId, systemId.toString()); + if (systemAddress == address(0)) revert IWorldErrors.World_ResourceNotFound(systemId, systemId.toString()); // Allow access if the system is public or the caller has access to the namespace or name if (!publicAccess) AccessControl.requireAccess(systemId, caller); diff --git a/packages/world/src/World.sol b/packages/world/src/World.sol index 9627fea7cf..7ddbf969c4 100644 --- a/packages/world/src/World.sol +++ b/packages/world/src/World.sol @@ -65,12 +65,12 @@ contract World is StoreRead, IStoreData, IWorldKernel { function initialize(IModule coreModule) public requireNoCallback { // Only the initial creator of the World can initialize it if (msg.sender != creator) { - revert AccessDenied(ROOT_NAMESPACE_ID.toString(), msg.sender); + revert World_AccessDenied(ROOT_NAMESPACE_ID.toString(), msg.sender); } // The World can only be initialized once if (InstalledModules._get(CORE_MODULE_NAME, keccak256("")) != address(0)) { - revert WorldAlreadyInitialized(); + revert World_AlreadyInitialized(); } // Initialize the World by installing the core module @@ -291,7 +291,7 @@ contract World is StoreRead, IStoreData, IWorldKernel { return SystemCall.callWithHooksOrRevert(delegator, systemId, callData, msg.value); } - revert DelegationNotFound(delegator, msg.sender); + revert World_DelegationNotFound(delegator, msg.sender); } /************************************************************************ @@ -314,7 +314,7 @@ contract World is StoreRead, IStoreData, IWorldKernel { fallback() external payable requireNoCallback { (bytes32 systemId, bytes4 systemFunctionSelector) = FunctionSelectors._get(msg.sig); - if (systemId == 0) revert FunctionSelectorNotFound(msg.sig); + if (systemId == 0) revert World_FunctionSelectorNotFound(msg.sig); // Replace function selector in the calldata with the system function selector bytes memory callData = Bytes.setBytes4(msg.data, 0, systemFunctionSelector); diff --git a/packages/world/src/interfaces/IWorldErrors.sol b/packages/world/src/interfaces/IWorldErrors.sol index 2df3bfcb46..5cff530663 100644 --- a/packages/world/src/interfaces/IWorldErrors.sol +++ b/packages/world/src/interfaces/IWorldErrors.sol @@ -4,17 +4,17 @@ pragma solidity >=0.8.21; import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; interface IWorldErrors { - error WorldAlreadyInitialized(); - error ResourceExists(ResourceId resourceId, string resourceIdString); - error ResourceNotFound(ResourceId resourceId, string resourceIdString); - error AccessDenied(string resource, address caller); - error InvalidResourceId(ResourceId resourceId, string resourceIdString); - error SystemExists(address system); - error FunctionSelectorExists(bytes4 functionSelector); - error FunctionSelectorNotFound(bytes4 functionSelector); - error DelegationNotFound(address delegator, address delegatee); - error InsufficientBalance(uint256 balance, uint256 amount); - error InterfaceNotSupported(address contractAddress, bytes4 interfaceId); - error InvalidResourceType(bytes2 expected, ResourceId resourceId, string resourceIdString); - error WorldCallbackNotAllowed(bytes4 functionSelector); + error World_AlreadyInitialized(); + error World_ResourceAlreadyExists(ResourceId resourceId, string resourceIdString); + error World_ResourceNotFound(ResourceId resourceId, string resourceIdString); + error World_AccessDenied(string resource, address caller); + error World_InvalidResourceId(ResourceId resourceId, string resourceIdString); + error World_SystemAlreadyExists(address system); + error World_FunctionSelectorAlreadyExists(bytes4 functionSelector); + error World_FunctionSelectorNotFound(bytes4 functionSelector); + error World_DelegationNotFound(address delegator, address delegatee); + error World_InsufficientBalance(uint256 balance, uint256 amount); + error World_InterfaceNotSupported(address contractAddress, bytes4 interfaceId); + error World_InvalidResourceType(bytes2 expected, ResourceId resourceId, string resourceIdString); + error World_CallbackNotAllowed(bytes4 functionSelector); } diff --git a/packages/world/src/modules/core/implementations/BalanceTransferSystem.sol b/packages/world/src/modules/core/implementations/BalanceTransferSystem.sol index 3b1a59bbdc..9bae047ac2 100644 --- a/packages/world/src/modules/core/implementations/BalanceTransferSystem.sol +++ b/packages/world/src/modules/core/implementations/BalanceTransferSystem.sol @@ -26,7 +26,7 @@ contract BalanceTransferSystem is System, IWorldErrors { ) public virtual { // Require the target ID to be a namespace ID if (toNamespaceId.getType() != RESOURCE_NAMESPACE) { - revert InvalidResourceType(RESOURCE_NAMESPACE, toNamespaceId, toNamespaceId.toString()); + revert World_InvalidResourceType(RESOURCE_NAMESPACE, toNamespaceId, toNamespaceId.toString()); } // Require caller to have access to the namespace @@ -36,7 +36,7 @@ contract BalanceTransferSystem is System, IWorldErrors { uint256 balance = Balances._get(ResourceId.unwrap(fromNamespaceId)); // Require the balance balance to be greater or equal to the amount to transfer - if (amount > balance) revert InsufficientBalance(balance, amount); + if (amount > balance) revert World_InsufficientBalance(balance, amount); // Update the balances Balances._set(ResourceId.unwrap(fromNamespaceId), balance - amount); @@ -54,7 +54,7 @@ contract BalanceTransferSystem is System, IWorldErrors { uint256 balance = Balances._get(ResourceId.unwrap(fromNamespaceId)); // Require the balance balance to be greater or equal to the amount to transfer - if (amount > balance) revert InsufficientBalance(balance, amount); + if (amount > balance) revert World_InsufficientBalance(balance, amount); // Update the balances Balances._set(ResourceId.unwrap(fromNamespaceId), balance - amount); diff --git a/packages/world/src/modules/core/implementations/StoreRegistrationSystem.sol b/packages/world/src/modules/core/implementations/StoreRegistrationSystem.sol index 9b91816493..65c20fc66d 100644 --- a/packages/world/src/modules/core/implementations/StoreRegistrationSystem.sol +++ b/packages/world/src/modules/core/implementations/StoreRegistrationSystem.sol @@ -45,7 +45,7 @@ contract StoreRegistrationSystem is System, IWorldErrors { string[] calldata fieldNames ) public virtual { // Require the name to not be the namespace's root name - if (tableId.getName() == ROOT_NAME) revert InvalidResourceId(tableId, tableId.toString()); + if (tableId.getName() == ROOT_NAME) revert World_InvalidResourceId(tableId, tableId.toString()); // If the namespace doesn't exist yet, register it ResourceId namespaceId = tableId.getNamespaceId(); diff --git a/packages/world/src/modules/core/implementations/WorldRegistrationSystem.sol b/packages/world/src/modules/core/implementations/WorldRegistrationSystem.sol index 9a08b90f29..6ee8391a33 100644 --- a/packages/world/src/modules/core/implementations/WorldRegistrationSystem.sol +++ b/packages/world/src/modules/core/implementations/WorldRegistrationSystem.sol @@ -39,12 +39,12 @@ contract WorldRegistrationSystem is System, IWorldErrors { function registerNamespace(ResourceId namespaceId) public virtual { // Require the provided namespace ID to have type RESOURCE_NAMESPACE if (namespaceId.getType() != RESOURCE_NAMESPACE) { - revert InvalidResourceType(RESOURCE_NAMESPACE, namespaceId, namespaceId.toString()); + revert World_InvalidResourceType(RESOURCE_NAMESPACE, namespaceId, namespaceId.toString()); } // Require namespace to not exist yet if (ResourceIds._getExists(ResourceId.unwrap(namespaceId))) { - revert ResourceExists(namespaceId, namespaceId.toString()); + revert World_ResourceAlreadyExists(namespaceId, namespaceId.toString()); } // Register namespace resource ID @@ -97,19 +97,19 @@ contract WorldRegistrationSystem is System, IWorldErrors { function registerSystem(ResourceId systemId, WorldContextConsumer system, bool publicAccess) public virtual { // Require the provided system ID to have type RESOURCE_SYSTEM if (systemId.getType() != RESOURCE_SYSTEM) { - revert InvalidResourceType(RESOURCE_SYSTEM, systemId, systemId.toString()); + revert World_InvalidResourceType(RESOURCE_SYSTEM, systemId, systemId.toString()); } // Require the provided address to implement the WorldContextConsumer interface requireInterface(address(system), WORLD_CONTEXT_CONSUMER_INTERFACE_ID); // Require the name to not be the namespace's root name - if (systemId.getName() == ROOT_NAME) revert InvalidResourceId(systemId, systemId.toString()); + if (systemId.getName() == ROOT_NAME) revert World_InvalidResourceId(systemId, systemId.toString()); // Require this system to not be registered at a different system ID yet bytes32 existingSystemId = SystemRegistry._get(address(system)); if (existingSystemId != 0 && existingSystemId != ResourceId.unwrap(systemId)) { - revert SystemExists(address(system)); + revert World_SystemAlreadyExists(address(system)); } // If the namespace doesn't exist yet, register it @@ -171,7 +171,7 @@ contract WorldRegistrationSystem is System, IWorldErrors { // Require the function selector to be globally unique bytes32 existingSystemId = FunctionSelectors._getSystemId(worldFunctionSelector); - if (existingSystemId != 0) revert FunctionSelectorExists(worldFunctionSelector); + if (existingSystemId != 0) revert World_FunctionSelectorAlreadyExists(worldFunctionSelector); // Register the function selector bytes memory systemFunctionSignature = abi.encodePacked(systemFunctionName, systemFunctionArguments); @@ -199,7 +199,7 @@ contract WorldRegistrationSystem is System, IWorldErrors { // Require the function selector to be globally unique bytes32 existingSystemId = FunctionSelectors._getSystemId(worldFunctionSelector); - if (existingSystemId != 0) revert FunctionSelectorExists(worldFunctionSelector); + if (existingSystemId != 0) revert World_FunctionSelectorAlreadyExists(worldFunctionSelector); // Register the function selector FunctionSelectors._set(worldFunctionSelector, ResourceId.unwrap(systemId), systemFunctionSelector); diff --git a/packages/world/src/requireInterface.sol b/packages/world/src/requireInterface.sol index 420d78f1b2..10c927e163 100644 --- a/packages/world/src/requireInterface.sol +++ b/packages/world/src/requireInterface.sol @@ -10,9 +10,9 @@ import { IWorldErrors } from "./interfaces/IWorldErrors.sol"; function requireInterface(address contractAddress, bytes4 interfaceId) view { try IERC165(contractAddress).supportsInterface(interfaceId) returns (bool supported) { if (!supported) { - revert IWorldErrors.InterfaceNotSupported(contractAddress, interfaceId); + revert IWorldErrors.World_InterfaceNotSupported(contractAddress, interfaceId); } } catch { - revert IWorldErrors.InterfaceNotSupported(contractAddress, interfaceId); + revert IWorldErrors.World_InterfaceNotSupported(contractAddress, interfaceId); } } diff --git a/packages/world/test/AccessControl.t.sol b/packages/world/test/AccessControl.t.sol index f571dc85d3..6a508a01b8 100644 --- a/packages/world/test/AccessControl.t.sol +++ b/packages/world/test/AccessControl.t.sol @@ -98,7 +98,7 @@ contract AccessControlTest is Test, GasReporter, StoreMock { function testRequireAccessRevert() public { ResourceId tableId = _tableId; - vm.expectRevert(abi.encodeWithSelector(IWorldErrors.AccessDenied.selector, tableId.toString(), caller)); + vm.expectRevert(abi.encodeWithSelector(IWorldErrors.World_AccessDenied.selector, tableId.toString(), caller)); AccessControl.requireAccess(tableId, caller); } } diff --git a/packages/world/test/StandardDelegationsModule.t.sol b/packages/world/test/StandardDelegationsModule.t.sol index 7b8b936fae..52b4bb5787 100644 --- a/packages/world/test/StandardDelegationsModule.t.sol +++ b/packages/world/test/StandardDelegationsModule.t.sol @@ -66,7 +66,7 @@ contract StandardDelegationsModuleTest is Test, GasReporter { // Expect the delegation to have been used up vm.prank(delegatee); - vm.expectRevert(abi.encodeWithSelector(IWorldErrors.DelegationNotFound.selector, delegator, delegatee)); + vm.expectRevert(abi.encodeWithSelector(IWorldErrors.World_DelegationNotFound.selector, delegator, delegatee)); world.callFrom(delegator, systemId, abi.encodeCall(WorldTestSystem.msgSender, ())); } @@ -104,11 +104,11 @@ contract StandardDelegationsModuleTest is Test, GasReporter { // Set the timestamp to maxTimestamp+1 and expect the delegation to be expired vm.warp(maxTimestamp + 1); vm.prank(delegatee); - vm.expectRevert(abi.encodeWithSelector(IWorldErrors.DelegationNotFound.selector, delegator, delegatee)); + vm.expectRevert(abi.encodeWithSelector(IWorldErrors.World_DelegationNotFound.selector, delegator, delegatee)); world.callFrom(delegator, systemId, abi.encodeCall(WorldTestSystem.msgSender, ())); } - function testRegisterDelegationRevertInterfaceNotSupported() public { + function testRegisterDelegationRevertWorld_InterfaceNotSupported() public { // Register a system that is not a delegation control system System noDelegationControlSystem = new System(); ResourceId noDelegationControlId = WorldResourceIdLib.encode({ @@ -122,7 +122,7 @@ contract StandardDelegationsModuleTest is Test, GasReporter { vm.prank(delegator); vm.expectRevert( abi.encodeWithSelector( - IWorldErrors.InterfaceNotSupported.selector, + IWorldErrors.World_InterfaceNotSupported.selector, address(noDelegationControlSystem), DELEGATION_CONTROL_INTERFACE_ID ) diff --git a/packages/world/test/UniqueEntityModule.t.sol b/packages/world/test/UniqueEntityModule.t.sol index ec150d0a0a..d9bec364d6 100644 --- a/packages/world/test/UniqueEntityModule.t.sol +++ b/packages/world/test/UniqueEntityModule.t.sol @@ -84,7 +84,7 @@ contract UniqueEntityModuleTest is Test, GasReporter { // But changing the table directly isn't allowed vm.expectRevert( abi.encodeWithSelector( - IWorldErrors.AccessDenied.selector, + IWorldErrors.World_AccessDenied.selector, WorldResourceIdLib.encode({ typeId: RESOURCE_TABLE, namespace: NAMESPACE, name: TABLE_NAME }).toString(), alice ) diff --git a/packages/world/test/World.t.sol b/packages/world/test/World.t.sol index 5cb7b44cfb..8d1402bb08 100644 --- a/packages/world/test/World.t.sol +++ b/packages/world/test/World.t.sol @@ -184,11 +184,11 @@ contract WorldTest is Test, GasReporter { } // Expect an error when trying to write from an address that doesn't have access - function _expectAccessDenied(address caller, bytes14 namespace, bytes16 name, bytes2 resourceType) internal { + function _expectWorld_AccessDenied(address caller, bytes14 namespace, bytes16 name, bytes2 resourceType) internal { vm.prank(caller); vm.expectRevert( abi.encodeWithSelector( - IWorldErrors.AccessDenied.selector, + IWorldErrors.World_AccessDenied.selector, WorldResourceIdLib.encode({ typeId: resourceType, namespace: namespace, name: name }).toString(), caller ) @@ -209,7 +209,7 @@ contract WorldTest is Test, GasReporter { vm.prank(address(0x4242)); vm.expectRevert( abi.encodeWithSelector( - IWorldErrors.AccessDenied.selector, + IWorldErrors.World_AccessDenied.selector, WorldResourceIdLib.encodeNamespace(ROOT_NAMESPACE).toString(), address(0x4242) ) @@ -248,15 +248,15 @@ contract WorldTest is Test, GasReporter { ); // Expect it to not be possible to initialize the World again - vm.expectRevert(abi.encodeWithSelector(IWorldErrors.WorldAlreadyInitialized.selector)); + vm.expectRevert(abi.encodeWithSelector(IWorldErrors.World_AlreadyInitialized.selector)); newWorld.initialize(coreModule); } - function testRegisterModuleRevertInterfaceNotSupported() public { + function testRegisterModuleRevertWorld_InterfaceNotSupported() public { // Expect an error when trying to register a module that doesn't implement the IModule interface vm.expectRevert( abi.encodeWithSelector( - IWorldErrors.InterfaceNotSupported.selector, + IWorldErrors.World_InterfaceNotSupported.selector, Module(address(world)), // The World contract does not implement the IModule interface MODULE_INTERFACE_ID ) @@ -266,7 +266,7 @@ contract WorldTest is Test, GasReporter { // Expect an error when trying to register a root module that doesn't implement the IModule interface vm.expectRevert( abi.encodeWithSelector( - IWorldErrors.InterfaceNotSupported.selector, + IWorldErrors.World_InterfaceNotSupported.selector, Module(address(world)), // The World contract does not implement the IModule interface MODULE_INTERFACE_ID ) @@ -323,7 +323,9 @@ contract WorldTest is Test, GasReporter { assertTrue(ResourceIds.getExists(world, ResourceId.unwrap(namespaceId))); // Expect an error when registering an existing namespace - vm.expectRevert(abi.encodeWithSelector(IWorldErrors.ResourceExists.selector, namespaceId, namespaceId.toString())); + vm.expectRevert( + abi.encodeWithSelector(IWorldErrors.World_ResourceAlreadyExists.selector, namespaceId, namespaceId.toString()) + ); world.registerNamespace(namespaceId); } @@ -337,7 +339,7 @@ contract WorldTest is Test, GasReporter { // Expect an error when trying to register a namespace with an invalid type vm.expectRevert( abi.encodeWithSelector( - IWorldErrors.InvalidResourceType.selector, + IWorldErrors.World_InvalidResourceType.selector, RESOURCE_NAMESPACE, invalidNamespaceId, invalidNamespaceId.toString() @@ -394,7 +396,7 @@ contract WorldTest is Test, GasReporter { ); // Expect revert if caller is not the owner - _expectAccessDenied(address(this), namespace, 0, RESOURCE_NAMESPACE); + _expectWorld_AccessDenied(address(this), namespace, 0, RESOURCE_NAMESPACE); world.transferOwnership(namespaceId, address(1)); } @@ -448,13 +450,13 @@ contract WorldTest is Test, GasReporter { namespace: namespace, name: "otherTable" }); - _expectAccessDenied(address(0x01), namespace, "", RESOURCE_NAMESPACE); + _expectWorld_AccessDenied(address(0x01), namespace, "", RESOURCE_NAMESPACE); world.registerTable(otherTableId, fieldLayout, defaultKeySchema, valueSchema, keyNames, fieldNames); // Expect the World to not be allowed to call registerTable via an external call vm.prank(address(world)); vm.expectRevert( - abi.encodeWithSelector(IWorldErrors.WorldCallbackNotAllowed.selector, world.registerTable.selector) + abi.encodeWithSelector(IWorldErrors.World_CallbackNotAllowed.selector, world.registerTable.selector) ); world.registerTable(otherTableId, fieldLayout, defaultKeySchema, valueSchema, keyNames, fieldNames); } @@ -510,7 +512,7 @@ contract WorldTest is Test, GasReporter { assertEq(NamespaceOwner.get(world, ResourceId.unwrap(newNamespaceId)), address(this)); // Expect an error when registering an existing system at a new system ID - vm.expectRevert(abi.encodeWithSelector(IWorldErrors.SystemExists.selector, address(system))); + vm.expectRevert(abi.encodeWithSelector(IWorldErrors.World_SystemAlreadyExists.selector, address(system))); world.registerSystem( WorldResourceIdLib.encode({ typeId: RESOURCE_SYSTEM, namespace: "", name: "newSystem" }), system, @@ -532,13 +534,18 @@ contract WorldTest is Test, GasReporter { new string[](1) ); vm.expectRevert( - abi.encodeWithSelector(IWorldErrors.InvalidResourceType.selector, RESOURCE_SYSTEM, tableId, tableId.toString()) + abi.encodeWithSelector( + IWorldErrors.World_InvalidResourceType.selector, + RESOURCE_SYSTEM, + tableId, + tableId.toString() + ) ); world.registerSystem(tableId, newSystem, true); // Expect an error when registering a system in a namespace that is not owned by the caller System yetAnotherSystem = new System(); - _expectAccessDenied(address(0x01), "", "", RESOURCE_NAMESPACE); + _expectWorld_AccessDenied(address(0x01), "", "", RESOURCE_NAMESPACE); world.registerSystem( WorldResourceIdLib.encode({ typeId: RESOURCE_SYSTEM, namespace: "", name: "rootSystem" }), yetAnotherSystem, @@ -548,7 +555,7 @@ contract WorldTest is Test, GasReporter { // Expect the registration to fail when coming from the World vm.prank(address(world)); vm.expectRevert( - abi.encodeWithSelector(IWorldErrors.WorldCallbackNotAllowed.selector, world.registerSystem.selector) + abi.encodeWithSelector(IWorldErrors.World_CallbackNotAllowed.selector, world.registerSystem.selector) ); world.registerSystem( WorldResourceIdLib.encode({ typeId: RESOURCE_SYSTEM, namespace: "", name: "rootSystem" }), @@ -559,7 +566,7 @@ contract WorldTest is Test, GasReporter { // Expect the registration to fail if the provided address does not implement the WorldContextConsumer interface vm.expectRevert( abi.encodeWithSelector( - IWorldErrors.InterfaceNotSupported.selector, + IWorldErrors.World_InterfaceNotSupported.selector, address(world), WORLD_CONTEXT_CONSUMER_INTERFACE_ID ) @@ -635,7 +642,12 @@ contract WorldTest is Test, GasReporter { // Expect an error when trying to register a system at the same ID vm.expectRevert( - abi.encodeWithSelector(IWorldErrors.InvalidResourceType.selector, RESOURCE_SYSTEM, tableId, tableId.toString()) + abi.encodeWithSelector( + IWorldErrors.World_InvalidResourceType.selector, + RESOURCE_SYSTEM, + tableId, + tableId.toString() + ) ); world.registerSystem(tableId, system, false); @@ -740,7 +752,7 @@ contract WorldTest is Test, GasReporter { assertTrue(Bool.get(world, tableId)); // Expect an error when trying to write from an address that doesn't have access - _expectAccessDenied(address(0x01), "testSetField", "testTable", RESOURCE_TABLE); + _expectWorld_AccessDenied(address(0x01), "testSetField", "testTable", RESOURCE_TABLE); world.setField(tableId, singletonKey, 0, abi.encodePacked(true), fieldLayout); // Expect the World to not have access @@ -783,7 +795,7 @@ contract WorldTest is Test, GasReporter { assertEq(AddressArray.get(world, tableId, key), dataToPush); // Expect an error when trying to write from an address that doesn't have access - _expectAccessDenied(address(0x01), namespace, name, RESOURCE_TABLE); + _expectWorld_AccessDenied(address(0x01), namespace, name, RESOURCE_TABLE); world.pushToField(tableId, keyTuple, 0, encodedData, fieldLayout); // Expect the World to not have access @@ -833,7 +845,7 @@ contract WorldTest is Test, GasReporter { assertTrue(Bool.get(world, tableId)); // Expect an error when trying to delete from an address that doesn't have access - _expectAccessDenied(address(0x02), namespace, name, RESOURCE_TABLE); + _expectWorld_AccessDenied(address(0x02), namespace, name, RESOURCE_TABLE); world.deleteRecord(tableId, singletonKey, fieldLayout); // Expect the World to not have access @@ -874,7 +886,7 @@ contract WorldTest is Test, GasReporter { assertEq(returnStruct.input, bytes32(uint256(0x123))); // Expect an error when trying to call a private system from an address that doesn't have access - _expectAccessDenied(address(0x01), "namespace", "testSystem", RESOURCE_SYSTEM); + _expectWorld_AccessDenied(address(0x01), "namespace", "testSystem", RESOURCE_SYSTEM); world.call(systemId, abi.encodeCall(WorldTestSystem.msgSender, ())); // Expect the World to have not access @@ -970,7 +982,7 @@ contract WorldTest is Test, GasReporter { assertEq(returnedAddress, delegator); } - function testCallFromFailDelegationNotFound() public { + function testCallFromFailWorld_DelegationNotFound() public { // Register a new system WorldTestSystem system = new WorldTestSystem(); ResourceId systemId = WorldResourceIdLib.encode({ @@ -983,7 +995,7 @@ contract WorldTest is Test, GasReporter { // Expect a revert when attempting to perform a call on behalf of an address that doesn't have a delegation vm.expectRevert( abi.encodeWithSelector( - IWorldErrors.DelegationNotFound.selector, + IWorldErrors.World_DelegationNotFound.selector, address(2), // Delegator address(1) // Delegatee ) @@ -1073,7 +1085,7 @@ contract WorldTest is Test, GasReporter { // Expect an error when trying to register an address that doesn't implement the IStoreHook interface vm.expectRevert( - abi.encodeWithSelector(IWorldErrors.InterfaceNotSupported.selector, address(world), STORE_HOOK_INTERFACE_ID) + abi.encodeWithSelector(IWorldErrors.World_InterfaceNotSupported.selector, address(world), STORE_HOOK_INTERFACE_ID) ); world.registerStoreHook( tableId, @@ -1176,7 +1188,11 @@ contract WorldTest is Test, GasReporter { // Expect the registration to fail if the contract does not implement the system hook interface vm.expectRevert( - abi.encodeWithSelector(IWorldErrors.InterfaceNotSupported.selector, address(world), SYSTEM_HOOK_INTERFACE_ID) + abi.encodeWithSelector( + IWorldErrors.World_InterfaceNotSupported.selector, + address(world), + SYSTEM_HOOK_INTERFACE_ID + ) ); world.registerSystemHook( systemId, @@ -1378,13 +1394,13 @@ contract WorldTest is Test, GasReporter { bytes4 sysFunc = WorldTestSystem.msgSender.selector; // Expect an error when trying to register a root function selector from an account without access - _expectAccessDenied(address(0x01), "", "", RESOURCE_NAMESPACE); + _expectWorld_AccessDenied(address(0x01), "", "", RESOURCE_NAMESPACE); world.registerRootFunctionSelector(systemId, worldFunc, sysFunc); // Expect the World to not be able to register a root function selector when calling the function externally vm.prank(address(world)); vm.expectRevert( - abi.encodeWithSelector(IWorldErrors.WorldCallbackNotAllowed.selector, world.registerRootFunctionSelector.selector) + abi.encodeWithSelector(IWorldErrors.World_CallbackNotAllowed.selector, world.registerRootFunctionSelector.selector) ); world.registerRootFunctionSelector(systemId, "smth", "smth"); diff --git a/packages/world/test/WorldBalance.t.sol b/packages/world/test/WorldBalance.t.sol index 3a6e889925..e231ca9fbb 100644 --- a/packages/world/test/WorldBalance.t.sol +++ b/packages/world/test/WorldBalance.t.sol @@ -176,7 +176,7 @@ contract WorldBalanceTest is Test, GasReporter { assertEq(Balances.get(world, ResourceId.unwrap(namespaceId)), value); } - function testTransferBalanceToNamespaceRevertInsufficientBalance() public { + function testTransferBalanceToNamespaceRevertWorld_InsufficientBalance() public { uint256 value = 1 ether; // Expect the root and non root namespaces to have no balance @@ -194,7 +194,7 @@ contract WorldBalanceTest is Test, GasReporter { assertEq(Balances.get(world, ResourceId.unwrap(ROOT_NAMESPACE_ID)), value); // Expect revert when attempting to transfer more than the balance - vm.expectRevert(abi.encodeWithSelector(IWorldErrors.InsufficientBalance.selector, value, value + 1)); + vm.expectRevert(abi.encodeWithSelector(IWorldErrors.World_InsufficientBalance.selector, value, value + 1)); world.transferBalanceToNamespace(ROOT_NAMESPACE_ID, namespaceId, value + 1); // Expect the root namespace to have the value as balance @@ -204,7 +204,7 @@ contract WorldBalanceTest is Test, GasReporter { assertEq(Balances.get(world, ResourceId.unwrap(namespaceId)), 0); } - function testTransferBalanceToNamespaceRevertAccessDenied() public { + function testTransferBalanceToNamespaceRevertWorld_AccessDenied() public { uint256 value = 1 ether; // Expect the root and non root namespaces to have no balance @@ -223,7 +223,9 @@ contract WorldBalanceTest is Test, GasReporter { // Expect revert when attempting to transfer from a namespace without access vm.prank(caller); - vm.expectRevert(abi.encodeWithSelector(IWorldErrors.AccessDenied.selector, ROOT_NAMESPACE_ID.toString(), caller)); + vm.expectRevert( + abi.encodeWithSelector(IWorldErrors.World_AccessDenied.selector, ROOT_NAMESPACE_ID.toString(), caller) + ); world.transferBalanceToNamespace(ROOT_NAMESPACE_ID, namespaceId, value); // Expect the root namespace to have the value as balance @@ -233,7 +235,7 @@ contract WorldBalanceTest is Test, GasReporter { assertEq(Balances.get(world, ResourceId.unwrap(namespaceId)), 0); } - function testTransferBalanceToNamespaceRevertInvalidResourceType() public { + function testTransferBalanceToNamespaceRevertWorld_InvalidResourceType() public { uint256 value = 1 ether; // Expect the root namespace to have no balance @@ -254,7 +256,7 @@ contract WorldBalanceTest is Test, GasReporter { vm.prank(caller); vm.expectRevert( abi.encodeWithSelector( - IWorldErrors.InvalidResourceType.selector, + IWorldErrors.World_InvalidResourceType.selector, RESOURCE_NAMESPACE, invalidNamespace, invalidNamespace.toString() @@ -300,7 +302,7 @@ contract WorldBalanceTest is Test, GasReporter { assertEq(receiver.balance, value); } - function testTransferBalanceToAddressRevertInsufficientBalance() public { + function testTransferBalanceToAddressRevertWorld_InsufficientBalance() public { uint256 value = 1 ether; // Expect the root and non root namespaces to have no balance @@ -322,7 +324,7 @@ contract WorldBalanceTest is Test, GasReporter { assertEq(receiver.balance, 0); // Expect revert when attempting to transfer more than the balance - vm.expectRevert(abi.encodeWithSelector(IWorldErrors.InsufficientBalance.selector, value, value + 1)); + vm.expectRevert(abi.encodeWithSelector(IWorldErrors.World_InsufficientBalance.selector, value, value + 1)); world.transferBalanceToAddress(ROOT_NAMESPACE_ID, receiver, value + 1); // Expect the root namespace to have value as balance @@ -332,7 +334,7 @@ contract WorldBalanceTest is Test, GasReporter { assertEq(receiver.balance, 0); } - function testTransferBalanceToAddressRevertAccessDenied() public { + function testTransferBalanceToAddressRevertWorld_AccessDenied() public { uint256 value = 1 ether; // Expect the root and non root namespaces to have no balance @@ -357,7 +359,7 @@ contract WorldBalanceTest is Test, GasReporter { vm.prank(caller); vm.expectRevert( abi.encodeWithSelector( - IWorldErrors.AccessDenied.selector, + IWorldErrors.World_AccessDenied.selector, WorldResourceIdLib.encodeNamespace(ROOT_NAMESPACE).toString(), caller ) diff --git a/packages/world/test/WorldDynamicUpdate.t.sol b/packages/world/test/WorldDynamicUpdate.t.sol index ab3bc46e04..c8a1d76972 100644 --- a/packages/world/test/WorldDynamicUpdate.t.sol +++ b/packages/world/test/WorldDynamicUpdate.t.sol @@ -76,9 +76,9 @@ contract UpdateInFieldTest is Test, GasReporter { } // Expect an error when trying to write from an address that doesn't have access - function _expectAccessDenied(address _caller, ResourceId _tableId) internal { + function _expectWorld_AccessDenied(address _caller, ResourceId _tableId) internal { vm.prank(_caller); - vm.expectRevert(abi.encodeWithSelector(IWorldErrors.AccessDenied.selector, _tableId.toString(), _caller)); + vm.expectRevert(abi.encodeWithSelector(IWorldErrors.World_AccessDenied.selector, _tableId.toString(), _caller)); } function testPopFromField() public { @@ -128,7 +128,7 @@ contract UpdateInFieldTest is Test, GasReporter { } // Expect an error when trying to write from an address that doesn't have access - _expectAccessDenied(address(0x01), tableId); + _expectWorld_AccessDenied(address(0x01), tableId); world.popFromField(tableId, keyTuple, 0, 20, fieldLayout); // Expect the World to not have access @@ -167,7 +167,7 @@ contract UpdateInFieldTest is Test, GasReporter { assertEq(AddressArray.get(world, tableId, key), initData); // Expect an error when trying to write from an address that doesn't have access - _expectAccessDenied(address(0x01), tableId); + _expectWorld_AccessDenied(address(0x01), tableId); world.updateInField(tableId, keyTuple, 0, 0, EncodeArray.encode(dataForUpdate), fieldLayout); // Expect the World to not have access From 0ca0a2d85ae0e1bbeb07356b5ff49a8752aa576b Mon Sep 17 00:00:00 2001 From: alvarius Date: Thu, 21 Sep 2023 23:06:39 +0100 Subject: [PATCH 04/12] Create large-drinks-sell.md --- .changeset/large-drinks-sell.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/large-drinks-sell.md diff --git a/.changeset/large-drinks-sell.md b/.changeset/large-drinks-sell.md new file mode 100644 index 0000000000..bb0f54afd9 --- /dev/null +++ b/.changeset/large-drinks-sell.md @@ -0,0 +1,5 @@ +--- +"@latticexyz/store": patch +"@latticexyz/world": patch +--- +Prefixed all errors with their respective library/contract for improved debugging. From 5472108462b730ef1ffdf4ad89ac06821c7023bb Mon Sep 17 00:00:00 2001 From: alvrs Date: Thu, 21 Sep 2023 23:24:40 +0100 Subject: [PATCH 05/12] prettier --- .changeset/large-drinks-sell.md | 1 + 1 file changed, 1 insertion(+) diff --git a/.changeset/large-drinks-sell.md b/.changeset/large-drinks-sell.md index bb0f54afd9..eaa9b5c5f2 100644 --- a/.changeset/large-drinks-sell.md +++ b/.changeset/large-drinks-sell.md @@ -2,4 +2,5 @@ "@latticexyz/store": patch "@latticexyz/world": patch --- + Prefixed all errors with their respective library/contract for improved debugging. From a0bf828d570bfa691d6f63af42879dcb71439352 Mon Sep 17 00:00:00 2001 From: alvrs Date: Fri, 22 Sep 2023 11:39:48 +0100 Subject: [PATCH 06/12] prefix module errors --- packages/world/src/interfaces/IModule.sol | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/world/src/interfaces/IModule.sol b/packages/world/src/interfaces/IModule.sol index f67e27f7d5..e5c474634a 100644 --- a/packages/world/src/interfaces/IModule.sol +++ b/packages/world/src/interfaces/IModule.sol @@ -10,8 +10,8 @@ bytes4 constant MODULE_INTERFACE_ID = IModule.getName.selector ^ ERC165_INTERFACE_ID; interface IModule is IERC165 { - error RootInstallNotSupported(); - error NonRootInstallNotSupported(); + error Module_RootInstallNotSupported(); + error Module_NonRootInstallNotSupported(); /** * Return the module name as a bytes16. From f41c4523e401d72151f929fabb3f0bf3902b88c1 Mon Sep 17 00:00:00 2001 From: alvrs Date: Fri, 22 Sep 2023 16:08:37 +0100 Subject: [PATCH 07/12] undo rename of expectWorldAccessDenied function --- packages/world/test/World.t.sol | 23 +++++++++++--------- packages/world/test/WorldDynamicUpdate.t.sol | 6 ++--- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/packages/world/test/World.t.sol b/packages/world/test/World.t.sol index 8d1402bb08..3d821168fa 100644 --- a/packages/world/test/World.t.sol +++ b/packages/world/test/World.t.sol @@ -184,7 +184,7 @@ contract WorldTest is Test, GasReporter { } // Expect an error when trying to write from an address that doesn't have access - function _expectWorld_AccessDenied(address caller, bytes14 namespace, bytes16 name, bytes2 resourceType) internal { + function _expectWorldAccessDenied(address caller, bytes14 namespace, bytes16 name, bytes2 resourceType) internal { vm.prank(caller); vm.expectRevert( abi.encodeWithSelector( @@ -396,7 +396,7 @@ contract WorldTest is Test, GasReporter { ); // Expect revert if caller is not the owner - _expectWorld_AccessDenied(address(this), namespace, 0, RESOURCE_NAMESPACE); + _expectWorldAccessDenied(address(this), namespace, 0, RESOURCE_NAMESPACE); world.transferOwnership(namespaceId, address(1)); } @@ -450,7 +450,7 @@ contract WorldTest is Test, GasReporter { namespace: namespace, name: "otherTable" }); - _expectWorld_AccessDenied(address(0x01), namespace, "", RESOURCE_NAMESPACE); + _expectWorldAccessDenied(address(0x01), namespace, "", RESOURCE_NAMESPACE); world.registerTable(otherTableId, fieldLayout, defaultKeySchema, valueSchema, keyNames, fieldNames); // Expect the World to not be allowed to call registerTable via an external call @@ -545,7 +545,7 @@ contract WorldTest is Test, GasReporter { // Expect an error when registering a system in a namespace that is not owned by the caller System yetAnotherSystem = new System(); - _expectWorld_AccessDenied(address(0x01), "", "", RESOURCE_NAMESPACE); + _expectWorldAccessDenied(address(0x01), "", "", RESOURCE_NAMESPACE); world.registerSystem( WorldResourceIdLib.encode({ typeId: RESOURCE_SYSTEM, namespace: "", name: "rootSystem" }), yetAnotherSystem, @@ -752,7 +752,7 @@ contract WorldTest is Test, GasReporter { assertTrue(Bool.get(world, tableId)); // Expect an error when trying to write from an address that doesn't have access - _expectWorld_AccessDenied(address(0x01), "testSetField", "testTable", RESOURCE_TABLE); + _expectWorldAccessDenied(address(0x01), "testSetField", "testTable", RESOURCE_TABLE); world.setField(tableId, singletonKey, 0, abi.encodePacked(true), fieldLayout); // Expect the World to not have access @@ -795,7 +795,7 @@ contract WorldTest is Test, GasReporter { assertEq(AddressArray.get(world, tableId, key), dataToPush); // Expect an error when trying to write from an address that doesn't have access - _expectWorld_AccessDenied(address(0x01), namespace, name, RESOURCE_TABLE); + _expectWorldAccessDenied(address(0x01), namespace, name, RESOURCE_TABLE); world.pushToField(tableId, keyTuple, 0, encodedData, fieldLayout); // Expect the World to not have access @@ -845,7 +845,7 @@ contract WorldTest is Test, GasReporter { assertTrue(Bool.get(world, tableId)); // Expect an error when trying to delete from an address that doesn't have access - _expectWorld_AccessDenied(address(0x02), namespace, name, RESOURCE_TABLE); + _expectWorldAccessDenied(address(0x02), namespace, name, RESOURCE_TABLE); world.deleteRecord(tableId, singletonKey, fieldLayout); // Expect the World to not have access @@ -886,7 +886,7 @@ contract WorldTest is Test, GasReporter { assertEq(returnStruct.input, bytes32(uint256(0x123))); // Expect an error when trying to call a private system from an address that doesn't have access - _expectWorld_AccessDenied(address(0x01), "namespace", "testSystem", RESOURCE_SYSTEM); + _expectWorldAccessDenied(address(0x01), "namespace", "testSystem", RESOURCE_SYSTEM); world.call(systemId, abi.encodeCall(WorldTestSystem.msgSender, ())); // Expect the World to have not access @@ -1394,13 +1394,16 @@ contract WorldTest is Test, GasReporter { bytes4 sysFunc = WorldTestSystem.msgSender.selector; // Expect an error when trying to register a root function selector from an account without access - _expectWorld_AccessDenied(address(0x01), "", "", RESOURCE_NAMESPACE); + _expectWorldAccessDenied(address(0x01), "", "", RESOURCE_NAMESPACE); world.registerRootFunctionSelector(systemId, worldFunc, sysFunc); // Expect the World to not be able to register a root function selector when calling the function externally vm.prank(address(world)); vm.expectRevert( - abi.encodeWithSelector(IWorldErrors.World_CallbackNotAllowed.selector, world.registerRootFunctionSelector.selector) + abi.encodeWithSelector( + IWorldErrors.World_CallbackNotAllowed.selector, + world.registerRootFunctionSelector.selector + ) ); world.registerRootFunctionSelector(systemId, "smth", "smth"); diff --git a/packages/world/test/WorldDynamicUpdate.t.sol b/packages/world/test/WorldDynamicUpdate.t.sol index c8a1d76972..085aed3ee9 100644 --- a/packages/world/test/WorldDynamicUpdate.t.sol +++ b/packages/world/test/WorldDynamicUpdate.t.sol @@ -76,7 +76,7 @@ contract UpdateInFieldTest is Test, GasReporter { } // Expect an error when trying to write from an address that doesn't have access - function _expectWorld_AccessDenied(address _caller, ResourceId _tableId) internal { + function _expectWorldAccessDenied(address _caller, ResourceId _tableId) internal { vm.prank(_caller); vm.expectRevert(abi.encodeWithSelector(IWorldErrors.World_AccessDenied.selector, _tableId.toString(), _caller)); } @@ -128,7 +128,7 @@ contract UpdateInFieldTest is Test, GasReporter { } // Expect an error when trying to write from an address that doesn't have access - _expectWorld_AccessDenied(address(0x01), tableId); + _expectWorldAccessDenied(address(0x01), tableId); world.popFromField(tableId, keyTuple, 0, 20, fieldLayout); // Expect the World to not have access @@ -167,7 +167,7 @@ contract UpdateInFieldTest is Test, GasReporter { assertEq(AddressArray.get(world, tableId, key), initData); // Expect an error when trying to write from an address that doesn't have access - _expectWorld_AccessDenied(address(0x01), tableId); + _expectWorldAccessDenied(address(0x01), tableId); world.updateInField(tableId, keyTuple, 0, 0, EncodeArray.encode(dataForUpdate), fieldLayout); // Expect the World to not have access From 90607a3a25dcec5569301d3ed00233db6859ed17 Mon Sep 17 00:00:00 2001 From: alvrs Date: Fri, 22 Sep 2023 16:09:32 +0100 Subject: [PATCH 08/12] rename WorldCallbackNotAllowed to World_CallbackNotAllowed --- packages/world/src/World.sol | 2 +- packages/world/test/World.t.sol | 12 +++++++----- packages/world/test/WorldDynamicUpdate.t.sol | 6 ++++-- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/packages/world/src/World.sol b/packages/world/src/World.sol index 7ddbf969c4..91e35b256b 100644 --- a/packages/world/src/World.sol +++ b/packages/world/src/World.sol @@ -54,7 +54,7 @@ contract World is StoreRead, IStoreData, IWorldKernel { */ modifier requireNoCallback() { if (msg.sender == address(this)) { - revert WorldCallbackNotAllowed(msg.sig); + revert World_CallbackNotAllowed(msg.sig); } _; } diff --git a/packages/world/test/World.t.sol b/packages/world/test/World.t.sol index 3d821168fa..bf0d9608b9 100644 --- a/packages/world/test/World.t.sol +++ b/packages/world/test/World.t.sol @@ -730,7 +730,7 @@ contract WorldTest is Test, GasReporter { // Expect the World to not have access vm.prank(address(world)); - vm.expectRevert(abi.encodeWithSelector(IWorldErrors.WorldCallbackNotAllowed.selector, world.setRecord.selector)); + vm.expectRevert(abi.encodeWithSelector(IWorldErrors.World_CallbackNotAllowed.selector, world.setRecord.selector)); TwoFields.set(world, tableId, true, true); } @@ -757,7 +757,7 @@ contract WorldTest is Test, GasReporter { // Expect the World to not have access vm.prank(address(world)); - vm.expectRevert(abi.encodeWithSelector(IWorldErrors.WorldCallbackNotAllowed.selector, world.setField.selector)); + vm.expectRevert(abi.encodeWithSelector(IWorldErrors.World_CallbackNotAllowed.selector, world.setField.selector)); world.setField(tableId, singletonKey, 0, abi.encodePacked(true), fieldLayout); } @@ -800,7 +800,7 @@ contract WorldTest is Test, GasReporter { // Expect the World to not have access vm.prank(address(world)); - vm.expectRevert(abi.encodeWithSelector(IWorldErrors.WorldCallbackNotAllowed.selector, world.pushToField.selector)); + vm.expectRevert(abi.encodeWithSelector(IWorldErrors.World_CallbackNotAllowed.selector, world.pushToField.selector)); world.pushToField(tableId, keyTuple, 0, encodedData, fieldLayout); } @@ -850,7 +850,9 @@ contract WorldTest is Test, GasReporter { // Expect the World to not have access vm.prank(address(world)); - vm.expectRevert(abi.encodeWithSelector(IWorldErrors.WorldCallbackNotAllowed.selector, world.deleteRecord.selector)); + vm.expectRevert( + abi.encodeWithSelector(IWorldErrors.World_CallbackNotAllowed.selector, world.deleteRecord.selector) + ); world.deleteRecord(tableId, singletonKey, fieldLayout); } @@ -891,7 +893,7 @@ contract WorldTest is Test, GasReporter { // Expect the World to have not access vm.prank(address(world)); - vm.expectRevert(abi.encodeWithSelector(IWorldErrors.WorldCallbackNotAllowed.selector, world.call.selector)); + vm.expectRevert(abi.encodeWithSelector(IWorldErrors.World_CallbackNotAllowed.selector, world.call.selector)); world.call(systemId, abi.encodeCall(WorldTestSystem.msgSender, ())); // Expect errors from the system to be forwarded diff --git a/packages/world/test/WorldDynamicUpdate.t.sol b/packages/world/test/WorldDynamicUpdate.t.sol index 085aed3ee9..6414158fca 100644 --- a/packages/world/test/WorldDynamicUpdate.t.sol +++ b/packages/world/test/WorldDynamicUpdate.t.sol @@ -133,7 +133,9 @@ contract UpdateInFieldTest is Test, GasReporter { // Expect the World to not have access vm.prank(address(world)); - vm.expectRevert(abi.encodeWithSelector(IWorldErrors.WorldCallbackNotAllowed.selector, world.popFromField.selector)); + vm.expectRevert( + abi.encodeWithSelector(IWorldErrors.World_CallbackNotAllowed.selector, world.popFromField.selector) + ); world.popFromField(tableId, keyTuple, 0, 20, fieldLayout); } @@ -173,7 +175,7 @@ contract UpdateInFieldTest is Test, GasReporter { // Expect the World to not have access vm.prank(address(world)); vm.expectRevert( - abi.encodeWithSelector(IWorldErrors.WorldCallbackNotAllowed.selector, world.updateInField.selector) + abi.encodeWithSelector(IWorldErrors.World_CallbackNotAllowed.selector, world.updateInField.selector) ); world.updateInField(tableId, keyTuple, 0, 0, EncodeArray.encode(dataForUpdate), fieldLayout); } From cee3b351d0749096d6d9527b0f5cc31f76664930 Mon Sep 17 00:00:00 2001 From: alvrs Date: Fri, 22 Sep 2023 16:14:15 +0100 Subject: [PATCH 09/12] merge fixes --- packages/store/gas-report.json | 12 ++++++------ packages/world/src/modules/core/CoreModule.sol | 2 +- .../modules/keysintable/KeysInTableModule.sol | 2 +- .../keyswithvalue/KeysWithValueModule.sol | 2 +- .../StandardDelegationsModule.sol | 2 +- packages/world/test/AccessControl.t.sol | 4 +++- packages/world/test/World.t.sol | 18 +++++++++--------- packages/world/test/WorldDynamicUpdate.t.sol | 6 +++--- 8 files changed, 25 insertions(+), 23 deletions(-) diff --git a/packages/store/gas-report.json b/packages/store/gas-report.json index 866d3ea5a4..c03f37d8ef 100644 --- a/packages/store/gas-report.json +++ b/packages/store/gas-report.json @@ -81,7 +81,7 @@ "file": "test/FieldLayout.t.sol", "test": "testGetNumDynamicFields", "name": "get number of dynamic fields from field layout", - "gasUsed": 389 + "gasUsed": 390 }, { "file": "test/FieldLayout.t.sol", @@ -93,7 +93,7 @@ "file": "test/FieldLayout.t.sol", "test": "testGetNumStaticFields", "name": "get number of static fields from field layout", - "gasUsed": 311 + "gasUsed": 312 }, { "file": "test/FieldLayout.t.sol", @@ -117,7 +117,7 @@ "file": "test/FieldLayout.t.sol", "test": "testValidate", "name": "validate field layout", - "gasUsed": 3993 + "gasUsed": 3995 }, { "file": "test/Gas.t.sol", @@ -441,7 +441,7 @@ "file": "test/Schema.t.sol", "test": "testGetNumDynamicFields", "name": "get number of dynamic fields from schema", - "gasUsed": 389 + "gasUsed": 390 }, { "file": "test/Schema.t.sol", @@ -453,7 +453,7 @@ "file": "test/Schema.t.sol", "test": "testGetNumStaticFields", "name": "get number of static fields from schema", - "gasUsed": 311 + "gasUsed": 312 }, { "file": "test/Schema.t.sol", @@ -477,7 +477,7 @@ "file": "test/Schema.t.sol", "test": "testValidate", "name": "validate schema", - "gasUsed": 11497 + "gasUsed": 11499 }, { "file": "test/Slice.t.sol", diff --git a/packages/world/src/modules/core/CoreModule.sol b/packages/world/src/modules/core/CoreModule.sol index 91c3bb4edf..0a63273cf7 100644 --- a/packages/world/src/modules/core/CoreModule.sol +++ b/packages/world/src/modules/core/CoreModule.sol @@ -56,7 +56,7 @@ contract CoreModule is Module { } function install(bytes memory) public pure { - revert NonRootInstallNotSupported(); + revert Module_NonRootInstallNotSupported(); } /** diff --git a/packages/world/src/modules/keysintable/KeysInTableModule.sol b/packages/world/src/modules/keysintable/KeysInTableModule.sol index dd10f5c8ea..5a702c0b18 100644 --- a/packages/world/src/modules/keysintable/KeysInTableModule.sol +++ b/packages/world/src/modules/keysintable/KeysInTableModule.sol @@ -104,6 +104,6 @@ contract KeysInTableModule is Module { } function install(bytes memory) public pure { - revert NonRootInstallNotSupported(); + revert Module_NonRootInstallNotSupported(); } } diff --git a/packages/world/src/modules/keyswithvalue/KeysWithValueModule.sol b/packages/world/src/modules/keyswithvalue/KeysWithValueModule.sol index ea0eb947e4..35a14aa3ba 100644 --- a/packages/world/src/modules/keyswithvalue/KeysWithValueModule.sol +++ b/packages/world/src/modules/keyswithvalue/KeysWithValueModule.sol @@ -86,6 +86,6 @@ contract KeysWithValueModule is Module { } function install(bytes memory) public pure { - revert NonRootInstallNotSupported(); + revert Module_NonRootInstallNotSupported(); } } diff --git a/packages/world/src/modules/std-delegations/StandardDelegationsModule.sol b/packages/world/src/modules/std-delegations/StandardDelegationsModule.sol index e4834d3309..3e2edbd09a 100644 --- a/packages/world/src/modules/std-delegations/StandardDelegationsModule.sol +++ b/packages/world/src/modules/std-delegations/StandardDelegationsModule.sol @@ -45,6 +45,6 @@ contract StandardDelegationsModule is Module { } function install(bytes memory) public pure { - revert NonRootInstallNotSupported(); + revert Module_NonRootInstallNotSupported(); } } diff --git a/packages/world/test/AccessControl.t.sol b/packages/world/test/AccessControl.t.sol index 6a508a01b8..11b52a3c50 100644 --- a/packages/world/test/AccessControl.t.sol +++ b/packages/world/test/AccessControl.t.sol @@ -89,7 +89,9 @@ contract AccessControlTest is Test, GasReporter, StoreMock { endGasReport(); vm.prank(caller); - vm.expectRevert(abi.encodeWithSelector(IWorldErrors.AccessDenied.selector, tableId.toString(), address(this))); + vm.expectRevert( + abi.encodeWithSelector(IWorldErrors.World_AccessDenied.selector, tableId.toString(), address(this)) + ); startGasReport("AccessControl: requireAccess (this address)"); AccessControl.requireAccess(tableId, address(this)); endGasReport(); diff --git a/packages/world/test/World.t.sol b/packages/world/test/World.t.sol index bf0d9608b9..a4665f796f 100644 --- a/packages/world/test/World.t.sol +++ b/packages/world/test/World.t.sol @@ -184,7 +184,7 @@ contract WorldTest is Test, GasReporter { } // Expect an error when trying to write from an address that doesn't have access - function _expectWorldAccessDenied(address caller, bytes14 namespace, bytes16 name, bytes2 resourceType) internal { + function _expectAccessDenied(address caller, bytes14 namespace, bytes16 name, bytes2 resourceType) internal { vm.prank(caller); vm.expectRevert( abi.encodeWithSelector( @@ -396,7 +396,7 @@ contract WorldTest is Test, GasReporter { ); // Expect revert if caller is not the owner - _expectWorldAccessDenied(address(this), namespace, 0, RESOURCE_NAMESPACE); + _expectAccessDenied(address(this), namespace, 0, RESOURCE_NAMESPACE); world.transferOwnership(namespaceId, address(1)); } @@ -450,7 +450,7 @@ contract WorldTest is Test, GasReporter { namespace: namespace, name: "otherTable" }); - _expectWorldAccessDenied(address(0x01), namespace, "", RESOURCE_NAMESPACE); + _expectAccessDenied(address(0x01), namespace, "", RESOURCE_NAMESPACE); world.registerTable(otherTableId, fieldLayout, defaultKeySchema, valueSchema, keyNames, fieldNames); // Expect the World to not be allowed to call registerTable via an external call @@ -545,7 +545,7 @@ contract WorldTest is Test, GasReporter { // Expect an error when registering a system in a namespace that is not owned by the caller System yetAnotherSystem = new System(); - _expectWorldAccessDenied(address(0x01), "", "", RESOURCE_NAMESPACE); + _expectAccessDenied(address(0x01), "", "", RESOURCE_NAMESPACE); world.registerSystem( WorldResourceIdLib.encode({ typeId: RESOURCE_SYSTEM, namespace: "", name: "rootSystem" }), yetAnotherSystem, @@ -752,7 +752,7 @@ contract WorldTest is Test, GasReporter { assertTrue(Bool.get(world, tableId)); // Expect an error when trying to write from an address that doesn't have access - _expectWorldAccessDenied(address(0x01), "testSetField", "testTable", RESOURCE_TABLE); + _expectAccessDenied(address(0x01), "testSetField", "testTable", RESOURCE_TABLE); world.setField(tableId, singletonKey, 0, abi.encodePacked(true), fieldLayout); // Expect the World to not have access @@ -795,7 +795,7 @@ contract WorldTest is Test, GasReporter { assertEq(AddressArray.get(world, tableId, key), dataToPush); // Expect an error when trying to write from an address that doesn't have access - _expectWorldAccessDenied(address(0x01), namespace, name, RESOURCE_TABLE); + _expectAccessDenied(address(0x01), namespace, name, RESOURCE_TABLE); world.pushToField(tableId, keyTuple, 0, encodedData, fieldLayout); // Expect the World to not have access @@ -845,7 +845,7 @@ contract WorldTest is Test, GasReporter { assertTrue(Bool.get(world, tableId)); // Expect an error when trying to delete from an address that doesn't have access - _expectWorldAccessDenied(address(0x02), namespace, name, RESOURCE_TABLE); + _expectAccessDenied(address(0x02), namespace, name, RESOURCE_TABLE); world.deleteRecord(tableId, singletonKey, fieldLayout); // Expect the World to not have access @@ -888,7 +888,7 @@ contract WorldTest is Test, GasReporter { assertEq(returnStruct.input, bytes32(uint256(0x123))); // Expect an error when trying to call a private system from an address that doesn't have access - _expectWorldAccessDenied(address(0x01), "namespace", "testSystem", RESOURCE_SYSTEM); + _expectAccessDenied(address(0x01), "namespace", "testSystem", RESOURCE_SYSTEM); world.call(systemId, abi.encodeCall(WorldTestSystem.msgSender, ())); // Expect the World to have not access @@ -1396,7 +1396,7 @@ contract WorldTest is Test, GasReporter { bytes4 sysFunc = WorldTestSystem.msgSender.selector; // Expect an error when trying to register a root function selector from an account without access - _expectWorldAccessDenied(address(0x01), "", "", RESOURCE_NAMESPACE); + _expectAccessDenied(address(0x01), "", "", RESOURCE_NAMESPACE); world.registerRootFunctionSelector(systemId, worldFunc, sysFunc); // Expect the World to not be able to register a root function selector when calling the function externally diff --git a/packages/world/test/WorldDynamicUpdate.t.sol b/packages/world/test/WorldDynamicUpdate.t.sol index 6414158fca..3d054da1e7 100644 --- a/packages/world/test/WorldDynamicUpdate.t.sol +++ b/packages/world/test/WorldDynamicUpdate.t.sol @@ -76,7 +76,7 @@ contract UpdateInFieldTest is Test, GasReporter { } // Expect an error when trying to write from an address that doesn't have access - function _expectWorldAccessDenied(address _caller, ResourceId _tableId) internal { + function _expectAccessDenied(address _caller, ResourceId _tableId) internal { vm.prank(_caller); vm.expectRevert(abi.encodeWithSelector(IWorldErrors.World_AccessDenied.selector, _tableId.toString(), _caller)); } @@ -128,7 +128,7 @@ contract UpdateInFieldTest is Test, GasReporter { } // Expect an error when trying to write from an address that doesn't have access - _expectWorldAccessDenied(address(0x01), tableId); + _expectAccessDenied(address(0x01), tableId); world.popFromField(tableId, keyTuple, 0, 20, fieldLayout); // Expect the World to not have access @@ -169,7 +169,7 @@ contract UpdateInFieldTest is Test, GasReporter { assertEq(AddressArray.get(world, tableId, key), initData); // Expect an error when trying to write from an address that doesn't have access - _expectWorldAccessDenied(address(0x01), tableId); + _expectAccessDenied(address(0x01), tableId); world.updateInField(tableId, keyTuple, 0, 0, EncodeArray.encode(dataForUpdate), fieldLayout); // Expect the World to not have access From 0f45386644b686e97dfecb6ab87673b5ff211a98 Mon Sep 17 00:00:00 2001 From: alvrs Date: Fri, 22 Sep 2023 18:40:53 +0100 Subject: [PATCH 10/12] gas report --- packages/store/gas-report.json | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/store/gas-report.json b/packages/store/gas-report.json index c03f37d8ef..866d3ea5a4 100644 --- a/packages/store/gas-report.json +++ b/packages/store/gas-report.json @@ -81,7 +81,7 @@ "file": "test/FieldLayout.t.sol", "test": "testGetNumDynamicFields", "name": "get number of dynamic fields from field layout", - "gasUsed": 390 + "gasUsed": 389 }, { "file": "test/FieldLayout.t.sol", @@ -93,7 +93,7 @@ "file": "test/FieldLayout.t.sol", "test": "testGetNumStaticFields", "name": "get number of static fields from field layout", - "gasUsed": 312 + "gasUsed": 311 }, { "file": "test/FieldLayout.t.sol", @@ -117,7 +117,7 @@ "file": "test/FieldLayout.t.sol", "test": "testValidate", "name": "validate field layout", - "gasUsed": 3995 + "gasUsed": 3993 }, { "file": "test/Gas.t.sol", @@ -441,7 +441,7 @@ "file": "test/Schema.t.sol", "test": "testGetNumDynamicFields", "name": "get number of dynamic fields from schema", - "gasUsed": 390 + "gasUsed": 389 }, { "file": "test/Schema.t.sol", @@ -453,7 +453,7 @@ "file": "test/Schema.t.sol", "test": "testGetNumStaticFields", "name": "get number of static fields from schema", - "gasUsed": 312 + "gasUsed": 311 }, { "file": "test/Schema.t.sol", @@ -477,7 +477,7 @@ "file": "test/Schema.t.sol", "test": "testValidate", "name": "validate schema", - "gasUsed": 11499 + "gasUsed": 11497 }, { "file": "test/Slice.t.sol", From d90cbf71105c0e835d438a39105ff7d6782296c2 Mon Sep 17 00:00:00 2001 From: alvrs Date: Fri, 22 Sep 2023 19:05:59 +0100 Subject: [PATCH 11/12] self review --- packages/store/gas-report.json | 12 ++++++------ packages/world/test/StandardDelegationsModule.t.sol | 2 +- packages/world/test/World.t.sol | 4 ++-- packages/world/test/WorldBalance.t.sol | 10 +++++----- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/packages/store/gas-report.json b/packages/store/gas-report.json index 866d3ea5a4..c03f37d8ef 100644 --- a/packages/store/gas-report.json +++ b/packages/store/gas-report.json @@ -81,7 +81,7 @@ "file": "test/FieldLayout.t.sol", "test": "testGetNumDynamicFields", "name": "get number of dynamic fields from field layout", - "gasUsed": 389 + "gasUsed": 390 }, { "file": "test/FieldLayout.t.sol", @@ -93,7 +93,7 @@ "file": "test/FieldLayout.t.sol", "test": "testGetNumStaticFields", "name": "get number of static fields from field layout", - "gasUsed": 311 + "gasUsed": 312 }, { "file": "test/FieldLayout.t.sol", @@ -117,7 +117,7 @@ "file": "test/FieldLayout.t.sol", "test": "testValidate", "name": "validate field layout", - "gasUsed": 3993 + "gasUsed": 3995 }, { "file": "test/Gas.t.sol", @@ -441,7 +441,7 @@ "file": "test/Schema.t.sol", "test": "testGetNumDynamicFields", "name": "get number of dynamic fields from schema", - "gasUsed": 389 + "gasUsed": 390 }, { "file": "test/Schema.t.sol", @@ -453,7 +453,7 @@ "file": "test/Schema.t.sol", "test": "testGetNumStaticFields", "name": "get number of static fields from schema", - "gasUsed": 311 + "gasUsed": 312 }, { "file": "test/Schema.t.sol", @@ -477,7 +477,7 @@ "file": "test/Schema.t.sol", "test": "testValidate", "name": "validate schema", - "gasUsed": 11497 + "gasUsed": 11499 }, { "file": "test/Slice.t.sol", diff --git a/packages/world/test/StandardDelegationsModule.t.sol b/packages/world/test/StandardDelegationsModule.t.sol index 52b4bb5787..42e49f5372 100644 --- a/packages/world/test/StandardDelegationsModule.t.sol +++ b/packages/world/test/StandardDelegationsModule.t.sol @@ -108,7 +108,7 @@ contract StandardDelegationsModuleTest is Test, GasReporter { world.callFrom(delegator, systemId, abi.encodeCall(WorldTestSystem.msgSender, ())); } - function testRegisterDelegationRevertWorld_InterfaceNotSupported() public { + function testRegisterDelegationRevertInterfaceNotSupported() public { // Register a system that is not a delegation control system System noDelegationControlSystem = new System(); ResourceId noDelegationControlId = WorldResourceIdLib.encode({ diff --git a/packages/world/test/World.t.sol b/packages/world/test/World.t.sol index a4665f796f..eb15f8ef04 100644 --- a/packages/world/test/World.t.sol +++ b/packages/world/test/World.t.sol @@ -252,7 +252,7 @@ contract WorldTest is Test, GasReporter { newWorld.initialize(coreModule); } - function testRegisterModuleRevertWorld_InterfaceNotSupported() public { + function testRegisterModuleRevertInterfaceNotSupported() public { // Expect an error when trying to register a module that doesn't implement the IModule interface vm.expectRevert( abi.encodeWithSelector( @@ -984,7 +984,7 @@ contract WorldTest is Test, GasReporter { assertEq(returnedAddress, delegator); } - function testCallFromFailWorld_DelegationNotFound() public { + function testCallFromFailDelegationNotFound() public { // Register a new system WorldTestSystem system = new WorldTestSystem(); ResourceId systemId = WorldResourceIdLib.encode({ diff --git a/packages/world/test/WorldBalance.t.sol b/packages/world/test/WorldBalance.t.sol index e231ca9fbb..7da180a53e 100644 --- a/packages/world/test/WorldBalance.t.sol +++ b/packages/world/test/WorldBalance.t.sol @@ -176,7 +176,7 @@ contract WorldBalanceTest is Test, GasReporter { assertEq(Balances.get(world, ResourceId.unwrap(namespaceId)), value); } - function testTransferBalanceToNamespaceRevertWorld_InsufficientBalance() public { + function testTransferBalanceToNamespaceRevertInsufficientBalance() public { uint256 value = 1 ether; // Expect the root and non root namespaces to have no balance @@ -204,7 +204,7 @@ contract WorldBalanceTest is Test, GasReporter { assertEq(Balances.get(world, ResourceId.unwrap(namespaceId)), 0); } - function testTransferBalanceToNamespaceRevertWorld_AccessDenied() public { + function testTransferBalanceToNamespaceRevertAccessDenied() public { uint256 value = 1 ether; // Expect the root and non root namespaces to have no balance @@ -235,7 +235,7 @@ contract WorldBalanceTest is Test, GasReporter { assertEq(Balances.get(world, ResourceId.unwrap(namespaceId)), 0); } - function testTransferBalanceToNamespaceRevertWorld_InvalidResourceType() public { + function testTransferBalanceToNamespaceRevertInvalidResourceType() public { uint256 value = 1 ether; // Expect the root namespace to have no balance @@ -302,7 +302,7 @@ contract WorldBalanceTest is Test, GasReporter { assertEq(receiver.balance, value); } - function testTransferBalanceToAddressRevertWorld_InsufficientBalance() public { + function testTransferBalanceToAddressRevertInsufficientBalance() public { uint256 value = 1 ether; // Expect the root and non root namespaces to have no balance @@ -334,7 +334,7 @@ contract WorldBalanceTest is Test, GasReporter { assertEq(receiver.balance, 0); } - function testTransferBalanceToAddressRevertWorld_AccessDenied() public { + function testTransferBalanceToAddressRevertAccessDenied() public { uint256 value = 1 ether; // Expect the root and non root namespaces to have no balance From 407c784a90f72d9ec68418f084e7ed6403db4d72 Mon Sep 17 00:00:00 2001 From: alvrs Date: Fri, 22 Sep 2023 19:29:19 +0100 Subject: [PATCH 12/12] gas-report --- packages/store/gas-report.json | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/store/gas-report.json b/packages/store/gas-report.json index c03f37d8ef..866d3ea5a4 100644 --- a/packages/store/gas-report.json +++ b/packages/store/gas-report.json @@ -81,7 +81,7 @@ "file": "test/FieldLayout.t.sol", "test": "testGetNumDynamicFields", "name": "get number of dynamic fields from field layout", - "gasUsed": 390 + "gasUsed": 389 }, { "file": "test/FieldLayout.t.sol", @@ -93,7 +93,7 @@ "file": "test/FieldLayout.t.sol", "test": "testGetNumStaticFields", "name": "get number of static fields from field layout", - "gasUsed": 312 + "gasUsed": 311 }, { "file": "test/FieldLayout.t.sol", @@ -117,7 +117,7 @@ "file": "test/FieldLayout.t.sol", "test": "testValidate", "name": "validate field layout", - "gasUsed": 3995 + "gasUsed": 3993 }, { "file": "test/Gas.t.sol", @@ -441,7 +441,7 @@ "file": "test/Schema.t.sol", "test": "testGetNumDynamicFields", "name": "get number of dynamic fields from schema", - "gasUsed": 390 + "gasUsed": 389 }, { "file": "test/Schema.t.sol", @@ -453,7 +453,7 @@ "file": "test/Schema.t.sol", "test": "testGetNumStaticFields", "name": "get number of static fields from schema", - "gasUsed": 312 + "gasUsed": 311 }, { "file": "test/Schema.t.sol", @@ -477,7 +477,7 @@ "file": "test/Schema.t.sol", "test": "testValidate", "name": "validate schema", - "gasUsed": 11499 + "gasUsed": 11497 }, { "file": "test/Slice.t.sol",