Skip to content

Commit

Permalink
Add testAgentExecutionTransactToTransferERC20
Browse files Browse the repository at this point in the history
  • Loading branch information
yrong committed Apr 24, 2024
1 parent 1fb852d commit 1113521
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 7 deletions.
32 changes: 26 additions & 6 deletions contracts/test/Gateway.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ import {
import {WETH9} from "canonical-weth/WETH9.sol";
import {UD60x18, ud60x18, convert} from "prb/math/src/UD60x18.sol";
import {HelloWorld} from "./mocks/HelloWorld.sol";
import {IERC20} from "../src/interfaces/IERC20.sol";

contract GatewayTest is Test {
ParaID public bridgeHubParaID = ParaID.wrap(1001);
Expand Down Expand Up @@ -100,16 +101,12 @@ contract GatewayTest is Test {
HelloWorld helloWorld;

event SaidHello(string indexed message);
event Transfer(address indexed src, address indexed dst, uint256 wad);

function setUp() public {
AgentExecutor executor = new AgentExecutor();
gatewayLogic = new MockGateway(
address(0),
address(executor),
bridgeHubParaID,
bridgeHubAgentID,
foreignTokenDecimals,
maxDestinationFee
address(0), address(executor), bridgeHubParaID, bridgeHubAgentID, foreignTokenDecimals, maxDestinationFee
);
Gateway.Config memory config = Gateway.Config({
mode: OperatingMode.Normal,
Expand Down Expand Up @@ -928,4 +925,27 @@ contract GatewayTest is Test {

MockGateway(address(gateway)).agentExecutePublic(abi.encode(params));
}

function testAgentExecutionTransactToTransferERC20() public {
token.transfer(address(assetHubAgent), 200);

uint256 balanceBefore = IERC20(address(token)).balanceOf(account1);

uint256 amount = 50;
bytes memory payload = abi.encodeCall(IERC20.transfer, (account1, amount));

AgentExecuteParams memory params = AgentExecuteParams({
agentID: assetHubAgentID,
payload: abi.encode(AgentExecuteCommand.Transact, abi.encode(address(token), payload, 100000))
});

// Expect the WETH9 contract to emit `Transfer`
vm.expectEmit(true, false, false, false);
emit Transfer(address(assetHubAgent), account1, amount);

MockGateway(address(gateway)).agentExecutePublic(abi.encode(params));

uint256 balanceAfter = IERC20(address(token)).balanceOf(account1);
assertEq(balanceBefore + amount, balanceAfter);
}
}
2 changes: 1 addition & 1 deletion contracts/test/mocks/MockGatewayV2.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ library AdditionalStorage {
}

// Used to test upgrades.
contract MockGatewayV2 is IInitializable {
contract MockGatewayV2 is IInitializable {
// Reinitialize gateway with some additional storage fields
function initialize(bytes memory params) external {
AdditionalStorage.Layout storage $ = AdditionalStorage.layout();
Expand Down

0 comments on commit 1113521

Please sign in to comment.