Skip to content

Commit 87bf873

Browse files
RahulMaganti47Rahul Maganti
and
Rahul Maganti
authored
evm: add fuzz tests (#239)
* rate_limit: add fuzz test for outbound transfers * trimmed_amounts: add fuzz tests for left inverse and saturating add * trimmed_amount: add more fuzz tests * ntt_manager: add fuzz test for countSetBits * rate_limit: add fuzz test for inbound rate limiting * rate_limit: add fuzz test for backflow * fix: use bound instead of assume for uints * evm: remove unnecessary bounds in fuzz test for saturatingAdd * evm: change the inputs to the circular backflow tests to uint256 * evm: modify trimming is left inverse to support more decimals * evm: rebasing changes * evm: use bound in place of vm.assume * evm: test against inputs greater than u64MAX * evm: use explicit error selectors in reverts * evm: rename inputs for more clarity * evm: simplify trimming is left inverse test * evm: test additional invariants * evm: use bound instead of assume --------- Co-authored-by: Rahul Maganti <rahulmaganti@rahuls-mbp.mynetworksettings.com>
1 parent 9c040a2 commit 87bf873

File tree

3 files changed

+569
-28
lines changed

3 files changed

+569
-28
lines changed

evm/test/NttManager.t.sol

+14-6
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,20 @@ contract TestNttManager is Test, IRateLimiterEvents {
7272

7373
// === pure unit tests
7474

75-
function test_countSetBits() public {
76-
assertEq(countSetBits(5), 2);
77-
assertEq(countSetBits(0), 0);
78-
assertEq(countSetBits(15), 4);
79-
assertEq(countSetBits(16), 1);
80-
assertEq(countSetBits(65535), 16);
75+
// naive implementation of countSetBits to test against
76+
function simpleCount(uint64 n) public pure returns (uint8) {
77+
uint8 count;
78+
79+
while (n > 0) {
80+
count += uint8(n & 1);
81+
n >>= 1;
82+
}
83+
84+
return count;
85+
}
86+
87+
function testFuzz_countSetBits(uint64 n) public {
88+
assertEq(simpleCount(n), countSetBits(n));
8189
}
8290

8391
// === Deployments with rate limiter disabled

0 commit comments

Comments
 (0)