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.cpp87
1 files changed, 77 insertions, 10 deletions
diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp
index 3a4a2dad..42f69099 100644
--- a/test/libsolidity/SolidityEndToEndTest.cpp
+++ b/test/libsolidity/SolidityEndToEndTest.cpp
@@ -2105,7 +2105,7 @@ BOOST_AUTO_TEST_CASE(packed_keccak256_complex_types)
char const* sourceCode = R"(
contract test {
uint120[3] x;
- function f() view returns (bytes32 hash1, bytes32 hash2, bytes32 hash3) {
+ function f() returns (bytes32 hash1, bytes32 hash2, bytes32 hash3) {
uint120[] memory y = new uint120[](3);
x[0] = y[0] = uint120(-2);
x[1] = y[1] = uint120(-3);
@@ -7610,6 +7610,33 @@ BOOST_AUTO_TEST_CASE(multi_variable_declaration)
ABI_CHECK(callContractFunction("f()", encodeArgs()), encodeArgs(true));
}
+BOOST_AUTO_TEST_CASE(typed_multi_variable_declaration)
+{
+ char const* sourceCode = R"(
+ contract C {
+ struct S { uint x; }
+ S s;
+ function g() internal returns (uint, S storage, uint) {
+ s.x = 7;
+ return (1, s, 2);
+ }
+ function f() returns (bool) {
+ (uint x1, S storage y1, uint z1) = g();
+ if (x1 != 1 || y1.x != 7 || z1 != 2) return false;
+ (, S storage y2,) = g();
+ if (y2.x != 7) return false;
+ (uint x2,,) = g();
+ if (x2 != 1) return false;
+ (,,uint z2) = g();
+ if (z2 != 2) return false;
+ return true;
+ }
+ }
+ )";
+ compileAndRun(sourceCode);
+ ABI_CHECK(callContractFunction("f()", encodeArgs()), encodeArgs(true));
+}
+
BOOST_AUTO_TEST_CASE(tuples)
{
char const* sourceCode = R"(
@@ -10660,12 +10687,24 @@ BOOST_AUTO_TEST_CASE(revert_with_cause)
{
char const* sourceCode = R"(
contract D {
+ string constant msg1 = "test1234567890123456789012345678901234567890";
+ string msg2 = "test1234567890123456789012345678901234567890";
function f() public {
revert("test123");
}
function g() public {
revert("test1234567890123456789012345678901234567890");
}
+ function h() public {
+ revert(msg1);
+ }
+ function i() public {
+ revert(msg2);
+ }
+ function j() public {
+ string memory msg3 = "test1234567890123456789012345678901234567890";
+ revert(msg3);
+ }
}
contract C {
D d = new D();
@@ -10686,6 +10725,15 @@ BOOST_AUTO_TEST_CASE(revert_with_cause)
function g() public returns (bool, bytes) {
return forward(address(d), msg.data);
}
+ function h() public returns (bool, bytes) {
+ return forward(address(d), msg.data);
+ }
+ function i() public returns (bool, bytes) {
+ return forward(address(d), msg.data);
+ }
+ function j() public returns (bool, bytes) {
+ return forward(address(d), msg.data);
+ }
}
)";
compileAndRun(sourceCode, 0, "C");
@@ -10693,6 +10741,9 @@ BOOST_AUTO_TEST_CASE(revert_with_cause)
bytes const errorSignature = bytes{0x08, 0xc3, 0x79, 0xa0};
ABI_CHECK(callContractFunction("f()"), haveReturndata ? encodeArgs(0, 0x40, 0x64) + errorSignature + encodeArgs(0x20, 7, "test123") + bytes(28, 0) : bytes());
ABI_CHECK(callContractFunction("g()"), haveReturndata ? encodeArgs(0, 0x40, 0x84) + errorSignature + encodeArgs(0x20, 44, "test1234567890123456789012345678901234567890") + bytes(28, 0): bytes());
+ ABI_CHECK(callContractFunction("h()"), haveReturndata ? encodeArgs(0, 0x40, 0x84) + errorSignature + encodeArgs(0x20, 44, "test1234567890123456789012345678901234567890") + bytes(28, 0): bytes());
+ ABI_CHECK(callContractFunction("i()"), haveReturndata ? encodeArgs(0, 0x40, 0x84) + errorSignature + encodeArgs(0x20, 44, "test1234567890123456789012345678901234567890") + bytes(28, 0): bytes());
+ ABI_CHECK(callContractFunction("j()"), haveReturndata ? encodeArgs(0, 0x40, 0x84) + errorSignature + encodeArgs(0x20, 44, "test1234567890123456789012345678901234567890") + bytes(28, 0): bytes());
}
BOOST_AUTO_TEST_CASE(require_with_message)
@@ -10701,6 +10752,7 @@ BOOST_AUTO_TEST_CASE(require_with_message)
contract D {
bool flag = false;
string storageError = "abc";
+ string constant constantError = "abc";
function f(uint x) public {
require(x > 7, "failed");
}
@@ -10718,6 +10770,13 @@ BOOST_AUTO_TEST_CASE(require_with_message)
function h() public {
require(false, storageError);
}
+ function i() public {
+ require(false, constantError);
+ }
+ function j() public {
+ string memory errMsg = "msg";
+ require(false, errMsg);
+ }
}
contract C {
D d = new D();
@@ -10741,6 +10800,12 @@ BOOST_AUTO_TEST_CASE(require_with_message)
function h() public returns (bool, bytes) {
return forward(address(d), msg.data);
}
+ function i() public returns (bool, bytes) {
+ return forward(address(d), msg.data);
+ }
+ function j() public returns (bool, bytes) {
+ return forward(address(d), msg.data);
+ }
}
)";
compileAndRun(sourceCode, 0, "C");
@@ -10751,6 +10816,8 @@ BOOST_AUTO_TEST_CASE(require_with_message)
ABI_CHECK(callContractFunction("g()"), haveReturndata ? encodeArgs(1, 0x40, 0) : bytes());
ABI_CHECK(callContractFunction("g()"), haveReturndata ? encodeArgs(0, 0x40, 0x64) + errorSignature + encodeArgs(0x20, 18, "only on second run") + bytes(28, 0) : bytes());
ABI_CHECK(callContractFunction("h()"), haveReturndata ? encodeArgs(0, 0x40, 0x64) + errorSignature + encodeArgs(0x20, 3, "abc") + bytes(28, 0): bytes());
+ ABI_CHECK(callContractFunction("i()"), haveReturndata ? encodeArgs(0, 0x40, 0x64) + errorSignature + encodeArgs(0x20, 3, "abc") + bytes(28, 0): bytes());
+ ABI_CHECK(callContractFunction("j()"), haveReturndata ? encodeArgs(0, 0x40, 0x64) + errorSignature + encodeArgs(0x20, 3, "msg") + bytes(28, 0): bytes());
}
BOOST_AUTO_TEST_CASE(bubble_up_error_messages)
@@ -10877,9 +10944,9 @@ BOOST_AUTO_TEST_CASE(negative_stack_height)
bool Aboolc;
bool exists;
}
- function nredit(uint startindex) public constant returns(uint[500] CIDs, uint[500] dates, uint[500] RIDs, bool[500] Cboolas, uint[500] amounts){}
- function return500InvoicesByDates(uint begindate, uint enddate, uint startindex) public constant returns(uint[500] AIDs, bool[500] Aboolas, uint[500] dates, bytes32[3][500] Abytesas, bytes32[3][500] bytesbs, bytes32[2][500] bytescs, uint[500] amounts, bool[500] Aboolbs, bool[500] Aboolcs){}
- function return500PaymentsByDates(uint begindate, uint enddate, uint startindex) public constant returns(uint[500] BIDs, uint[500] dates, uint[500] RIDs, bool[500] Bboolas, bytes32[3][500] bytesbs,bytes32[2][500] bytescs, uint[500] amounts, bool[500] Bboolbs){}
+ function nredit(uint startindex) public pure returns(uint[500] CIDs, uint[500] dates, uint[500] RIDs, bool[500] Cboolas, uint[500] amounts){}
+ function return500InvoicesByDates(uint begindate, uint enddate, uint startindex) public view returns(uint[500] AIDs, bool[500] Aboolas, uint[500] dates, bytes32[3][500] Abytesas, bytes32[3][500] bytesbs, bytes32[2][500] bytescs, uint[500] amounts, bool[500] Aboolbs, bool[500] Aboolcs){}
+ function return500PaymentsByDates(uint begindate, uint enddate, uint startindex) public view returns(uint[500] BIDs, uint[500] dates, uint[500] RIDs, bool[500] Bboolas, bytes32[3][500] bytesbs,bytes32[2][500] bytescs, uint[500] amounts, bool[500] Bboolbs){}
}
)";
compileAndRun(sourceCode, 0, "C");
@@ -11065,13 +11132,13 @@ BOOST_AUTO_TEST_CASE(bare_call_invalid_address)
char const* sourceCode = R"(
contract C {
/// Calling into non-existant account is successful (creates the account)
- function f() external view returns (bool) {
+ function f() external returns (bool) {
return address(0x4242).call();
}
- function g() external view returns (bool) {
+ function g() external returns (bool) {
return address(0x4242).callcode();
}
- function h() external view returns (bool) {
+ function h() external returns (bool) {
return address(0x4242).delegatecall();
}
}
@@ -11093,13 +11160,13 @@ BOOST_AUTO_TEST_CASE(delegatecall_return_value)
function get() external view returns (uint) {
return value;
}
- function get_delegated() external view returns (bool) {
+ function get_delegated() external returns (bool) {
return this.delegatecall(bytes4(sha3("get()")));
}
function assert0() external view {
assert(value == 0);
}
- function assert0_delegated() external view returns (bool) {
+ function assert0_delegated() external returns (bool) {
return this.delegatecall(bytes4(sha3("assert0()")));
}
}
@@ -11560,7 +11627,7 @@ BOOST_AUTO_TEST_CASE(abi_encode_v2)
require(y[0] == "e");
}
S s;
- function f4() public view returns (bytes r) {
+ function f4() public returns (bytes r) {
string memory x = "abc";
s.a = 7;
s.b.push(2);