Skip to content

Commit

Permalink
add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
alvrs committed Sep 20, 2023
1 parent 2944c82 commit 6574e1f
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
21 changes: 21 additions & 0 deletions packages/store/test/StoreCore.t.sol
Expand Up @@ -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;

Expand Down
1 change: 1 addition & 0 deletions packages/store/test/StoreCoreGas.t.sol
Expand Up @@ -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,
Expand Down
16 changes: 16 additions & 0 deletions packages/world/test/World.t.sol
Expand Up @@ -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);
Expand Down Expand Up @@ -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));
Expand Down

0 comments on commit 6574e1f

Please sign in to comment.