Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
skosito committed Jul 17, 2024
1 parent 718787f commit 09e5d90
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 13 deletions.
12 changes: 6 additions & 6 deletions contracts/prototypes/evm/GatewayEVMUpgradeTest.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,20 @@ contract GatewayEVMUpgradeTest is Initializable, OwnableUpgradeable, UUPSUpgrade
address public custody;
address public tssAddress;
address public zetaConnector;
address public zetaAsset;
address public zeta;

event ExecutedV2(address indexed destination, uint256 value, bytes data);

constructor() {}

function initialize(address _tssAddress, address _zetaAsset) public initializer {
function initialize(address _tssAddress, address _zeta) public initializer {
__Ownable_init();
__UUPSUpgradeable_init();

if (_tssAddress == address(0)) revert ZeroAddress();

tssAddress = _tssAddress;
zetaAsset = _zetaAsset;
zeta = _zeta;
}

function _authorizeUpgrade(address newImplementation) internal override onlyOwner() {}
Expand Down Expand Up @@ -80,7 +80,7 @@ contract GatewayEVMUpgradeTest is Initializable, OwnableUpgradeable, UUPSUpgrade
uint256 remainingBalance = IERC20(token).balanceOf(address(this));
if (remainingBalance > 0) {
address destination = address(custody);
if (token == zetaAsset) {
if (token == zeta) {
destination = address(zetaConnector);
}
IERC20(token).safeTransfer(address(destination), remainingBalance);
Expand All @@ -106,7 +106,7 @@ contract GatewayEVMUpgradeTest is Initializable, OwnableUpgradeable, UUPSUpgrade
if (amount == 0) revert InsufficientERC20Amount();

address destination = address(custody);
if (asset == zetaAsset) {
if (asset == zeta) {
destination = address(zetaConnector);
}
IERC20(asset).safeTransferFrom(msg.sender, address(destination), amount);
Expand All @@ -129,7 +129,7 @@ contract GatewayEVMUpgradeTest is Initializable, OwnableUpgradeable, UUPSUpgrade
if (amount == 0) revert InsufficientERC20Amount();

address destination = address(custody);
if (asset == zetaAsset) {
if (asset == zeta) {
destination = address(zetaConnector);
}
IERC20(asset).safeTransferFrom(msg.sender, address(destination), amount);
Expand Down
11 changes: 8 additions & 3 deletions testFoundry/GatewayEVM.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ contract GatewayEVMTest is Test, IGatewayEVMErrors, IGatewayEVMEvents, IReceiver

proxy = address(new ERC1967Proxy(
address(new GatewayEVM()),
abi.encodeWithSelector(GatewayEVM.initialize.selector, (tssAddress, zeta))
abi.encodeWithSelector(GatewayEVM.initialize.selector, tssAddress, address(zeta))
));
gateway = GatewayEVM(proxy);
custody = new ERC20CustodyNew(address(gateway));
Expand Down Expand Up @@ -180,7 +180,9 @@ contract GatewayEVMInboundTest is Test, IGatewayEVMErrors, IGatewayEVMEvents, IR

GatewayEVM gateway;
ERC20CustodyNew custody;
ZetaConnectorNew zetaConnector;
TestERC20 token;
TestERC20 zeta;
address owner;
address destination;
address tssAddress;
Expand All @@ -193,14 +195,17 @@ contract GatewayEVMInboundTest is Test, IGatewayEVMErrors, IGatewayEVMEvents, IR
tssAddress = address(0x5678);

token = new TestERC20("test", "TTK");
address proxy = address(new ERC1967Proxy(
zeta = new TestERC20("zeta", "ZETA");
address proxy = address(new ERC1967Proxy(
address(new GatewayEVM()),
abi.encodeWithSelector(GatewayEVM.initialize.selector, (tssAddress))
abi.encodeWithSelector(GatewayEVM.initialize.selector, tssAddress, address(zeta))
));
gateway = GatewayEVM(proxy);
custody = new ERC20CustodyNew(address(gateway));
zetaConnector = new ZetaConnectorNew(address(gateway), address(zeta));

gateway.setCustody(address(custody));
gateway.setConnector(address(zetaConnector));

token.mint(owner, ownerAmount);
}
Expand Down
8 changes: 7 additions & 1 deletion testFoundry/GatewayEVMUpgrade.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import "contracts/prototypes/evm/GatewayEVM.sol";
import "contracts/prototypes/evm/GatewayEVMUpgradeTest.sol";
import "contracts/prototypes/evm/ReceiverEVM.sol";
import "contracts/prototypes/evm/ERC20CustodyNew.sol";
import "contracts/prototypes/evm/ZetaConnectorNew.sol";
import "contracts/prototypes/evm/TestERC20.sol";
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
Expand All @@ -23,7 +24,9 @@ contract GatewayEVMUUPSUpgradeTest is Test, IGatewayEVMErrors, IGatewayEVMEvents
GatewayEVM gateway;
ReceiverEVM receiver;
ERC20CustodyNew custody;
ZetaConnectorNew zetaConnector;
TestERC20 token;
TestERC20 zeta;
address owner;
address destination;
address tssAddress;
Expand All @@ -34,17 +37,20 @@ contract GatewayEVMUUPSUpgradeTest is Test, IGatewayEVMErrors, IGatewayEVMEvents
tssAddress = address(0x5678);

token = new TestERC20("test", "TTK");
zeta = new TestERC20("zeta", "ZETA");

proxy = address(new ERC1967Proxy(
address(new GatewayEVM()),
abi.encodeWithSelector(GatewayEVM.initialize.selector, (tssAddress))
abi.encodeWithSelector(GatewayEVM.initialize.selector, tssAddress, zeta)
));
gateway = GatewayEVM(proxy);

custody = new ERC20CustodyNew(address(gateway));
zetaConnector = new ZetaConnectorNew(address(gateway), address(zeta));
receiver = new ReceiverEVM();

gateway.setCustody(address(custody));
gateway.setConnector(address(zetaConnector));

token.mint(owner, 1000000);
token.transfer(address(custody), 500000);
Expand Down
10 changes: 9 additions & 1 deletion testFoundry/GatewayEVMZEVM.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import "forge-std/Vm.sol";
import "contracts/prototypes/evm/GatewayEVM.sol";
import "contracts/prototypes/evm/ReceiverEVM.sol";
import "contracts/prototypes/evm/ERC20CustodyNew.sol";
import "contracts/prototypes/evm/ZetaConnectorNew.sol";
import "contracts/prototypes/evm/TestERC20.sol";
import "contracts/prototypes/evm/ReceiverEVM.sol";

Expand All @@ -29,7 +30,9 @@ contract GatewayEVMZEVMTest is Test, IGatewayEVMErrors, IGatewayEVMEvents, IGate
address proxyEVM;
GatewayEVM gatewayEVM;
ERC20CustodyNew custody;
ZetaConnectorNew zetaConnector;
TestERC20 token;
TestERC20 zeta;
ReceiverEVM receiverEVM;
address ownerEVM;
address destination;
Expand All @@ -51,14 +54,18 @@ contract GatewayEVMZEVMTest is Test, IGatewayEVMErrors, IGatewayEVMEvents, IGate
ownerZEVM = address(0x4321);

token = new TestERC20("test", "TTK");
zeta = new TestERC20("zeta", "ZETA");

proxyEVM = address(new ERC1967Proxy(
address(new GatewayEVM()),
abi.encodeWithSelector(GatewayEVM.initialize.selector, (tssAddress))
abi.encodeWithSelector(GatewayEVM.initialize.selector, tssAddress, address(zeta))
));
gatewayEVM = GatewayEVM(proxyEVM);
custody = new ERC20CustodyNew(address(gatewayEVM));
zetaConnector = new ZetaConnectorNew(address(gatewayEVM), address(zeta));

gatewayEVM.setCustody(address(custody));
gatewayEVM.setConnector(address(zetaConnector));

token.mint(ownerEVM, 1000000);
token.transfer(address(custody), 500000);
Expand Down Expand Up @@ -139,6 +146,7 @@ contract GatewayEVMZEVMTest is Test, IGatewayEVMErrors, IGatewayEVMEvents, IGate
vm.expectEmit(true, true, true, true, address(gatewayZEVM));
emit Withdrawal(
ownerZEVM,
address(zrc20),
abi.encodePacked(receiverEVM),
1000000,
0,
Expand Down
4 changes: 2 additions & 2 deletions testFoundry/GatewayZEVM.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ contract GatewayZEVMInboundTest is Test, IGatewayZEVMEvents, IGatewayZEVMErrors
uint256 ownerBalanceBefore = zrc20.balanceOf(owner);

vm.expectEmit(true, true, true, true, address(gateway));
emit Withdrawal(owner, abi.encodePacked(addr1), 1, 0, zrc20.PROTOCOL_FLAT_FEE(), "");
emit Withdrawal(owner, address(zrc20), abi.encodePacked(addr1), 1, 0, zrc20.PROTOCOL_FLAT_FEE(), "");
gateway.withdraw(abi.encodePacked(addr1), 1, address(zrc20));

uint256 ownerBalanceAfter = zrc20.balanceOf(owner);
Expand All @@ -63,7 +63,7 @@ contract GatewayZEVMInboundTest is Test, IGatewayZEVMEvents, IGatewayZEVMErrors

bytes memory message = abi.encodeWithSignature("hello(address)", addr1);
vm.expectEmit(true, true, true, true, address(gateway));
emit Withdrawal(owner, abi.encodePacked(addr1), 1, 0, zrc20.PROTOCOL_FLAT_FEE(), message);
emit Withdrawal(owner, address(zrc20), abi.encodePacked(addr1), 1, 0, zrc20.PROTOCOL_FLAT_FEE(), message);
gateway.withdrawAndCall(abi.encodePacked(addr1), 1, address(zrc20), message);

uint256 ownerBalanceAfter = zrc20.balanceOf(owner);
Expand Down

0 comments on commit 09e5d90

Please sign in to comment.