diff options
author | Alex Beregszaszi <alex@rtfs.hu> | 2016-08-27 02:37:10 +0800 |
---|---|---|
committer | chriseth <c@ethdev.com> | 2016-09-06 03:28:28 +0800 |
commit | 962531af96a8a3ed6b28462d43c69d78fa48d511 (patch) | |
tree | 596929bcbcc12d93597067057edb3311de88af5a /test/libsolidity/SolidityEndToEndTest.cpp | |
parent | 680b83b2a44a8f943d6d78028ad4326f4b3b64c2 (diff) | |
download | dexon-solidity-962531af96a8a3ed6b28462d43c69d78fa48d511.tar.gz dexon-solidity-962531af96a8a3ed6b28462d43c69d78fa48d511.tar.zst dexon-solidity-962531af96a8a3ed6b28462d43c69d78fa48d511.zip |
Merged in changes from chriseth/payable
Diffstat (limited to 'test/libsolidity/SolidityEndToEndTest.cpp')
-rw-r--r-- | test/libsolidity/SolidityEndToEndTest.cpp | 49 |
1 files changed, 37 insertions, 12 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() } |