@ -120,53 +120,52 @@ contract TestDeliveryProvider is Test {
deliveryProvider . updatePrice ( updateChainId , updateGasPrice , updateNativeCurrencyPrice ) ;
}
/*
TODO : Uncomment these tests once revert messages are back in
function testCannotGetPriceBeforeUpdateSrcPrice (
uint16 dstChainId ,
uint128 dstGasPrice ,
uint128 dstNativeCurrencyPrice
uint64 dstGasPrice ,
WeiPrice dstNativeCurrencyPrice
)
public
{
vm . assume ( dstChainId > 0 ) ;
vm . assume ( dstChainId != TEST_ORACLE_CHAIN_ID ) ;
vm . assume ( dstGasPrice > 0 ) ;
vm . assume ( dstNativeCurrencyPrice > 0 ) ;
vm . assume ( dstNativeCurrencyPrice . unwrap ( ) > 0 ) ;
initializeDeliveryProvider ( ) ;
/ / update the price with reasonable values
deliveryProvider . updatePrice ( dstChainId , dstGasPrice , dstNativeCurrencyPrice ) ;
deliveryProvider . updatePrice ( dstChainId , GasPrice . wrap ( dstGasPrice ) , dstNativeCurrencyPrice ) ;
/ / you shall not pass
vm . expectRevert ( " srcNativeCurrencyPrice == 0 " ) ;
vm . expectRevert ( abi . encodeWithSignature ( " PriceIsZero(uint16) " , TEST_ORACLE_CHAIN_ID ) ) ;
deliveryProvider . quoteDeliveryOverhead ( dstChainId ) ;
}
function testCannotGetPriceBeforeUpdateDstPrice (
uint16 dstChainId ,
uint128 srcGasPrice ,
uint128 srcNativeCurrencyPrice
uint64 srcGasPrice ,
WeiPrice srcNativeCurrencyPrice
)
public
{
vm . assume ( dstChainId > 0 ) ;
vm . assume ( dstChainId != TEST_ORACLE_CHAIN_ID ) ;
vm . assume ( srcGasPrice > 0 ) ;
vm . assume ( srcNativeCurrencyPrice > 0 ) ;
vm . assume ( srcNativeCurrencyPrice . unwrap ( ) > 0 ) ;
initializeDeliveryProvider ( ) ;
/ / update the price with reasonable values
/ / vm . prank ( deliveryProvider . owner ( ) ) ;
deliveryProvider . updatePrice ( TEST_ORACLE_CHAIN_ID , srcGasPrice , srcNativeCurrencyPrice ) ;
deliveryProvider . updatePrice ( TEST_ORACLE_CHAIN_ID , GasPrice . wrap ( srcGasPrice ) , srcNativeCurrencyPrice ) ;
/ / you shall not pass
vm . expectRevert ( " dstNativeCurrencyPrice == 0 " ) ;
vm . expectRevert ( abi . encodeWithSignature ( " PriceIsZero(uint16) " , dstChainId ) ) ;
deliveryProvider . quoteDeliveryOverhead ( dstChainId ) ;
}
* /
function testUpdatePrice (
uint16 dstChainId ,
@ -268,4 +267,109 @@ contract TestDeliveryProvider is Test {
assertTrue ( newAddress == updated ) ;
}
function testQuoteDeliveryOverhead (
uint16 dstChainId ,
uint64 dstGasPrice ,
uint64 dstNativeCurrencyPrice ,
uint64 srcGasPrice ,
uint64 srcNativeCurrencyPrice ,
uint32 gasOverhead
) public {
initializeDeliveryProvider ( ) ;
vm . assume ( dstChainId > 0 ) ;
vm . assume ( dstChainId != TEST_ORACLE_CHAIN_ID ) ; / / wormhole . chainId ( )
vm . assume ( dstGasPrice > 0 ) ;
vm . assume ( dstNativeCurrencyPrice > 0 ) ;
vm . assume ( srcGasPrice > 0 ) ;
vm . assume ( srcNativeCurrencyPrice > 0 ) ;
vm . assume ( dstGasPrice >= dstNativeCurrencyPrice / srcNativeCurrencyPrice ) ;
vm . assume ( dstGasPrice * uint256 ( dstNativeCurrencyPrice ) / srcNativeCurrencyPrice < 2 ** 72 ) ;
vm . assume ( gasOverhead < uint256 ( 2 ) ** 31 ) ;
/ / update the prices with reasonable values
deliveryProvider . updatePrice (
dstChainId , GasPrice . wrap ( dstGasPrice ) , WeiPrice . wrap ( dstNativeCurrencyPrice )
) ;
deliveryProvider . updatePrice (
TEST_ORACLE_CHAIN_ID , GasPrice . wrap ( srcGasPrice ) , WeiPrice . wrap ( srcNativeCurrencyPrice )
) ;
deliveryProvider . updateAssetConversionBuffer ( dstChainId , 5 , 100 ) ;
deliveryProvider . updateDeliverGasOverhead ( dstChainId , Gas . wrap ( gasOverhead ) ) ;
deliveryProvider . updateMaximumBudget ( dstChainId , Wei . wrap ( uint256 ( 2 ) ** 191 ) ) ;
/ / verify price
uint256 expectedOverhead = (
uint256 ( dstNativeCurrencyPrice ) * ( uint256 ( dstGasPrice ) * gasOverhead ) + ( srcNativeCurrencyPrice - 1 )
) / srcNativeCurrencyPrice ;
LocalNative deliveryOverhead = deliveryProvider . quoteDeliveryOverhead ( dstChainId ) ;
require ( expectedOverhead == LocalNative . unwrap ( deliveryOverhead ) , " deliveryProvider overhead quote is not what is expected " ) ;
}
function testQuoteDeliveryPrice (
uint16 dstChainId ,
uint64 dstGasPrice ,
uint64 dstNativeCurrencyPrice ,
uint64 srcGasPrice ,
uint64 srcNativeCurrencyPrice ,
uint32 gasLimit ,
uint32 gasOverhead ,
uint64 receiverValue
) public {
initializeDeliveryProvider ( ) ;
vm . assume ( dstChainId > 0 ) ;
vm . assume ( dstChainId != TEST_ORACLE_CHAIN_ID ) ; / / wormhole . chainId ( )
vm . assume ( dstGasPrice > 0 ) ;
vm . assume ( dstNativeCurrencyPrice > 0 ) ;
vm . assume ( srcGasPrice > 0 ) ;
vm . assume ( srcNativeCurrencyPrice > 0 ) ;
vm . assume ( dstGasPrice >= dstNativeCurrencyPrice / srcNativeCurrencyPrice ) ;
vm . assume ( dstGasPrice * uint256 ( dstNativeCurrencyPrice ) / srcNativeCurrencyPrice < 2 ** 72 ) ;
vm . assume ( gasLimit < uint256 ( 2 ) ** 31 ) ;
vm . assume ( gasOverhead < uint256 ( 2 ) ** 31 ) ;
/ / update the prices with reasonable values
deliveryProvider . updatePrice (
dstChainId , GasPrice . wrap ( dstGasPrice ) , WeiPrice . wrap ( dstNativeCurrencyPrice )
) ;
deliveryProvider . updatePrice (
TEST_ORACLE_CHAIN_ID , GasPrice . wrap ( srcGasPrice ) , WeiPrice . wrap ( srcNativeCurrencyPrice )
) ;
deliveryProvider . updateAssetConversionBuffer ( dstChainId , 5 , 100 ) ;
deliveryProvider . updateDeliverGasOverhead ( dstChainId , Gas . wrap ( gasOverhead ) ) ;
deliveryProvider . updateMaximumBudget ( dstChainId , Wei . wrap ( uint256 ( 2 ) ** 191 ) ) ;
/ / verify price
uint256 expectedGasCost = (
uint256 ( dstNativeCurrencyPrice ) * ( uint256 ( dstGasPrice ) * ( gasLimit ) ) + ( srcNativeCurrencyPrice - 1 )
) / srcNativeCurrencyPrice ;
uint256 expectedOverheadCost = (
uint256 ( dstNativeCurrencyPrice ) * ( uint256 ( dstGasPrice ) * ( gasOverhead ) ) + ( srcNativeCurrencyPrice - 1 )
) / srcNativeCurrencyPrice ;
uint256 expectedReceiverValueCost = (
uint256 ( dstNativeCurrencyPrice ) * ( receiverValue ) * 105 + ( srcNativeCurrencyPrice * uint256 ( 100 ) - 1 )
) / srcNativeCurrencyPrice / 100 ;
( LocalNative nativePriceQuote , ) = deliveryProvider . quoteEvmDeliveryPrice ( dstChainId , Gas . wrap ( gasLimit ) , TargetNative . wrap ( receiverValue ) ) ;
require ( expectedGasCost == LocalNative . unwrap ( deliveryProvider . quoteGasCost ( dstChainId , Gas . wrap ( gasLimit ) ) ) , " Gas cost is not what is expected " ) ;
require ( expectedOverheadCost == LocalNative . unwrap ( deliveryProvider . quoteGasCost ( dstChainId , Gas . wrap ( gasOverhead ) ) ) , " Overhead cost is not what is expected " ) ;
require ( expectedGasCost + expectedOverheadCost + expectedReceiverValueCost == LocalNative . unwrap ( nativePriceQuote ) , " deliveryProvider price quote is not what is expected " ) ;
}
}