Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
N
nebula
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
exchain
nebula
Commits
7fe44b99
Unverified
Commit
7fe44b99
authored
Oct 26, 2023
by
Maurelian
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
test(ctb): Add tests for all reverts in Liveness Module
parent
63fceb39
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
124 additions
and
9 deletions
+124
-9
LivenessModule.t.sol
packages/contracts-bedrock/test/LivenessModule.t.sol
+124
-9
No files found.
packages/contracts-bedrock/test/LivenessModule.t.sol
View file @
7fe44b99
...
...
@@ -33,6 +33,7 @@ contract LivenessModule_TestInit is Test, SafeTestTools {
event SignersRecorded(bytes32 indexed txHash, address[] signers);
uint256 initTime = 10;
uint256 livenessInterval = 30 days;
uint256 minOwners = 6;
LivenessModule livenessModule;
...
...
@@ -86,6 +87,10 @@ contract LivenessModule_TestInit is Test, SafeTestTools {
/// @dev Sets up the test environment
function setUp() public {
// Set the block timestamp to the initTime, so that signatures recorded in the first block
// are non-zero.
vm.warp(initTime);
// Create a Safe with 10 owners
(, uint256[] memory keys) = makeAddrsAndKeys(10);
safeInstance = _setupSafe(keys, 8);
...
...
@@ -107,7 +112,7 @@ contract LivenessModule_TestInit is Test, SafeTestTools {
contract LivenessModule_Constructor_Test is LivenessModule_TestInit {
/// @dev Tests that the constructor fails if the minOwners is greater than the number of owners
function test_constructor_minOwnersGreaterThanOwners_revert() external {
function test_constructor_minOwnersGreaterThanOwners_revert
s
() external {
vm.expectRevert("LivenessModule: minOwners must be less than the number of owners");
new LivenessModule({
_safe: safeInstance.safe,
...
...
@@ -117,6 +122,22 @@ contract LivenessModule_Constructor_Test is LivenessModule_TestInit {
_fallbackOwner: address(0)
});
}
/// @dev Tests that the constructor fails if the minOwners is greater than the number of owners
function test_constructor_wrongThreshold_reverts() external {
uint256 wrongThreshold = livenessModule.get75PercentThreshold(safeInstance.owners.length) + 1;
vm.mockCall(
address(safeInstance.safe), abi.encodeCall(OwnerManager.getThreshold, ()), abi.encode(wrongThreshold)
);
vm.expectRevert("LivenessModule: Safe must have a threshold of 75% of the number of owners");
new LivenessModule({
_safe: safeInstance.safe,
_livenessGuard: livenessGuard,
_livenessInterval: livenessInterval,
_minOwners: minOwners,
_fallbackOwner: address(0)
});
}
}
contract LivenessModule_Getters_Test is LivenessModule_TestInit {
...
...
@@ -157,11 +178,91 @@ contract LivenessModule_Get75PercentThreshold_Test is LivenessModule_TestInit {
}
}
contract LivenessModule_RemoveOwner_TestFail is LivenessModule_TestInit {
contract LivenessModule_RemoveOwner
s
_TestFail is LivenessModule_TestInit {
using SafeTestLib for SafeInstance;
// "LivenessModule: guard has been changed"
function test_removeOwner_guardChanged_revert() external {
/// @dev Tests with different length owner arrays
function test_removeOwners_differentArrayLengths_reverts() external {
address[] memory ownersToRemove = new address[](1);
address[] memory prevOwners = new address[](2);
vm.expectRevert("LivenessModule: arrays must be the same length");
livenessModule.removeOwners(prevOwners, ownersToRemove);
}
/// @dev Test removing an owner which has recently signed a transaction
function test_removeOwners_ownerHasSignedRecently_reverts() external {
/// Will sign a transaction with the first M owners in the owners list
vm.warp(block.timestamp + livenessInterval);
safeInstance.execTransaction({ to: address(1111), value: 0, data: hex"abba" });
vm.expectRevert(
"LivenessModule: the safe still has sufficient owners, or the owner to remove has signed recently"
);
_removeAnOwner(safeInstance.owners[0]);
}
/// @dev Test removing an owner which has recently called showLiveness
function test_removeOwners_ownerHasShownLivenessRecently_reverts() external {
/// Will sign a transaction with the first M owners in the owners list
vm.warp(block.timestamp + livenessInterval);
vm.prank(safeInstance.owners[0]);
livenessGuard.showLiveness();
vm.expectRevert(
"LivenessModule: the safe still has sufficient owners, or the owner to remove has signed recently"
);
_removeAnOwner(safeInstance.owners[0]);
}
/// @dev Test removing an owner with an incorrect previous owner
function test_removeOwners_wrongPreviousOwner_reverts() external {
address[] memory prevOwners = new address[](1);
address[] memory ownersToRemove = new address[](1);
ownersToRemove[0] = safeInstance.owners[0];
prevOwners[0] = ownersToRemove[0]; // incorrect.
vm.warp(block.timestamp + livenessInterval);
vm.expectRevert("LivenessModule: failed to remove owner");
livenessModule.removeOwners(prevOwners, ownersToRemove);
}
/// @dev Tests if removing all owners works correctly
function test_removeOwners_swapToFallBackOwner_reverts() external {
uint256 numOwners = safeInstance.owners.length;
address[] memory ownersToRemove = new address[](numOwners);
for (uint256 i = 0; i < numOwners; i++) {
ownersToRemove[i] = safeInstance.owners[i];
}
address[] memory prevOwners = _getPrevOwners(ownersToRemove);
// Incorrectly set the final owner to address(0)
ownersToRemove[ownersToRemove.length - 1] = address(0);
vm.warp(block.timestamp + livenessInterval);
vm.expectRevert("LivenessModule: failed to swap to fallback owner");
livenessModule.removeOwners(prevOwners, ownersToRemove);
}
/// @dev Tests if remove owners reverts if it removes too many owners without swapping to the fallback owner
function test_removeOwners_belowMinButNotToFallbackOwner_reverts() external {
// Remove all but one owner
uint256 numOwners = safeInstance.owners.length - 1;
address[] memory ownersToRemove = new address[](numOwners);
for (uint256 i = 0; i < numOwners; i++) {
ownersToRemove[i] = safeInstance.owners[i];
}
address[] memory prevOwners = _getPrevOwners(ownersToRemove);
vm.warp(block.timestamp + livenessInterval);
vm.expectRevert(
"LivenessModule: Safe must have the minimum number of owners or be owned solely by the fallback owner"
);
livenessModule.removeOwners(prevOwners, ownersToRemove);
}
/// @dev Tests if remove owners reverts if the current Safe.guard does note match the expected
/// livenessGuard address.
function test_removeOwners_guardChanged_reverts() external {
address[] memory ownersToRemove = new address[](1);
ownersToRemove[0] = safeInstance.owners[0];
address[] memory prevOwners = _getPrevOwners(ownersToRemove);
...
...
@@ -174,15 +275,29 @@ contract LivenessModule_RemoveOwner_TestFail is LivenessModule_TestInit {
vm.expectRevert("LivenessModule: guard has been changed");
livenessModule.removeOwners(prevOwners, ownersToRemove);
}
function test_removeOwners_invalidThreshold_reverts() external {
address[] memory ownersToRemove = new address[](0);
address[] memory prevOwners = new address[](0);
uint256 wrongThreshold = safeInstance.safe.getThreshold() + 1;
vm.mockCall(
address(safeInstance.safe), abi.encodeCall(OwnerManager.getThreshold, ()), abi.encode(wrongThreshold)
);
vm.warp(block.timestamp + livenessInterval + 1);
vm.expectRevert("LivenessModule: Safe must have a threshold of 75% of the number of owners");
livenessModule.removeOwners(prevOwners, ownersToRemove);
}
}
contract LivenessModule_RemoveOwner_Test is LivenessModule_TestInit {
contract LivenessModule_RemoveOwner
s
_Test is LivenessModule_TestInit {
/// @dev Tests if removing one owner works correctly
function test_removeOwner_oneOwner_succeeds() external {
function test_removeOwner
s
_oneOwner_succeeds() external {
uint256 ownersBefore = safeInstance.owners.length;
address ownerToRemove = safeInstance.owners[0];
// vm.warp(block.timestamp + 30 days
);
vm.warp(block.timestamp + livenessInterval + 1
);
_removeAnOwner(ownerToRemove);
assertFalse(safeInstance.safe.isOwner(ownerToRemove));
...
...
@@ -190,7 +305,7 @@ contract LivenessModule_RemoveOwner_Test is LivenessModule_TestInit {
}
/// @dev Tests if removing all owners works correctly
function test_removeOwner_allOwners_succeeds() external {
function test_removeOwner
s
_allOwners_succeeds() external {
uint256 numOwners = safeInstance.owners.length;
address[] memory ownersToRemove = new address[](numOwners);
...
...
@@ -199,7 +314,7 @@ contract LivenessModule_RemoveOwner_Test is LivenessModule_TestInit {
}
address[] memory prevOwners = _getPrevOwners(ownersToRemove);
vm.warp(block.timestamp +
30 days
);
vm.warp(block.timestamp +
livenessInterval + 1
);
livenessModule.removeOwners(prevOwners, ownersToRemove);
assertEq(safeInstance.safe.getOwners().length, 1);
assertEq(safeInstance.safe.getOwners()[0], fallbackOwner);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment