Skip to content

Commit

Permalink
PBHVerifierConstruction.t.sol
Browse files Browse the repository at this point in the history
  • Loading branch information
0xForerunner committed Dec 16, 2024
1 parent d7643d0 commit 35fe656
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 14 deletions.
1 change: 0 additions & 1 deletion contracts/src/PBHVerifierImplV1.sol
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,6 @@ contract PBHVerifierImplV1 is WorldIDImpl {
/// @param _numPbhPerMonth The number of allowed PBH transactions per month.
///
/// @custom:reverts string If called more than once at the same initialisation number.
/// @custom:reverts InvalidWorldId if `_worldId` is set to the zero address
function initialize(IWorldIDGroups _worldId, uint8 _numPbhPerMonth) public reinitializer(1) {
// First, ensure that all of the parent contracts are initialised.
__delegateInit();
Expand Down
40 changes: 40 additions & 0 deletions contracts/test/PBHVerifierConstruction.t.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.21;

import {PBHVerifierTest} from "./PBHVerifierTest.sol";
import {IWorldIDGroups} from "@world-id-contracts/interfaces/IWorldIDGroups.sol";

import {PBHVerifierImplV1 as PBHVerifierImpl} from "../src/PBHVerifierImplV1.sol";
import {PBHVerifier} from "../src/PBHVerifier.sol";

/// @title World ID Router Construction Tests
/// @notice Contains tests for the WorldID router
/// @author Worldcoin
/// @dev This test suite tests both the proxy and the functionality of the underlying implementation
/// so as to test everything in the context of how it will be deployed.
contract PBHVerifierConstruction is PBHVerifierTest {
/// @notice Taken from Initializable.sol
event Initialized(uint8 version);

/// @notice Tests if it is possible to construct a router without a delegate.
function testCanConstructPBHVerifierWithNoDelegate() public {
// Setup
address dummy = address(this);
bytes memory data = new bytes(0x0);

// Test
pbhVerifier = new PBHVerifier(dummy, data);
}

/// @notice Tests that it is possible to properly construct and initialise a router.
function testCanConstructRouterWithDelegate(IWorldIDGroups dummy) public {
// Setup
vm.expectEmit(true, true, true, true);
emit Initialized(1);
pbhVerifierImpl = new PBHVerifierImpl();
bytes memory callData = abi.encodeCall(PBHVerifierImpl.initialize, (dummy, 30));

// Test
pbhVerifier = new PBHVerifier(address(pbhVerifierImpl), callData);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import {PBHVerifierImplV1 as PBHVerifierImpl} from "../src/PBHVerifierImplV1.sol
import {PBHVerifier} from "../src/PBHVerifier.sol";
// import {WorldIDTest} from "@world-id-contracts/test/WorldIdTest.sol";

/// @title World ID Router Test.
/// @notice Contains tests for the WorldID Router.
/// @title PBHVerifier Test.
/// @notice Contains tests for the PBHVerifier.
/// @author Worldcoin
/// @dev This test suite tests both the proxy and the functionality of the underlying implementation
/// so as to test everything in the context of how it will be deployed.
Expand All @@ -28,12 +28,7 @@ contract PBHVerifierTest is WorldIDTest {

IWorldIDGroups internal nullManager = IWorldIDGroups(address(0));
IWorldIDGroups internal thisWorldID;

/// @notice Emitted when a group is enabled in the router.
///
/// @param initialGroupIdentityManager The address of the identity manager to be used for the first group
event GroupIdentityManagerRouterImplInitialized(IWorldIDGroups initialGroupIdentityManager);


///////////////////////////////////////////////////////////////////////////////
/// TEST ORCHESTRATION ///
///////////////////////////////////////////////////////////////////////////////
Expand All @@ -47,7 +42,7 @@ contract PBHVerifierTest is WorldIDTest {
// Label the addresses for better errors.
hevm.label(thisAddress, "Sender");
hevm.label(pbhVerifierAddress, "PBHVerifier");
hevm.label(pbhVerifierImplAddress, "PBHVerifierImplementation");
hevm.label(pbhVerifierImplAddress, "PBHVerifierImpl");
}

///////////////////////////////////////////////////////////////////////////////
Expand All @@ -62,9 +57,8 @@ contract PBHVerifierTest is WorldIDTest {
pbhVerifierImpl = new PBHVerifierImpl();
pbhVerifierImplAddress = address(pbhVerifierImpl);

vm.expectEmit(true, true, true, true);

emit GroupIdentityManagerRouterImplInitialized(initialGroupAddress);
// TODO: why does this not work?
// vm.expectEmit(true, true, true, true);

bytes memory initCallData = abi.encodeCall(PBHVerifierImpl.initialize, (initialGroupAddress, 30));

Expand All @@ -74,7 +68,7 @@ contract PBHVerifierTest is WorldIDTest {

/// @notice Constructs a new router without initializing the delegate.
/// @dev It is constructed in the globals.
function makeUninitRouter() public {
function makeUninitPBHVerifier() public {
pbhVerifierImpl = new PBHVerifierImpl();
pbhVerifierImplAddress = address(pbhVerifierImpl);
pbhVerifier = new PBHVerifier(pbhVerifierImplAddress, new bytes(0x0));
Expand Down

0 comments on commit 35fe656

Please sign in to comment.