Skip to content

Commit 5a4d0a1

Browse files
committed
🐞 Fix clearHi() and clearLo() bugs; add tests
1 parent d27e48f commit 5a4d0a1

File tree

8 files changed

+51
-21
lines changed

8 files changed

+51
-21
lines changed

test/avalanche/addresses.t.sol

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {TRYB, TRYB_DEPLOYER, USDC, USDC_DEPLOYER, USDT, USDT_DEPLOYER} from "ava
66
import {Test} from "forge-std/Test.sol";
77

88
contract addressesTest is Test {
9-
function testDeployerConsistency() public pure {
9+
function testDeployerConsistency() external pure {
1010
assertEq(vm.computeCreateAddress(TRYB_DEPLOYER, 2), address(TRYB));
1111
assertEq(vm.computeCreateAddress(USDC_DEPLOYER, 4), address(USDC));
1212
assertEq(vm.computeCreateAddress(USDT_DEPLOYER, 2), address(USDT));

test/kimlikdao/IProtocolFund.t.sol

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22

33
pragma solidity ^0.8.0;
44

5-
import {RedeemInfo, RedeemInfoFrom} from "kimlikdao/IProtocolFund.sol";
65
import {Test} from "forge-std/Test.sol";
6+
import {RedeemInfo, RedeemInfoFrom} from "kimlikdao/IProtocolFund.sol";
77
import {uint48x2From} from "types/uint48x2.sol";
88

99
contract amountAddrTest is Test {
10-
function testAccessors() public pure {
10+
function testAccessors() external pure {
1111
RedeemInfo info = RedeemInfoFrom(uint48x2From(2, 1), address(0x1337ACC));
1212

1313
(uint256 total, uint256 amount, address addr) = info.unpack();

test/types/amountAddr.t.sol

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
pragma solidity ^0.8.0;
44

5-
import {amountAddr, amountAddrFrom} from "types/amountAddr.sol";
65
import {Test} from "forge-std/Test.sol";
6+
import {amountAddr, amountAddrFrom} from "types/amountAddr.sol";
77

88
contract amountAddrTest is Test {
9-
function testAccessors() public pure {
9+
function testAccessors() external pure {
1010
amountAddr aaddr = amountAddrFrom(1, address(0x1337ACC));
1111

1212
assertEq(aaddr.addr(), address(0x1337ACC));

test/types/uint128x2.t.sol

+21-5
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,18 @@
22

33
pragma solidity ^0.8.0;
44

5-
import {uint128x2, uint128x2From} from "types/uint128x2.sol";
65
import {Test} from "forge-std/Test.sol";
6+
import {uint128x2, uint128x2From} from "types/uint128x2.sol";
77

88
contract uint128x2Test is Test {
9-
function testAccessors() public pure {
9+
function testAccessors() external pure {
1010
uint128x2 pair = uint128x2From(1, 2);
1111

1212
assertEq(pair.lo(), 2);
1313
assertEq(pair.hi(), 1);
1414
}
1515

16-
function testIncDec() public pure {
16+
function testIncDec() external pure {
1717
uint128x2 pair = uint128x2From(300, 500);
1818
pair = pair.inc(200);
1919

@@ -32,7 +32,7 @@ contract uint128x2Test is Test {
3232
assert(pair2 == pair3);
3333
}
3434

35-
function tesetClear() public pure {
35+
function tesetClear() external pure {
3636
uint128x2 i = uint128x2From(2, 1);
3737

3838
i = i.clearHi();
@@ -47,12 +47,28 @@ contract uint128x2Test is Test {
4747
assertEq(j.lo(), 0);
4848
}
4949

50-
function testSum() public pure {
50+
function testSum() external pure {
5151
uint128x2 i = uint128x2From(type(uint128).max - 1, 1);
5252

5353
assertEq(i.sum(), type(uint128).max);
5454
assertEq(uint128x2From(1, 2).sum(), 3);
5555
assertEq(uint128x2From(2, 3).sum(), 5);
5656
assertEq(uint128x2From(1337, 1338).sum(), 2 * 1337 + 1);
5757
}
58+
59+
function testClearLo() external pure {
60+
uint128x2 n = uint128x2From(2, 1);
61+
n = n.clearLo();
62+
63+
assertEq(n.hi(), 2);
64+
assertEq(n.lo(), 0);
65+
}
66+
67+
function testClearHi() external pure {
68+
uint128x2 n = uint128x2From(100, 50);
69+
n = n.clearHi();
70+
71+
assertEq(n.hi(), 0);
72+
assertEq(n.lo(), 50);
73+
}
5874
}

test/types/uint48x2.t.sol

+20-6
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,18 @@
22

33
pragma solidity ^0.8.0;
44

5-
import {uint48x2, uint48x2From} from "types/uint48x2.sol";
65
import {Test} from "forge-std/Test.sol";
6+
import {uint48x2, uint48x2From} from "types/uint48x2.sol";
77

88
contract uint48x2Test is Test {
9-
function testAccessors() public pure {
9+
function testAccessors() external pure {
1010
uint48x2 pair = uint48x2From(1, 2);
1111

1212
assertEq(pair.lo(), 2);
1313
assertEq(pair.hi(), 1);
1414
}
1515

16-
function testIncDec() public pure {
16+
function testIncDec() external pure {
1717
uint48x2 pair = uint48x2From(300, 500);
1818
pair = pair.inc(200);
1919

@@ -32,7 +32,7 @@ contract uint48x2Test is Test {
3232
assert(pair2 == pair3);
3333
}
3434

35-
function tesetClear() public pure {
35+
function tesetClear() external pure {
3636
uint48x2 i = uint48x2From(2, 1);
3737

3838
i = i.clearHi();
@@ -47,7 +47,7 @@ contract uint48x2Test is Test {
4747
assertEq(j.lo(), 0);
4848
}
4949

50-
function testSum() public pure {
50+
function testSum() external pure {
5151
uint48x2 i = uint48x2From(type(uint48).max - 1, 1);
5252

5353
assertEq(i.sum(), type(uint48).max);
@@ -56,10 +56,24 @@ contract uint48x2Test is Test {
5656
assertEq(uint48x2From(1337, 1338).sum(), 2 * 1337 + 1);
5757
}
5858

59-
function testSetLo() public pure {
59+
function testSetLo() external pure {
6060
uint48x2 i = uint48x2From(2, 3);
6161

6262
assertEq(i.setLo(4).hi(), 2);
6363
assertEq(i.setLo(4).lo(), 4);
6464
}
65+
66+
function testClearLo() external pure {
67+
uint48x2 n = uint48x2From(3, 2).clearLo();
68+
69+
assertEq(n.hi(), 3);
70+
assertEq(n.lo(), 0);
71+
}
72+
73+
function testClearHi() external pure {
74+
uint48x2 n = uint48x2From(3, 2).clearHi();
75+
76+
assertEq(n.hi(), 0);
77+
assertEq(n.lo(), 2);
78+
}
6579
}

test/zksync/L2Log.t.sol

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {Test} from "forge-std/Test.sol";
66
import {L2LogLocator, L2LogLocatorFrom} from "zksync/L2Log.sol";
77

88
contract L2LogLocatorTest is Test {
9-
function testAccessors() public pure {
9+
function testAccessors() external pure {
1010
L2LogLocator l = L2LogLocatorFrom(1, 2, 3);
1111
assertEq(l.batchNumber(), 1);
1212
assertEq(l.messageIndex(), 2);

types/uint128x2.sol

+2-2
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,11 @@ function sum(uint128x2 self) pure returns (uint256) {
6363
}
6464

6565
function clearLo(uint128x2 self) pure returns (uint128x2) {
66-
return uint128x2.wrap(uint128x2.unwrap(self) & ~type(uint128).max);
66+
return uint128x2.wrap(uint128x2.unwrap(self) & (~uint256(0) << 128));
6767
}
6868

6969
function clearHi(uint128x2 self) pure returns (uint128x2) {
70-
return uint128x2.wrap(uint128x2.unwrap(self) & type(uint128).max);
70+
return uint128x2.wrap(uint128x2.unwrap(self) & (~uint256(0) >> 128));
7171
}
7272

7373
function equal(uint128x2 self, uint128x2 other) pure returns (bool) {

types/uint48x2.sol

+2-2
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,11 @@ function sum(uint48x2 self) pure returns (uint256) {
6565
}
6666

6767
function clearLo(uint48x2 self) pure returns (uint48x2) {
68-
return uint48x2.wrap(uint48x2.unwrap(self) & ~type(uint48).max);
68+
return uint48x2.wrap(uint48x2.unwrap(self) & (~uint256(0) << 48));
6969
}
7070

7171
function clearHi(uint48x2 self) pure returns (uint48x2) {
72-
return uint48x2.wrap(uint48x2.unwrap(self) & type(uint48).max);
72+
return uint48x2.wrap(uint48x2.unwrap(self) & (~uint256(0) >> 208));
7373
}
7474

7575
function equal(uint48x2 self, uint48x2 other) pure returns (bool) {

0 commit comments

Comments
 (0)