Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Procedural SafeCast.sol generation #3245

Merged
merged 23 commits into from May 21, 2022
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/test.yml
Expand Up @@ -30,6 +30,7 @@ jobs:
FORCE_COLOR: 1
ENABLE_GAS_REPORT: true
- run: npm run test:inheritance
- run: npm run test:generation
- name: Print gas report
run: cat gas-report.txt

Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -7,6 +7,7 @@
* `CrossChainEnabledPolygonChild`: replace the `require` statement with the custom error `NotCrossChainCall`. ([#3380](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/3380))
* `ERC20FlashMint`: Add customizable flash fee receiver. ([#3327](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/3327))
* `Strings`: add a new overloaded function `toHexString` that converts an `address` with fixed length of 20 bytes to its not checksummed ASCII `string` hexadecimal representation. ([#3403](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/3403))
* `SafeCast`: add support for many more types, using procedural code generation. ([#3245](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/3245))

## 4.6.0 (2022-04-26)

Expand Down
200 changes: 200 additions & 0 deletions contracts/mocks/SafeCastMock.sol
Expand Up @@ -12,26 +12,122 @@ contract SafeCastMock {
return a.toUint256();
}

function toUint248(uint256 a) public pure returns (uint248) {
return a.toUint248();
}

function toUint240(uint256 a) public pure returns (uint240) {
return a.toUint240();
}

function toUint232(uint256 a) public pure returns (uint232) {
return a.toUint232();
}

function toUint224(uint256 a) public pure returns (uint224) {
return a.toUint224();
}

function toUint216(uint256 a) public pure returns (uint216) {
return a.toUint216();
}

function toUint208(uint256 a) public pure returns (uint208) {
return a.toUint208();
}

function toUint200(uint256 a) public pure returns (uint200) {
return a.toUint200();
}

function toUint192(uint256 a) public pure returns (uint192) {
return a.toUint192();
}

function toUint184(uint256 a) public pure returns (uint184) {
return a.toUint184();
}

function toUint176(uint256 a) public pure returns (uint176) {
return a.toUint176();
}

function toUint168(uint256 a) public pure returns (uint168) {
return a.toUint168();
}

function toUint160(uint256 a) public pure returns (uint160) {
return a.toUint160();
}

function toUint152(uint256 a) public pure returns (uint152) {
return a.toUint152();
}

function toUint144(uint256 a) public pure returns (uint144) {
return a.toUint144();
}

function toUint136(uint256 a) public pure returns (uint136) {
return a.toUint136();
}

function toUint128(uint256 a) public pure returns (uint128) {
return a.toUint128();
}

function toUint120(uint256 a) public pure returns (uint120) {
return a.toUint120();
}

function toUint112(uint256 a) public pure returns (uint112) {
return a.toUint112();
}

function toUint104(uint256 a) public pure returns (uint104) {
return a.toUint104();
}

function toUint96(uint256 a) public pure returns (uint96) {
return a.toUint96();
}

function toUint88(uint256 a) public pure returns (uint88) {
return a.toUint88();
}

function toUint80(uint256 a) public pure returns (uint80) {
return a.toUint80();
}

function toUint72(uint256 a) public pure returns (uint72) {
return a.toUint72();
}

function toUint64(uint256 a) public pure returns (uint64) {
return a.toUint64();
}

function toUint56(uint256 a) public pure returns (uint56) {
return a.toUint56();
}

function toUint48(uint256 a) public pure returns (uint48) {
return a.toUint48();
}

function toUint40(uint256 a) public pure returns (uint40) {
return a.toUint40();
}

function toUint32(uint256 a) public pure returns (uint32) {
return a.toUint32();
}

function toUint24(uint256 a) public pure returns (uint24) {
return a.toUint24();
}

function toUint16(uint256 a) public pure returns (uint16) {
return a.toUint16();
}
Expand All @@ -44,18 +140,122 @@ contract SafeCastMock {
return a.toInt256();
}

function toInt248(int256 a) public pure returns (int248) {
return a.toInt248();
}

function toInt240(int256 a) public pure returns (int240) {
return a.toInt240();
}

function toInt232(int256 a) public pure returns (int232) {
return a.toInt232();
}

function toInt224(int256 a) public pure returns (int224) {
return a.toInt224();
}

function toInt216(int256 a) public pure returns (int216) {
return a.toInt216();
}

function toInt208(int256 a) public pure returns (int208) {
return a.toInt208();
}

function toInt200(int256 a) public pure returns (int200) {
return a.toInt200();
}

function toInt192(int256 a) public pure returns (int192) {
return a.toInt192();
}

function toInt184(int256 a) public pure returns (int184) {
return a.toInt184();
}

function toInt176(int256 a) public pure returns (int176) {
return a.toInt176();
}

function toInt168(int256 a) public pure returns (int168) {
return a.toInt168();
}

function toInt160(int256 a) public pure returns (int160) {
return a.toInt160();
}

function toInt152(int256 a) public pure returns (int152) {
return a.toInt152();
}

function toInt144(int256 a) public pure returns (int144) {
return a.toInt144();
}

function toInt136(int256 a) public pure returns (int136) {
return a.toInt136();
}

function toInt128(int256 a) public pure returns (int128) {
return a.toInt128();
}

function toInt120(int256 a) public pure returns (int120) {
return a.toInt120();
}

function toInt112(int256 a) public pure returns (int112) {
return a.toInt112();
}

function toInt104(int256 a) public pure returns (int104) {
return a.toInt104();
}

function toInt96(int256 a) public pure returns (int96) {
return a.toInt96();
}

function toInt88(int256 a) public pure returns (int88) {
return a.toInt88();
}

function toInt80(int256 a) public pure returns (int80) {
return a.toInt80();
}

function toInt72(int256 a) public pure returns (int72) {
return a.toInt72();
}

function toInt64(int256 a) public pure returns (int64) {
return a.toInt64();
}

function toInt56(int256 a) public pure returns (int56) {
return a.toInt56();
}

function toInt48(int256 a) public pure returns (int48) {
return a.toInt48();
}

function toInt40(int256 a) public pure returns (int40) {
return a.toInt40();
}

function toInt32(int256 a) public pure returns (int32) {
return a.toInt32();
}

function toInt24(int256 a) public pure returns (int24) {
return a.toInt24();
}

function toInt16(int256 a) public pure returns (int16) {
return a.toInt16();
}
Expand Down