From 6574e1fad4663279fb74ec7921d6bff2d22247ff Mon Sep 17 00:00:00 2001 From: alvrs Date: Wed, 20 Sep 2023 19:38:07 +0100 Subject: [PATCH] add more tests --- packages/store/test/StoreCore.t.sol | 21 +++++++++++++++++++++ packages/store/test/StoreCoreGas.t.sol | 1 + packages/world/test/World.t.sol | 16 ++++++++++++++++ 3 files changed, 38 insertions(+) diff --git a/packages/store/test/StoreCore.t.sol b/packages/store/test/StoreCore.t.sol index 21d2aa9e46..75fc9e759f 100644 --- a/packages/store/test/StoreCore.t.sol +++ b/packages/store/test/StoreCore.t.sol @@ -92,6 +92,27 @@ contract StoreCoreTest is Test, StoreMock { assertTrue(ResourceIds._getExists(ResourceId.unwrap(tableId))); } + function testRevertTableExists() public { + ResourceId tableId = _tableId; + FieldLayout fieldLayout = FieldLayoutEncodeHelper.encode(1, 0); + Schema keySchema = SchemaEncodeHelper.encode(SchemaType.UINT8); + Schema valueSchema = SchemaEncodeHelper.encode(SchemaType.UINT8); + string[] memory keyNames = new string[](1); + string[] memory fieldNames = new string[](1); + + IStore(this).registerTable(tableId, fieldLayout, keySchema, valueSchema, keyNames, fieldNames); + + // Expect a revert when registering a table that already exists + vm.expectRevert( + abi.encodeWithSelector( + IStoreErrors.StoreCore_TableAlreadyExists.selector, + ResourceId.unwrap(tableId), + string(bytes.concat(ResourceId.unwrap(tableId))) + ) + ); + IStore(this).registerTable(tableId, fieldLayout, keySchema, valueSchema, keyNames, fieldNames); + } + function testRevertRegisterInvalidFieldLayout() public { ResourceId tableId = _tableId; diff --git a/packages/store/test/StoreCoreGas.t.sol b/packages/store/test/StoreCoreGas.t.sol index 8769cd4bd3..645872210f 100644 --- a/packages/store/test/StoreCoreGas.t.sol +++ b/packages/store/test/StoreCoreGas.t.sol @@ -78,6 +78,7 @@ contract StoreCoreGasTest is Test, GasReporter, StoreMock { function testHasFieldLayout() public { ResourceId tableId = _tableId; + ResourceId tableId2 = _tableId2; Schema valueSchema = SchemaEncodeHelper.encode( SchemaType.UINT8, diff --git a/packages/world/test/World.t.sol b/packages/world/test/World.t.sol index 13cfcf2f23..ebd05cd8a8 100644 --- a/packages/world/test/World.t.sol +++ b/packages/world/test/World.t.sol @@ -314,11 +314,24 @@ contract WorldTest is Test, GasReporter { "caller should have access" ); + // Expect the resource ID to have been registered + assertTrue(ResourceIds.getExists(world, ResourceId.unwrap(namespaceId))); + // Expect an error when registering an existing namespace vm.expectRevert(abi.encodeWithSelector(IWorldErrors.ResourceExists.selector, namespaceId.toString())); world.registerNamespace(namespaceId); } + function testRegisterNamespaceRevertInvalidType() public { + ResourceId invalidNamespaceId = WorldResourceIdLib.encode("namespace", "name", RESOURCE_TABLE); + + // Expect an error when trying to register a namespace with an invalid type + vm.expectRevert( + abi.encodeWithSelector(IWorldErrors.InvalidResourceType.selector, string(bytes.concat(RESOURCE_TABLE))) + ); + world.registerNamespace(invalidNamespaceId); + } + function testTransferNamespace() public { bytes14 namespace = "testTransfer"; ResourceId namespaceId = WorldResourceIdLib.encodeNamespace(namespace); @@ -440,6 +453,9 @@ contract WorldTest is Test, GasReporter { (address registeredAddress, bool publicAccess) = Systems.get(world, ResourceId.unwrap(systemId)); assertEq(registeredAddress, address(system)); + // Expect the system's resource ID to have been registered + assertTrue(ResourceIds.getExists(world, ResourceId.unwrap(systemId))); + // Expect the system namespace to be owned by the caller address routeOwner = NamespaceOwner.get(world, ResourceId.unwrap(namespaceId)); assertEq(routeOwner, address(this));