aboutsummaryrefslogtreecommitdiffstats
path: root/test/libsolidity
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
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')
-rw-r--r--test/libsolidity/GasMeter.cpp2
-rw-r--r--test/libsolidity/SolidityEndToEndTest.cpp56
-rw-r--r--test/libsolidity/SolidityNameAndTypeResolution.cpp13
3 files changed, 70 insertions, 1 deletions
diff --git a/test/libsolidity/GasMeter.cpp b/test/libsolidity/GasMeter.cpp
index 25df9e4d..9f947af3 100644
--- a/test/libsolidity/GasMeter.cpp
+++ b/test/libsolidity/GasMeter.cpp
@@ -59,7 +59,7 @@ public:
void testCreationTimeGas(string const& _sourceCode)
{
- EVMSchedule schedule;// TODO: make relevant to supposed context.
+ EVMSchedule schedule;
compileAndRun(_sourceCode);
auto state = make_shared<KnownState>();
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
diff --git a/test/libsolidity/SolidityNameAndTypeResolution.cpp b/test/libsolidity/SolidityNameAndTypeResolution.cpp
index 5f6c0535..b2e46b7d 100644
--- a/test/libsolidity/SolidityNameAndTypeResolution.cpp
+++ b/test/libsolidity/SolidityNameAndTypeResolution.cpp
@@ -3232,6 +3232,19 @@ BOOST_AUTO_TEST_CASE(int10abc_is_identifier)
BOOST_CHECK(success(text));
}
+BOOST_AUTO_TEST_CASE(library_functions_do_not_have_value)
+{
+ char const* text = R"(
+ library L { function l() {} }
+ contract test {
+ function f() {
+ L.l.value;
+ }
+ }
+ )";
+ BOOST_CHECK(!success(text));
+}
+
BOOST_AUTO_TEST_SUITE_END()
}