Skip to content

Commit

Permalink
Merge pull request #151 from pooltogether/pool-1640-rename-extendedsa…
Browse files Browse the repository at this point in the history
…fecast

fix(contracts): rename ExtendedSafeCast
  • Loading branch information
PierrickGT committed Oct 1, 2021
2 parents 5b8d6e4 + ec1e547 commit 6303ff6
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pragma solidity 0.8.6;
* Can be combined with {SafeMath} and {SignedSafeMath} to extend it to smaller types, by performing
* all math on `uint256` and `int256` and then downcasting.
*/
library ExtendedSafeCast {
library ExtendedSafeCastLib {
/**
* @dev Returns the downcasted uint208 from uint256, reverting on
* overflow (when the input is greater than largest uint208).
Expand Down
4 changes: 2 additions & 2 deletions contracts/libraries/TwabLib.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ pragma solidity 0.8.6;

import "@openzeppelin/contracts/utils/math/SafeCast.sol";

import "./ExtendedSafeCast.sol";
import "./ExtendedSafeCastLib.sol";
import "./OverflowSafeComparatorLib.sol";
import "./RingBufferLib.sol";
import "./ObservationLib.sol";
Expand All @@ -14,7 +14,7 @@ import "./ObservationLib.sol";
/// @author PoolTogether Inc.
library TwabLib {
using OverflowSafeComparatorLib for uint32;
using ExtendedSafeCast for uint256;
using ExtendedSafeCastLib for uint256;

/// @notice The maximum number of twab entries
uint24 public constant MAX_CARDINALITY = 16777215; // 2**24
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

pragma solidity 0.8.6;

import "../../libraries/ExtendedSafeCast.sol";
import "../../libraries/ExtendedSafeCastLib.sol";

contract ExtendedSafeCastHarness {
using ExtendedSafeCast for uint256;
contract ExtendedSafeCastLibHarness {
using ExtendedSafeCastLib for uint256;

function toUint208(uint256 value) external pure returns (uint208) {
return value.toUint208();
Expand Down
14 changes: 7 additions & 7 deletions test/libraries/ExtendedSafeCast.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,25 @@ import { ethers } from 'hardhat';
const { utils } = ethers;
const { parseEther: toWei } = utils;

describe('ExtendedSafeCast', () => {
let ExtendedSafeCast: Contract;
let ExtendedSafeCastFactory: ContractFactory;
describe('ExtendedSafeCastLib', () => {
let ExtendedSafeCastLib: Contract;
let ExtendedSafeCastLibFactory: ContractFactory;

before(async () => {
ExtendedSafeCastFactory = await ethers.getContractFactory('ExtendedSafeCastHarness');
ExtendedSafeCast = await ExtendedSafeCastFactory.deploy();
ExtendedSafeCastLibFactory = await ethers.getContractFactory('ExtendedSafeCastLibHarness');
ExtendedSafeCastLib = await ExtendedSafeCastLibFactory.deploy();
});

describe('toUint208()', () => {
it('should return uint256 downcasted to uint208', async () => {
const value = toWei('1');

expect(await ExtendedSafeCast.toUint208(value)).to.equal(value);
expect(await ExtendedSafeCastLib.toUint208(value)).to.equal(value);
});
it('should fail to return value if value passed does not fit in 208 bits', async () => {
const value = BigNumber.from(2).pow(209);

await expect(ExtendedSafeCast.toUint208(value)).to.be.revertedWith(
await expect(ExtendedSafeCastLib.toUint208(value)).to.be.revertedWith(
"SafeCast: value doesn't fit in 208 bits",
);
});
Expand Down

0 comments on commit 6303ff6

Please sign in to comment.