aboutsummaryrefslogtreecommitdiffstats
path: root/test/libsolidity/SolidityEndToEndTest.cpp
diff options
context:
space:
mode:
authorchriseth <c@ethdev.com>2016-03-07 23:55:53 +0800
committerchriseth <c@ethdev.com>2016-03-12 00:49:32 +0800
commite5514becb89c945f59fd440696d0bb3122edbe99 (patch)
tree6358ae151c50802b3cb0c158f7b8b06c53669fd4 /test/libsolidity/SolidityEndToEndTest.cpp
parent60a21c6487743578af6fd4e1540a36a2b80fcac7 (diff)
downloaddexon-solidity-e5514becb89c945f59fd440696d0bb3122edbe99.tar.gz
dexon-solidity-e5514becb89c945f59fd440696d0bb3122edbe99.tar.zst
dexon-solidity-e5514becb89c945f59fd440696d0bb3122edbe99.zip
BREAKING: Implement delegatecall and make default for library calls.
Diffstat (limited to 'test/libsolidity/SolidityEndToEndTest.cpp')
-rw-r--r--test/libsolidity/SolidityEndToEndTest.cpp56
1 files changed, 56 insertions, 0 deletions
diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp
index b54393e4..388f5a69 100644
--- a/test/libsolidity/SolidityEndToEndTest.cpp
+++ b/test/libsolidity/SolidityEndToEndTest.cpp
@@ -2890,6 +2890,62 @@ BOOST_AUTO_TEST_CASE(generic_callcode)
BOOST_CHECK_EQUAL(m_state.balance(c_senderAddress), 50);
}
+BOOST_AUTO_TEST_CASE(generic_delegatecall)
+{
+ char const* sourceCode = R"**(
+ contract receiver {
+ uint public received;
+ address public sender;
+ uint public value;
+ function receive(uint256 x) { received = x; sender = msg.sender; value = msg.value; }
+ }
+ contract sender {
+ uint public received;
+ address public sender;
+ uint public value;
+ function doSend(address rec)
+ {
+ bytes4 signature = bytes4(bytes32(sha3("receive(uint256)")));
+ rec.delegatecall(signature, 23);
+ }
+ }
+ )**";
+ compileAndRun(sourceCode, 0, "receiver");
+ u160 const c_receiverAddress = m_contractAddress;
+ compileAndRun(sourceCode, 50, "sender");
+ u160 const c_senderAddress = m_contractAddress;
+ BOOST_CHECK(m_sender != c_senderAddress); // just for sanity
+ BOOST_CHECK(callContractFunctionWithValue("doSend(address)", 11, c_receiverAddress) == encodeArgs());
+ BOOST_CHECK(callContractFunction("received()") == encodeArgs(u256(23)));
+ BOOST_CHECK(callContractFunction("sender()") == encodeArgs(u160(m_sender)));
+ BOOST_CHECK(callContractFunction("value()") == encodeArgs(u256(11)));
+ m_contractAddress = c_receiverAddress;
+ BOOST_CHECK(callContractFunction("received()") == encodeArgs(u256(0)));
+ BOOST_CHECK(callContractFunction("sender()") == encodeArgs(u256(0)));
+ BOOST_CHECK(callContractFunction("value()") == encodeArgs(u256(0)));
+ BOOST_CHECK(m_state.storage(c_receiverAddress).empty());
+ BOOST_CHECK(!m_state.storage(c_senderAddress).empty());
+ BOOST_CHECK_EQUAL(m_state.balance(c_receiverAddress), 0);
+ BOOST_CHECK_EQUAL(m_state.balance(c_senderAddress), 50 + 11);
+}
+
+BOOST_AUTO_TEST_CASE(library_call_in_homestead)
+{
+ char const* sourceCode = R"(
+ library Lib { function m() returns (address) { return msg.sender; } }
+ contract Test {
+ address public sender;
+ function f() {
+ sender = Lib.m();
+ }
+ }
+ )";
+ compileAndRun(sourceCode, 0, "Lib");
+ compileAndRun(sourceCode, 0, "Test", bytes(), map<string, Address>{{"Lib", m_contractAddress}});
+ BOOST_CHECK(callContractFunction("f()") == encodeArgs());
+ BOOST_CHECK(callContractFunction("sender()") == encodeArgs(u160(m_sender)));
+}
+
BOOST_AUTO_TEST_CASE(store_bytes)
{
// this test just checks that the copy loop does not mess up the stack