Skip to content

Commit

Permalink
test: add unregistration test and gas report
Browse files Browse the repository at this point in the history
  • Loading branch information
yonadaa committed Jan 17, 2024
1 parent b3a90db commit 4b2f271
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
6 changes: 6 additions & 0 deletions packages/world/gas-report.json
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,12 @@
"name": "Write data to the table",
"gasUsed": 39056
},
{
"file": "test/World.t.sol",
"test": "testUnregisterUnlimitedDelegation",
"name": "unregister an unlimited delegation",
"gasUsed": 26191
},
{
"file": "test/WorldDynamicUpdate.t.sol",
"test": "testPopFromDynamicField",
Expand Down
43 changes: 43 additions & 0 deletions packages/world/test/World.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -1112,6 +1112,49 @@ contract WorldTest is Test, GasReporter {
);
}

function testUnregisterUnlimitedDelegation() public {
// Register a new system
WorldTestSystem system = new WorldTestSystem();
ResourceId systemId = WorldResourceIdLib.encode({
typeId: RESOURCE_SYSTEM,
namespace: "namespace",
name: "testSystem"
});
world.registerNamespace(systemId.getNamespaceId());
world.registerSystem(systemId, system, true);

// Register an unlimited delegation
address delegator = address(1);
address delegatee = address(2);
vm.prank(delegator);
world.registerDelegation(delegatee, UNLIMITED_DELEGATION, new bytes(0));

// Call a system from the delegatee on behalf of the delegator
vm.prank(delegatee);
bytes memory returnData = world.callFrom(delegator, systemId, abi.encodeCall(WorldTestSystem.msgSender, ()));
address returnedAddress = abi.decode(returnData, (address));

// Expect the system to have received the delegator's address
assertEq(returnedAddress, delegator);

// Unregister the delegation
vm.prank(delegator);
startGasReport("unregister an unlimited delegation");
world.unregisterDelegation(delegatee);
endGasReport();

// 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.World_DelegationNotFound.selector,
delegator,
delegatee // Invalid delegatee
)
);
vm.prank(delegatee);
world.callFrom(delegator, systemId, abi.encodeCall(WorldTestSystem.msgSender, ()));
}

function testRegisterStoreHook() public {
FieldLayout fieldLayout = Bool.getFieldLayout();
Schema valueSchema = Bool.getValueSchema();
Expand Down

0 comments on commit 4b2f271

Please sign in to comment.