Skip to content

Commit

Permalink
add more connector tests
Browse files Browse the repository at this point in the history
  • Loading branch information
skosito committed Aug 7, 2024
1 parent 9b0385e commit 8c3e4f6
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 0 deletions.
37 changes: 37 additions & 0 deletions v2/test/ZetaConnectorNative.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,11 @@ contract ZetaConnectorNativeTest is
address destination;
address tssAddress;

error EnforcedPause();
error AccessControlUnauthorizedAccount(address account, bytes32 neededRole);

bytes32 public constant WITHDRAWER_ROLE = keccak256("WITHDRAWER_ROLE");
bytes32 public constant PAUSER_ROLE = keccak256("PAUSER_ROLE");

function setUp() public {
owner = address(this);
Expand Down Expand Up @@ -88,6 +90,41 @@ contract ZetaConnectorNativeTest is
assertEq(balanceAfter, amount);
}

function testWithdrawTogglePause() public {
uint256 amount = 100_000;
bytes32 internalSendHash = "";

vm.prank(tssAddress);
vm.expectRevert(abi.encodeWithSelector(AccessControlUnauthorizedAccount.selector, tssAddress, PAUSER_ROLE));
zetaConnector.pause();

vm.prank(tssAddress);
vm.expectRevert(abi.encodeWithSelector(AccessControlUnauthorizedAccount.selector, tssAddress, PAUSER_ROLE));
zetaConnector.unpause();

vm.prank(owner);
zetaConnector.pause();

vm.expectRevert(EnforcedPause.selector);
vm.prank(tssAddress);
zetaConnector.withdraw(destination, amount, internalSendHash);

vm.prank(owner);
zetaConnector.unpause();

uint256 balanceBefore = zetaToken.balanceOf(destination);
assertEq(balanceBefore, 0);

bytes memory data = abi.encodeWithSignature("transfer(address,uint256)", destination, amount);
vm.expectCall(address(zetaToken), 0, data);
vm.expectEmit(true, true, true, true, address(zetaConnector));
emit Withdraw(destination, amount);
vm.prank(tssAddress);
zetaConnector.withdraw(destination, amount, internalSendHash);
uint256 balanceAfter = zetaToken.balanceOf(destination);
assertEq(balanceAfter, amount);
}

function testWithdrawFailsIfSenderIsNotWithdrawer() public {
uint256 amount = 100_000;
bytes32 internalSendHash = "";
Expand Down
38 changes: 38 additions & 0 deletions v2/test/ZetaConnectorNonNative.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,11 @@ contract ZetaConnectorNonNativeTest is

error AccessControlUnauthorizedAccount(address account, bytes32 neededRole);
error ExceedsMaxSupply();
error EnforcedPause();

bytes32 public constant WITHDRAWER_ROLE = keccak256("WITHDRAWER_ROLE");
bytes32 public constant TSS_ROLE = keccak256("TSS_ROLE");
bytes32 public constant PAUSER_ROLE = keccak256("PAUSER_ROLE");

function setUp() public {
owner = address(this);
Expand Down Expand Up @@ -91,6 +93,42 @@ contract ZetaConnectorNonNativeTest is
assertEq(balanceAfter, amount);
}

function testWithdrawTogglePause() public {
uint256 amount = 100_000;
bytes32 internalSendHash = "";

vm.prank(tssAddress);
vm.expectRevert(abi.encodeWithSelector(AccessControlUnauthorizedAccount.selector, tssAddress, PAUSER_ROLE));
zetaConnector.pause();

vm.prank(tssAddress);
vm.expectRevert(abi.encodeWithSelector(AccessControlUnauthorizedAccount.selector, tssAddress, PAUSER_ROLE));
zetaConnector.unpause();

vm.prank(owner);
zetaConnector.pause();

vm.expectRevert(EnforcedPause.selector);
vm.prank(tssAddress);
zetaConnector.withdraw(destination, amount, internalSendHash);

vm.prank(owner);
zetaConnector.unpause();

uint256 balanceBefore = zetaToken.balanceOf(destination);
assertEq(balanceBefore, 0);

bytes memory data =
abi.encodeWithSignature("mint(address,uint256,bytes32)", destination, amount, internalSendHash);
vm.expectCall(address(zetaToken), 0, data);
vm.expectEmit(true, true, true, true, address(zetaConnector));
emit Withdraw(destination, amount);
vm.prank(tssAddress);
zetaConnector.withdraw(destination, amount, internalSendHash);
uint256 balanceAfter = zetaToken.balanceOf(destination);
assertEq(balanceAfter, amount);
}

function testWithdrawFailsIfSenderIsNotWithdrawer() public {
uint256 amount = 100_000;
bytes32 internalSendHash = "";
Expand Down

0 comments on commit 8c3e4f6

Please sign in to comment.