@@ -1229,7 +1229,7 @@ contract EntropyTest is Test, EntropyTestUtils, EntropyEvents {
12291229 // Test the corner case caused by the CALL opcode passing at most 63/64ths of the current gas
12301230 // to the sub-call.
12311231 function testRequestWithCallbackUsingTooMuchGas2 () public {
1232- // With a 64M gas limit, we will pass ~63M gas to the callback (which is insufficient), but still
1232+ // With a 64M gas limit, we will pass ~63M gas to the callback (which is insufficient), but still
12331233 // have ~1M gas to execute code within the revealWithCallback method, which should be enough to
12341234 // run all of the logic subsequent to the excessivelySafeCall.
12351235 uint32 defaultGasLimit = 64000000 ;
@@ -1246,10 +1246,6 @@ contract EntropyTest is Test, EntropyTestUtils, EntropyEvents {
12461246 uint64 assignedSequenceNumber = consumer.requestEntropy {value: fee}(
12471247 userRandomNumber
12481248 );
1249- EntropyStructs.Request memory req = random.getRequest (
1250- provider1,
1251- assignedSequenceNumber
1252- );
12531249
12541250 // The transaction reverts if the provider does not provide enough gas to forward
12551251 // the gasLimit to the callback transaction.
@@ -1573,32 +1569,66 @@ contract EntropyTest is Test, EntropyTestUtils, EntropyEvents {
15731569 assertEq (fee, random.getFee (provider1));
15741570 }
15751571
1576- function testRoundGas () public {
1577- // TODO: test this with the full request/reveal flow and update the max value
1572+ function testGasLimitsAndFeeRounding () public {
1573+ vm.prank (provider1);
1574+ random.setDefaultGasLimit (20000 );
1575+ vm.prank (provider1);
1576+ random.setProviderFee (1 );
15781577
15791578 // Test exact multiples of 10,000
1580- assertEq (random. roundGas ( 0 ) , 0 );
1581- assertEq (random. roundGas ( 10000 ) , 1 );
1582- assertEq (random. roundGas ( 20000 ) , 2 );
1583- assertEq (random. roundGas ( 100000 ) , 10 );
1579+ assertGasLimit10k ( 0 , 0 , 1 );
1580+ assertGasLimit10k ( 10000 , 1 , 1 );
1581+ assertGasLimit10k ( 20000 , 2 , 1 );
1582+ assertGasLimit10k ( 100000 , 10 , 5 );
15841583
15851584 // Test values just below multiples of 10,000
1586- assertEq (random.roundGas (9999 ), 1 );
1587- assertEq (random.roundGas (19999 ), 2 );
1588- assertEq (random.roundGas (99999 ), 10 );
1585+ assertGasLimit10k (9999 , 1 , 1 );
1586+ assertGasLimit10k (19999 , 2 , 1 );
1587+ assertGasLimit10k (39999 , 4 , 2 );
1588+ assertGasLimit10k (99999 , 10 , 5 );
15891589
15901590 // Test values just above multiples of 10,000
1591- assertEq (random.roundGas (10001 ), 2 );
1592- assertEq (random.roundGas (20001 ), 3 );
1593- assertEq (random.roundGas (100001 ), 11 );
1591+ assertGasLimit10k (10001 , 2 , 1 );
1592+ assertGasLimit10k (20001 , 3 , 1 );
1593+ assertGasLimit10k (100001 , 11 , 5 );
1594+ assertGasLimit10k (110001 , 12 , 6 );
15941595
15951596 // Test middle values
1596- assertEq (random. roundGas ( 5000 ) , 1 );
1597- assertEq (random. roundGas ( 15000 ) , 2 );
1598- assertEq (random. roundGas ( 25000 ) , 3 );
1597+ assertGasLimit10k ( 5000 , 1 , 1 );
1598+ assertGasLimit10k ( 15000 , 2 , 1 );
1599+ assertGasLimit10k ( 25000 , 3 , 1 );
15991600
1600- // Test maximum uint32 value
1601- assertEq (random.roundGas (type (uint32 ).max), 429497 ); // (2^32 - 1) / 10000 rounded up
1601+ // Test maximum value
1602+ assertGasLimit10k (
1603+ uint32 (type (uint16 ).max) * 10000 ,
1604+ type (uint16 ).max,
1605+ uint128 (type (uint16 ).max) / 2
1606+ );
1607+ }
1608+
1609+ // Helper method to create a request with a specific gas limit and check the gasLimit10k field
1610+ function assertGasLimit10k (
1611+ uint32 gasLimit ,
1612+ uint16 expectedGasLimit10k ,
1613+ uint128 expectedProviderFee
1614+ ) internal {
1615+ // Create a request with callback
1616+ bytes32 userRandomNumber = bytes32 (uint (42 ));
1617+ uint fee = random.getFeeForGas (provider1, gasLimit);
1618+ assertEq (fee - random.getPythFee (), expectedProviderFee);
1619+
1620+ vm.deal (user1, fee);
1621+ vm.prank (user1);
1622+ uint64 sequenceNumber = random.requestWithCallbackAndGasLimit {
1623+ value: fee
1624+ }(provider1, userRandomNumber, gasLimit);
1625+
1626+ // Check the gasLimit10k field in the request
1627+ EntropyStructs.Request memory req = random.getRequest (
1628+ provider1,
1629+ sequenceNumber
1630+ );
1631+ assertEq (req.gasLimit10k, expectedGasLimit10k);
16021632 }
16031633}
16041634
0 commit comments