Skip to content

Commit

Permalink
Merge pull request #108 from worldcoin/dcbuild3r/minor-fixes
Browse files Browse the repository at this point in the history
minor fixes part 2
  • Loading branch information
dcbuild3r authored Sep 7, 2023
2 parents 26da155 + 52f2c77 commit 597f154
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 6 deletions.
6 changes: 4 additions & 2 deletions src/PolygonStateBridge.sol
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,12 @@ contract PolygonStateBridge is FxBaseRootTunnel, Ownable2Step {
/// @notice Emitted when an attempt is made to renounce ownership.
error CannotRenounceOwnership();

/// @notice Emitted when an attempt is made to set the FxChildTunnel to the zero address.
/// @notice Emitted when an attempt is made to set the FxBaseRootTunnel,
/// FxChildTunnel, CheckpointManager or WorldIDIdentityManager addresses to the zero address.
error AddressZero();

/// @notice Emitted when an attempt is made to set the FxChildTunnel when it has already been set.
/// @notice Emitted when an attempt is made to set the FxBaseRootTunnel's
/// fxChildTunnel when it has already been set.
error FxBaseRootChildTunnelAlreadySet();

///////////////////////////////////////////////////////////////////
Expand Down
11 changes: 9 additions & 2 deletions src/PolygonWorldID.sol
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,14 @@ contract PolygonWorldID is WorldIDBridge, FxBaseChildTunnel, Ownable2Step {
/// @notice Emitted when an attempt is made to renounce ownership.
error CannotRenounceOwnership();

/// @notice Emitted when an attempt is made to set the FxChildTunnel to the zero address.
/// @notice Emitted when an attempt is made to set the FxBaseChildTunnel or
/// the FxRoot Tunnel to the zero address.
error AddressZero();

/// @notice Emitted when an attempt is made to set the FxBaseChildTunnel's
/// fxRootTunnel when it has already been set.
error FxBaseChildRootTunnelAlreadySet();

///////////////////////////////////////////////////////////////////////////////
/// CONSTRUCTION ///
///////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -127,7 +132,9 @@ contract PolygonWorldID is WorldIDBridge, FxBaseChildTunnel, Ownable2Step {
///
/// @custom:reverts string If the root tunnel has already been set.
function setFxRootTunnel(address _fxRootTunnel) external virtual override onlyOwner {
require(fxRootTunnel == address(0x0), "FxBaseChildTunnel: ROOT_TUNNEL_ALREADY_SET");
if (fxRootTunnel != address(0)) {
revert FxBaseChildRootTunnelAlreadySet();
}

if (_fxRootTunnel == address(0x0)) {
revert AddressZero();
Expand Down
5 changes: 3 additions & 2 deletions src/test/PolygonStateBridge.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ contract PolygonStateBridgeTest is PRBTest, StdCheats {
/// @notice Emitted when an attempt is made to set the FxChildTunnel to the zero address.
error AddressZero();

/// @notice Emitted when an attempt is made to set the FxChildTunnel when it has already been set.
/// @notice Emitted when an attempt is made to set the FxBaseRootTunnel's
/// fxChildTunnel when it has already been set.
error FxBaseRootChildTunnelAlreadySet();

function setUp() public {
Expand Down Expand Up @@ -196,7 +197,7 @@ contract PolygonStateBridgeTest is PRBTest, StdCheats {
polygonStateBridge.setFxChildTunnel(address(0));
}

/// @notice tests that the FxChildTunnel can't be set once it has already been set
/// @notice tests that the FxBaseRootTunnel's fxChildTunnel can't be set once it has already been set
function test_cannotSetFxChildTunnelMoreThanOnce_reverts(address _fxChildTunnel) public {
vm.assume(_fxChildTunnel != address(0));

Expand Down
17 changes: 17 additions & 0 deletions src/test/PolygonWorldID.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ contract PolygonWorldIDTest is PRBTest, StdCheats {
/// @notice Thrown when setFxRootTunnel is called for the first time
event SetFxRootTunnel(address fxRootTunnel);

/// @notice Emitted when an attempt is made to set the FxBaseChildTunnel's
/// fxRootTunnel when it has already been set.
error FxBaseChildRootTunnelAlreadySet();

function setUp() public {
/// @notice Initialize the PolygonWorldID contract
vm.prank(owner);
Expand Down Expand Up @@ -108,6 +112,19 @@ contract PolygonWorldIDTest is PRBTest, StdCheats {
new PolygonWorldID(treeDepth, address(0));
}

/// @notice tests that the FxBaseChildTunnel's fxRootTunnel can't be set once it has already been set
function test_cannotSetFxRootTunnelMoreThanOnce_reverts(address _fxRootTunnel) public {
vm.assume(_fxRootTunnel != address(0));

vm.prank(owner);
id.setFxRootTunnel(_fxRootTunnel);

vm.expectRevert(FxBaseChildRootTunnelAlreadySet.selector);

vm.prank(owner);
id.setFxRootTunnel(_fxRootTunnel);
}

/// @notice Tests that a nonPendingOwner can't accept ownership of PolygonWorldID
/// @param newOwner the new owner of the contract
function test_notOwner_acceptOwnership_reverts(address newOwner, address randomAddress)
Expand Down

0 comments on commit 597f154

Please sign in to comment.