-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9c362dd
commit 2bdecad
Showing
6 changed files
with
59 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// SPDX-License-Identifier: BSD-3-Clause | ||
// solhint-disable not-rely-on-time | ||
pragma solidity ^0.8.15; | ||
|
||
import { Test } from "forge-std/Test.sol"; | ||
|
||
import { calculateGasRebate } from "../../contracts/governance/CollectiveGovernance.sol"; | ||
|
||
contract GasRebateTest is Test { | ||
function testGasRebate() public { | ||
uint256 startGas = gasleft(); | ||
(uint256 gasRebate, uint256 gasUsed) = calculateGasRebate(startGas, 1 ether, 200 gwei, 200000); | ||
assertApproxEqAbs(gasRebate, 72234 gwei, 5000 gwei); | ||
assertTrue(gasUsed > 0); | ||
} | ||
|
||
function testMaximumRebate(uint256 gasLimit) public { | ||
vm.assume(gasLimit >= 30 gwei && gasLimit <= 200 gwei); | ||
uint256 testNetGas = 251154; | ||
uint256 startGas = gasleft(); | ||
uint i; | ||
do { | ||
i = 3 * 13 * startGas; | ||
} while (startGas - gasleft() < testNetGas); | ||
(uint256 gasRebate, uint256 gasUsed) = calculateGasRebate(startGas, gasLimit, 200 gwei, 200000); | ||
emit log_uint(gasRebate); | ||
assertEq(gasRebate, gasLimit); | ||
emit log_uint(gasUsed); | ||
assertTrue(gasUsed >= testNetGas); | ||
} | ||
|
||
function testRebateRealWorldTarget(uint256 gasUsedTarget) public { | ||
vm.assume(gasUsedTarget > 30000 && gasUsedTarget < 255000); | ||
uint256 startGas = gasleft(); | ||
uint i; | ||
do { | ||
i = 3 * 13 * startGas; | ||
} while (startGas - gasleft() < gasUsedTarget); | ||
(uint256 gasRebate, uint256 gasUsed) = calculateGasRebate(startGas, 2000 gwei, 200 gwei, 200000); | ||
emit log_uint(gasRebate); | ||
assertEq(gasRebate, 2000 gwei); | ||
emit log_uint(gasUsed); | ||
assertTrue(gasUsed >= gasUsedTarget); | ||
} | ||
} |