diff --git a/packages/world/gas-report.json b/packages/world/gas-report.json index 007eafe3d9..6a678ca004 100644 --- a/packages/world/gas-report.json +++ b/packages/world/gas-report.json @@ -105,7 +105,7 @@ "file": "test/World.t.sol", "test": "testRegisterRootFunctionSelector", "name": "Register a root function selector", - "gasUsed": 80433 + "gasUsed": 80428 }, { "file": "test/World.t.sol", @@ -172,5 +172,11 @@ "test": "testGetType", "name": "get type from a resource ID", "gasUsed": 4 + }, + { + "file": "test/WorldResourceId.t.sol", + "test": "testToString", + "name": "convert resource ID to string", + "gasUsed": 3287 } ] diff --git a/packages/world/src/WorldResourceId.sol b/packages/world/src/WorldResourceId.sol index 1a784b7161..fe2d2c9776 100644 --- a/packages/world/src/WorldResourceId.sol +++ b/packages/world/src/WorldResourceId.sol @@ -99,9 +99,9 @@ library WorldResourceIdInstance { abi.encodePacked( resourceType, ":", - resourceNamespace == bytes14("") ? bytes14("") : resourceNamespace, + resourceNamespace == bytes14("") ? "" : WorldResourceIdLib.toTrimmedString(resourceNamespace), ":", - resourceName == bytes16("") ? bytes16("") : resourceName + resourceName == bytes16("") ? "" : WorldResourceIdLib.toTrimmedString(resourceName) ) ); } diff --git a/packages/world/test/WorldResourceId.t.sol b/packages/world/test/WorldResourceId.t.sol index 1ed06df233..e8e4d8dcea 100644 --- a/packages/world/test/WorldResourceId.t.sol +++ b/packages/world/test/WorldResourceId.t.sol @@ -53,6 +53,20 @@ contract WorldResourceIdTest is Test, GasReporter { assertEq(ResourceId.unwrap(namespaceId), ResourceId.unwrap(WorldResourceIdLib.encodeNamespace("namespace"))); } + function testToString() public { + ResourceId resourceId = WorldResourceIdLib.encode({ + typeId: RESOURCE_SYSTEM, + namespace: "namespace", + name: "name" + }); + + startGasReport("convert resource ID to string"); + string memory resourceIdString = resourceId.toString(); + endGasReport(); + + assertEq(resourceIdString, "sy:namespace:name"); + } + function testGetType() public { ResourceId resourceId = WorldResourceIdLib.encode({ typeId: RESOURCE_SYSTEM,