test: tighten 44 bare expectReverts + 17 new tests (Phase 9) - #11
Merged
Conversation
Tighten every `vm.expectRevert()` (bare) across kToken / kOFT / kOFTAdapter unit tests to use specific selectors so role-check or state-check regressions cannot pass silently behind unrelated reverts (insufficient balance, allowance, proxy initialization, etc.). Tightened reverts (44 total): - kToken.t.sol (29) — KTOKEN_WRONG_ROLE / KTOKEN_IS_PAUSED / KTOKEN_ACCOUNT_FROZEN / KTOKEN_ZERO_ADDRESS, ERC20.InsufficientBalance, ERC20.InsufficientAllowance, Ownable.Unauthorized, Initializable.InvalidInitialization - kOFT.t.sol (11) — same plus kOFT.ZeroAddress and OZ's OwnableUnauthorizedAccount(address) for OFTCoreUpgradeable's owner check - kOFTAdater.t.sol (4) — KTOKEN_WRONG_ROLE, Initializable.InvalidInitialization Added missing tests (17 in kToken.t.sol): - Role revocation: revokeAdminRole (success / non-owner / revoked admin cannot grant minter), revokeEmergencyRole (success / non-admin / revoked emergency admin cannot pause), grantEmergencyRole non-admin revert. - emergencyWithdraw input validation: zero destination, zero amount, ETH transfer failure (via a non-payable rejector contract). - initialize zero-address checks: zero owner / admin / emergency admin / minter — each spun up via MinimalUUPSFactory so the revert lands during the initializer call. - UUPS upgrade authorization: success (verifies the ERC-1967 implementation slot), non-owner revert, zero-implementation revert. Mutation-verified: 12 strategic source mutations on kToken.sol — all 12 killed by the suite (skip role checks in mint / grantMinterRole / freeze / setPaused / emergencyWithdraw, skip _checkOwner in _authorizeUpgrade, skip _checkPaused / _checkNotFrozen in _beforeTokenTransfer, weaken the owner / zero-amount / zero-address / zero-owner-init guards). Suite: 120 -> 137 passing, no regressions.
Solthodox
self-requested a review
May 6, 2026 17:36
Solthodox
approved these changes
May 6, 2026
Solthodox
left a comment
Contributor
There was a problem hiding this comment.
forge fmt missing but good
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
vm.expectRevert()calls across all 3 unit test files to use specific selectors. A bareexpectRevert()succeeds on any revert; this lets a role-check regression pass silently behind an allowance failure, balance failure, or proxy-init revert. Specific selectors prevent that.kToken.t.sol(revoke role flows, emergencyWithdraw input validation, initialize zero-address checks, UUPS upgrade authorization).kToken.sol— all 12 killed.Tightened reverts (44 total)
test/unit/kToken.t.solKTOKEN_WRONG_ROLE,KTOKEN_IS_PAUSED,KTOKEN_ACCOUNT_FROZEN,KTOKEN_ZERO_ADDRESS,ERC20.InsufficientBalance,ERC20.InsufficientAllowance,Ownable.Unauthorized,Initializable.InvalidInitializationtest/unit/kOFT.t.solkOFT.ZeroAddress, OZ'sOwnableUnauthorizedAccount(address)forOFTCoreUpgradeable's owner checktest/unit/kOFTAdater.t.solKTOKEN_WRONG_ROLE,Initializable.InvalidInitializationNew tests (17, all in kToken.t.sol)
revokeAdminRole(success / non-owner / revoked-admin-cannot-grant-minter),revokeEmergencyRole(success / non-admin / revoked-emergency-admin-cannot-pause),grantEmergencyRolenon-admin revert.emergencyWithdrawinput validation — zero destination, zero amount, and the ETH-transfer-failure branch (via a non-payableETHRejectorhelper contract).initializezero-address checks — separate tests for zero owner / admin / emergency admin / minter, each going throughMinimalUUPSFactory.deployAndCallso the revert lands during the initializer call.Mutation verification
12 strategic mutations applied to
src/kToken.sol, full suite (137 tests) run after each, source restored between runs:mint()skip_checkMintertest_Mint_RevertsForNonMintergrantMinterRole()skip_checkAdmintest_GrantMinterRole_RevertsForNonAdmin_authorizeUpgradeskip_checkOwnertest_AuthorizeUpgrade_RevertsForNonOwner_beforeTokenTransferskip_checkPausedtest_Pause_BlocksTransfers_beforeTokenTransferskip_checkNotFrozentest_FrozenAccount_CannotTransferfreeze()skip_checkBlacklistAdmintest_FreezeAccount_RevertsForNonAdminsetPaused()skip_checkEmergencyAdmintest_SetPaused_RevertsForNonEmergencyAdminemergencyWithdraw()skip_checkEmergencyAdmintest_EmergencyWithdraw_RevertsForNonEmergencyAdminfreeze()weaken_account != owner()test_CannotFreezeOwneremergencyWithdrawweaken_amount != 0test_EmergencyWithdraw_RevertsForZeroAmountemergencyWithdrawweaken_to != address(0)test_EmergencyWithdraw_RevertsForZeroDestinationinitialize()weaken_owner != address(0)test_Initialize_RevertsForZeroOwnerSource MD5 verified equal to baseline before and after the run.
Test plan
forge test— 137 passed, 0 failed (89 in kTokenUnitTest, 39 in kOFTUnitTest, 9 in kOFTAdapterTest)vm.expectRevert()remaining intest/🤖 Generated with Claude Code