mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Sort tests.
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
contract C {
|
||||
uint256 public x;
|
||||
modifier run() {
|
||||
for (uint256 i = 0; i < 10; i++) {
|
||||
_;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
function f() public run {
|
||||
uint256 k = x;
|
||||
uint256 t = k + 1;
|
||||
x = t;
|
||||
}
|
||||
}
|
||||
|
||||
// ----
|
||||
// x() -> 0
|
||||
// f() ->
|
||||
// x() -> 1
|
||||
@@ -0,0 +1,20 @@
|
||||
contract C {
|
||||
uint256 public x;
|
||||
modifier run() {
|
||||
for (uint256 i = 0; i < 10; i++) {
|
||||
if (i % 2 == 1) continue;
|
||||
_;
|
||||
}
|
||||
}
|
||||
|
||||
function f() public run {
|
||||
uint256 k = x;
|
||||
uint256 t = k + 1;
|
||||
x = t;
|
||||
}
|
||||
}
|
||||
|
||||
// ----
|
||||
// x() -> 0
|
||||
// f() ->
|
||||
// x() -> 5
|
||||
@@ -0,0 +1,13 @@
|
||||
contract C {
|
||||
function getOne() public payable nonFree returns (uint256 r) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
modifier nonFree {
|
||||
if (msg.value > 0) _;
|
||||
}
|
||||
}
|
||||
|
||||
// ----
|
||||
// getOne() -> 0
|
||||
// getOne(), 1 wei -> 1
|
||||
+49
@@ -0,0 +1,49 @@
|
||||
contract A {
|
||||
uint256 data;
|
||||
|
||||
constructor() public mod1 {
|
||||
f1();
|
||||
}
|
||||
|
||||
function f1() public mod2 {
|
||||
data |= 0x1;
|
||||
}
|
||||
|
||||
function f2() public {
|
||||
data |= 0x20;
|
||||
}
|
||||
|
||||
function f3() public virtual {}
|
||||
|
||||
modifier mod1 virtual {
|
||||
f2();
|
||||
_;
|
||||
}
|
||||
modifier mod2 {
|
||||
f3();
|
||||
if (false) _;
|
||||
}
|
||||
|
||||
function getData() public returns (uint256 r) {
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
contract C is A {
|
||||
modifier mod1 override {
|
||||
f4();
|
||||
_;
|
||||
}
|
||||
|
||||
function f3() public override {
|
||||
data |= 0x300;
|
||||
}
|
||||
|
||||
function f4() public {
|
||||
data |= 0x4000;
|
||||
}
|
||||
}
|
||||
|
||||
// ----
|
||||
// getData() -> 0x4300
|
||||
@@ -0,0 +1,27 @@
|
||||
contract A {
|
||||
uint256 data;
|
||||
|
||||
constructor() public mod1 {
|
||||
data |= 2;
|
||||
}
|
||||
|
||||
modifier mod1 virtual {
|
||||
data |= 1;
|
||||
_;
|
||||
}
|
||||
|
||||
function getData() public returns (uint256 r) {
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
contract C is A {
|
||||
modifier mod1 override {
|
||||
data |= 4;
|
||||
_;
|
||||
}
|
||||
}
|
||||
|
||||
// ----
|
||||
// getData() -> 6
|
||||
@@ -0,0 +1,28 @@
|
||||
library L {
|
||||
struct S {
|
||||
uint256 v;
|
||||
}
|
||||
modifier mod(S storage s) {
|
||||
s.v++;
|
||||
_;
|
||||
}
|
||||
|
||||
function libFun(S storage s) internal mod(s) {
|
||||
s.v += 0x100;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
contract Test {
|
||||
using L for *;
|
||||
L.S s;
|
||||
|
||||
function f() public returns (uint256) {
|
||||
s.libFun();
|
||||
L.libFun(s);
|
||||
return s.v;
|
||||
}
|
||||
}
|
||||
|
||||
// ----
|
||||
// f() -> 0x202
|
||||
@@ -0,0 +1,34 @@
|
||||
// Tests that virtual lookup for modifiers in libraries does not consider
|
||||
// the current inheritance hierarchy.
|
||||
library L {
|
||||
struct S {
|
||||
uint256 v;
|
||||
}
|
||||
modifier mod(S storage s) {
|
||||
s.v++;
|
||||
_;
|
||||
}
|
||||
|
||||
function libFun(S storage s) internal mod(s) {
|
||||
s.v += 0x100;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
contract Test {
|
||||
using L for *;
|
||||
L.S s;
|
||||
modifier mod(L.S storage) {
|
||||
revert();
|
||||
_;
|
||||
}
|
||||
|
||||
function f() public returns (uint256) {
|
||||
s.libFun();
|
||||
L.libFun(s);
|
||||
return s.v;
|
||||
}
|
||||
}
|
||||
|
||||
// ----
|
||||
// f() -> 0x202
|
||||
@@ -0,0 +1,19 @@
|
||||
contract C {
|
||||
modifier mod1 {
|
||||
uint8 a = 1;
|
||||
uint8 b = 2;
|
||||
_;
|
||||
}
|
||||
modifier mod2(bool a) {
|
||||
if (a) return;
|
||||
else _;
|
||||
}
|
||||
|
||||
function f(bool a) public mod1 mod2(a) returns (uint256 r) {
|
||||
return 3;
|
||||
}
|
||||
}
|
||||
|
||||
// ----
|
||||
// f(bool): true -> 0
|
||||
// f(bool): false -> 3
|
||||
@@ -0,0 +1,13 @@
|
||||
contract C {
|
||||
modifier repeat(uint256 count) {
|
||||
uint256 i;
|
||||
for (i = 0; i < count; ++i) _;
|
||||
}
|
||||
|
||||
function f() public repeat(10) returns (uint256 r) {
|
||||
r += 1;
|
||||
}
|
||||
}
|
||||
|
||||
// ----
|
||||
// f() -> 10
|
||||
@@ -0,0 +1,14 @@
|
||||
contract C {
|
||||
modifier repeat(bool twice) {
|
||||
if (twice) _;
|
||||
_;
|
||||
}
|
||||
|
||||
function f(bool twice) public repeat(twice) returns (uint256 r) {
|
||||
r += 1;
|
||||
}
|
||||
}
|
||||
|
||||
// ----
|
||||
// f(bool): false -> 1
|
||||
// f(bool): true -> 2
|
||||
@@ -0,0 +1,17 @@
|
||||
// Note that return sets the return variable and jumps to the end of the current function or
|
||||
// modifier code block.
|
||||
contract C {
|
||||
modifier repeat(bool twice) {
|
||||
if (twice) _;
|
||||
_;
|
||||
}
|
||||
|
||||
function f(bool twice) public repeat(twice) returns (uint256 r) {
|
||||
r += 1;
|
||||
return r;
|
||||
}
|
||||
}
|
||||
|
||||
// ----
|
||||
// f(bool): false -> 1
|
||||
// f(bool): true -> 2
|
||||
@@ -0,0 +1,15 @@
|
||||
contract C {
|
||||
uint256 public a;
|
||||
modifier mod(uint256 x) {
|
||||
a += x;
|
||||
_;
|
||||
}
|
||||
|
||||
function f(uint256 x) public mod(2) mod(5) mod(x) returns (uint256) {
|
||||
return a;
|
||||
}
|
||||
}
|
||||
|
||||
// ----
|
||||
// f(uint256): 3 -> 10
|
||||
// a() -> 10
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
contract C {
|
||||
uint256 public a;
|
||||
modifier mod(uint256 x) {
|
||||
uint256 b = x;
|
||||
a += b;
|
||||
_;
|
||||
a -= b;
|
||||
assert(b == x);
|
||||
}
|
||||
|
||||
function f(uint256 x) public mod(2) mod(5) mod(x) returns (uint256) {
|
||||
return a;
|
||||
}
|
||||
}
|
||||
|
||||
// ----
|
||||
// f(uint256): 3 -> 10
|
||||
// a() -> 0
|
||||
@@ -0,0 +1,19 @@
|
||||
contract A {
|
||||
function f() public mod returns (bool r) {
|
||||
return true;
|
||||
}
|
||||
|
||||
modifier mod virtual {
|
||||
_;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
contract C is A {
|
||||
modifier mod override {
|
||||
if (false) _;
|
||||
}
|
||||
}
|
||||
|
||||
// ----
|
||||
// f() -> false
|
||||
@@ -0,0 +1,16 @@
|
||||
contract C {
|
||||
uint256 public x;
|
||||
modifier setsx {
|
||||
_;
|
||||
x = 9;
|
||||
}
|
||||
|
||||
function f() public setsx returns (uint256) {
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
|
||||
// ----
|
||||
// x() -> 0
|
||||
// f() -> 2
|
||||
// x() -> 9
|
||||
@@ -0,0 +1,20 @@
|
||||
contract C {
|
||||
uint256 public x;
|
||||
modifier run() {
|
||||
for (uint256 i = 1; i < 10; i++) {
|
||||
if (i == 5) return;
|
||||
_;
|
||||
}
|
||||
}
|
||||
|
||||
function f() public run {
|
||||
uint256 k = x;
|
||||
uint256 t = k + 1;
|
||||
x = t;
|
||||
}
|
||||
}
|
||||
|
||||
// ----
|
||||
// x() -> 0
|
||||
// f() ->
|
||||
// x() -> 4
|
||||
@@ -0,0 +1,20 @@
|
||||
contract C {
|
||||
uint256 public x;
|
||||
modifier run() {
|
||||
for (uint256 i = 0; i < 10; i++) {
|
||||
_;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
function f() public run {
|
||||
uint256 k = x;
|
||||
uint256 t = k + 1;
|
||||
x = t;
|
||||
}
|
||||
}
|
||||
|
||||
// ----
|
||||
// x() -> 0
|
||||
// f() ->
|
||||
// x() -> 1
|
||||
Reference in New Issue
Block a user