Skip to content

Commit

Permalink
added test
Browse files Browse the repository at this point in the history
  • Loading branch information
alistair-singh committed Oct 22, 2024
1 parent e87ddb2 commit 375fdeb
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
33 changes: 33 additions & 0 deletions contracts/src/DepositWETH9AndSend.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: 2023 Snowfork <[email protected]>
pragma solidity 0.8.25;

import {IGateway} from "./interfaces/IGateway.sol";
import {WETH9} from "canonical-weth/WETH9.sol";
import {ParaID, MultiAddress} from "./Types.sol";

contract DepositWETH9AndSend {
address public immutable GATEWAY_PROXY;
address payable public immutable WETH_INSTANCE;

constructor(address _gatewayProxy, address payable _wethInstance) {
GATEWAY_PROXY = _gatewayProxy;
WETH_INSTANCE = _wethInstance;
}

// Transfer ERC20 tokens to a Polkadot parachain
function sendToken(
ParaID destinationChain,
MultiAddress calldata destinationAddress,
uint128 destinationFee,
uint128 amount
) external payable {
WETH9(WETH_INSTANCE).deposit{value: amount}();
WETH9(WETH_INSTANCE).approve(GATEWAY_PROXY, amount);

uint256 fee = msg.value - amount;
IGateway(GATEWAY_PROXY).sendToken{value: fee}(
WETH_INSTANCE, destinationChain, destinationAddress, destinationFee, amount
);
}
}
28 changes: 28 additions & 0 deletions contracts/test/Gateway.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {Gateway} from "../src/Gateway.sol";
import {MockGateway} from "./mocks/MockGateway.sol";
import {MockGatewayV2} from "./mocks/MockGatewayV2.sol";
import {GatewayProxy} from "../src/GatewayProxy.sol";
import {DepositWETH9AndSend} from "../src/DepositWETH9AndSend.sol";

import {AgentExecutor} from "../src/AgentExecutor.sol";
import {Agent} from "../src/Agent.sol";
Expand Down Expand Up @@ -76,6 +77,7 @@ contract GatewayTest is Test {

MockGateway public gatewayLogic;
GatewayProxy public gateway;
DepositWETH9AndSend public depositAndSend;

WETH9 public token;

Expand Down Expand Up @@ -154,6 +156,9 @@ contract GatewayTest is Test {
recipientAddress20 = multiAddressFromBytes20(bytes20(keccak256("recipient")));

dotTokenID = bytes32(uint256(1));

// Deposit and send
depositAndSend = new DepositWETH9AndSend(address(gateway), payable(token));
}

function makeCreateAgentCommand() public pure returns (Command, bytes memory) {
Expand Down Expand Up @@ -609,6 +614,29 @@ contract GatewayTest is Test {
IGateway(address(gateway)).sendToken{value: fee}(address(token), destPara, recipientAddress32, 1, 1);
}


function testDepositAndSendTokenAddress32() public {
// Multilocation for recipient
ParaID destPara = ParaID.wrap(2043);

// register token first
uint256 fee = IGateway(address(gateway)).quoteRegisterTokenFee();
IGateway(address(gateway)).registerToken{value: fee}(address(token));

fee = IGateway(address(gateway)).quoteSendTokenFee(address(token), destPara, 1);

vm.expectEmit(true, true, false, true);
emit IGateway.TokenSent(address(token), address(depositAndSend), destPara, recipientAddress32, 1);

// Expect the gateway to emit `OutboundMessageAccepted`
vm.expectEmit(true, false, false, false);
emit IGateway.OutboundMessageAccepted(assetHubParaID.into(), 1, messageID, bytes(""));

uint128 amount = 1;

depositAndSend.sendToken{value: fee + amount}(destPara, recipientAddress32, 1, amount);
}

function testSendTokenAddress32ToAssetHub() public {
// Let gateway lock up to 1 tokens
token.approve(address(gateway), 1);
Expand Down

0 comments on commit 375fdeb

Please sign in to comment.