trustless-generic-relayer/ethereum/forge-test/GasOracle.t.sol

209 lines
6.6 KiB
Solidity
Raw Normal View History

// SPDX-License-Identifier: Apache 2
pragma solidity ^0.8.0;
import "../contracts/gasOracle/GasOracle.sol";
import {Implementation} from "../wormhole/ethereum/contracts/Implementation.sol";
import "forge-std/Test.sol";
import "forge-std/console.sol";
2022-09-13 14:44:12 -07:00
contract TestGasOracle is Test {
uint16 constant TEST_ORACLE_CHAIN_ID = 2;
Implementation internal wormhole;
2022-09-13 14:44:12 -07:00
GasOracle internal gasOracle;
function initializeGasOracle() internal {
wormhole = new Implementation();
// chainId, governanceChainId
vm.store(address(wormhole), bytes32(0), 0x0000000000000000000000000000000000000000000000000000000000010002);
gasOracle = new GasOracle(address(wormhole));
2022-09-13 14:44:12 -07:00
require(gasOracle.owner() == address(this), "owner() != expected");
require(gasOracle.chainId() == wormhole.chainId(), "chainId() != expected");
require(address(gasOracle.wormhole()) == address(wormhole), "wormhole() != expected");
}
2022-09-13 14:44:12 -07:00
function testCannotUpdatePriceWithChainIdZero(uint128 updateGasPrice, uint128 updateNativeCurrencyPrice) public {
vm.assume(updateGasPrice > 0);
vm.assume(updateNativeCurrencyPrice > 0);
initializeGasOracle();
// you shall not pass
vm.expectRevert("updateChainId == 0");
2022-09-13 14:44:12 -07:00
gasOracle.updatePrice(
0, // updateChainId
updateGasPrice,
updateNativeCurrencyPrice
);
}
2022-09-13 14:44:12 -07:00
function testCannotUpdatePriceWithGasPriceZero(uint16 updateChainId, uint128 updateNativeCurrencyPrice) public {
vm.assume(updateChainId > 0);
vm.assume(updateNativeCurrencyPrice > 0);
initializeGasOracle();
// you shall not pass
vm.expectRevert("updateGasPrice == 0");
2022-09-13 14:44:12 -07:00
gasOracle.updatePrice(
updateChainId,
0, // updateGasPrice == 0
updateNativeCurrencyPrice
);
}
2022-09-13 14:44:12 -07:00
function testCannotUpdatePriceWithNativeCurrencyPriceZero(uint16 updateChainId, uint128 updateGasPrice) public {
vm.assume(updateChainId > 0);
vm.assume(updateGasPrice > 0);
initializeGasOracle();
// you shall not pass
vm.expectRevert("updateNativeCurrencyPrice == 0");
2022-09-13 14:44:12 -07:00
gasOracle.updatePrice(
updateChainId,
updateGasPrice,
0 // updateNativeCurrencyPrice == 0
);
}
function testCanUpdatePriceOnlyAsOwner(
address oracleOwner,
uint16 updateChainId,
2022-09-13 14:44:12 -07:00
uint128 updateGasPrice,
uint128 updateNativeCurrencyPrice
)
public
{
vm.assume(oracleOwner != address(0));
2022-09-13 14:44:12 -07:00
vm.assume(oracleOwner != address(this));
vm.assume(updateChainId > 0);
vm.assume(updateGasPrice > 0);
vm.assume(updateNativeCurrencyPrice > 0);
initializeGasOracle();
// you shall not pass
2022-09-13 14:44:12 -07:00
vm.prank(oracleOwner);
vm.expectRevert("owner() != _msgSender()");
2022-09-13 14:44:12 -07:00
gasOracle.updatePrice(updateChainId, updateGasPrice, updateNativeCurrencyPrice);
}
function testCannotGetPriceBeforeUpdateSrcPrice(
uint16 dstChainId,
2022-09-13 14:44:12 -07:00
uint128 dstGasPrice,
uint128 dstNativeCurrencyPrice
)
public
{
vm.assume(dstChainId > 0);
vm.assume(dstChainId != TEST_ORACLE_CHAIN_ID);
vm.assume(dstGasPrice > 0);
vm.assume(dstNativeCurrencyPrice > 0);
initializeGasOracle();
// update the price with reasonable values
2022-09-13 14:44:12 -07:00
gasOracle.updatePrice(dstChainId, dstGasPrice, dstNativeCurrencyPrice);
// you shall not pass
vm.expectRevert("srcNativeCurrencyPrice == 0");
Add tests for send and deliver functionality (#9) * Complete send and deliver functionality * Clean up * Add tests for relayer send method * ethereum: remove interfaces * ethereum: fix test * ethereum: rename directory * ethereum: clean up; add ts tests * Add tests and clean up * ethereum: fix test * ethereum: fix output * Add reentrancy protection and reduce gas overhead for relayers * Add tests for full batch delivery * Update relayer contracts to reflect changes to batch VAA implementation * add rewards payout * implement redeliveries, replay protection * Complete full batch test suite * sdk: add sdk * sdk: fix package.json * Add partial batch unit test and add to integration test * Fix comments in integration test * sdk: fix tsconfig.json * ethereum: fix build * Add relayer registration to integration test * Finish integration test suite * ethereum: fix readAbi * ethereum: fix merge conflict * Complete full batch test suite * Add partial batch unit test and add to integration test * Finish integration test suite * Fix local validator test * Fix merge conflict * Add Makefile * Add documentation to relayer contracts * Fix Makefile * ethereum: clean up * ethereum: fix interface * ethereum: fix method names and tests * Prepare integration test for off-chain relayer changes * Refactor contracts Co-authored-by: Drew <dsterioti@users.noreply.github.com> Co-authored-by: Karl Kempe <karlkempe@users.noreply.github.com> Co-authored-by: valentin <valentinvonalbrecht@yahoo.de> Co-authored-by: justinschuldt <justinschuldt@gmail.com>
2022-09-30 09:18:49 -07:00
gasOracle.computeGasCost(dstChainId, 1);
}
function testCannotGetPriceBeforeUpdateDstPrice(
uint16 dstChainId,
2022-09-13 14:44:12 -07:00
uint128 srcGasPrice,
uint128 srcNativeCurrencyPrice
)
public
{
vm.assume(dstChainId > 0);
vm.assume(dstChainId != TEST_ORACLE_CHAIN_ID);
vm.assume(srcGasPrice > 0);
vm.assume(srcNativeCurrencyPrice > 0);
initializeGasOracle();
// update the price with reasonable values
2022-09-13 14:44:12 -07:00
//vm.prank(gasOracle.owner());
gasOracle.updatePrice(gasOracle.chainId(), srcGasPrice, srcNativeCurrencyPrice);
// you shall not pass
vm.expectRevert("dstNativeCurrencyPrice == 0");
Add tests for send and deliver functionality (#9) * Complete send and deliver functionality * Clean up * Add tests for relayer send method * ethereum: remove interfaces * ethereum: fix test * ethereum: rename directory * ethereum: clean up; add ts tests * Add tests and clean up * ethereum: fix test * ethereum: fix output * Add reentrancy protection and reduce gas overhead for relayers * Add tests for full batch delivery * Update relayer contracts to reflect changes to batch VAA implementation * add rewards payout * implement redeliveries, replay protection * Complete full batch test suite * sdk: add sdk * sdk: fix package.json * Add partial batch unit test and add to integration test * Fix comments in integration test * sdk: fix tsconfig.json * ethereum: fix build * Add relayer registration to integration test * Finish integration test suite * ethereum: fix readAbi * ethereum: fix merge conflict * Complete full batch test suite * Add partial batch unit test and add to integration test * Finish integration test suite * Fix local validator test * Fix merge conflict * Add Makefile * Add documentation to relayer contracts * Fix Makefile * ethereum: clean up * ethereum: fix interface * ethereum: fix method names and tests * Prepare integration test for off-chain relayer changes * Refactor contracts Co-authored-by: Drew <dsterioti@users.noreply.github.com> Co-authored-by: Karl Kempe <karlkempe@users.noreply.github.com> Co-authored-by: valentin <valentinvonalbrecht@yahoo.de> Co-authored-by: justinschuldt <justinschuldt@gmail.com>
2022-09-30 09:18:49 -07:00
gasOracle.computeGasCost(dstChainId, 1);
}
function testUpdatePrice(
uint16 dstChainId,
2022-09-13 14:44:12 -07:00
uint128 dstGasPrice,
Add tests for send and deliver functionality (#9) * Complete send and deliver functionality * Clean up * Add tests for relayer send method * ethereum: remove interfaces * ethereum: fix test * ethereum: rename directory * ethereum: clean up; add ts tests * Add tests and clean up * ethereum: fix test * ethereum: fix output * Add reentrancy protection and reduce gas overhead for relayers * Add tests for full batch delivery * Update relayer contracts to reflect changes to batch VAA implementation * add rewards payout * implement redeliveries, replay protection * Complete full batch test suite * sdk: add sdk * sdk: fix package.json * Add partial batch unit test and add to integration test * Fix comments in integration test * sdk: fix tsconfig.json * ethereum: fix build * Add relayer registration to integration test * Finish integration test suite * ethereum: fix readAbi * ethereum: fix merge conflict * Complete full batch test suite * Add partial batch unit test and add to integration test * Finish integration test suite * Fix local validator test * Fix merge conflict * Add Makefile * Add documentation to relayer contracts * Fix Makefile * ethereum: clean up * ethereum: fix interface * ethereum: fix method names and tests * Prepare integration test for off-chain relayer changes * Refactor contracts Co-authored-by: Drew <dsterioti@users.noreply.github.com> Co-authored-by: Karl Kempe <karlkempe@users.noreply.github.com> Co-authored-by: valentin <valentinvonalbrecht@yahoo.de> Co-authored-by: justinschuldt <justinschuldt@gmail.com>
2022-09-30 09:18:49 -07:00
uint64 dstNativeCurrencyPrice,
2022-09-13 14:44:12 -07:00
uint128 srcGasPrice,
Add tests for send and deliver functionality (#9) * Complete send and deliver functionality * Clean up * Add tests for relayer send method * ethereum: remove interfaces * ethereum: fix test * ethereum: rename directory * ethereum: clean up; add ts tests * Add tests and clean up * ethereum: fix test * ethereum: fix output * Add reentrancy protection and reduce gas overhead for relayers * Add tests for full batch delivery * Update relayer contracts to reflect changes to batch VAA implementation * add rewards payout * implement redeliveries, replay protection * Complete full batch test suite * sdk: add sdk * sdk: fix package.json * Add partial batch unit test and add to integration test * Fix comments in integration test * sdk: fix tsconfig.json * ethereum: fix build * Add relayer registration to integration test * Finish integration test suite * ethereum: fix readAbi * ethereum: fix merge conflict * Complete full batch test suite * Add partial batch unit test and add to integration test * Finish integration test suite * Fix local validator test * Fix merge conflict * Add Makefile * Add documentation to relayer contracts * Fix Makefile * ethereum: clean up * ethereum: fix interface * ethereum: fix method names and tests * Prepare integration test for off-chain relayer changes * Refactor contracts Co-authored-by: Drew <dsterioti@users.noreply.github.com> Co-authored-by: Karl Kempe <karlkempe@users.noreply.github.com> Co-authored-by: valentin <valentinvonalbrecht@yahoo.de> Co-authored-by: justinschuldt <justinschuldt@gmail.com>
2022-09-30 09:18:49 -07:00
uint64 srcNativeCurrencyPrice,
uint64 gasLimit
)
public
{
vm.assume(dstChainId > 0);
vm.assume(dstChainId != TEST_ORACLE_CHAIN_ID);
vm.assume(dstGasPrice > 0);
vm.assume(dstNativeCurrencyPrice > 0);
vm.assume(srcGasPrice > 0);
vm.assume(srcNativeCurrencyPrice > 0);
initializeGasOracle();
// update the prices with reasonable values
2022-09-13 14:44:12 -07:00
gasOracle.updatePrice(dstChainId, dstGasPrice, dstNativeCurrencyPrice);
gasOracle.updatePrice(gasOracle.chainId(), srcGasPrice, srcNativeCurrencyPrice);
// verify price
Add tests for send and deliver functionality (#9) * Complete send and deliver functionality * Clean up * Add tests for relayer send method * ethereum: remove interfaces * ethereum: fix test * ethereum: rename directory * ethereum: clean up; add ts tests * Add tests and clean up * ethereum: fix test * ethereum: fix output * Add reentrancy protection and reduce gas overhead for relayers * Add tests for full batch delivery * Update relayer contracts to reflect changes to batch VAA implementation * add rewards payout * implement redeliveries, replay protection * Complete full batch test suite * sdk: add sdk * sdk: fix package.json * Add partial batch unit test and add to integration test * Fix comments in integration test * sdk: fix tsconfig.json * ethereum: fix build * Add relayer registration to integration test * Finish integration test suite * ethereum: fix readAbi * ethereum: fix merge conflict * Complete full batch test suite * Add partial batch unit test and add to integration test * Finish integration test suite * Fix local validator test * Fix merge conflict * Add Makefile * Add documentation to relayer contracts * Fix Makefile * ethereum: clean up * ethereum: fix interface * ethereum: fix method names and tests * Prepare integration test for off-chain relayer changes * Refactor contracts Co-authored-by: Drew <dsterioti@users.noreply.github.com> Co-authored-by: Karl Kempe <karlkempe@users.noreply.github.com> Co-authored-by: valentin <valentinvonalbrecht@yahoo.de> Co-authored-by: justinschuldt <justinschuldt@gmail.com>
2022-09-30 09:18:49 -07:00
uint256 expected = (uint256(dstGasPrice) * dstNativeCurrencyPrice * gasLimit) / srcNativeCurrencyPrice;
require(gasOracle.computeGasCost(dstChainId, gasLimit) == expected, "gasOracle.computeGasCost(...) != expected");
}
2022-09-13 13:51:57 -07:00
function testUpdatePrices(
uint16 dstChainId,
2022-09-13 14:44:12 -07:00
uint128 dstGasPrice,
Add tests for send and deliver functionality (#9) * Complete send and deliver functionality * Clean up * Add tests for relayer send method * ethereum: remove interfaces * ethereum: fix test * ethereum: rename directory * ethereum: clean up; add ts tests * Add tests and clean up * ethereum: fix test * ethereum: fix output * Add reentrancy protection and reduce gas overhead for relayers * Add tests for full batch delivery * Update relayer contracts to reflect changes to batch VAA implementation * add rewards payout * implement redeliveries, replay protection * Complete full batch test suite * sdk: add sdk * sdk: fix package.json * Add partial batch unit test and add to integration test * Fix comments in integration test * sdk: fix tsconfig.json * ethereum: fix build * Add relayer registration to integration test * Finish integration test suite * ethereum: fix readAbi * ethereum: fix merge conflict * Complete full batch test suite * Add partial batch unit test and add to integration test * Finish integration test suite * Fix local validator test * Fix merge conflict * Add Makefile * Add documentation to relayer contracts * Fix Makefile * ethereum: clean up * ethereum: fix interface * ethereum: fix method names and tests * Prepare integration test for off-chain relayer changes * Refactor contracts Co-authored-by: Drew <dsterioti@users.noreply.github.com> Co-authored-by: Karl Kempe <karlkempe@users.noreply.github.com> Co-authored-by: valentin <valentinvonalbrecht@yahoo.de> Co-authored-by: justinschuldt <justinschuldt@gmail.com>
2022-09-30 09:18:49 -07:00
uint64 dstNativeCurrencyPrice,
2022-09-13 14:44:12 -07:00
uint128 srcGasPrice,
Add tests for send and deliver functionality (#9) * Complete send and deliver functionality * Clean up * Add tests for relayer send method * ethereum: remove interfaces * ethereum: fix test * ethereum: rename directory * ethereum: clean up; add ts tests * Add tests and clean up * ethereum: fix test * ethereum: fix output * Add reentrancy protection and reduce gas overhead for relayers * Add tests for full batch delivery * Update relayer contracts to reflect changes to batch VAA implementation * add rewards payout * implement redeliveries, replay protection * Complete full batch test suite * sdk: add sdk * sdk: fix package.json * Add partial batch unit test and add to integration test * Fix comments in integration test * sdk: fix tsconfig.json * ethereum: fix build * Add relayer registration to integration test * Finish integration test suite * ethereum: fix readAbi * ethereum: fix merge conflict * Complete full batch test suite * Add partial batch unit test and add to integration test * Finish integration test suite * Fix local validator test * Fix merge conflict * Add Makefile * Add documentation to relayer contracts * Fix Makefile * ethereum: clean up * ethereum: fix interface * ethereum: fix method names and tests * Prepare integration test for off-chain relayer changes * Refactor contracts Co-authored-by: Drew <dsterioti@users.noreply.github.com> Co-authored-by: Karl Kempe <karlkempe@users.noreply.github.com> Co-authored-by: valentin <valentinvonalbrecht@yahoo.de> Co-authored-by: justinschuldt <justinschuldt@gmail.com>
2022-09-30 09:18:49 -07:00
uint64 srcNativeCurrencyPrice,
uint64 gasLimit
2022-09-13 13:51:57 -07:00
)
public
{
vm.assume(dstChainId > 0);
vm.assume(dstChainId != TEST_ORACLE_CHAIN_ID); // wormhole.chainId()
2022-09-13 13:51:57 -07:00
vm.assume(dstGasPrice > 0);
vm.assume(dstNativeCurrencyPrice > 0);
vm.assume(srcGasPrice > 0);
vm.assume(srcNativeCurrencyPrice > 0);
initializeGasOracle();
2022-09-13 13:51:57 -07:00
2022-09-13 14:44:12 -07:00
GasOracle.UpdatePrice[] memory updates = new GasOracle.UpdatePrice[](2);
updates[0] = GasOracle.UpdatePrice({
chainId: gasOracle.chainId(),
2022-09-13 13:51:57 -07:00
gasPrice: srcGasPrice,
nativeCurrencyPrice: srcNativeCurrencyPrice
});
2022-09-13 14:44:12 -07:00
updates[1] = GasOracle.UpdatePrice({
chainId: dstChainId,
gasPrice: dstGasPrice,
nativeCurrencyPrice: dstNativeCurrencyPrice
});
2022-09-13 13:51:57 -07:00
// update the prices with reasonable values
2022-09-13 14:44:12 -07:00
gasOracle.updatePrices(updates);
2022-09-13 13:51:57 -07:00
// verify price
Add tests for send and deliver functionality (#9) * Complete send and deliver functionality * Clean up * Add tests for relayer send method * ethereum: remove interfaces * ethereum: fix test * ethereum: rename directory * ethereum: clean up; add ts tests * Add tests and clean up * ethereum: fix test * ethereum: fix output * Add reentrancy protection and reduce gas overhead for relayers * Add tests for full batch delivery * Update relayer contracts to reflect changes to batch VAA implementation * add rewards payout * implement redeliveries, replay protection * Complete full batch test suite * sdk: add sdk * sdk: fix package.json * Add partial batch unit test and add to integration test * Fix comments in integration test * sdk: fix tsconfig.json * ethereum: fix build * Add relayer registration to integration test * Finish integration test suite * ethereum: fix readAbi * ethereum: fix merge conflict * Complete full batch test suite * Add partial batch unit test and add to integration test * Finish integration test suite * Fix local validator test * Fix merge conflict * Add Makefile * Add documentation to relayer contracts * Fix Makefile * ethereum: clean up * ethereum: fix interface * ethereum: fix method names and tests * Prepare integration test for off-chain relayer changes * Refactor contracts Co-authored-by: Drew <dsterioti@users.noreply.github.com> Co-authored-by: Karl Kempe <karlkempe@users.noreply.github.com> Co-authored-by: valentin <valentinvonalbrecht@yahoo.de> Co-authored-by: justinschuldt <justinschuldt@gmail.com>
2022-09-30 09:18:49 -07:00
uint256 expected = (uint256(dstGasPrice) * dstNativeCurrencyPrice * gasLimit) / srcNativeCurrencyPrice;
require(gasOracle.computeGasCost(dstChainId, gasLimit) == expected, "gasOracle.computeGasCost(...) != expected");
2022-09-13 13:51:57 -07:00
}
}