Skip to content

Commit

Permalink
locanet fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
skosito committed Aug 8, 2024
1 parent a32bf14 commit ca54018
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 3 deletions.
5 changes: 5 additions & 0 deletions v2/scripts/localnet/EvmDepositAndCall.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ pragma solidity 0.8.26;

import "forge-std/Script.sol";
import "src/evm/GatewayEVM.sol";
import "src/evm/ERC20Custody.sol";
import "test/utils/TestZContract.sol";
import "test/utils/TestERC20.sol";

Expand All @@ -12,6 +13,7 @@ contract EvmDepositAndCallScript is Script {
function run() external {
address payable gatewayEVMAddress = payable(vm.envOr("GATEWAY_EVM", 0x9fE46736679d2D9a65F0992F2272dE9f3c7fa6e0));
address payable zContractAddress = payable(vm.envOr("Z_CONTRACT", 0x68B1D87F95878fE05B998F19b66F4baba5De1aed));
address custodyAddress = vm.envOr("CUSTODY", 0xDc64a140Aa3E981100a9becA4E685f962f0cF6C9);
address erc20Address = vm.envOr("ERC20", 0x9A676e781A523b5d0C0e43731313A708CB607508);
uint256 amount = vm.envOr("AMOUNT", uint256(1));
string memory mnemonic = "test test test test test test test test test test test junk";
Expand All @@ -23,6 +25,9 @@ contract EvmDepositAndCallScript is Script {
GatewayEVM gatewayEVM = GatewayEVM(gatewayEVMAddress);
TestZContract zContract = TestZContract(zContractAddress);
TestERC20 erc20 = TestERC20(erc20Address);
ERC20Custody custody = ERC20Custody(custodyAddress);

custody.whitelist(erc20Address);

// Approve the ERC20 transfer
erc20.approve(gatewayEVMAddress, amount);
Expand Down
2 changes: 1 addition & 1 deletion v2/scripts/localnet/ZevmWithdrawAndCall.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ pragma solidity 0.8.26;
import "forge-std/Script.sol";
import "src/zevm/GatewayZEVM.sol";
import "test/utils/ReceiverEVM.sol";
import "test/utils/ZRC20.sol";
import "src/zevm/ZRC20.sol";

// ZevmWithdrawAndCallScript executes withdrawAndCall method on GatewayZEVM and it should be used on localnet.
// It uses anvil private key, and sets default contract addresses deployed on fresh localnet, that can be overriden with env vars.
Expand Down
4 changes: 2 additions & 2 deletions v2/scripts/localnet/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ const startWorker = async () => {
chainID,
},
testContracts.zrc20.target,
0,
1,
zContract,
payload,
deployOpts
Expand All @@ -271,7 +271,7 @@ const startWorker = async () => {
.execute(
[protocolContracts.gatewayZEVM.target, await fungibleModuleSigner.getAddress(), 1],
asset,
0,
1,
receiver,
payload,
deployOpts
Expand Down
1 change: 1 addition & 0 deletions v2/src/evm/GatewayEVM.sol
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,7 @@ contract GatewayEVM is
/// @param receiver Address of the receiver.
/// @param payload Calldata to pass to the call.
function call(address receiver, bytes calldata payload) external whenNotPaused nonReentrant {
if (receiver == address(0)) revert ZeroAddress();
emit Call(msg.sender, receiver, payload);
}

Expand Down
7 changes: 7 additions & 0 deletions v2/test/GatewayEVM.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -488,4 +488,11 @@ contract GatewayEVMInboundTest is Test, IGatewayEVMErrors, IGatewayEVMEvents, IR
emit Call(owner, destination, payload);
gateway.call(destination, payload);
}

function testCallWithPayloadFailsIfDestinationIsZeroAddress() public {
bytes memory payload = abi.encodeWithSignature("hello(address)", destination);

vm.expectRevert(ZeroAddress.selector);
gateway.call(address(0), payload);
}
}

0 comments on commit ca54018

Please sign in to comment.