Skip to content

Commit

Permalink
Addressed review feedback from @jrhea
Browse files Browse the repository at this point in the history
  • Loading branch information
jalextowle committed Aug 17, 2024
1 parent 57c2f70 commit b9bae53
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 4 deletions.
2 changes: 1 addition & 1 deletion contracts/src/interfaces/IChainlinkAggregatorV3.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8.0;
pragma solidity ^0.8.20;

interface IChainlinkAggregatorV3 {
function decimals() external view returns (uint8);
Expand Down
2 changes: 0 additions & 2 deletions contracts/src/libraries/SafeCast.sol
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ library SafeCast {
y = uint128(x);
}

// FIXME: Add unit tests for this.
//
/// @notice This function safely casts an int256 to an uint256.
/// @param x The int256 to cast to uint256.
/// @return y The uint256 casted from x.
Expand Down
4 changes: 4 additions & 0 deletions contracts/test/MockSafeCast.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ contract MockSafeCast {
y = SafeCast.toUint128(x);
}

function toUint256(int256 x) external pure returns (uint256 y) {
y = SafeCast.toUint256(x);
}

function toInt128(uint256 x) external pure returns (int128 y) {
y = SafeCast.toInt128(x);
}
Expand Down
2 changes: 1 addition & 1 deletion test/instances/chainlink/ChainlinkTest.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -640,7 +640,7 @@ contract ChainlinkHyperdriveTest is InstanceTest {
assertApproxEqAbs(
baseProceeds,
_shortAmount.mulDown(_variableRate),
1e9
1e4
);

// Ensure that the withdrawal was processed as expected.
Expand Down
17 changes: 17 additions & 0 deletions test/units/libraries/SafeCast.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,23 @@ contract SafeCastTest is BaseTest {
mock.toUint128(2 ** 255);
}

function test_toUint256() public {
MockSafeCast mock = new MockSafeCast();

uint256 cast_num = mock.toUint256(0);
assertEq(cast_num, uint256(0));
cast_num = mock.toUint256(1);
assertEq(cast_num, uint256(1));
cast_num = mock.toUint256(type(int256).max);
assertEq(cast_num, uint256(type(int256).max));

vm.expectRevert();
mock.toUint256(-1);

vm.expectRevert();
mock.toUint256(type(int256).min);
}

function test_toInt128_fromUint256_fuzz(uint256 num) public {
MockSafeCast mock = new MockSafeCast();

Expand Down

0 comments on commit b9bae53

Please sign in to comment.