Files
openzeppelin-contracts/contracts/mocks/SafeCastMock.sol
pepelu 4476a2d531 Unsigned conversion #2111 (#2123)
* Add signed to unsigned conversion to SafeCast

* Update SafeCast exception message

* Add test for SafeCast int to uint conversion

- Update SafeCastMock
- Add tests for SafeCast int256 to uint256

* Update SafeCast int to uint definition

Apply suggestions from code review.

Co-Authored-By: Nicolás Venturo <nicolas.venturo@gmail.com>

* Update test for SafeCast int to uint conversion

* Update SafeCast test after code review

- Change "downcasts" to "casts"
- Move test closer to its function

* Fix error in SafeCast toUint256 description

* Fix breaking error in SafeCast

* Add uint256 to int256 conversion to SafeCast

- Add function
- Add mock
- Add test

* Update SafeCast unsigned to signed conversion

- Update error in conversion to be more clear
- Update constants in test to be powers of 2 instead of shifts

* Add changelog entry

* Update SafeCast tests

- Add minus in INT256_MIN for clarity

Co-Authored-By: Nicolás Venturo <nicolas.venturo@gmail.com>

Co-authored-by: Nicolás Venturo <nicolas.venturo@gmail.com>
2020-03-27 10:56:30 -03:00

37 lines
822 B
Solidity

pragma solidity ^0.6.0;
import "../utils/SafeCast.sol";
contract SafeCastMock {
using SafeCast for uint;
using SafeCast for int;
function toUint256(int a) public pure returns (uint256) {
return a.toUint256();
}
function toInt256(uint a) public pure returns (int256) {
return a.toInt256();
}
function toUint128(uint a) public pure returns (uint128) {
return a.toUint128();
}
function toUint64(uint a) public pure returns (uint64) {
return a.toUint64();
}
function toUint32(uint a) public pure returns (uint32) {
return a.toUint32();
}
function toUint16(uint a) public pure returns (uint16) {
return a.toUint16();
}
function toUint8(uint a) public pure returns (uint8) {
return a.toUint8();
}
}