aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorchriseth <c@ethdev.com>2016-09-01 02:43:24 +0800
committerchriseth <c@ethdev.com>2016-09-06 03:28:28 +0800
commit9c64edf11052f2918f10ccd202bbfda628005562 (patch)
tree55d5cd9610711cc4c035fceb89f5b6ed0881a795 /test
parent962531af96a8a3ed6b28462d43c69d78fa48d511 (diff)
downloaddexon-solidity-9c64edf11052f2918f10ccd202bbfda628005562.tar
dexon-solidity-9c64edf11052f2918f10ccd202bbfda628005562.tar.gz
dexon-solidity-9c64edf11052f2918f10ccd202bbfda628005562.tar.bz2
dexon-solidity-9c64edf11052f2918f10ccd202bbfda628005562.tar.lz
dexon-solidity-9c64edf11052f2918f10ccd202bbfda628005562.tar.xz
dexon-solidity-9c64edf11052f2918f10ccd202bbfda628005562.tar.zst
dexon-solidity-9c64edf11052f2918f10ccd202bbfda628005562.zip
Change function type to include and propagate payable and constant modifier.
Diffstat (limited to 'test')
-rw-r--r--test/libsolidity/Assembly.cpp2
-rw-r--r--test/libsolidity/SolidityEndToEndTest.cpp59
-rw-r--r--test/libsolidity/SolidityNameAndTypeResolution.cpp18
3 files changed, 45 insertions, 34 deletions
diff --git a/test/libsolidity/Assembly.cpp b/test/libsolidity/Assembly.cpp
index 81332f4f..8d7a3540 100644
--- a/test/libsolidity/Assembly.cpp
+++ b/test/libsolidity/Assembly.cpp
@@ -115,7 +115,7 @@ BOOST_AUTO_TEST_CASE(location_test)
AssemblyItems items = compileContract(sourceCode);
vector<SourceLocation> locations =
vector<SourceLocation>(18, SourceLocation(2, 75, n)) +
- vector<SourceLocation>(28, SourceLocation(20, 72, n)) +
+ vector<SourceLocation>(31, SourceLocation(20, 72, n)) +
vector<SourceLocation>{SourceLocation(42, 51, n), SourceLocation(65, 67, n)} +
vector<SourceLocation>(4, SourceLocation(58, 67, n)) +
vector<SourceLocation>(3, SourceLocation(20, 72, n));
diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp
index c1f1b148..006d41c2 100644
--- a/test/libsolidity/SolidityEndToEndTest.cpp
+++ b/test/libsolidity/SolidityEndToEndTest.cpp
@@ -1526,8 +1526,10 @@ BOOST_AUTO_TEST_CASE(convert_uint_to_fixed_bytes_greater_size)
}
})";
compileAndRun(sourceCode);
- BOOST_CHECK(callContractFunction("UintToBytes(uint16)", u256("0x6162")) ==
- encodeArgs(string("\0\0\0\0\0\0ab", 8)));
+ BOOST_CHECK(
+ callContractFunction("UintToBytes(uint16)", u256("0x6162")) ==
+ encodeArgs(string("\0\0\0\0\0\0ab", 8))
+ );
}
BOOST_AUTO_TEST_CASE(send_ether)
@@ -2053,7 +2055,7 @@ BOOST_AUTO_TEST_CASE(contracts_as_addresses)
{
char const* sourceCode = R"(
contract helper {
- function() { } // can receive ether
+ function() payable { } // can receive ether
}
contract test {
helper h;
@@ -2065,6 +2067,7 @@ BOOST_AUTO_TEST_CASE(contracts_as_addresses)
}
)";
compileAndRun(sourceCode, 20);
+ BOOST_CHECK_EQUAL(balanceAt(m_contractAddress), 20 - 5);
BOOST_REQUIRE(callContractFunction("getBalance()") == encodeArgs(u256(20 - 5), u256(5)));
}
@@ -2938,11 +2941,10 @@ BOOST_AUTO_TEST_CASE(generic_delegatecall)
uint public received;
address public sender;
uint public value;
- function sender() payable {}
function doSend(address rec) payable
{
bytes4 signature = bytes4(bytes32(sha3("receive(uint256)")));
- rec.delegatecall(signature, 23);
+ if (rec.delegatecall(signature, 23)) {}
}
}
)**";
@@ -5961,7 +5963,7 @@ BOOST_AUTO_TEST_CASE(reject_ether_sent_to_library)
function f(address x) returns (bool) {
return x.send(1);
}
- function () {}
+ function () payable {}
}
)";
compileAndRun(sourceCode, 0, "lib");
@@ -6879,7 +6881,7 @@ BOOST_AUTO_TEST_CASE(skip_dynamic_types_for_structs)
BOOST_AUTO_TEST_CASE(failed_create)
{
char const* sourceCode = R"(
- contract D { }
+ contract D { function D() payable {} }
contract C {
uint public x;
function f(uint amount) returns (address) {
@@ -7029,7 +7031,7 @@ BOOST_AUTO_TEST_CASE(mutex)
else
return fund.withdrawUnprotected(10);
}
- function() {
+ function() payable {
callDepth++;
if (callDepth < 4)
attackInternal();
@@ -7104,55 +7106,47 @@ BOOST_AUTO_TEST_CASE(payable_function)
{
char const* sourceCode = R"(
contract C {
+ uint public a;
function f() payable returns (uint) {
return msg.value;
}
- function() payable returns (uint) {
- return msg.value;
+ function() payable {
+ a = msg.value + 1;
}
}
)";
compileAndRun(sourceCode, 0, "C");
BOOST_CHECK(callContractFunctionWithValue("f()", 27) == encodeArgs(u256(27)));
- BOOST_CHECK(callContractFunctionWithValue("", 27) == encodeArgs(u256(27)));
-}
-
-BOOST_AUTO_TEST_CASE(non_payable_throw_constructor)
-{
- char const* sourceCode = R"(
- contract C {
- function C() { }
- }
- contract D {
- function D() payable {}
- function f() returns (uint) {
- (new C).value(2)();
- return 2;
- }
- }
- )";
- compileAndRun(sourceCode, 27, "D");
- BOOST_CHECK(callContractFunction("f()") == encodeArgs());
BOOST_CHECK_EQUAL(balanceAt(m_contractAddress), 27);
+ BOOST_CHECK(callContractFunctionWithValue("", 27) == encodeArgs());
+ BOOST_CHECK_EQUAL(balanceAt(m_contractAddress), 27 + 27);
+ BOOST_CHECK(callContractFunction("a()") == encodeArgs(u256(28)));
+ BOOST_CHECK_EQUAL(balanceAt(m_contractAddress), 27 + 27);
}
BOOST_AUTO_TEST_CASE(non_payable_throw)
{
char const* sourceCode = R"(
contract C {
- string public a;
+ uint public a;
function f() returns (uint) {
return msg.value;
}
- function() returns (uint) {
- return msg.value;
+ function() {
+ a = msg.value + 1;
}
}
)";
compileAndRun(sourceCode, 0, "C");
BOOST_CHECK(callContractFunctionWithValue("f()", 27) == encodeArgs());
+ BOOST_CHECK_EQUAL(balanceAt(m_contractAddress), 0);
+ BOOST_CHECK(callContractFunction("") == encodeArgs());
+ BOOST_CHECK(callContractFunction("a()") == encodeArgs(u256(1)));
BOOST_CHECK(callContractFunctionWithValue("", 27) == encodeArgs());
+ BOOST_CHECK_EQUAL(balanceAt(m_contractAddress), 0);
+ BOOST_CHECK(callContractFunction("a()") == encodeArgs(u256(1)));
BOOST_CHECK(callContractFunctionWithValue("a()", 27) == encodeArgs());
+ BOOST_CHECK_EQUAL(balanceAt(m_contractAddress), 0);
}
BOOST_AUTO_TEST_CASE(no_nonpayable_circumvention_by_modifier)
@@ -7169,6 +7163,7 @@ BOOST_AUTO_TEST_CASE(no_nonpayable_circumvention_by_modifier)
)";
compileAndRun(sourceCode);
BOOST_CHECK(callContractFunctionWithValue("f()", 27) == encodeArgs());
+ BOOST_CHECK_EQUAL(balanceAt(m_contractAddress), 0);
}
diff --git a/test/libsolidity/SolidityNameAndTypeResolution.cpp b/test/libsolidity/SolidityNameAndTypeResolution.cpp
index e193745d..3adf4612 100644
--- a/test/libsolidity/SolidityNameAndTypeResolution.cpp
+++ b/test/libsolidity/SolidityNameAndTypeResolution.cpp
@@ -3911,7 +3911,23 @@ BOOST_AUTO_TEST_CASE(calling_nonpayable)
char const* text = R"(
contract receiver { function nopay() {} }
contract test {
- function_argument_mem_to_storage f() { (new receiver()).nopay.value(10)(); }
+ function f() { (new receiver()).nopay.value(10)(); }
+ }
+ )";
+ BOOST_CHECK(expectError(text) == Error::Type::TypeError);
+}
+
+BOOST_AUTO_TEST_CASE(non_payable_constructor)
+{
+ char const* text = R"(
+ contract C {
+ function C() { }
+ }
+ contract D {
+ function f() returns (uint) {
+ (new C).value(2)();
+ return 2;
+ }
}
)";
BOOST_CHECK(expectError(text) == Error::Type::TypeError);