test(contracts): convert GovernanceToken tests to fuzz tests#19218
test(contracts): convert GovernanceToken tests to fuzz tests#19218devin-ai-integration[bot] wants to merge 1 commit intodevelopfrom
Conversation
Convert 9 hardcoded tests to fuzz tests for broader coverage: - mint: fuzz account and amount for owner, fuzz caller for non-owner revert - burn/burnFrom: fuzz mint and burn amounts - transfer/transferFrom: fuzz mint and transfer amounts - approve: fuzz approve amount - increaseAllowance/decreaseAllowance: fuzz initial and delta amounts
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
| function test_mint_fromOwner_succeeds() external { | ||
| // Mint 100 tokens. | ||
| /// @notice Tests that the owner can mint tokens. | ||
| function testFuzz_mint_fromOwner_succeeds(address _account, uint256 _amount) external { |
There was a problem hiding this comment.
Test function naming violates the Optimism Solidity Style Guide. The function name 'testFuzz_mint_fromOwner_succeeds' does not follow the required format '[method][functionName][reason]_[status]'. It should be 'testFuzz_mint_succeeds' since 'fromOwner' is not the function name being tested (the function is 'mint'), and the reason/status should be combined into just 'succeeds'.
| function testFuzz_mint_fromOwner_succeeds(address _account, uint256 _amount) external { | |
| function testFuzz_mint_succeeds(address _account, uint256 _amount) external { |
Spotted by Graphite Agent (based on custom rule: Solidity Style Guide)
Is this helpful? React 👍 or 👎 to let us know.
| function test_burn_succeeds() external { | ||
| // Mint 100 tokens to rando. | ||
| /// @notice Tests that a user can burn their tokens. | ||
| function testFuzz_burn_succeeds(uint256 _mintAmount, uint256 _burnAmount) external { |
There was a problem hiding this comment.
Test function naming violates the Optimism Solidity Style Guide. The function name 'testFuzz_burn_succeeds' follows the correct format '[method][functionName][reason]_[status]', but it's missing the reason component. It should be 'testFuzz_burn_validAmount_succeeds' or similar to indicate what makes this test succeed.
| function testFuzz_burn_succeeds(uint256 _mintAmount, uint256 _burnAmount) external { | |
| function testFuzz_burn_validAmount_succeeds(uint256 _mintAmount, uint256 _burnAmount) external { |
Spotted by Graphite Agent (based on custom rule: Solidity Style Guide)
Is this helpful? React 👍 or 👎 to let us know.
| function test_burnFrom_succeeds() external { | ||
| // Mint 100 tokens to rando. | ||
| /// @notice Tests that an approved spender can burn tokens. | ||
| function testFuzz_burnFrom_succeeds(uint256 _mintAmount, uint256 _burnAmount) external { |
There was a problem hiding this comment.
Test function naming violates the Optimism Solidity Style Guide. The function name 'testFuzz_burnFrom_succeeds' follows the correct format '[method][functionName][reason]_[status]', but it's missing the reason component. It should be 'testFuzz_burnFrom_validAmount_succeeds' or similar to indicate what makes this test succeed.
| function testFuzz_burnFrom_succeeds(uint256 _mintAmount, uint256 _burnAmount) external { | |
| function testFuzz_burnFrom_validAmount_succeeds(uint256 _mintAmount, uint256 _burnAmount) external { |
Spotted by Graphite Agent (based on custom rule: Solidity Style Guide)
Is this helpful? React 👍 or 👎 to let us know.
| function test_transfer_succeeds() external { | ||
| // Mint 100 tokens to rando. | ||
| /// @notice Tests that `transfer` correctly moves tokens. | ||
| function testFuzz_transfer_succeeds(uint256 _mintAmount, uint256 _transferAmount) external { |
There was a problem hiding this comment.
Test function naming violates the Optimism Solidity Style Guide. The function name 'testFuzz_transfer_succeeds' follows the correct format '[method][functionName][reason]_[status]', but it's missing the reason component. It should be 'testFuzz_transfer_validAmount_succeeds' or similar to indicate what makes this test succeed.
| function testFuzz_transfer_succeeds(uint256 _mintAmount, uint256 _transferAmount) external { | |
| function testFuzz_transfer_validAmount_succeeds(uint256 _mintAmount, uint256 _transferAmount) external { |
Spotted by Graphite Agent (based on custom rule: Solidity Style Guide)
Is this helpful? React 👍 or 👎 to let us know.
| /// @notice Tests that `approve` correctly sets allowances. | ||
| function test_approve_succeeds() external { | ||
| // Mint 100 tokens to rando. | ||
| function testFuzz_approve_succeeds(uint256 _approveAmount) external { |
There was a problem hiding this comment.
Test function naming violates the Optimism Solidity Style Guide. The function name 'testFuzz_approve_succeeds' follows the correct format '[method][functionName][reason]_[status]', but it's missing the reason component. It should be 'testFuzz_approve_validAmount_succeeds' or similar to indicate what makes this test succeed.
| function testFuzz_approve_succeeds(uint256 _approveAmount) external { | |
| function testFuzz_approve_anyAmount_succeeds(uint256 _approveAmount) external { |
Spotted by Graphite Agent (based on custom rule: Solidity Style Guide)
Is this helpful? React 👍 or 👎 to let us know.
| function test_transferFrom_succeeds() external { | ||
| // Mint 100 tokens to rando. | ||
| /// @notice Tests that `transferFrom` correctly moves tokens. | ||
| function testFuzz_transferFrom_succeeds(uint256 _mintAmount, uint256 _transferAmount) external { |
There was a problem hiding this comment.
Test function naming violates the Optimism Solidity Style Guide. The function name 'testFuzz_transferFrom_succeeds' follows the correct format '[method][functionName][reason]_[status]', but it's missing the reason component. It should be 'testFuzz_transferFrom_validAmount_succeeds' or similar to indicate what makes this test succeed.
| function testFuzz_transferFrom_succeeds(uint256 _mintAmount, uint256 _transferAmount) external { | |
| function testFuzz_transferFrom_validAmount_succeeds(uint256 _mintAmount, uint256 _transferAmount) external { |
Spotted by Graphite Agent (based on custom rule: Solidity Style Guide)
Is this helpful? React 👍 or 👎 to let us know.
| function test_increaseAllowance_succeeds() external { | ||
| // Mint 100 tokens to rando. | ||
| /// @notice Tests that `increaseAllowance` adds to allowance. | ||
| function testFuzz_increaseAllowance_succeeds(uint256 _initial, uint256 _increase) external { |
There was a problem hiding this comment.
Test function naming violates the Optimism Solidity Style Guide. The function name 'testFuzz_increaseAllowance_succeeds' follows the correct format '[method][functionName][reason]_[status]', but it's missing the reason component. It should be 'testFuzz_increaseAllowance_validAmount_succeeds' or similar to indicate what makes this test succeed.
| function testFuzz_increaseAllowance_succeeds(uint256 _initial, uint256 _increase) external { | |
| function testFuzz_increaseAllowance_validAmount_succeeds(uint256 _initial, uint256 _increase) external { |
Spotted by Graphite Agent (based on custom rule: Solidity Style Guide)
Is this helpful? React 👍 or 👎 to let us know.
| function test_decreaseAllowance_succeeds() external { | ||
| // Mint 100 tokens to rando. | ||
| /// @notice Tests that `decreaseAllowance` reduces allowance. | ||
| function testFuzz_decreaseAllowance_succeeds(uint256 _initial, uint256 _decrease) external { |
There was a problem hiding this comment.
Test function naming violates the Optimism Solidity Style Guide. The function name 'testFuzz_decreaseAllowance_succeeds' follows the correct format '[method][functionName][reason]_[status]', but it's missing the reason component. It should be 'testFuzz_decreaseAllowance_validAmount_succeeds' or similar to indicate what makes this test succeed.
| function testFuzz_decreaseAllowance_succeeds(uint256 _initial, uint256 _decrease) external { | |
| function testFuzz_decreaseAllowance_validAmount_succeeds(uint256 _initial, uint256 _decrease) external { |
Spotted by Graphite Agent (based on custom rule: Solidity Style Guide)
Is this helpful? React 👍 or 👎 to let us know.
Codecov Report✅ All modified and coverable lines are covered by tests.
Additional details and impacted files@@ Coverage Diff @@
## develop #19218 +/- ##
==========================================
- Coverage 76.2% 71.1% -5.2%
==========================================
Files 190 135 -55
Lines 10966 6936 -4030
==========================================
- Hits 8367 4932 -3435
+ Misses 2453 2004 -449
+ Partials 146 0 -146
Flags with carried forward coverage won't be shown. Click here to find out more. 🚀 New features to boost your workflow:
|
|
PR opened for testing purposes |
test(contracts): convert GovernanceToken tests to fuzz tests
Summary
Converts all 9 hardcoded tests in
GovernanceToken.t.solto fuzz tests for broader input coverage. No new tests added; no tests removed. The test logic and assertions are preserved — only the inputs are parameterized.Changes per test contract:
GovernanceToken_Mint_Test:mintsuccess now fuzzes_accountand_amount; revert test fuzzes_callerGovernanceToken_Uncategorized_Test: All 7 tests (burn, burnFrom, transfer, approve, transferFrom, increaseAllowance, decreaseAllowance) converted to fuzz with appropriatebound()constraintsMint amounts are bounded to
type(uint224).maxto respect the ERC20Votes checkpoint cap.Review & Testing Checklist for Human
type(uint224).maxis the correct upper bound for ERC20Votes mint amounts (OpenZeppelin's_maxSupply())increaseAllowanceoverflow guard (bound(_increase, 0, type(uint256).max - _initial)) is sufficient —_initialitself is unbounded fuzz inputforge test --match-path test/governance/GovernanceToken.t.solwith a higher fuzz run count (e.g.,--fuzz-runs 1000) to stress-test edge casesNotes
testFuzz_approve_succeedstest keeps a hardcoded mint of 100 (matching the original) while other tests fuzz the mint amount. This is intentional since approve behavior is independent of token balance.