Skip to content

Commit

Permalink
Merge pull request #448 from superform-xyz/coverage-improvements
Browse files Browse the repository at this point in the history
chore: cover all uncovered lines
  • Loading branch information
0xTimepunk authored Jan 19, 2024
2 parents 0bab864 + b40231e commit 5e8225f
Show file tree
Hide file tree
Showing 6 changed files with 169 additions and 1 deletion.
31 changes: 31 additions & 0 deletions test/unit/crosschain-data/adapters/HyperlaneImplementation.t.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// SPDX-License-Identifier: Unlicense
pragma solidity ^0.8.23;

import "../../../utils/BaseSetup.sol";

import { ISuperRegistry } from "src/interfaces/ISuperRegistry.sol";
import { HyperlaneImplementation } from "src/crosschain-data/adapters/hyperlane/HyperlaneImplementation.sol";
import { Error } from "src/libraries/Error.sol";

contract HyperlaneImplementationUnitTest is BaseSetup {
HyperlaneImplementation hyperlaneImplementation;

function setUp() public override {
super.setUp();

ISuperRegistry superRegistry = ISuperRegistry(getContract(ETH, "SuperRegistry"));

vm.selectFork(FORKS[ETH]);
hyperlaneImplementation = HyperlaneImplementation(payable(superRegistry.getAmbAddress(2)));
}

function test_setHyperlaneConfig_ZERO_ADDRESS() public {
vm.prank(deployer);
vm.expectRevert(Error.ZERO_ADDRESS.selector);
hyperlaneImplementation.setHyperlaneConfig(IMailbox(address(0)), IInterchainGasPaymaster(address(420)));

vm.prank(deployer);
vm.expectRevert(Error.ZERO_ADDRESS.selector);
hyperlaneImplementation.setHyperlaneConfig(IMailbox(address(420)), IInterchainGasPaymaster(address(0)));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,15 @@ contract LayerzeroImplementationUnitTest is BaseSetup {
layerzeroImplementation.dispatchPayload(deployer, 420, bytes("hi test"), "");
}

function test_layerzeroDispatchPayload_InvalidChainId2() public {
vm.prank(deployer);
layerzeroImplementation.setTrustedRemote(111, bytes(""));

vm.prank(getContract(ETH, "CoreStateRegistry"));
vm.expectRevert(Error.INVALID_CHAIN_ID.selector);
layerzeroImplementation.dispatchPayload(deployer, 10, bytes("hi test"), "");
}

function test_lzReceive_InvalidChainId() public {
vm.prank(deployer);
layerzeroImplementation.setTrustedRemote(0, bytes("test"));
Expand Down
5 changes: 5 additions & 0 deletions test/unit/roles/SuperRBAC.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,11 @@ contract SuperRBACTest is BaseSetup {
superRBAC.setRoleAdmin(keccak256("NEW_ROLE"), keccak256("PROTOCOL_ADMIN_ROLE"));
}

function test_revokeRoleWithoutBroadcast() public {
vm.startPrank(deployer);
superRBAC.revokeRoleSuperBroadcast(superRBAC.PAYMENT_ADMIN_ROLE(), "", superRegistry.PAYMENT_ADMIN());
}

function test_revokeSuperBroadcast_CannotRevoke() public {
vm.deal(deployer, 1 ether);
vm.startPrank(deployer);
Expand Down
51 changes: 50 additions & 1 deletion test/unit/super-registry/SuperRegistry.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,34 @@ contract SuperRegistryTest is BaseSetup {
superRegistry.setBridgeAddresses(bridgeId, bridgeAddress, bridgeValidator);
}

function test_setBridgeAddresses_and_revertZeroValues() public {
uint8[] memory bridgeId = new uint8[](1);
address[] memory bridgeAddress = new address[](1);
address[] memory bridgeValidator = new address[](1);

bridgeId[0] = 20;
bridgeAddress[0] = address(0);
bridgeValidator[0] = address(0x2);

vm.prank(deployer);
vm.expectRevert(Error.ZERO_ADDRESS.selector);
superRegistry.setBridgeAddresses(bridgeId, bridgeAddress, bridgeValidator);

bridgeAddress[0] = address(0x2);
bridgeId[0] = 0;

vm.prank(deployer);
vm.expectRevert(Error.ZERO_INPUT_VALUE.selector);
superRegistry.setBridgeAddresses(bridgeId, bridgeAddress, bridgeValidator);

bridgeId[0] = 20;
bridgeValidator[0] = address(0);

vm.prank(deployer);
vm.expectRevert(Error.ZERO_ADDRESS.selector);
superRegistry.setBridgeAddresses(bridgeId, bridgeAddress, bridgeValidator);
}

function test_setBridgeAddresses_array_mismatch_address() public {
uint8[] memory bridgeId = new uint8[](3);
address[] memory bridgeAddress = new address[](2);
Expand Down Expand Up @@ -362,7 +390,7 @@ contract SuperRegistryTest is BaseSetup {
function test_setQuorum_invalid_chainId() public {
vm.prank(deployer);
vm.expectRevert(Error.INVALID_CHAIN_ID.selector);
superRegistry.setRequiredMessagingQuorum(0,2);
superRegistry.setRequiredMessagingQuorum(0, 2);
}

function test_getAmbId() public {
Expand Down Expand Up @@ -459,4 +487,25 @@ contract SuperRegistryTest is BaseSetup {
assertEq(superRegistry.getAddress(ids[0]), newAddresses[0]);
assertEq(superRegistry.getAddress(ids[1]), newAddresses[1]);
}

function test_batchSetAddress_ArrayLengthMismatch() public {
vm.selectFork(FORKS[ETH]);

// Define ids, newAddresses, and chainIds
bytes32[] memory ids = new bytes32[](2);
ids[0] = keccak256(abi.encodePacked("id1"));
ids[1] = keccak256(abi.encodePacked("id2"));

address[] memory newAddresses = new address[](1);
newAddresses[0] = address(0x123);

uint64[] memory chainIds = new uint64[](2);
chainIds[0] = 1;
chainIds[1] = 1;

// Call batchSetAddress
vm.prank(deployer);
vm.expectRevert(Error.ARRAY_LENGTH_MISMATCH.selector);
superRegistry.batchSetAddress(ids, newAddresses, chainIds);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,28 @@ contract SuperformFactoryChangePauseTest is BaseSetup {
assertEq(status, true);
}

function test_changeFormImplementationPauseStatusNoBroadcastRevertCase() public {
vm.startPrank(deployer);

vm.selectFork(FORKS[chainId]);

address superRegistry = getContract(chainId, "SuperRegistry");

/// @dev Deploying Forms
address formImplementation1 = address(new ERC4626Form(superRegistry));
uint32 formImplementationId = 0;

// Deploying Forms Using AddImplementation. Not Testing Reverts As Already Tested
SuperformFactory(getContract(chainId, "SuperformFactory")).addFormImplementation(
formImplementation1, formImplementationId, 1
);

vm.expectRevert(Error.MSG_VALUE_NOT_ZERO.selector);
SuperformFactory(getContract(chainId, "SuperformFactory")).changeFormImplementationPauseStatus{ value: 1 ether }(
formImplementationId, ISuperformFactory.PauseStatus.PAUSED, ""
);
}

function test_revert_changeFormImplementationPauseStatus_INVALID_FORM_ID() public {
vm.startPrank(deployer);

Expand Down
52 changes: 52 additions & 0 deletions test/unit/superform-forms/superform-form.ERC4626Form.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -631,6 +631,58 @@ contract SuperformERC4626FormTest is ProtocolActions {
SuperformRouter(payable(router)).singleDirectSingleVaultWithdraw(req);
}

function test_superformDirectWithdrawZeroCollateral() public {
vm.selectFork(FORKS[ETH]);
vm.startPrank(deployer);

address superRegistry = getContract(chainId, "SuperRegistry");

/// @dev Deploying Forms
address formImplementation = address(new ERC4626Form(superRegistry));
uint32 formImplementationId = 0;

VaultMockFailedWithdraw vault =
new VaultMockFailedWithdraw(IERC20(getContract(ETH, "DAI")), "Mock Vault", "Mock");

// Deploying Forms Using AddImplementation. Not Testing Reverts As Already Tested
SuperformFactory(getContract(chainId, "SuperformFactory")).addFormImplementation(
formImplementation, formImplementationId, 1
);
/// @dev Creating superform using formImplementationId and failed deposit vault
(uint256 superformId,) = SuperformFactory(getContract(chainId, "SuperformFactory")).createSuperform(
formImplementationId, address(vault)
);

vm.stopPrank();
address router = getContract(ETH, "SuperformRouter");
vm.startPrank(router);
SuperPositions(getContract(ETH, "SuperPositions")).mintSingle(deployer, superformId, 1e18);
vm.stopPrank();

vm.startPrank(deployer);
/// @dev superform data with 1e18 final amount
SingleVaultSFData memory data = SingleVaultSFData(
superformId,
1,
1,
10_000,
LiqRequest("", getContract(ETH, "DAI"), address(0), 1, ETH, 0),
"",
false,
false,
receiverAddress,
receiverAddress,
""
);

SingleDirectSingleVaultStateReq memory req = SingleDirectSingleVaultStateReq(data);

SuperPositions(getContract(ETH, "SuperPositions")).setApprovalForAll(router, true);

vm.expectRevert(Error.WITHDRAW_ZERO_COLLATERAL.selector);
SuperformRouter(payable(router)).singleDirectSingleVaultWithdraw(req);
}

function test_superformXChainWithdrawalWithoutUpdatingTxData() public {
/// @dev prank deposits (just mint super-shares)
_successfulDeposit(false);
Expand Down

0 comments on commit 5e8225f

Please sign in to comment.