Skip to content

Commit

Permalink
Adds new manager tests
Browse files Browse the repository at this point in the history
  • Loading branch information
neokry committed Jul 19, 2023
1 parent 6dce92e commit 682d317
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 4 deletions.
5 changes: 4 additions & 1 deletion src/manager/IManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,12 @@ interface IManager is IUUPS, IOwnable {
/// @dev Reverts if at least one founder is not provided upon deploy
error FOUNDER_REQUIRED();

/// @dev Reverts if implementation parameters are incorrect length or not registered
/// @dev Reverts if implementation parameters are incorrect length
error INVALID_IMPLEMENTATION_PARAMS();

/// @dev Reverts if an implementation is not registered
error IMPLEMENTATION_NOT_REGISTERED();

/// @dev Reverts if an implementation type is not valid on registration
error INVALID_IMPLEMENTATION_TYPE();

Expand Down
6 changes: 3 additions & 3 deletions src/manager/Manager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,12 @@ contract Manager is IManager, VersionedContract, UUPS, Ownable, ManagerStorageV1
uint256 implAddressesLength = _implAddresses.length;

// Ensure implementation parameters are correct length
if (implAddressesLength != IMPLEMENTATION_TYPE_COUNT || implAddressesLength != IMPLEMENTATION_TYPE_COUNT)
revert INVALID_IMPLEMENTATION_PARAMS();
if (implAddressesLength != IMPLEMENTATION_TYPE_COUNT || _implData.length != IMPLEMENTATION_TYPE_COUNT) revert INVALID_IMPLEMENTATION_PARAMS();

// Ensure all implementations are registered
unchecked {
for (uint256 i; i < implAddressesLength; ++i) {
if (!isImplementation[uint8(i)][_implAddresses[i]]) revert INVALID_IMPLEMENTATION_PARAMS();
if (!isImplementation[uint8(i)][_implAddresses[i]]) revert IMPLEMENTATION_NOT_REGISTERED();
}
}

Expand Down
77 changes: 77 additions & 0 deletions test/Manager.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,16 @@ contract ManagerTest is NounsBuilderTest {
mockImpl = new MockImpl();
}

function setupAltMock() internal virtual {
setMockFounderParams();

setMockTokenParams();

setMockAuctionParams();

setMockGovParams();
}

function test_GetAddresses() public {
deployMock();

Expand Down Expand Up @@ -130,4 +140,71 @@ contract ManagerTest is NounsBuilderTest {
vm.expectRevert(abi.encodeWithSignature("ONLY_OWNER()"));
manager.removeUpgrade(address(token), address(mockImpl));
}

function test_RegisterImplementation() public {
address owner = manager.owner();

vm.prank(owner);
manager.registerImplementation(0, address(mockImpl));

assertTrue(manager.isRegisteredImplementation(0, address(mockImpl)));
}

function test_RemoveImplementation() public {
address owner = manager.owner();

vm.prank(owner);
manager.registerImplementation(0, address(mockImpl));

vm.prank(owner);
manager.removeImplementation(0, address(mockImpl));

assertFalse(manager.isRegisteredImplementation(0, address(mockImpl)));
}

function testRevert_OnlyOwnerCanRegisterImplementation() public {
vm.expectRevert(abi.encodeWithSignature("ONLY_OWNER()"));
manager.registerImplementation(0, address(mockImpl));
}

function testRevert_OnlyOwnerCanRemoveImplementation() public {
vm.expectRevert(abi.encodeWithSignature("ONLY_OWNER()"));
manager.removeImplementation(0, address(mockImpl));
}

function testRevert_InvalidImplementationType() public {
address owner = manager.owner();

vm.prank(owner);
vm.expectRevert(abi.encodeWithSignature("INVALID_IMPLEMENTATION_TYPE()"));
manager.registerImplementation(8, address(mockImpl));
}

function testRevert_InvalidImplementationAddresses() public {
address[] memory altImplAddresses = new address[](1);

setupAltMock();

vm.expectRevert(abi.encodeWithSignature("INVALID_IMPLEMENTATION_PARAMS()"));
deploy(foundersArr, altImplAddresses, implData);
}

function testRevert_InvalidImplementationData() public {
bytes[] memory altImplData = new bytes[](1);

setupAltMock();

vm.expectRevert(abi.encodeWithSignature("INVALID_IMPLEMENTATION_PARAMS()"));
deploy(foundersArr, implAddresses, altImplData);
}

function testRevert_UnregisteredImplementation() public {
address[] memory altImplAddresses = new address[](5);
altImplAddresses[0] = address(24);

setupAltMock();

vm.expectRevert(abi.encodeWithSignature("IMPLEMENTATION_NOT_REGISTERED()"));
deploy(foundersArr, altImplAddresses, implData);
}
}

0 comments on commit 682d317

Please sign in to comment.