Skip to content
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

tests: optimize foundry tests to use bit operation over modulo #812

Merged
merged 2 commits into from
Dec 1, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions tests/foundry/LSP6KeyManager/LSP6Utils.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ contract LSP6UtilsTests is Test {
function testIsCBAOfAllowedERC725YDataKeysWithInvalidShorterCBAAtTheBeginning(
uint16 elementLength
) public view {
uint8 numberBetween1and32 = uint8((elementLength % 32) + 1); // +1 to avoid having 0
uint8 numberBetween1and32 = uint8((elementLength & (32 - 1)) + 1); // +1 to avoid having 0
bytes memory invalidAllowedKey = _generateElementCBA(
numberBetween1and32,
numberBetween1and32 - 1
Expand All @@ -212,7 +212,7 @@ contract LSP6UtilsTests is Test {
function testIsCBAOfAllowedERC725YDataKeysWithInvalidShorterCBAInTheMiddle(
uint16 elementLength
) public view {
uint8 numberBetween1and32 = uint8((elementLength % 32) + 1); // +1 to avoid having 0
uint8 numberBetween1and32 = uint8((elementLength & (32 - 1)) + 1); // +1 to avoid having 0
bytes memory validAllowedKeysBefore = _generateElementCBA(
numberBetween1and32,
numberBetween1and32
Expand All @@ -238,7 +238,7 @@ contract LSP6UtilsTests is Test {
function testIsCBAOfAllowedERC725YDataKeysWithInvalidShorterCBAAtTheEnd(
uint16 elementLength
) public view {
uint8 numberBetween1and32 = uint8((elementLength % 32) + 1); // +1 to avoid having 0
uint8 numberBetween1and32 = uint8((elementLength & (32 - 1)) + 1); // +1 to avoid having 0
bytes memory validAllowedKeys = _generateElementCBA(
numberBetween1and32,
numberBetween1and32
Expand Down
Loading