@@ -6,7 +6,7 @@ import "./mocks/LogarithmicBucketsMock.sol";
66
77contract TestLogarithmicBuckets is LogarithmicBucketsMock , Test {
88 using BucketDLL for BucketDLL.List;
9- using LogarithmicBuckets for LogarithmicBuckets.BucketList ;
9+ using LogarithmicBuckets for LogarithmicBuckets.Buckets ;
1010
1111 uint256 public accountsLength = 50 ;
1212 address [] public accounts;
@@ -21,30 +21,30 @@ contract TestLogarithmicBuckets is LogarithmicBucketsMock, Test {
2121 }
2222
2323 function testInsertOneSingleAccount (bool _head ) public {
24- bucketList .update (accounts[0 ], 3 , _head);
24+ buckets .update (accounts[0 ], 3 , _head);
2525
26- assertEq (bucketList. getValueOf ( accounts[0 ]) , 3 );
27- assertEq (bucketList .getMatch (0 ), accounts[0 ]);
28- assertEq (bucketList. getBucketOf ( 3 ) .getHead (), accounts[0 ]);
29- assertEq (bucketList. getBucketOf ( 2 ) .getHead (), accounts[0 ]);
26+ assertEq (buckets.valueOf[ accounts[0 ]] , 3 );
27+ assertEq (buckets .getMatch (0 ), accounts[0 ]);
28+ assertEq (buckets.buckets[ 2 ] .getHead (), accounts[0 ]);
29+ assertEq (buckets.buckets[ 2 ] .getHead (), accounts[0 ]);
3030 }
3131
3232 function testUpdatingFromZeroToZeroShouldRevert (bool _head ) public {
3333 vm.expectRevert (abi.encodeWithSignature ("ZeroValue() " ));
34- bucketList .update (accounts[0 ], 0 , _head);
34+ buckets .update (accounts[0 ], 0 , _head);
3535 }
3636
3737 function testShouldNotInsertZeroAddress (bool _head ) public {
3838 vm.expectRevert (abi.encodeWithSignature ("ZeroAddress() " ));
39- bucketList .update (address (0 ), 10 , _head);
39+ buckets .update (address (0 ), 10 , _head);
4040 }
4141
4242 function testShouldHaveTheRightOrderWithinABucketFIFO () public {
43- bucketList .update (accounts[0 ], 16 , false );
44- bucketList .update (accounts[1 ], 16 , false );
45- bucketList .update (accounts[2 ], 16 , false );
43+ buckets .update (accounts[0 ], 16 , false );
44+ buckets .update (accounts[1 ], 16 , false );
45+ buckets .update (accounts[2 ], 16 , false );
4646
47- BucketDLL.List storage list = bucketList. getBucketOf ( 16 ) ;
47+ BucketDLL.List storage list = buckets.buckets[ 16 ] ;
4848 address head = list.getNext (address (0 ));
4949 address next1 = list.getNext (head);
5050 address next2 = list.getNext (next1);
@@ -54,11 +54,11 @@ contract TestLogarithmicBuckets is LogarithmicBucketsMock, Test {
5454 }
5555
5656 function testShouldHaveTheRightOrderWithinABucketLIFO () public {
57- bucketList .update (accounts[0 ], 16 , true );
58- bucketList .update (accounts[1 ], 16 , true );
59- bucketList .update (accounts[2 ], 16 , true );
57+ buckets .update (accounts[0 ], 16 , true );
58+ buckets .update (accounts[1 ], 16 , true );
59+ buckets .update (accounts[2 ], 16 , true );
6060
61- BucketDLL.List storage list = bucketList. getBucketOf ( 16 ) ;
61+ BucketDLL.List storage list = buckets.buckets[ 16 ] ;
6262 address head = list.getNext (address (0 ));
6363 address next1 = list.getNext (head);
6464 address next2 = list.getNext (next1);
@@ -68,52 +68,52 @@ contract TestLogarithmicBuckets is LogarithmicBucketsMock, Test {
6868 }
6969
7070 function testInsertRemoveOneSingleAccount (bool _head1 , bool _head2 ) public {
71- bucketList .update (accounts[0 ], 1 , _head1);
72- bucketList .update (accounts[0 ], 0 , _head2);
71+ buckets .update (accounts[0 ], 1 , _head1);
72+ buckets .update (accounts[0 ], 0 , _head2);
7373
74- assertEq (bucketList. getValueOf ( accounts[0 ]) , 0 );
75- assertEq (bucketList .getMatch (0 ), address (0 ));
76- assertEq (bucketList. getBucketOf ( 1 ) .getHead (), address (0 ));
74+ assertEq (buckets.valueOf[ accounts[0 ]] , 0 );
75+ assertEq (buckets .getMatch (0 ), address (0 ));
76+ assertEq (buckets.buckets[ 1 ] .getHead (), address (0 ));
7777 }
7878
7979 function testShouldInsertTwoAccounts (bool _head1 , bool _head2 ) public {
80- bucketList .update (accounts[0 ], 16 , _head1);
81- bucketList .update (accounts[1 ], 4 , _head2);
80+ buckets .update (accounts[0 ], 16 , _head1);
81+ buckets .update (accounts[1 ], 4 , _head2);
8282
83- assertEq (bucketList .getMatch (16 ), accounts[0 ]);
84- assertEq (bucketList .getMatch (2 ), accounts[1 ]);
85- assertEq (bucketList. getBucketOf ( 4 ) .getHead (), accounts[1 ]);
83+ assertEq (buckets .getMatch (16 ), accounts[0 ]);
84+ assertEq (buckets .getMatch (2 ), accounts[1 ]);
85+ assertEq (buckets.buckets[ 4 ] .getHead (), accounts[1 ]);
8686 }
8787
8888 function testShouldRemoveOneAccountOverTwo () public {
89- bucketList .update (accounts[0 ], 4 , false );
90- bucketList .update (accounts[1 ], 16 , false );
91- bucketList .update (accounts[0 ], 0 , false );
92-
93- assertEq (bucketList .getMatch (4 ), accounts[1 ]);
94- assertEq (bucketList. getValueOf ( accounts[0 ]) , 0 );
95- assertEq (bucketList. getValueOf ( accounts[1 ]) , 16 );
96- assertEq (bucketList. getBucketOf ( 16 ) .getHead (), accounts[1 ]);
97- assertEq (bucketList. getBucketOf ( 4 ) .getHead (), address (0 ));
89+ buckets .update (accounts[0 ], 4 , false );
90+ buckets .update (accounts[1 ], 16 , false );
91+ buckets .update (accounts[0 ], 0 , false );
92+
93+ assertEq (buckets .getMatch (4 ), accounts[1 ]);
94+ assertEq (buckets.valueOf[ accounts[0 ]] , 0 );
95+ assertEq (buckets.valueOf[ accounts[1 ]] , 16 );
96+ assertEq (buckets.buckets[ 16 ] .getHead (), accounts[1 ]);
97+ assertEq (buckets.buckets[ 4 ] .getHead (), address (0 ));
9898 }
9999
100100 function testShouldRemoveBothAccounts () public {
101- bucketList .update (accounts[0 ], 4 , true );
102- bucketList .update (accounts[1 ], 4 , true );
103- bucketList .update (accounts[0 ], 0 , true );
104- bucketList .update (accounts[1 ], 0 , true );
101+ buckets .update (accounts[0 ], 4 , true );
102+ buckets .update (accounts[1 ], 4 , true );
103+ buckets .update (accounts[0 ], 0 , true );
104+ buckets .update (accounts[1 ], 0 , true );
105105
106- assertEq (bucketList .getMatch (4 ), address (0 ));
106+ assertEq (buckets .getMatch (4 ), address (0 ));
107107 }
108108
109109 function testGetMatch () public {
110- assertEq (bucketList .getMatch (0 ), address (0 ));
111- assertEq (bucketList .getMatch (1000 ), address (0 ));
110+ assertEq (buckets .getMatch (0 ), address (0 ));
111+ assertEq (buckets .getMatch (1000 ), address (0 ));
112112
113- bucketList .update (accounts[0 ], 16 , false );
114- assertEq (bucketList .getMatch (1 ), accounts[0 ], "head before " );
115- assertEq (bucketList .getMatch (16 ), accounts[0 ], "head equal " );
116- assertEq (bucketList .getMatch (32 ), accounts[0 ], "head above " );
113+ buckets .update (accounts[0 ], 16 , false );
114+ assertEq (buckets .getMatch (1 ), accounts[0 ], "head before " );
115+ assertEq (buckets .getMatch (16 ), accounts[0 ], "head equal " );
116+ assertEq (buckets .getMatch (32 ), accounts[0 ], "head above " );
117117 }
118118
119119 function isPowerOfTwo (uint256 x ) public pure returns (bool ) {
@@ -134,8 +134,8 @@ contract TestLogarithmicBuckets is LogarithmicBucketsMock, Test {
134134
135135 function testProveNextBucket (uint256 _value ) public {
136136 uint256 curr = LogarithmicBuckets.computeBucket (_value);
137- uint256 next = nextBucket (_value);
138- uint256 bucketsMask = bucketList .bucketsMask;
137+ uint256 next = nextBucketValue (_value);
138+ uint256 bucketsMask = buckets .bucketsMask;
139139 // check that `next` is a strictly higer non-empty bucket, or zero
140140 assertTrue (next == 0 || isPowerOfTwo (next));
141141 assertTrue (next == 0 || next > curr);
@@ -151,8 +151,8 @@ contract TestLogarithmicBuckets is LogarithmicBucketsMock, Test {
151151
152152 function testProvePrevBucket (uint256 _value ) public {
153153 uint256 curr = LogarithmicBuckets.computeBucket (_value);
154- uint256 prev = prevBucket (_value);
155- uint256 bucketsMask = bucketList .bucketsMask;
154+ uint256 prev = prevBucketValue (_value);
155+ uint256 bucketsMask = buckets .bucketsMask;
156156 // check that `prev` is a non-empty bucket that is lower than or equal to `curr`; or zero
157157 assertTrue (prev == 0 || isPowerOfTwo (prev));
158158 assertTrue (prev <= curr);
0 commit comments