diff --git a/packages/store/test/StoreCore.t.sol b/packages/store/test/StoreCore.t.sol index 8085388797..21d2aa9e46 100644 --- a/packages/store/test/StoreCore.t.sol +++ b/packages/store/test/StoreCore.t.sol @@ -42,10 +42,12 @@ contract StoreCoreTest is Test, StoreMock { mapping(uint256 => bytes) private testMapping; Schema defaultKeySchema = SchemaEncodeHelper.encode(SchemaType.BYTES32); string[] defaultKeyNames = new string[](1); - ResourceId tableId = ResourceIdLib.encode("some table", RESOURCE_TABLE); - ResourceId tableId2 = ResourceIdLib.encode("some other table", RESOURCE_TABLE); + ResourceId _tableId = ResourceIdLib.encode("some table", RESOURCE_TABLE); + ResourceId _tableId2 = ResourceIdLib.encode("some other table", RESOURCE_TABLE); + + function testRegisterTable() public { + ResourceId tableId = _tableId; - function testRegisterAndGetFieldLayout() public { FieldLayout fieldLayout = FieldLayoutEncodeHelper.encode(1, 2, 1, 2, 0); Schema keySchema = SchemaEncodeHelper.encode(SchemaType.UINT8, SchemaType.UINT16); Schema valueSchema = SchemaEncodeHelper.encode( @@ -85,9 +87,14 @@ contract StoreCoreTest is Test, StoreMock { bytes memory loadedFieldNames = Tables.getAbiEncodedFieldNames(IStore(this), ResourceId.unwrap(tableId)); assertEq(loadedFieldNames, abi.encode(fieldNames)); + + // Expect the table ID to be registered + assertTrue(ResourceIds._getExists(ResourceId.unwrap(tableId))); } function testRevertRegisterInvalidFieldLayout() public { + ResourceId tableId = _tableId; + string[] memory keyNames = new string[](2); string[] memory fieldNames = new string[](4); FieldLayout invalidFieldLayout = FieldLayout.wrap(keccak256("random bytes as value field layout")); @@ -126,6 +133,9 @@ contract StoreCoreTest is Test, StoreMock { } function testHasFieldLayoutAndSchema() public { + ResourceId tableId = _tableId; + ResourceId tableId2 = _tableId2; + string[] memory keyNames = new string[](1); string[] memory fieldNames = new string[](4); FieldLayout fieldLayout = FieldLayoutEncodeHelper.encode(1, 2, 1, 2, 0); @@ -173,6 +183,8 @@ contract StoreCoreTest is Test, StoreMock { } function testRegisterTableRevertNames() public { + ResourceId tableId = _tableId; + FieldLayout fieldLayout = FieldLayoutEncodeHelper.encode(1, 0); Schema keySchema = SchemaEncodeHelper.encode( SchemaType.UINT8, @@ -194,6 +206,8 @@ contract StoreCoreTest is Test, StoreMock { } function testSetAndGetDynamicDataLength() public { + ResourceId tableId = _tableId; + FieldLayout fieldLayout = FieldLayoutEncodeHelper.encode(1, 2, 4, 2); Schema valueSchema = SchemaEncodeHelper.encode( SchemaType.UINT8, @@ -236,6 +250,8 @@ contract StoreCoreTest is Test, StoreMock { } function testSetAndGetStaticData() public { + ResourceId tableId = _tableId; + // Register table FieldLayout fieldLayout = FieldLayoutEncodeHelper.encode(1, 2, 1, 2, 0); Schema valueSchema = SchemaEncodeHelper.encode( @@ -272,6 +288,8 @@ contract StoreCoreTest is Test, StoreMock { } function testRevertSetAndGetStaticData() public { + ResourceId tableId = _tableId; + // Register table FieldLayout fieldLayout = FieldLayoutEncodeHelper.encode(1, 2, 1, 2, 0); Schema valueSchema = SchemaEncodeHelper.encode( @@ -294,6 +312,8 @@ contract StoreCoreTest is Test, StoreMock { } function testSetAndGetStaticDataSpanningWords() public { + ResourceId tableId = _tableId; + // Register table FieldLayout fieldLayout = FieldLayoutEncodeHelper.encode(16, 32, 0); { @@ -329,6 +349,8 @@ contract StoreCoreTest is Test, StoreMock { } function testSetAndGetDynamicData() public { + ResourceId tableId = _tableId; + // Register table FieldLayout fieldLayout = FieldLayoutEncodeHelper.encode(16, 2); { @@ -413,6 +435,8 @@ contract StoreCoreTest is Test, StoreMock { } function testSetAndGetField() public { + ResourceId tableId = _tableId; + SetAndGetData memory _data; _data.tableId = tableId; @@ -628,6 +652,8 @@ contract StoreCoreTest is Test, StoreMock { } function testDeleteData() public { + ResourceId tableId = _tableId; + // Register table FieldLayout fieldLayout = FieldLayoutEncodeHelper.encode(16, 2); { @@ -718,6 +744,8 @@ contract StoreCoreTest is Test, StoreMock { } function testPushToField() public { + ResourceId tableId = _tableId; + TestPushToFieldData memory data = TestPushToFieldData(tableId, new bytes32[](0), 0, "", "", "", "", "", "", ""); // Register table @@ -857,6 +885,8 @@ contract StoreCoreTest is Test, StoreMock { } function testUpdateInField() public { + ResourceId tableId = _tableId; + TestUpdateInFieldData memory data = TestUpdateInFieldData( tableId, new bytes32[](0), @@ -1001,6 +1031,8 @@ contract StoreCoreTest is Test, StoreMock { } function testAccessEmptyData() public { + ResourceId tableId = _tableId; + FieldLayout fieldLayout = FieldLayoutEncodeHelper.encode(4, 1); Schema valueSchema = SchemaEncodeHelper.encode(SchemaType.UINT32, SchemaType.UINT32_ARRAY); @@ -1027,6 +1059,8 @@ contract StoreCoreTest is Test, StoreMock { } function testRegisterHook() public { + ResourceId tableId = _tableId; + bytes32[] memory keyTuple = new bytes32[](1); keyTuple[0] = "some key"; @@ -1071,6 +1105,8 @@ contract StoreCoreTest is Test, StoreMock { } function testUnregisterHook() public { + ResourceId tableId = _tableId; + bytes32[] memory keyTuple = new bytes32[](1); keyTuple[0] = "some key"; @@ -1185,6 +1221,8 @@ contract StoreCoreTest is Test, StoreMock { } function testHooksDynamicData() public { + ResourceId tableId = _tableId; + bytes32[] memory keyTuple = new bytes32[](1); keyTuple[0] = "some key"; diff --git a/packages/store/test/StoreCoreGas.t.sol b/packages/store/test/StoreCoreGas.t.sol index b6bf8e1be8..8769cd4bd3 100644 --- a/packages/store/test/StoreCoreGas.t.sol +++ b/packages/store/test/StoreCoreGas.t.sol @@ -35,10 +35,12 @@ contract StoreCoreGasTest is Test, GasReporter, StoreMock { mapping(uint256 => bytes) private testMapping; Schema defaultKeySchema = SchemaEncodeHelper.encode(SchemaType.BYTES32); - ResourceId tableId = ResourceIdLib.encode("some table", RESOURCE_TABLE); - ResourceId tableId2 = ResourceIdLib.encode("some other table", RESOURCE_TABLE); + ResourceId _tableId = ResourceIdLib.encode("some table", RESOURCE_TABLE); + ResourceId _tableId2 = ResourceIdLib.encode("some other table", RESOURCE_TABLE); function testRegisterAndGetFieldLayout() public { + ResourceId tableId = _tableId; + FieldLayout fieldLayout = FieldLayoutEncodeHelper.encode(1, 2, 1, 2, 0); Schema valueSchema = SchemaEncodeHelper.encode( SchemaType.UINT8, @@ -75,6 +77,8 @@ contract StoreCoreGasTest is Test, GasReporter, StoreMock { } function testHasFieldLayout() public { + ResourceId tableId = _tableId; + Schema valueSchema = SchemaEncodeHelper.encode( SchemaType.UINT8, SchemaType.UINT16, @@ -94,6 +98,8 @@ contract StoreCoreGasTest is Test, GasReporter, StoreMock { } function testSetAndGetDynamicDataLength() public { + ResourceId tableId = _tableId; + Schema valueSchema = SchemaEncodeHelper.encode( SchemaType.UINT8, SchemaType.UINT16, @@ -128,6 +134,8 @@ contract StoreCoreGasTest is Test, GasReporter, StoreMock { } function testSetAndGetStaticData() public { + ResourceId tableId = _tableId; + // Register table Schema valueSchema = SchemaEncodeHelper.encode( SchemaType.UINT8, @@ -155,6 +163,8 @@ contract StoreCoreGasTest is Test, GasReporter, StoreMock { } function testSetAndGetStaticDataSpanningWords() public { + ResourceId tableId = _tableId; + // Register table Schema valueSchema = SchemaEncodeHelper.encode(SchemaType.UINT128, SchemaType.UINT256); FieldLayout fieldLayout = FieldLayoutEncodeHelper.encode(16, 32, 0); @@ -181,6 +191,8 @@ contract StoreCoreGasTest is Test, GasReporter, StoreMock { } function testSetAndGetDynamicData() public { + ResourceId tableId = _tableId; + // Register table FieldLayout fieldLayout = FieldLayoutEncodeHelper.encode(16, 2); Schema valueSchema = SchemaEncodeHelper.encode( @@ -251,6 +263,8 @@ contract StoreCoreGasTest is Test, GasReporter, StoreMock { } function testSetAndGetField() public { + ResourceId tableId = _tableId; + // Register table FieldLayout fieldLayout = FieldLayoutEncodeHelper.encode(16, 32, 2); Schema valueSchema = SchemaEncodeHelper.encode( @@ -339,6 +353,8 @@ contract StoreCoreGasTest is Test, GasReporter, StoreMock { } function testDeleteData() public { + ResourceId tableId = _tableId; + // Register table FieldLayout fieldLayout = FieldLayoutEncodeHelper.encode(16, 2); Schema valueSchema = SchemaEncodeHelper.encode( @@ -390,6 +406,8 @@ contract StoreCoreGasTest is Test, GasReporter, StoreMock { } function testPushToField() public { + ResourceId tableId = _tableId; + // Register table FieldLayout fieldLayout = FieldLayoutEncodeHelper.encode(32, 2); Schema valueSchema = SchemaEncodeHelper.encode( @@ -474,6 +492,8 @@ contract StoreCoreGasTest is Test, GasReporter, StoreMock { } function testUpdateInField() public { + ResourceId tableId = _tableId; + TestUpdateInFieldData memory data = TestUpdateInFieldData("", "", "", "", "", "", ""); // Register table FieldLayout fieldLayout = FieldLayoutEncodeHelper.encode(32, 2); @@ -549,6 +569,8 @@ contract StoreCoreGasTest is Test, GasReporter, StoreMock { } function testAccessEmptyData() public { + ResourceId tableId = _tableId; + FieldLayout fieldLayout = FieldLayoutEncodeHelper.encode(4, 1); Schema valueSchema = SchemaEncodeHelper.encode(SchemaType.UINT32, SchemaType.UINT32_ARRAY); @@ -580,6 +602,8 @@ contract StoreCoreGasTest is Test, GasReporter, StoreMock { } function testHooks() public { + ResourceId tableId = _tableId; + bytes32[] memory keyTuple = new bytes32[](1); keyTuple[0] = keccak256("some key"); @@ -621,6 +645,8 @@ contract StoreCoreGasTest is Test, GasReporter, StoreMock { } function testHooksDynamicData() public { + ResourceId tableId = _tableId; + bytes32[] memory keyTuple = new bytes32[](1); keyTuple[0] = keccak256("some key"); diff --git a/packages/world/src/interfaces/IBalanceTransferSystem.sol b/packages/world/src/interfaces/IBalanceTransferSystem.sol index 3660f06395..a00a3bc15c 100644 --- a/packages/world/src/interfaces/IBalanceTransferSystem.sol +++ b/packages/world/src/interfaces/IBalanceTransferSystem.sol @@ -3,7 +3,7 @@ pragma solidity >=0.8.0; /* Autogenerated file. Do not edit manually. */ -import { ResourceId } from "./../WorldResourceId.sol"; +import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; interface IBalanceTransferSystem { function transferBalanceToNamespace(ResourceId fromNamespaceId, ResourceId toNamespaceId, uint256 amount) external; diff --git a/packages/world/src/modules/core/implementations/BalanceTransferSystem.sol b/packages/world/src/modules/core/implementations/BalanceTransferSystem.sol index cef8d380dd..52cf7d90c1 100644 --- a/packages/world/src/modules/core/implementations/BalanceTransferSystem.sol +++ b/packages/world/src/modules/core/implementations/BalanceTransferSystem.sol @@ -1,15 +1,19 @@ // SPDX-License-Identifier: MIT pragma solidity >=0.8.0; +import { ResourceId, ResourceIdInstance } from "@latticexyz/store/src/ResourceId.sol"; + import { System } from "../../../System.sol"; import { revertWithBytes } from "../../../revertWithBytes.sol"; -import { ResourceId, WorldResourceIdLib, WorldResourceIdInstance } from "../../../WorldResourceId.sol"; +import { WorldResourceIdLib, WorldResourceIdInstance } from "../../../WorldResourceId.sol"; import { AccessControl } from "../../../AccessControl.sol"; +import { RESOURCE_NAMESPACE } from "../../../worldResourceTypes.sol"; import { IWorldErrors } from "../../../interfaces/IWorldErrors.sol"; import { Balances } from "../tables/Balances.sol"; contract BalanceTransferSystem is System, IWorldErrors { + using ResourceIdInstance for ResourceId; using WorldResourceIdInstance for ResourceId; /** diff --git a/packages/world/test/WorldBalance.t.sol b/packages/world/test/WorldBalance.t.sol index 8d776e6116..c53e65026a 100644 --- a/packages/world/test/WorldBalance.t.sol +++ b/packages/world/test/WorldBalance.t.sol @@ -231,7 +231,7 @@ contract WorldBalanceTest is Test, GasReporter { assertEq(Balances.get(world, ResourceId.unwrap(namespaceId)), 0); } - function testTransferBalanceToNamespaceRevertInvalidResourceType() { + function testTransferBalanceToNamespaceRevertInvalidResourceType() public { uint256 value = 1 ether; // Expect the root namespace to have no balance