From 16e48219d3071038bf7f696f234b50f6370a1171 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Sun, 5 Feb 2017 22:43:36 +0000 Subject: Add test for address.transfer() --- test/libsolidity/SolidityEndToEndTest.cpp | 36 +++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'test/libsolidity') diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp index 68f8fbef..cb0cc168 100644 --- a/test/libsolidity/SolidityEndToEndTest.cpp +++ b/test/libsolidity/SolidityEndToEndTest.cpp @@ -1681,6 +1681,42 @@ BOOST_AUTO_TEST_CASE(send_ether) BOOST_CHECK_EQUAL(balanceAt(address), amount); } +BOOST_AUTO_TEST_CASE(transfer_ether) +{ + char const* sourceCode = R"( + contract A { + function A() payable {} + function a(address addr, uint amount) returns (uint) { + addr.transfer(amount); + return this.balance; + } + function b(address addr, uint amount) { + addr.transfer(amount); + } + } + + contract B { + } + + contract C { + function () payable { + throw; + } + } + )"; + compileAndRun(sourceCode, 0, "B"); + u160 const nonPayableRecipient = m_contractAddress; + compileAndRun(sourceCode, 0, "C"); + u160 const oogRecipient = m_contractAddress; + compileAndRun(sourceCode, 20, "A"); + u160 payableRecipient(23); + BOOST_CHECK(callContractFunction("a(address,uint256)", payableRecipient, 10) == encodeArgs(10)); + BOOST_CHECK_EQUAL(balanceAt(payableRecipient), 10); + BOOST_CHECK_EQUAL(balanceAt(m_contractAddress), 10); + BOOST_CHECK(callContractFunction("b(address,uint256)", nonPayableRecipient, 10) == encodeArgs()); + BOOST_CHECK(callContractFunction("b(address,uint256)", oogRecipient, 10) == encodeArgs()); +} + BOOST_AUTO_TEST_CASE(log0) { char const* sourceCode = R"( -- cgit From ba437ef31a95f40f510a475e8b329f061e929b90 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Mon, 6 Feb 2017 16:14:43 +0000 Subject: Add type checking test for address methods --- test/libsolidity/SolidityNameAndTypeResolution.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'test/libsolidity') diff --git a/test/libsolidity/SolidityNameAndTypeResolution.cpp b/test/libsolidity/SolidityNameAndTypeResolution.cpp index a1ebc300..bb274614 100644 --- a/test/libsolidity/SolidityNameAndTypeResolution.cpp +++ b/test/libsolidity/SolidityNameAndTypeResolution.cpp @@ -5108,6 +5108,24 @@ BOOST_AUTO_TEST_CASE(early_exit_on_fatal_errors) CHECK_ERROR(text, DeclarationError, "Identifier not found or not unique"); } +BOOST_AUTO_TEST_CASE(address_methods) +{ + char const* text = R"( + contract C { + function f() { + address addr; + uint balance = addr.balance; + bool callRet = addr.call(); + bool callcodeRet = addr.callcode(); + bool delegatecallRet = addr.delegatecall(); + bool sendRet = addr.send(1); + addr.transfer(1); + } + } + )"; + CHECK_SUCCESS(text); +} + BOOST_AUTO_TEST_SUITE_END() } -- cgit From 81006dae98ee18c33994af0274de10857774ff70 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Mon, 6 Feb 2017 16:54:05 +0000 Subject: Support gas modifier on addr.transfer() --- test/libsolidity/SolidityEndToEndTest.cpp | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'test/libsolidity') diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp index cb0cc168..30430aef 100644 --- a/test/libsolidity/SolidityEndToEndTest.cpp +++ b/test/libsolidity/SolidityEndToEndTest.cpp @@ -1693,6 +1693,10 @@ BOOST_AUTO_TEST_CASE(transfer_ether) function b(address addr, uint amount) { addr.transfer(amount); } + function c(address addr, uint amount, uint gas) returns (uint) { + addr.transfer.gas(gas)(amount); + return this.balance; + } } contract B { @@ -1715,6 +1719,8 @@ BOOST_AUTO_TEST_CASE(transfer_ether) BOOST_CHECK_EQUAL(balanceAt(m_contractAddress), 10); BOOST_CHECK(callContractFunction("b(address,uint256)", nonPayableRecipient, 10) == encodeArgs()); BOOST_CHECK(callContractFunction("b(address,uint256)", oogRecipient, 10) == encodeArgs()); + BOOST_CHECK(callContractFunction("c(address,uint256,uint256)", payableRecipient, 1, 9000) == encodeArgs(9)); + BOOST_CHECK(callContractFunction("c(address,uint256,uint256)", payableRecipient, 1, 0) == encodeArgs()); } BOOST_AUTO_TEST_CASE(log0) -- cgit From cde027d144643883106d8bcef034c9e8ace2b3b2 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Sun, 12 Feb 2017 14:07:52 +0000 Subject: Fix test for gas overloading in .transfer() --- test/libsolidity/SolidityEndToEndTest.cpp | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'test/libsolidity') diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp index 30430aef..f77a8935 100644 --- a/test/libsolidity/SolidityEndToEndTest.cpp +++ b/test/libsolidity/SolidityEndToEndTest.cpp @@ -1707,11 +1707,22 @@ BOOST_AUTO_TEST_CASE(transfer_ether) throw; } } + + contract D { + // This takes about ~3600 gas, which exceeds the 2300 gas stipend. + function () payable { + bytes32 tmp = 1; + for (uint i = 0; i < 20; i++) + tmp = sha3(tmp); + } + } )"; compileAndRun(sourceCode, 0, "B"); u160 const nonPayableRecipient = m_contractAddress; compileAndRun(sourceCode, 0, "C"); u160 const oogRecipient = m_contractAddress; + compileAndRun(sourceCode, 0, "D"); + u160 const expensiveRecipient = m_contractAddress; compileAndRun(sourceCode, 20, "A"); u160 payableRecipient(23); BOOST_CHECK(callContractFunction("a(address,uint256)", payableRecipient, 10) == encodeArgs(10)); @@ -1719,8 +1730,8 @@ BOOST_AUTO_TEST_CASE(transfer_ether) BOOST_CHECK_EQUAL(balanceAt(m_contractAddress), 10); BOOST_CHECK(callContractFunction("b(address,uint256)", nonPayableRecipient, 10) == encodeArgs()); BOOST_CHECK(callContractFunction("b(address,uint256)", oogRecipient, 10) == encodeArgs()); - BOOST_CHECK(callContractFunction("c(address,uint256,uint256)", payableRecipient, 1, 9000) == encodeArgs(9)); - BOOST_CHECK(callContractFunction("c(address,uint256,uint256)", payableRecipient, 1, 0) == encodeArgs()); + BOOST_CHECK(callContractFunction("c(address,uint256,uint256)", expensiveRecipient, 1, 9000) == encodeArgs(9)); + BOOST_CHECK(callContractFunction("c(address,uint256,uint256)", expensiveRecipient, 1, 0) == encodeArgs()); } BOOST_AUTO_TEST_CASE(log0) -- cgit From 4d290e551c2d563671f9d56744883d3f3dff98ec Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Fri, 24 Feb 2017 00:27:36 +0000 Subject: Disallow setting .gas() on .transfer() --- test/libsolidity/SolidityEndToEndTest.cpp | 17 ----------------- 1 file changed, 17 deletions(-) (limited to 'test/libsolidity') diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp index f77a8935..cb0cc168 100644 --- a/test/libsolidity/SolidityEndToEndTest.cpp +++ b/test/libsolidity/SolidityEndToEndTest.cpp @@ -1693,10 +1693,6 @@ BOOST_AUTO_TEST_CASE(transfer_ether) function b(address addr, uint amount) { addr.transfer(amount); } - function c(address addr, uint amount, uint gas) returns (uint) { - addr.transfer.gas(gas)(amount); - return this.balance; - } } contract B { @@ -1707,22 +1703,11 @@ BOOST_AUTO_TEST_CASE(transfer_ether) throw; } } - - contract D { - // This takes about ~3600 gas, which exceeds the 2300 gas stipend. - function () payable { - bytes32 tmp = 1; - for (uint i = 0; i < 20; i++) - tmp = sha3(tmp); - } - } )"; compileAndRun(sourceCode, 0, "B"); u160 const nonPayableRecipient = m_contractAddress; compileAndRun(sourceCode, 0, "C"); u160 const oogRecipient = m_contractAddress; - compileAndRun(sourceCode, 0, "D"); - u160 const expensiveRecipient = m_contractAddress; compileAndRun(sourceCode, 20, "A"); u160 payableRecipient(23); BOOST_CHECK(callContractFunction("a(address,uint256)", payableRecipient, 10) == encodeArgs(10)); @@ -1730,8 +1715,6 @@ BOOST_AUTO_TEST_CASE(transfer_ether) BOOST_CHECK_EQUAL(balanceAt(m_contractAddress), 10); BOOST_CHECK(callContractFunction("b(address,uint256)", nonPayableRecipient, 10) == encodeArgs()); BOOST_CHECK(callContractFunction("b(address,uint256)", oogRecipient, 10) == encodeArgs()); - BOOST_CHECK(callContractFunction("c(address,uint256,uint256)", expensiveRecipient, 1, 9000) == encodeArgs(9)); - BOOST_CHECK(callContractFunction("c(address,uint256,uint256)", expensiveRecipient, 1, 0) == encodeArgs()); } BOOST_AUTO_TEST_CASE(log0) -- cgit