The home for Hyperlane core contracts, sdk packages, and other infrastructure
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
hyperlane-monorepo/solidity/test/TestQuerySender.t.sol

78 lines
2.5 KiB

// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8.13;
import "forge-std/Test.sol";
import {InterchainQueryRouter} from "../contracts/middleware/InterchainQueryRouter.sol";
import {TestQuerySender} from "../contracts/test/TestQuerySender.sol";
import {MockHyperlaneEnvironment} from "./MockHyperlaneEnvironment.sol";
import {MockToken} from "../contracts/mock/MockToken.sol";
contract TestQuerySenderTest is Test {
MockHyperlaneEnvironment testEnvironment;
TestQuerySender sender;
uint32 originDomain = 123;
uint32 destinationDomain = 321;
function setUp() public {
testEnvironment = new MockHyperlaneEnvironment(
originDomain,
destinationDomain
);
sender = new TestQuerySender();
sender.initialize(address(testEnvironment.queryRouters(originDomain)));
}
function testSendAddressQuery(address owner) public {
vm.assume(owner != address(0x0));
// Deploy a random ownable contract
InterchainQueryRouter ownable = new InterchainQueryRouter();
// Set the routers owner
ownable.transferOwnership(owner);
sender.queryAddress(
destinationDomain,
address(ownable),
abi.encodeWithSelector(ownable.owner.selector)
);
testEnvironment.processNextPendingMessage();
testEnvironment.processNextPendingMessageFromDestination();
assertEq(sender.lastAddressResult(), owner);
}
function testSendUint256Query(uint256 balance) public {
vm.assume(balance > 0);
MockToken token = new MockToken();
token.mint(address(this), balance);
sender.queryUint256(
destinationDomain,
address(token),
abi.encodeWithSelector(token.balanceOf.selector, address(this))
);
testEnvironment.processNextPendingMessage();
testEnvironment.processNextPendingMessageFromDestination();
assertEq(sender.lastUint256Result(), balance);
}
function testSendBytesQuery(uint256 balance) public {
vm.assume(balance > 0);
MockToken token = new MockToken();
token.mint(address(this), balance);
sender.queryBytes32(
destinationDomain,
address(token),
abi.encodeWithSelector(token.balanceOf.selector, address(this))
);
testEnvironment.processNextPendingMessage();
testEnvironment.processNextPendingMessageFromDestination();
assertEq(sender.lastBytes32Result(), bytes32(balance));
}
}