-
Notifications
You must be signed in to change notification settings - Fork 9
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
Add test cases for EnumerableGuardianMap. #6
Changes from 2 commits
c9d60c9
71f8119
3edc0bd
c0ff1b8
e8f83bf
cf01dc7
122e194
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,21 +2,82 @@ | |
pragma solidity ^0.8.25; | ||
|
||
import "forge-std/console2.sol"; | ||
import { UnitBase } from "../../UnitBase.t.sol"; | ||
import {UnitBase} from "../../UnitBase.t.sol"; | ||
import {EnumerableGuardianMap, GuardianStorage, GuardianStatus} from "../../../../src/libraries/EnumerableGuardianMap.sol"; | ||
|
||
contract EnumerableGuardianMap_removeAll_Test is UnitBase { | ||
using EnumerableGuardianMap for EnumerableGuardianMap.AddressToGuardianMap; | ||
mapping(address account => EnumerableGuardianMap.AddressToGuardianMap guardian) | ||
internal guardiansStorage; | ||
|
||
function setUp() public override { | ||
super.setUp(); | ||
} | ||
|
||
function test_RemoveAll_RevertWhen_TooManyValuesToRemove() public view { | ||
// TODO: test | ||
function test_RemoveAll_Succeeds() public { | ||
bool result; | ||
|
||
for (uint256 i = 1; i <= 3; i++) { | ||
result = guardiansStorage[accountAddress].set({ | ||
key: vm.addr(i), | ||
value: GuardianStorage( | ||
GuardianStatus.REQUESTED, | ||
guardianWeights[1] | ||
) | ||
}); | ||
assertEq(result, true); | ||
} | ||
address[] memory addresses = new address[](3); | ||
addresses[0] = vm.addr(1); | ||
addresses[1] = vm.addr(2); | ||
addresses[2] = vm.addr(3); | ||
guardiansStorage[accountAddress].removeAll(addresses); | ||
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. Can you add an assert to check that the values are no longer in storage? |
||
} | ||
|
||
function test_RemoveAll_Succeeds() public view { | ||
// TODO: test | ||
function test_RemoveAll_RemovesMaxNumberOfValues() public { | ||
bool result; | ||
|
||
for ( | ||
uint256 i = 1; | ||
i <= EnumerableGuardianMap.MAX_NUMBER_OF_GUARDIANS; | ||
i++ | ||
) { | ||
result = guardiansStorage[accountAddress].set({ | ||
key: vm.addr(i), | ||
value: GuardianStorage( | ||
GuardianStatus.REQUESTED, | ||
guardianWeights[1] | ||
) | ||
}); | ||
assertEq(result, true); | ||
} | ||
|
||
address[] memory addresses = new address[]( | ||
EnumerableGuardianMap.MAX_NUMBER_OF_GUARDIANS | ||
); | ||
for ( | ||
uint256 i = 0; | ||
i < EnumerableGuardianMap.MAX_NUMBER_OF_GUARDIANS; | ||
i++ | ||
) { | ||
addresses[i] = vm.addr(i + 1); | ||
} | ||
guardiansStorage[accountAddress].removeAll(addresses); | ||
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. Same here, can you add an assert to check that the values are no longer in storage? |
||
} | ||
function test_RemoveAll_RemovesMaxNumberOfValues() public view { | ||
// TODO: test | ||
|
||
function test_RemoveAll_RevertWhen_TooManyValuesToRemove() public { | ||
address[] memory addresses = new address[]( | ||
EnumerableGuardianMap.MAX_NUMBER_OF_GUARDIANS + 1 | ||
); | ||
|
||
for ( | ||
uint256 i = 0; | ||
i < EnumerableGuardianMap.MAX_NUMBER_OF_GUARDIANS + 1; | ||
i++ | ||
) { | ||
addresses[i] = vm.addr(i + 1); | ||
} | ||
vm.expectRevert(EnumerableGuardianMap.TooManyValuesToRemove.selector); | ||
guardiansStorage[accountAddress].removeAll(addresses); | ||
} | ||
} |
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.
cool, can you remove this test case then?