-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
test: initial structure for covering all key scenarios #1
Merged
Merged
Changes from 1 commit
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
f70c9da
test: initial structure for covering all key scenarios
petrovska-petro a823693
chore: add linting config
gosuto-inzasheru cd2e625
fix: safe is payable
gosuto-inzasheru 20802f4
fix: safe is v1.1.1
gosuto-inzasheru 0f6425c
fix: prank safe before disabling
gosuto-inzasheru c0b1ef0
ci: prevent duplicate test runs
gosuto-inzasheru d76361a
ci: inject env var from secrets
gosuto-inzasheru ed55b1e
test: adapt to safe verssion 1.1.1 and include tests for setters
petrovska-petro 4e38534
Merge branch 'feat/tests' of https://github.com/onchainification/aura…
petrovska-petro File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,13 +34,16 @@ contract AuraLockerModule is | |
ERRORS | ||
//////////////////////////////////////////////////////////////////////////*/ | ||
error NotKeeper(address agent); | ||
error NotGovernance(address agent); | ||
|
||
error ZeroAddressValue(); | ||
|
||
error ModuleNotEnabled(); | ||
|
||
error TxFromModuleFailed(); | ||
|
||
error NothingToLock(uint256 timestamp); | ||
|
||
/*////////////////////////////////////////////////////////////////////////// | ||
EVENTS | ||
//////////////////////////////////////////////////////////////////////////*/ | ||
|
@@ -61,13 +64,19 @@ contract AuraLockerModule is | |
_; | ||
} | ||
|
||
/// @notice Enforce that the function is called by governance only | ||
modifier onlyGovernance() { | ||
if (msg.sender != BALANCER_MULTISIG) revert NotGovernance(msg.sender); | ||
_; | ||
} | ||
|
||
/*////////////////////////////////////////////////////////////////////////// | ||
EXTERNAL METHODS | ||
//////////////////////////////////////////////////////////////////////////*/ | ||
|
||
/// @notice Assigns a new keeper address | ||
/// @param _keeper The address of the new keeper | ||
function setKeeper(address _keeper) external { | ||
function setKeeper(address _keeper) external onlyGovernance { | ||
if (_keeper == address(0)) revert ZeroAddressValue(); | ||
|
||
address oldKeeper = keeper; | ||
|
@@ -85,8 +94,7 @@ contract AuraLockerModule is | |
override | ||
returns (bool requiresLocking, bytes memory execPayload) | ||
{ | ||
// if (!SAFE.isModuleEnabled(address(this))) | ||
// return (false, bytes("AuraLocker module is not enabled")); | ||
if (!_isModuleEnabled()) return (false, bytes("AuraLocker module is not enabled")); | ||
|
||
(, uint256 unlockable,,) = AURA_LOCKER.lockedBalances(address(SAFE)); | ||
|
||
|
@@ -99,7 +107,10 @@ contract AuraLockerModule is | |
|
||
/// @notice The actual execution of the action determined by the `checkUpkeep` method (AURA locking) | ||
function performUpkeep(bytes calldata /* _performData */ ) external override onlyKeeper { | ||
// if (!SAFE.isModuleEnabled(address(this))) revert ModuleNotEnabled(); | ||
if (!_isModuleEnabled()) revert ModuleNotEnabled(); | ||
|
||
(, uint256 unlockable,,) = AURA_LOCKER.lockedBalances(address(SAFE)); | ||
if (unlockable == 0) revert NothingToLock(block.timestamp); | ||
|
||
// execute: `processExpiredLocks` via module | ||
if ( | ||
|
@@ -108,4 +119,13 @@ contract AuraLockerModule is | |
) | ||
) revert TxFromModuleFailed(); | ||
} | ||
|
||
/// @dev The Gnosis Safe version 1.1.1 does not expose directly `isModuleEnabled` method, so we need a workaround | ||
function _isModuleEnabled() internal view returns (bool) { | ||
address[] memory modules = SAFE.getModules(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
for (uint256 i = 0; i < modules.length; i++) { | ||
if (modules[i] == address(this)) return true; | ||
} | ||
return false; | ||
} | ||
} |
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 |
---|---|---|
|
@@ -8,7 +8,7 @@ import {ILockAura} from "../src/interfaces/aura/ILockAura.sol"; | |
import {AuraLockerModule} from "../src/AuraLockerModule.sol"; | ||
|
||
contract AuraLockerModuleTest is BaseFixture { | ||
function test_checkUpkeep_when_NotNewUnlock() public { | ||
function test_checkUpkeep_when_NotNewUnlock() public view { | ||
// at present nothing to lock | ||
(bool requiresLocking, bytes memory execPayload) = auraLockerModule.checkUpkeep(bytes("")); | ||
assertFalse(requiresLocking); | ||
|
@@ -27,16 +27,58 @@ contract AuraLockerModuleTest is BaseFixture { | |
// `disableModule(address prevModule, address module)` | ||
vm.prank(address(SAFE)); | ||
SAFE.disableModule(address(1), address(auraLockerModule)); | ||
// assertFalse(SAFE.isModuleEnabled(address(auraLockerModule))); | ||
address[] memory modules = SAFE.getModules(); | ||
for (uint256 i = 0; i < modules.length; i++) { | ||
if (modules[i] == address(auraLockerModule)) assertFalse(true); | ||
} | ||
|
||
// once module its removed, the keeper trying to call `performUpkeep` should revert | ||
vm.prank(auraLockerModule.keeper()); | ||
vm.expectRevert(abi.encodeWithSelector(AuraLockerModule.ModuleNotEnabled.selector)); | ||
auraLockerModule.performUpkeep(bytes("")); | ||
} | ||
|
||
function test_revertWhen_NothingToUnlock() public {} | ||
function testPerformUpkeep_revertWhen_NothingToLock() public { | ||
// force a `performUpkeep` when weeks did not go by | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "when not enough weeks went by"? |
||
skip(1 weeks); | ||
|
||
vm.prank(auraLockerModule.keeper()); | ||
vm.expectRevert(abi.encodeWithSelector(AuraLockerModule.NothingToLock.selector, block.timestamp)); | ||
auraLockerModule.performUpkeep(bytes("")); | ||
} | ||
|
||
function testPerformUpkeepSuccess() public { | ||
// move to future | ||
skip(16 weeks); | ||
(bool requiresLocking,) = auraLockerModule.checkUpkeep(bytes("")); | ||
assertTrue(requiresLocking); | ||
|
||
(uint256 totalAuraInLocker,, uint256 lockedBeforePerformUpkeep,) = AURA_LOCKER.lockedBalances(address(SAFE)); | ||
|
||
function testPerformUpkeepSuccess() public {} | ||
vm.prank(auraLockerModule.keeper()); | ||
auraLockerModule.performUpkeep(bytes("")); | ||
|
||
// check 2M where locked properly | ||
(,, uint256 lockedAfterPerformUpkeep,) = AURA_LOCKER.lockedBalances(address(SAFE)); | ||
assertGt(lockedAfterPerformUpkeep, lockedBeforePerformUpkeep); | ||
assertEq(totalAuraInLocker, lockedAfterPerformUpkeep); | ||
} | ||
|
||
function testPerformUpkeep_revertWhen_NotKeeper() public { | ||
vm.prank(address(454545)); | ||
vm.expectRevert(abi.encodeWithSelector(AuraLockerModule.NotKeeper.selector, address(454545))); | ||
auraLockerModule.performUpkeep(bytes("")); | ||
} | ||
|
||
function testSetKeeper_revertWhen_NotGovernance() public { | ||
vm.prank(address(454545)); | ||
vm.expectRevert(abi.encodeWithSelector(AuraLockerModule.NotGovernance.selector, address(454545))); | ||
auraLockerModule.setKeeper(address(454545)); | ||
} | ||
|
||
function testSetKeeper_revertWhen_AddressIsZero() public { | ||
vm.prank(address(SAFE)); | ||
vm.expectRevert(abi.encodeWithSelector(AuraLockerModule.ZeroAddressValue.selector)); | ||
auraLockerModule.setKeeper(address(0)); | ||
} | ||
} |
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
im guessing formally reverting it will prevent chainlink from making the actual call, and thus saving gas?