aboutsummaryrefslogtreecommitdiffstats
path: root/libsolidity
diff options
context:
space:
mode:
authorchriseth <c@ethdev.com>2015-06-10 21:36:30 +0800
committerchriseth <c@ethdev.com>2015-06-10 21:36:30 +0800
commitbcecae082219abb99157aca5afe9440fac20b516 (patch)
tree8adb81f80ff0099c836618cfd200df0a3f2bd48d /libsolidity
parent02379492122d420d454bb8e7e3825515b882101e (diff)
parent31fb199acbd9ae8d9d7e5183ce3debd594158837 (diff)
downloaddexon-solidity-bcecae082219abb99157aca5afe9440fac20b516.tar.gz
dexon-solidity-bcecae082219abb99157aca5afe9440fac20b516.tar.zst
dexon-solidity-bcecae082219abb99157aca5afe9440fac20b516.zip
Merge pull request #2122 from chriseth/sol_memoryArrays2
Use dynamic memory.
Diffstat (limited to 'libsolidity')
-rw-r--r--libsolidity/SolidityEndToEndTest.cpp51
-rw-r--r--libsolidity/SolidityNameAndTypeResolution.cpp10
2 files changed, 49 insertions, 12 deletions
diff --git a/libsolidity/SolidityEndToEndTest.cpp b/libsolidity/SolidityEndToEndTest.cpp
index fdd865e7..f12abd48 100644
--- a/libsolidity/SolidityEndToEndTest.cpp
+++ b/libsolidity/SolidityEndToEndTest.cpp
@@ -2396,7 +2396,7 @@ BOOST_AUTO_TEST_CASE(event_really_lots_of_data)
callContractFunction("deposit()");
BOOST_REQUIRE_EQUAL(m_logs.size(), 1);
BOOST_CHECK_EQUAL(m_logs[0].address, m_contractAddress);
- BOOST_CHECK(m_logs[0].data == encodeArgs(10, 4, 15) + FixedHash<4>(dev::sha3("deposit()")).asBytes());
+ BOOST_CHECK(m_logs[0].data == encodeArgs(10, 0x60, 15, 4) + FixedHash<4>(dev::sha3("deposit()")).asBytes());
BOOST_REQUIRE_EQUAL(m_logs[0].topics.size(), 1);
BOOST_CHECK_EQUAL(m_logs[0].topics[0], dev::sha3(string("Deposit(uint256,bytes,uint256)")));
}
@@ -2420,7 +2420,7 @@ BOOST_AUTO_TEST_CASE(event_really_lots_of_data_from_storage)
callContractFunction("deposit()");
BOOST_REQUIRE_EQUAL(m_logs.size(), 1);
BOOST_CHECK_EQUAL(m_logs[0].address, m_contractAddress);
- BOOST_CHECK(m_logs[0].data == encodeArgs(10, 3, 15) + asBytes("ABC"));
+ BOOST_CHECK(m_logs[0].data == encodeArgs(10, 0x60, 15, 3) + asBytes("ABC"));
BOOST_REQUIRE_EQUAL(m_logs[0].topics.size(), 1);
BOOST_CHECK_EQUAL(m_logs[0].topics[0], dev::sha3(string("Deposit(uint256,bytes,uint256)")));
}
@@ -2531,6 +2531,27 @@ BOOST_AUTO_TEST_CASE(sha3_with_bytes)
BOOST_CHECK(callContractFunction("foo()") == encodeArgs(true));
}
+BOOST_AUTO_TEST_CASE(iterated_sha3_with_bytes)
+{
+ char const* sourceCode = R"(
+ contract c {
+ bytes data;
+ function foo() returns (bytes32)
+ {
+ data.length = 3;
+ data[0] = "x";
+ data[1] = "y";
+ data[2] = "z";
+ return sha3("b", sha3(data), "a");
+ }
+ }
+ )";
+ compileAndRun(sourceCode);
+ BOOST_CHECK(callContractFunction("foo()") == encodeArgs(
+ u256(dev::sha3(bytes{'b'} + dev::sha3("xyz").asBytes() + bytes{'a'}))
+ ));
+}
+
BOOST_AUTO_TEST_CASE(generic_call)
{
char const* sourceCode = R"**(
@@ -4185,6 +4206,32 @@ BOOST_AUTO_TEST_CASE(failing_send)
BOOST_REQUIRE(callContractFunction("callHelper(address)", c_helperAddress) == encodeArgs(true, 20));
}
+BOOST_AUTO_TEST_CASE(reusing_memory)
+{
+ // Invoke some features that use memory and test that they do not interfere with each other.
+ char const* sourceCode = R"(
+ contract Helper {
+ uint public flag;
+ function Helper(uint x) {
+ flag = x;
+ }
+ }
+ contract Main {
+ mapping(uint => uint) map;
+ function f(uint x) returns (uint) {
+ map[x] = x;
+ return (new Helper(uint(sha3(this.g(map[x]))))).flag();
+ }
+ function g(uint a) returns (uint)
+ {
+ return map[a];
+ }
+ }
+ )";
+ compileAndRun(sourceCode, 0, "Main");
+ BOOST_REQUIRE(callContractFunction("f(uint256)", 0x34) == encodeArgs(dev::sha3(dev::toBigEndian(u256(0x34)))));
+}
+
BOOST_AUTO_TEST_SUITE_END()
}
diff --git a/libsolidity/SolidityNameAndTypeResolution.cpp b/libsolidity/SolidityNameAndTypeResolution.cpp
index b078fe6a..3948a4a2 100644
--- a/libsolidity/SolidityNameAndTypeResolution.cpp
+++ b/libsolidity/SolidityNameAndTypeResolution.cpp
@@ -558,16 +558,6 @@ BOOST_AUTO_TEST_CASE(function_external_call_not_allowed_conversion)
BOOST_CHECK_THROW(parseTextAndResolveNames(text), TypeError);
}
-// todo delete when implemented
-BOOST_AUTO_TEST_CASE(arrays_in_internal_functions)
-{
- char const* text = R"(
- contract Test {
- function foo(address[] addresses) {}
- })";
- BOOST_CHECK_THROW(parseTextAndResolveNames(text), TypeError);
-}
-
BOOST_AUTO_TEST_CASE(function_internal_allowed_conversion)
{
char const* text = R"(