aboutsummaryrefslogtreecommitdiffstats
path: root/test/libsolidity
diff options
context:
space:
mode:
authorAlex Beregszaszi <alex@rtfs.hu>2016-08-27 02:37:10 +0800
committerchriseth <c@ethdev.com>2016-09-06 03:28:28 +0800
commit962531af96a8a3ed6b28462d43c69d78fa48d511 (patch)
tree596929bcbcc12d93597067057edb3311de88af5a /test/libsolidity
parent680b83b2a44a8f943d6d78028ad4326f4b3b64c2 (diff)
downloaddexon-solidity-962531af96a8a3ed6b28462d43c69d78fa48d511.tar.gz
dexon-solidity-962531af96a8a3ed6b28462d43c69d78fa48d511.tar.zst
dexon-solidity-962531af96a8a3ed6b28462d43c69d78fa48d511.zip
Merged in changes from chriseth/payable
Diffstat (limited to 'test/libsolidity')
-rw-r--r--test/libsolidity/SolidityEndToEndTest.cpp49
-rw-r--r--test/libsolidity/SolidityNameAndTypeResolution.cpp64
-rw-r--r--test/libsolidity/SolidityParser.cpp10
3 files changed, 110 insertions, 13 deletions
diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp
index 65f81dea..c1f1b148 100644
--- a/test/libsolidity/SolidityEndToEndTest.cpp
+++ b/test/libsolidity/SolidityEndToEndTest.cpp
@@ -2085,11 +2085,11 @@ BOOST_AUTO_TEST_CASE(gas_and_value_basic)
function sendAmount(uint amount) payable returns (uint256 bal) {
return h.getBalance.value(amount)();
}
- function outOfGas() payable returns (bool ret) {
+ function outOfGas() returns (bool ret) {
h.setFlag.gas(2)(); // should fail due to OOG
return true;
}
- function checkState() payable returns (bool flagAfter, uint myBal) {
+ function checkState() returns (bool flagAfter, uint myBal) {
flagAfter = h.getFlag();
myBal = this.balance;
}
@@ -2098,15 +2098,15 @@ BOOST_AUTO_TEST_CASE(gas_and_value_basic)
compileAndRun(sourceCode, 20);
BOOST_REQUIRE(callContractFunction("sendAmount(uint256)", 5) == encodeArgs(5));
// call to helper should not succeed but amount should be transferred anyway
- BOOST_REQUIRE(callContractFunction("outOfGas()", 5) == bytes());
- BOOST_REQUIRE(callContractFunction("checkState()", 5) == encodeArgs(false, 20 - 5));
+ BOOST_REQUIRE(callContractFunction("outOfGas()") == bytes());
+ BOOST_REQUIRE(callContractFunction("checkState()") == encodeArgs(false, 20 - 5));
}
BOOST_AUTO_TEST_CASE(gas_for_builtin)
{
char const* sourceCode = R"(
contract Contract {
- function test(uint g) payable returns (bytes32 data, bool flag) {
+ function test(uint g) returns (bytes32 data, bool flag) {
data = ripemd160.gas(g)("abc");
flag = true;
}
@@ -2151,7 +2151,7 @@ BOOST_AUTO_TEST_CASE(value_insane)
contract test {
helper h;
function test() payable { h = new helper(); }
- function sendAmount(uint amount) payable returns (uint256 bal) {
+ function sendAmount(uint amount) returns (uint256 bal) {
var x1 = h.getBalance.value;
var x2 = x1(amount).gas;
var x3 = x2(1000).value;
@@ -7090,18 +7090,17 @@ BOOST_AUTO_TEST_CASE(calling_nonexisting_contract_throws)
BOOST_CHECK(callContractFunction("h()") == encodeArgs(u256(7)));
}
-BOOST_AUTO_TEST_CASE(payable_accept_explicit_constructor)
+BOOST_AUTO_TEST_CASE(payable_constructor)
{
char const* sourceCode = R"(
contract C {
- function () payable { }
+ function C() payable { }
}
)";
compileAndRun(sourceCode, 27, "C");
}
-
-BOOST_AUTO_TEST_CASE(payable_accept_explicit)
+BOOST_AUTO_TEST_CASE(payable_function)
{
char const* sourceCode = R"(
contract C {
@@ -7122,10 +7121,19 @@ BOOST_AUTO_TEST_CASE(non_payable_throw_constructor)
{
char const* sourceCode = R"(
contract C {
- function() { }
+ function C() { }
+ }
+ contract D {
+ function D() payable {}
+ function f() returns (uint) {
+ (new C).value(2)();
+ return 2;
+ }
}
)";
- compileAndRun(sourceCode, 27, "C");
+ compileAndRun(sourceCode, 27, "D");
+ BOOST_CHECK(callContractFunction("f()") == encodeArgs());
+ BOOST_CHECK_EQUAL(balanceAt(m_contractAddress), 27);
}
BOOST_AUTO_TEST_CASE(non_payable_throw)
@@ -7147,6 +7155,23 @@ BOOST_AUTO_TEST_CASE(non_payable_throw)
BOOST_CHECK(callContractFunctionWithValue("a()", 27) == encodeArgs());
}
+BOOST_AUTO_TEST_CASE(no_nonpayable_circumvention_by_modifier)
+{
+ char const* sourceCode = R"(
+ contract C {
+ modifier tryCircumvent {
+ if (false) _ // avoid the function, we should still not accept ether
+ }
+ function f() tryCircumvent returns (uint) {
+ return msg.value;
+ }
+ }
+ )";
+ compileAndRun(sourceCode);
+ BOOST_CHECK(callContractFunctionWithValue("f()", 27) == encodeArgs());
+}
+
+
BOOST_AUTO_TEST_SUITE_END()
}
diff --git a/test/libsolidity/SolidityNameAndTypeResolution.cpp b/test/libsolidity/SolidityNameAndTypeResolution.cpp
index 8d4890d1..e193745d 100644
--- a/test/libsolidity/SolidityNameAndTypeResolution.cpp
+++ b/test/libsolidity/SolidityNameAndTypeResolution.cpp
@@ -3852,7 +3852,69 @@ BOOST_AUTO_TEST_CASE(modifier_without_underscore)
modifier m() {}
}
)";
- BOOST_CHECK(expectError(text, true) == Error::Type::SyntaxError);
+ BOOST_CHECK(expectError(text) == Error::Type::SyntaxError);
+}
+
+BOOST_AUTO_TEST_CASE(payable_in_library)
+{
+ char const* text = R"(
+ library test {
+ function f() payable {}
+ }
+ )";
+ BOOST_CHECK(expectError(text) == Error::Type::TypeError);
+}
+
+BOOST_AUTO_TEST_CASE(payable_internal)
+{
+ char const* text = R"(
+ contract test {
+ function f() payable internal {}
+ }
+ )";
+ BOOST_CHECK(expectError(text) == Error::Type::TypeError);
+}
+
+BOOST_AUTO_TEST_CASE(illegal_override_payable)
+{
+ char const* text = R"(
+ contract B { function f() payable {} }
+ contract C is B { function f() {} }
+ )";
+ BOOST_CHECK(expectError(text) == Error::Type::TypeError);
+}
+
+BOOST_AUTO_TEST_CASE(illegal_override_payable_nonpayable)
+{
+ char const* text = R"(
+ contract B { function f() {} }
+ contract C is B { function f() payable {} }
+ )";
+ BOOST_CHECK(expectError(text) == Error::Type::TypeError);
+}
+
+BOOST_AUTO_TEST_CASE(calling_payable)
+{
+ char const* text = R"(
+ contract receiver { function pay() payable {} }
+ contract test {
+ funciton f() { (new receiver()).pay.value(10)(); }
+ recevier r = new receiver();
+ function g() { r.pay.value(10)(); }
+ }
+ )";
+ BOOST_CHECK(success(text));
+}
+
+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)(); }
+ }
+ )";
+ BOOST_CHECK(expectError(text) == Error::Type::TypeError);
}
BOOST_AUTO_TEST_CASE(warn_nonpresent_pragma)
diff --git a/test/libsolidity/SolidityParser.cpp b/test/libsolidity/SolidityParser.cpp
index 0c0e343b..a81a9828 100644
--- a/test/libsolidity/SolidityParser.cpp
+++ b/test/libsolidity/SolidityParser.cpp
@@ -1231,6 +1231,16 @@ BOOST_AUTO_TEST_CASE(invalid_fixed_conversion_leading_zeroes_check)
BOOST_CHECK(!successParse(text));
}
+BOOST_AUTO_TEST_CASE(payable_accessor)
+{
+ char const* text = R"(
+ contract test {
+ uint payable x;
+ }
+ )";
+ BOOST_CHECK(!successParse(text));
+}
+
BOOST_AUTO_TEST_SUITE_END()
}