aboutsummaryrefslogtreecommitdiffstats
path: root/test/libsolidity/SolidityEndToEndTest.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'test/libsolidity/SolidityEndToEndTest.cpp')
-rw-r--r--test/libsolidity/SolidityEndToEndTest.cpp135
1 files changed, 75 insertions, 60 deletions
diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp
index 7ea6cf98..31842777 100644
--- a/test/libsolidity/SolidityEndToEndTest.cpp
+++ b/test/libsolidity/SolidityEndToEndTest.cpp
@@ -49,6 +49,25 @@ namespace test
BOOST_FIXTURE_TEST_SUITE(SolidityEndToEndTest, SolidityExecutionFramework)
+BOOST_AUTO_TEST_CASE(transaction_status)
+{
+ char const* sourceCode = R"(
+ contract test {
+ function f() { }
+ function g() { revert(); }
+ function h() { assert(false); }
+ }
+ )";
+ compileAndRun(sourceCode);
+ callContractFunction("f()");
+ BOOST_CHECK(m_transactionSuccessful);
+ callContractFunction("g()");
+ BOOST_CHECK(!m_transactionSuccessful);
+ callContractFunction("h()");
+ BOOST_CHECK(!m_transactionSuccessful);
+}
+
+
BOOST_AUTO_TEST_CASE(smoke_test)
{
char const* sourceCode = R"(
@@ -305,7 +324,7 @@ BOOST_AUTO_TEST_CASE(conditional_expression_functions)
function y() returns (uint) { return 2; }
function f(bool cond) returns (uint) {
- var z = cond ? x : y;
+ function () returns (uint) z = cond ? x : y;
return z();
}
}
@@ -433,7 +452,7 @@ BOOST_AUTO_TEST_CASE(while_loop)
contract test {
function f(uint n) returns(uint nfac) {
nfac = 1;
- var i = 2;
+ uint i = 2;
while (i <= n) nfac *= i++;
}
}
@@ -460,7 +479,7 @@ BOOST_AUTO_TEST_CASE(do_while_loop)
contract test {
function f(uint n) returns(uint nfac) {
nfac = 1;
- var i = 2;
+ uint i = 2;
do { nfac *= i++; } while (i <= n);
}
}
@@ -561,7 +580,8 @@ BOOST_AUTO_TEST_CASE(for_loop)
contract test {
function f(uint n) returns(uint nfac) {
nfac = 1;
- for (var i = 2; i <= n; i++)
+ uint i;
+ for (i = 2; i <= n; i++)
nfac *= i;
}
}
@@ -735,7 +755,7 @@ BOOST_AUTO_TEST_CASE(many_local_variables)
char const* sourceCode = R"(
contract test {
function run(uint x1, uint x2, uint x3) returns(uint y) {
- var a = 0x1; var b = 0x10; var c = 0x100;
+ uint8 a = 0x1; uint8 b = 0x10; uint16 c = 0x100;
y = a + b + c + x1 + x2 + x3;
y += b + x2;
}
@@ -1252,7 +1272,7 @@ BOOST_AUTO_TEST_CASE(struct_reference)
}
function set() {
data.z = 2;
- var map = data.recursive;
+ mapping(uint8 => s2) map = data.recursive;
s2 inner = map[0];
inner.z = 3;
inner.recursive[0].z = inner.recursive[1].z + 1;
@@ -1836,8 +1856,7 @@ BOOST_AUTO_TEST_CASE(uncalled_blockhash)
contract C {
function f() public view returns (bytes32)
{
- var x = block.blockhash;
- return x(block.number - 1);
+ return (block.blockhash)(block.number - 1);
}
}
)";
@@ -2061,7 +2080,7 @@ BOOST_AUTO_TEST_CASE(packed_keccak256)
char const* sourceCode = R"(
contract test {
function a(bytes32 input) returns (bytes32 hash) {
- var b = 65536;
+ uint24 b = 65536;
uint c = 256;
return keccak256(abi.encodePacked(8, input, b, input, c));
}
@@ -2113,7 +2132,7 @@ BOOST_AUTO_TEST_CASE(packed_sha256)
char const* sourceCode = R"(
contract test {
function a(bytes32 input) returns (bytes32 hash) {
- var b = 65536;
+ uint24 b = 65536;
uint c = 256;
return sha256(abi.encodePacked(8, input, b, input, c));
}
@@ -2140,7 +2159,7 @@ BOOST_AUTO_TEST_CASE(packed_ripemd160)
char const* sourceCode = R"(
contract test {
function a(bytes32 input) returns (bytes32 hash) {
- var b = 65536;
+ uint24 b = 65536;
uint c = 256;
return ripemd160(abi.encodePacked(8, input, b, input, c));
}
@@ -2319,9 +2338,8 @@ BOOST_AUTO_TEST_CASE(inter_contract_calls_with_local_vars)
contract Main {
Helper h;
function callHelper(uint a, uint b) returns (uint c) {
- var fu = h.multiply;
- var y = 9;
- var ret = fu(a, b);
+ uint8 y = 9;
+ uint256 ret = h.multiply(a, b);
return ret + y;
}
function getHelper() returns (address haddress) {
@@ -2568,10 +2586,8 @@ BOOST_AUTO_TEST_CASE(value_complex)
helper h;
constructor() payable { h = new helper(); }
function sendAmount(uint amount) payable returns (uint256 bal) {
- var x1 = h.getBalance.value(amount);
uint someStackElement = 20;
- var x2 = x1.gas(1000);
- return x2.value(amount + 3)();// overwrite value
+ return h.getBalance.value(amount).gas(1000).value(amount + 3)();
}
}
)";
@@ -2591,10 +2607,7 @@ BOOST_AUTO_TEST_CASE(value_insane)
helper h;
constructor() payable { h = new helper(); }
function sendAmount(uint amount) returns (uint256 bal) {
- var x1 = h.getBalance.value;
- var x2 = x1(amount).gas;
- var x3 = x2(1000).value;
- return x3(amount + 3)();// overwrite value
+ return h.getBalance.value(amount).gas(1000).value(amount + 3)();// overwrite value
}
}
)";
@@ -2815,7 +2828,7 @@ BOOST_AUTO_TEST_CASE(function_modifier_local_variables)
{
char const* sourceCode = R"(
contract C {
- modifier mod1 { var a = 1; var b = 2; _; }
+ modifier mod1 { uint8 a = 1; uint8 b = 2; _; }
modifier mod2(bool a) { if (a) return; else _; }
function f(bool a) mod1 mod2(a) returns (uint r) { return 3; }
}
@@ -2829,7 +2842,7 @@ BOOST_AUTO_TEST_CASE(function_modifier_loop)
{
char const* sourceCode = R"(
contract C {
- modifier repeat(uint count) { for (var i = 0; i < count; ++i) _; }
+ modifier repeat(uint count) { uint i; for (i = 0; i < count; ++i) _; }
function f() repeat(10) returns (uint r) { r += 1; }
}
)";
@@ -3007,8 +3020,7 @@ BOOST_AUTO_TEST_CASE(crazy_elementary_typenames_on_stack)
function f() returns (uint r) {
uint; uint; uint; uint;
int x = -7;
- var a = uint;
- return a(x);
+ return uint(x);
}
}
)";
@@ -3106,9 +3118,11 @@ BOOST_AUTO_TEST_CASE(short_data_calls_fallback)
compileAndRun(sourceCode);
// should call fallback
sendMessage(asBytes("\xd8\x8e\x0b"), false, 0);
+ BOOST_CHECK(m_transactionSuccessful);
ABI_CHECK(callContractFunction("x()"), encodeArgs(2));
// should call function
sendMessage(asBytes(string("\xd8\x8e\x0b") + string(1, 0)), false, 0);
+ BOOST_CHECK(m_transactionSuccessful);
ABI_CHECK(callContractFunction("x()"), encodeArgs(3));
}
@@ -3793,6 +3807,7 @@ BOOST_AUTO_TEST_CASE(bytes_from_calldata_to_memory)
compileAndRun(sourceCode);
bytes calldata1 = FixedHash<4>(dev::keccak256("f()")).asBytes() + bytes(61, 0x22) + bytes(12, 0x12);
sendMessage(calldata1, false);
+ BOOST_CHECK(m_transactionSuccessful);
BOOST_CHECK(m_output == encodeArgs(dev::keccak256(bytes{'a', 'b', 'c'} + calldata1)));
}
@@ -3928,7 +3943,8 @@ BOOST_AUTO_TEST_CASE(copy_from_calldata_removes_bytes_data)
ABI_CHECK(callContractFunction("set()", 1, 2, 3, 4, 5), encodeArgs(true));
BOOST_CHECK(!storageEmpty(m_contractAddress));
sendMessage(bytes(), false);
- BOOST_CHECK(m_output == bytes());
+ BOOST_CHECK(m_transactionSuccessful);
+ BOOST_CHECK(m_output.empty());
BOOST_CHECK(storageEmpty(m_contractAddress));
}
@@ -4074,7 +4090,7 @@ BOOST_AUTO_TEST_CASE(struct_copy_via_local)
function test() returns (bool) {
data1.a = 1;
data1.b = 2;
- var x = data1;
+ Struct memory x = data1;
data2 = x;
return data2.a == data1.a && data2.b == data1.b;
}
@@ -6243,6 +6259,7 @@ BOOST_AUTO_TEST_CASE(evm_exceptions_in_constructor_out_of_baund)
}
)";
ABI_CHECK(compileAndRunWithoutCheck(sourceCode, 0, "A"), encodeArgs());
+ BOOST_CHECK(!m_transactionSuccessful);
}
BOOST_AUTO_TEST_CASE(positive_integers_to_signed)
@@ -6295,7 +6312,7 @@ BOOST_AUTO_TEST_CASE(send_zero_ether)
contract Main {
constructor() payable {}
function s() returns (bool) {
- var r = new Receiver();
+ Receiver r = new Receiver();
return r.send(0);
}
}
@@ -6578,7 +6595,7 @@ BOOST_AUTO_TEST_CASE(bytes_in_constructors_packer)
}
contract Creator {
function f(uint x, bytes s) returns (uint r, byte ch) {
- var c = new Main(s, x);
+ Main c = new Main(s, x);
r = c.m_x();
ch = c.part(x);
}
@@ -6617,7 +6634,7 @@ BOOST_AUTO_TEST_CASE(arrays_in_constructors)
}
contract Creator {
function f(uint x, address[] s) returns (uint r, address ch) {
- var c = new Main(s, x);
+ Main c = new Main(s, x);
r = c.m_x();
ch = c.part(x);
}
@@ -7369,8 +7386,8 @@ BOOST_AUTO_TEST_CASE(constant_string_literal)
string constant public x = "abefghijklmnopqabcdefghijklmnopqabcdefghijklmnopqabca";
constructor() {
- var xx = x;
- var bb = b;
+ string memory xx = x;
+ bytes32 bb = b;
}
function getB() returns (bytes32) { return b; }
function getX() returns (string) { return x; }
@@ -7461,7 +7478,7 @@ BOOST_AUTO_TEST_CASE(cross_contract_types)
contract Lib { struct S {uint a; uint b; } }
contract Test {
function f() returns (uint r) {
- var x = Lib.S({a: 2, b: 3});
+ Lib.S memory x = Lib.S({a: 2, b: 3});
r = x.b;
}
}
@@ -7546,7 +7563,7 @@ BOOST_AUTO_TEST_CASE(fixed_arrays_as_return_type)
contract B {
function f() returns (uint16[5] res, uint16[5] res2)
{
- var a = new A();
+ A a = new A();
res = a.f(2);
res2 = a.f(1000);
}
@@ -7829,13 +7846,13 @@ BOOST_AUTO_TEST_CASE(multi_variable_declaration)
a = 1; b = 2; c = 3;
}
function f() returns (bool) {
- var (x, y, z) = g();
+ (uint x, uint y, uint z) = g();
if (x != 1 || y != 2 || z != 3) return false;
- var (, a,) = g();
+ (, uint a,) = g();
if (a != 2) return false;
- var (b,) = g();
+ (uint b,) = g();
if (b != 1) return false;
- var (,c) = g();
+ (, uint c) = g();
if (c != 3) return false;
return true;
}
@@ -8037,11 +8054,11 @@ BOOST_AUTO_TEST_CASE(create_memory_array)
contract C {
struct S { uint[2] a; bytes b; }
function f() returns (byte, uint, uint, byte) {
- var x = new bytes(200);
+ bytes memory x = new bytes(200);
x[199] = 'A';
- var y = new uint[2][](300);
+ uint[2][] memory y = new uint[2][](300);
y[203][1] = 8;
- var z = new S[](180);
+ S[] memory z = new S[](180);
z[170].a[1] = 4;
z[170].b = new bytes(102);
z[170].b[99] = 'B';
@@ -8331,8 +8348,7 @@ BOOST_AUTO_TEST_CASE(bound_function_in_var)
D.s public x;
function f(uint a) returns (uint) {
x.a = 6;
- var g = x.mul;
- return g({x: a});
+ return (x.mul)({x: a});
}
}
)";
@@ -9120,7 +9136,7 @@ BOOST_AUTO_TEST_CASE(skip_dynamic_types)
}
function g() returns (uint, uint) {
// Previous implementation "moved" b to the second place and did not skip.
- var (a, _, b) = this.f();
+ (uint a,, uint b) = this.f();
return (a, b);
}
}
@@ -9146,7 +9162,7 @@ BOOST_AUTO_TEST_CASE(skip_dynamic_types_for_structs)
s.a = "abc";
s.b = [7, 8, 9];
s.y = 6;
- var (x, a, y) = this.s();
+ (uint x,, uint y) = this.s();
return (x, y);
}
}
@@ -9188,7 +9204,7 @@ BOOST_AUTO_TEST_CASE(create_dynamic_array_with_zero_length)
char const* sourceCode = R"(
contract C {
function f() returns (uint) {
- var a = new uint[][](0);
+ uint[][] memory a = new uint[][](0);
return 7;
}
}
@@ -10039,7 +10055,7 @@ BOOST_AUTO_TEST_CASE(function_delete_stack)
contract C {
function a() returns (uint) { return 7; }
function test() returns (uint) {
- var y = a;
+ function () returns (uint) y = a;
delete y;
y();
}
@@ -10077,7 +10093,7 @@ BOOST_AUTO_TEST_CASE(function_array_cross_calls)
char const* sourceCode = R"(
contract D {
function f(function() external returns (function() external returns (uint))[] x)
- returns (function() external returns (uint)[3] r)
+ public returns (function() external returns (uint)[3] r)
{
r[0] = x[0]();
r[1] = x[1]();
@@ -10085,23 +10101,23 @@ BOOST_AUTO_TEST_CASE(function_array_cross_calls)
}
}
contract C {
- function test() returns (uint, uint, uint) {
+ function test() public returns (uint, uint, uint) {
function() external returns (function() external returns (uint))[] memory x =
new function() external returns (function() external returns (uint))[](10);
for (uint i = 0; i < x.length; i ++)
x[i] = this.h;
x[0] = this.htwo;
- var y = (new D()).f(x);
+ function() external returns (uint)[3] memory y = (new D()).f(x);
return (y[0](), y[1](), y[2]());
}
- function e() returns (uint) { return 5; }
- function f() returns (uint) { return 6; }
- function g() returns (uint) { return 7; }
+ function e() public returns (uint) { return 5; }
+ function f() public returns (uint) { return 6; }
+ function g() public returns (uint) { return 7; }
uint counter;
- function h() returns (function() external returns (uint)) {
+ function h() public returns (function() external returns (uint)) {
return counter++ == 0 ? this.f : this.g;
}
- function htwo() returns (function() external returns (uint)) {
+ function htwo() public returns (function() external returns (uint)) {
return this.e;
}
}
@@ -11230,7 +11246,7 @@ BOOST_AUTO_TEST_CASE(bubble_up_error_messages_through_create)
}
contract D {
function f() public {
- var x = new E();
+ E x = new E();
}
}
contract C {
@@ -11506,8 +11522,7 @@ BOOST_AUTO_TEST_CASE(function_types_sig)
}
function h() returns (bytes4) {
function () pure external returns (bytes4) fun = this.f;
- var funvar = fun;
- return funvar.selector;
+ return fun.selector;
}
function i() pure returns (bytes4) {
return this.x.selector;
@@ -11739,8 +11754,8 @@ BOOST_AUTO_TEST_CASE(snark)
Pairing.G1Point memory p2;
p1.X = 1; p1.Y = 2;
p2.X = 1; p2.Y = 2;
- var explict_sum = Pairing.add(p1, p2);
- var scalar_prod = Pairing.mul(p1, 2);
+ Pairing.G1Point memory explict_sum = Pairing.add(p1, p2);
+ Pairing.G1Point memory scalar_prod = Pairing.mul(p1, 2);
return (explict_sum.X == scalar_prod.X &&
explict_sum.Y == scalar_prod.Y);
}