Skip to content

Commit

Permalink
feat(world): add renounceOwnership function
Browse files Browse the repository at this point in the history
  • Loading branch information
yonadaa committed Jan 18, 2024
1 parent 7b28d32 commit 7090e77
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 4 deletions.
2 changes: 1 addition & 1 deletion packages/world/gas-report.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
"file": "test/Factories.t.sol",
"test": "testWorldFactory",
"name": "deploy world via WorldFactory",
"gasUsed": 12514303
"gasUsed": 12579230
},
{
"file": "test/World.t.sol",
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions packages/world/src/modules/core/CoreModule.sol
Original file line number Diff line number Diff line change
Expand Up @@ -140,11 +140,12 @@ contract CoreModule is Module {
* @dev Iterates through known function signatures and registers them.
*/
function _registerFunctionSelectors() internal {
string[3] memory functionSignaturesAccessManagement = [
string[4] memory functionSignaturesAccessManagement = [
// --- AccessManagementSystem ---
"grantAccess(bytes32,address)",
"revokeAccess(bytes32,address)",
"transferOwnership(bytes32,address)"
"transferOwnership(bytes32,address)",
"renounceOwnership(bytes32)"
];
for (uint256 i = 0; i < functionSignaturesAccessManagement.length; i++) {
_registerRootFunctionSelector(ACCESS_MANAGEMENT_SYSTEM_ID, functionSignaturesAccessManagement[i]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,20 @@ contract AccessManagementSystem is System {
// Grant access to new owner
ResourceAccess._set(namespaceId, newOwner, true);
}

/**
* @notice Renounces ownership of the given namespace
* @dev Requires the caller to own the namespace. Revoke ResourceAccess for previous owner
* @param namespaceId The ID of the namespace to transfer ownership.
*/
function renounceOwnership(ResourceId namespaceId) public virtual {
// Require the caller to own the namespace
AccessControl.requireOwner(namespaceId, _msgSender());

// Delete namespace owner
NamespaceOwner._deleteRecord(namespaceId);

// Revoke access from old owner
ResourceAccess._deleteRecord(namespaceId, _msgSender());
}
}
28 changes: 27 additions & 1 deletion packages/world/test/World.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -225,11 +225,12 @@ contract WorldTest is Test, GasReporter {
CoreRegistrationSystem coreRegistrationSystem = CoreRegistrationSystem(
Systems.getSystem(CORE_REGISTRATION_SYSTEM_ID)
);
bytes4[19] memory coreFunctionSignatures = [
bytes4[20] memory coreFunctionSignatures = [
// --- AccessManagementSystem ---
AccessManagementSystem.grantAccess.selector,
AccessManagementSystem.revokeAccess.selector,
AccessManagementSystem.transferOwnership.selector,
AccessManagementSystem.renounceOwnership.selector,
// --- BalanceTransferSystem ---
BalanceTransferSystem.transferBalanceToNamespace.selector,
BalanceTransferSystem.transferBalanceToAddress.selector,
Expand Down Expand Up @@ -426,6 +427,31 @@ contract WorldTest is Test, GasReporter {
world.transferOwnership(namespaceId, address(1));
}

function testRenounceNamespace() public {
bytes14 namespace = "testRenounce";
ResourceId namespaceId = WorldResourceIdLib.encodeNamespace(namespace);

world.registerNamespace(namespaceId);

// Expect the new owner to not be namespace owner before transfer
assertFalse(
(NamespaceOwner.get(namespaceId)) == address(0),
"new owner should not be namespace owner before transfer"
);

world.renounceOwnership(namespaceId);

// Expect the new owner to be zero address
assertEq(NamespaceOwner.get(namespaceId), address(0), "zero address should be namespace owner");

// Expect previous owner to no longer have access
assertEq(ResourceAccess.get(namespaceId, address(this)), false, "caller should no longer have access");

// Expect revert if caller is not the owner
_expectAccessDenied(address(this), namespace, 0, RESOURCE_NAMESPACE);
world.renounceOwnership(namespaceId);
}

function testRegisterTable() public {
FieldLayout fieldLayout = FieldLayoutEncodeHelper.encode(1, 32, 1);
Schema valueSchema = SchemaEncodeHelper.encode(SchemaType.BOOL, SchemaType.UINT256, SchemaType.STRING);
Expand Down

0 comments on commit 7090e77

Please sign in to comment.