Skip to content

Commit

Permalink
make zero error consistent and add unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthew Lam committed Oct 19, 2023
1 parent 3c9bc0f commit d18c657
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -736,6 +736,13 @@ contract ERC20BridgeTest is Test {
);
}

function testZeroTeleporterRegistryAddress() public {
vm.expectRevert(
"TeleporterUpgradeable: zero teleporter registry address"
);
new ERC20Bridge(address(0));
}

function _setUpBridgeToken(
bytes32 nativeChainID,
address nativeBridgeAddress,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ abstract contract TeleporterUpgradeable {
constructor(address teleporterRegistryAddress) {
require(
teleporterRegistryAddress != address(0),
"TeleporterUpgradeable: invalid teleporter registry address"
"TeleporterUpgradeable: zero teleporter registry address"
);

teleporterRegistry = TeleporterRegistry(teleporterRegistryAddress);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ contract TeleporterUpgradeableTest is Test {

function testInvalidRegistryAddress() public {
vm.expectRevert(
_formatErrorMessage("invalid teleporter registry address")
_formatTeleporterUpgradeableErrorMessage(
"zero teleporter registry address"
)
);
new ExampleUpgradeableApp(address(0));
}
Expand All @@ -64,7 +66,11 @@ contract TeleporterUpgradeableTest is Test {

assertEq(app.getMinTeleporterVersion(), 1);

vm.expectRevert(_formatErrorMessage("invalid teleporter sender"));
vm.expectRevert(
_formatTeleporterUpgradeableErrorMessage(
"invalid teleporter sender"
)
);
app.teleporterCall();

vm.prank(MOCK_TELEPORTER_MESSENGER_ADDRESS);
Expand Down Expand Up @@ -92,12 +98,16 @@ contract TeleporterUpgradeableTest is Test {
assertEq(app.getMinTeleporterVersion(), 2);

// Check that calling with the old teleporter address fails
vm.expectRevert(_formatErrorMessage("invalid teleporter sender"));
vm.expectRevert(
_formatTeleporterUpgradeableErrorMessage(
"invalid teleporter sender"
)
);
vm.prank(MOCK_TELEPORTER_MESSENGER_ADDRESS);
app.teleporterCall();
}

function _formatErrorMessage(
function _formatTeleporterUpgradeableErrorMessage(
string memory errorMessage
) private pure returns (bytes memory) {
return bytes(string.concat("TeleporterUpgradeable: ", errorMessage));
Expand Down

0 comments on commit d18c657

Please sign in to comment.