@@ -11,7 +11,7 @@ import {GasSpender} from "./GasSpender.sol";
1111import {Gateway} from "../src/Gateway.sol " ;
1212import {GasUtils} from "../src/GasUtils.sol " ;
1313import {IGmpReceiver} from "../src/interfaces/IGmpReceiver.sol " ;
14- import {GmpMessage, Signature, TssKey, GmpStatus, PrimitiveUtils, Batch} from "../src/Primitives.sol " ;
14+ import {GmpMessage, Signature, TssKey, GmpStatus, PrimitiveUtils, Batch, MAX_PAYLOAD_SIZE } from "../src/Primitives.sol " ;
1515
1616uint256 constant secret = 0x42 ;
1717uint256 constant nonce = 0x69 ;
@@ -49,7 +49,7 @@ contract GasUtilsTest is Test {
4949 /**
5050 * @dev Compare the estimated gas cost VS the actual gas cost of the `execute` method.
5151 */
52- function test_baseExecutionCost (uint16 messageSize , uint16 gasLimit ) external {
52+ function test_gas_calc_and_refund (uint16 messageSize , uint16 gasLimit ) external {
5353 vm.txGasPrice (1 );
5454 vm.assume (gasLimit >= 5000 );
5555 vm.assume (messageSize <= (0x6000 - 32 ));
@@ -99,4 +99,14 @@ contract GasUtilsTest is Test {
9999 console.log ("proxyOverheadGas " , proxyOverheadGas);
100100 assertEq (balanceAfter - balanceBefore - baseGas - mGasUsed, 0 , "Balance should not change " );
101101 }
102+
103+ function test_lin_approx (uint16 messageSize ) external pure {
104+ vm.assume (messageSize <= MAX_PAYLOAD_SIZE);
105+ uint256 calcGas = TestUtils.calcGas (messageSize);
106+ uint256 approxGas = TestUtils.linApproxGas (messageSize);
107+ assertGe (approxGas + 650 , calcGas);
108+ int256 error = int256 (approxGas) - int256 (calcGas);
109+ uint256 absError = error >= 0 ? uint256 (error ) : uint256 (- error );
110+ assertLe (absError, 750 );
111+ }
102112}
0 commit comments