Start of revert tests

This commit is contained in:
derpy-duck 2023-01-06 00:21:30 +00:00 committed by Joe Howarth
parent c95e4db5ff
commit a8bccd6753
2 changed files with 76 additions and 25 deletions

View File

@ -34,28 +34,31 @@ contract MockRelayerIntegration is IWormholeReceiver {
}
function sendMessage(bytes memory _message, uint16 targetChainId, address destination, address refundAddress) public payable {
executeSend(abi.encodePacked(uint8(0), _message), targetChainId, destination, refundAddress);
executeSend(abi.encodePacked(uint8(0), _message), targetChainId, destination, refundAddress, 0, 1);
}
function sendMessageWithForwardedResponse(bytes memory _message, uint16 targetChainId, address destination, address refundAddress) public payable {
executeSend(abi.encodePacked(uint8(1), _message), targetChainId, destination, refundAddress);
executeSend(abi.encodePacked(uint8(1), _message), targetChainId, destination, refundAddress, 0, 1);
}
function executeSend(bytes memory fullMessage, uint16 targetChainId, address destination, address refundAddress) internal {
wormhole.publishMessage{value: wormhole.messageFee()}(1, fullMessage, 200);
function sendMessageGeneral(bytes memory fullMessage, uint16 targetChainId, address destination, address refundAddress, uint256 applicationBudget, uint32 nonce) public payable {
executeSend(fullMessage, targetChainId, destination, refundAddress, applicationBudget, nonce);
}
function executeSend(bytes memory fullMessage, uint16 targetChainId, address destination, address refundAddress, uint256 applicationBudget, uint32 nonce) internal {
wormhole.publishMessage{value: wormhole.messageFee()}(nonce, fullMessage, 200);
uint256 applicationBudget = 0;
ICoreRelayer.DeliveryRequest memory request = ICoreRelayer.DeliveryRequest(
targetChainId, //target chain
relayer.toWormholeFormat(address(destination)), //target address
relayer.toWormholeFormat(address(refundAddress)), //refund address, This will be ignored on the target chain because the intent is to perform a forward
relayer.toWormholeFormat(address(refundAddress)), //refund address, This will be ignored on the target chain if the intent is to perform a forward
msg.value - 2*wormhole.messageFee(), //compute budget
applicationBudget, //application budget, not needed in this case.
relayer.getDefaultRelayParams() //no overrides
);
relayer.requestDelivery{value: msg.value - wormhole.messageFee()}(request, 1, relayer.getDefaultRelayProvider());
relayer.requestDelivery{value: msg.value - wormhole.messageFee()}(request, nonce, relayer.getDefaultRelayProvider());
}
@ -73,13 +76,13 @@ contract MockRelayerIntegration is IWormholeReceiver {
message = parsed.payload.slice(1, parsed.payload.length - 1);
if(forward) {
wormhole.publishMessage{value: wormhole.messageFee()}(1, abi.encodePacked(uint8(0), bytes("received!")), 200);
wormhole.publishMessage{value: wormhole.messageFee()}(parsed.nonce, abi.encodePacked(uint8(0), bytes("received!")), 200);
uint256 computeBudget = relayer.quoteGasDeliveryFee(parsed.emitterChainId, 500000, relayer.getDefaultRelayProvider());
ICoreRelayer.DeliveryRequest memory request = ICoreRelayer.DeliveryRequest(parsed.emitterChainId, parsed.emitterAddress, parsed.emitterAddress, computeBudget, 0, relayer.getDefaultRelayParams());
relayer.requestForward(request, parsed.emitterChainId, 1, relayer.getDefaultRelayProvider());
relayer.requestForward(request, parsed.emitterChainId, parsed.nonce, relayer.getDefaultRelayProvider());
}

View File

@ -279,9 +279,6 @@ contract TestCoreRelayer is Test {
uint32 wormholeFeeOnTargetInSourceCurrency = uint32(gasParams.wormholeFeeOnSource*map[SOURCE_CHAIN_ID].relayProvider.quoteAssetPrice(TARGET_CHAIN_ID)/map[SOURCE_CHAIN_ID].relayProvider.quoteAssetPrice(SOURCE_CHAIN_ID) + 1);
map[SOURCE_CHAIN_ID].relayProvider.updateWormholeFee(TARGET_CHAIN_ID, wormholeFeeOnTargetInSourceCurrency);
console.log(map[SOURCE_CHAIN_ID].wormhole.messageFee());
console.log(map[TARGET_CHAIN_ID].wormhole.messageFee());
uint256 payment = source.coreRelayer.quoteGasDeliveryFee(TARGET_CHAIN_ID, gasParams.targetGasLimit, source.relayProvider) + source.wormhole.messageFee();
source.integration.sendMessage{value: payment}(message, TARGET_CHAIN_ID, address(target.integration), address(target.refundAddress));
@ -295,8 +292,7 @@ contract TestCoreRelayer is Test {
uint256 howMuchGasRelayerCouldHavePaidForAndStillProfited = relayerProfit/gasParams.targetGasPrice/gasParams.targetNativePrice;
assertTrue(howMuchGasRelayerCouldHavePaidForAndStillProfited >= 30000); // takes around this much gas (seems to go from 36k-200k?!?)
console.log(USDcost);
console.log(relayerProfit);
assertTrue(USDcost == relayerProfit + 2*map[SOURCE_CHAIN_ID].wormhole.messageFee()*gasParams.sourceNativePrice, "We paid the exact amount");
}
@ -383,6 +379,67 @@ contract TestCoreRelayer is Test {
}
function testRevertRequestRedeliveryNotEnoughFunds(GasParameters memory gasParams, bytes memory message) public {
(uint16 SOURCE_CHAIN_ID, uint16 TARGET_CHAIN_ID, Contracts memory source, Contracts memory target) = standardAssumeAndSetupTwoChains(gasParams, 1000000);
vm.recordLogs();
// estimate the cost based on the intialized values
uint256 payment = source.coreRelayer.quoteGasRedeliveryFee(TARGET_CHAIN_ID, gasParams.targetGasLimit, source.relayProvider) + source.wormhole.messageFee();
uint256 paymentNotEnough = source.coreRelayer.quoteGasDeliveryFee(TARGET_CHAIN_ID, 10, source.relayProvider) + source.wormhole.messageFee();
source.integration.sendMessage{value: paymentNotEnough}(message, TARGET_CHAIN_ID, address(target.integration), address(target.refundAddress));
genericRelayer(SOURCE_CHAIN_ID, 2);
assertTrue((keccak256(target.integration.getMessage()) != keccak256(message)) || (keccak256(message) == keccak256(bytes(""))));
bytes32 deliveryVaaHash = vm.getRecordedLogs()[0].data.toBytes32(0);
ICoreRelayer.RedeliveryByTxHashRequest memory redeliveryRequest = ICoreRelayer.RedeliveryByTxHashRequest(SOURCE_CHAIN_ID, deliveryVaaHash, 1, TARGET_CHAIN_ID, payment - source.wormhole.messageFee(), 0, source.coreRelayer.getDefaultRelayParams());
vm.expectRevert(bytes("1"));
source.coreRelayer.requestRedelivery{value: payment-1}(redeliveryRequest, 1, source.relayProvider);
}
function testRevertNonceZero(GasParameters memory gasParams, bytes memory message) public {
(uint16 SOURCE_CHAIN_ID, uint16 TARGET_CHAIN_ID, Contracts memory source, Contracts memory target) = standardAssumeAndSetupTwoChains(gasParams, 1000000);
vm.recordLogs();
uint256 wormholeFee = source.wormhole.messageFee();
// estimate the cost based on the intialized values
uint256 computeBudget = source.coreRelayer.quoteGasDeliveryFee(TARGET_CHAIN_ID, gasParams.targetGasLimit, source.relayProvider);
vm.expectRevert(bytes("2"));
source.integration.sendMessageGeneral{value: computeBudget + wormholeFee}(abi.encodePacked(uint8(0), message), TARGET_CHAIN_ID, address(target.integration), address(target.refundAddress), 0, 0);
}
/** Forwarding tests 3-7.. need to think about how to test this.. some sort of way to control the forwarding request? Or maybe make a different relayerintegration for testing? */
/** Reentrnecy test for execute delivery 8 */
/** Redelivery 9-17 */
/** Delivery 18-24 */
/** Request delivery 25-27 */
/** asset conversoin 28-29 */
/*****
*
* GENERIC RELAYER CODE
*
*****/
mapping(uint256 => bool) nonceCompleted;
mapping(bytes32 => ICoreRelayer.TargetDeliveryParametersSingle) pastDeliveries;
@ -461,15 +518,6 @@ contract TestCoreRelayer is Test {
map[targetChain].coreRelayer.redeliverSingle{value: budget}(package);
}
}
/**
FORWARDING TESTS
*/
//This test confirms that forwarding a request produces the proper delivery instructions
//This test confirms that forwarding cannot occur when the contract is locked
//This test confirms that forwarding cannot occur if there are insufficient refunds after the request
}