mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
New tests.
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
contract C {
|
||||
function f() public returns (uint y) {
|
||||
unchecked{{
|
||||
uint max = type(uint).max;
|
||||
uint x = max + 1;
|
||||
y = x;
|
||||
}}
|
||||
}
|
||||
}
|
||||
// ====
|
||||
// compileViaYul: also
|
||||
// ----
|
||||
// f() -> 0x00
|
||||
@@ -0,0 +1,18 @@
|
||||
contract C {
|
||||
uint public x = msg.value - 10;
|
||||
constructor() payable {}
|
||||
}
|
||||
|
||||
contract D {
|
||||
function f() public {
|
||||
unchecked {
|
||||
new C();
|
||||
}
|
||||
}
|
||||
function g() public payable returns (uint) {
|
||||
return (new C{value: 11}()).x();
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// f() -> FAILURE
|
||||
// g(), 100 wei -> 1
|
||||
@@ -0,0 +1,13 @@
|
||||
contract C {
|
||||
// Input is still not checked - this needs ABIEncoderV2!
|
||||
function f(uint16 a, uint16 b) public returns (uint16) {
|
||||
return a + b;
|
||||
}
|
||||
}
|
||||
// ====
|
||||
// ABIEncoderV1Only: true
|
||||
// ----
|
||||
// f(uint16,uint16): 65534, 0 -> 0xfffe
|
||||
// f(uint16,uint16): 65536, 0 -> 0x00
|
||||
// f(uint16,uint16): 65535, 0 -> 0xffff
|
||||
// f(uint16,uint16): 65535, 1 -> FAILURE
|
||||
@@ -0,0 +1,14 @@
|
||||
contract C {
|
||||
function add(uint16 a, uint16 b) public returns (uint16) {
|
||||
return a + b;
|
||||
}
|
||||
|
||||
function f(uint16 a, uint16 b, uint16 c) public returns (uint16) {
|
||||
unchecked { return add(a, b) + c; }
|
||||
}
|
||||
}
|
||||
// ====
|
||||
// compileViaYul: also
|
||||
// ----
|
||||
// f(uint16,uint16,uint16): 0xe000, 0xe500, 2 -> FAILURE
|
||||
// f(uint16,uint16,uint16): 0xe000, 0x1000, 0x1000 -> 0x00
|
||||
@@ -0,0 +1,15 @@
|
||||
contract C {
|
||||
modifier add(uint16 a, uint16 b) {
|
||||
unchecked { a + b; }
|
||||
_;
|
||||
}
|
||||
|
||||
function f(uint16 a, uint16 b, uint16 c) public add(a, b) returns (uint16) {
|
||||
return b + c;
|
||||
}
|
||||
}
|
||||
// ====
|
||||
// compileViaYul: also
|
||||
// ----
|
||||
// f(uint16,uint16,uint16): 0xe000, 0xe500, 2 -> 58626
|
||||
// f(uint16,uint16,uint16): 0x1000, 0xe500, 0xe000 -> FAILURE
|
||||
@@ -2,6 +2,14 @@ contract C {
|
||||
function f(int a, int b) public pure returns (int) {
|
||||
return a % b;
|
||||
}
|
||||
function g(bool _check) public pure returns (int) {
|
||||
int x = type(int).min;
|
||||
if (_check) {
|
||||
return x / -1;
|
||||
} else {
|
||||
unchecked { return x / -1; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ====
|
||||
@@ -12,3 +20,5 @@ contract C {
|
||||
// f(int256,int256): -7, 5 -> -2
|
||||
// f(int256,int256): -7, 5 -> -2
|
||||
// f(int256,int256): -5, -5 -> 0
|
||||
// g(bool): true -> FAILURE
|
||||
// g(bool): false -> -57896044618658097711785492504343953926634992332820282019728792003956564819968
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
contract C {
|
||||
function add(uint16 a, uint16 b) public returns (uint16) {
|
||||
unchecked {
|
||||
return a + b;
|
||||
}
|
||||
}
|
||||
|
||||
function f(uint16 a) public returns (uint16) {
|
||||
return add(a, 0x100) + 0x100;
|
||||
}
|
||||
}
|
||||
// ====
|
||||
// compileViaYul: also
|
||||
// ----
|
||||
// f(uint16): 7 -> 0x0207
|
||||
// f(uint16): 0xffff -> 511
|
||||
// f(uint16): 0xfeff -> FAILURE
|
||||
@@ -0,0 +1,22 @@
|
||||
contract C {
|
||||
function div(uint256 a, uint256 b) public returns (uint256) {
|
||||
// Does not disable div by zero check
|
||||
unchecked {
|
||||
return a / b;
|
||||
}
|
||||
}
|
||||
|
||||
function mod(uint256 a, uint256 b) public returns (uint256) {
|
||||
// Does not disable div by zero check
|
||||
unchecked {
|
||||
return a % b;
|
||||
}
|
||||
}
|
||||
}
|
||||
// ====
|
||||
// compileViaYul: also
|
||||
// ----
|
||||
// div(uint256,uint256): 7, 2 -> 3
|
||||
// div(uint256,uint256): 7, 0 -> FAILURE # throws #
|
||||
// mod(uint256,uint256): 7, 2 -> 1
|
||||
// mod(uint256,uint256): 7, 0 -> FAILURE # throws #
|
||||
Reference in New Issue
Block a user