Dynamic copy to memory.

This commit is contained in:
Christian 2015-02-10 17:53:43 +01:00
parent 6e0ade681d
commit a5449d9b3e

View File

@ -668,7 +668,7 @@ BOOST_AUTO_TEST_CASE(mapping_state)
testSolidityAgainstCpp("getVoteCount(address)", getVoteCount, u160(0)); testSolidityAgainstCpp("getVoteCount(address)", getVoteCount, u160(0));
testSolidityAgainstCpp("getVoteCount(address)", getVoteCount, u160(1)); testSolidityAgainstCpp("getVoteCount(address)", getVoteCount, u160(1));
testSolidityAgainstCpp("getVoteCount(address)", getVoteCount, u160(2)); testSolidityAgainstCpp("getVoteCount(address)", getVoteCount, u160(2));
// voting without vote right shourd be rejected // voting without vote right should be rejected
testSolidityAgainstCpp("vote(address,address)", vote, u160(0), u160(2)); testSolidityAgainstCpp("vote(address,address)", vote, u160(0), u160(2));
testSolidityAgainstCpp("getVoteCount(address)", getVoteCount, u160(0)); testSolidityAgainstCpp("getVoteCount(address)", getVoteCount, u160(0));
testSolidityAgainstCpp("getVoteCount(address)", getVoteCount, u160(1)); testSolidityAgainstCpp("getVoteCount(address)", getVoteCount, u160(1));
@ -2276,68 +2276,66 @@ BOOST_AUTO_TEST_CASE(store_bytes)
BOOST_AUTO_TEST_CASE(call_forward_bytes) BOOST_AUTO_TEST_CASE(call_forward_bytes)
{ {
char const* sourceCode = R"( char const* sourceCode = R"(
contract C { contract receiver {
function save() { uint public received;
savedData = msg.data; function receive(uint x) { received += x + 1; }
} function() { received = 0x80; }
function forward() { }
this.call(savedData); contract sender {
} function sender() { rec = new receiver(); }
function clear() { function() { savedData = msg.data; }
delete savedData; function forward() { rec.call(savedData); }
} function clear() { delete savedData; }
function doubleIt(uint a) { val += a * 2; } function val() returns (uint) { return rec.received(); }
receiver rec;
bytes savedData; bytes savedData;
uint public val;
} }
)"; )";
compileAndRun(sourceCode); compileAndRun(sourceCode, 0, "sender");
FixedHash<4> innerHash(dev::sha3("doubleIt(uint256)")); BOOST_CHECK(callContractFunction("receive(uint256)", 7) == bytes());
BOOST_CHECK(callContractFunction("save()", innerHash.asBytes(), 7) == bytes()); BOOST_CHECK(callContractFunction("val()") == encodeArgs(0));
BOOST_CHECK(callContractFunction("val()") == bytes(0));
BOOST_CHECK(callContractFunction("forward()") == bytes()); BOOST_CHECK(callContractFunction("forward()") == bytes());
BOOST_CHECK(callContractFunction("val()") == bytes(14)); BOOST_CHECK(callContractFunction("val()") == encodeArgs(8));
BOOST_CHECK(callContractFunction("clear()") == bytes()); BOOST_CHECK(callContractFunction("clear()") == bytes());
BOOST_CHECK(callContractFunction("val()") == bytes(14)); BOOST_CHECK(callContractFunction("val()") == encodeArgs(8));
BOOST_CHECK(callContractFunction("forward()") == bytes()); BOOST_CHECK(callContractFunction("forward()") == bytes());
BOOST_CHECK(callContractFunction("val()") == bytes(14)); BOOST_CHECK(callContractFunction("val()") == encodeArgs(0x80));
} }
BOOST_AUTO_TEST_CASE(copying_bytes_multiassign) BOOST_AUTO_TEST_CASE(copying_bytes_multiassign)
{ {
char const* sourceCode = R"( char const* sourceCode = R"(
contract C { contract receiver {
function save() { uint public received;
data1 = data2 = msg.data; function receive(uint x) { received += x + 1; }
} function() { received = 0x80; }
}
contract sender {
function sender() { rec = new receiver(); }
function() { savedData1 = savedData2 = msg.data; }
function forward(bool selector) { function forward(bool selector) {
if (selector) if (selector) { rec.call(savedData1); delete savedData1; }
{ else { rec.call(savedData2); delete savedData2; }
this.call(data1);
delete data1;
}
else
{
this.call(data2);
delete data2;
}
} }
function doubleIt(uint a) returns (uint b) { val += a * 2; } function val() returns (uint) { return rec.received(); }
bytes data1; receiver rec;
bytes data2; bytes savedData1;
uint public val; bytes savedData2;
} }
)"; )";
compileAndRun(sourceCode); compileAndRun(sourceCode, 0, "sender");
FixedHash<4> innerHash(dev::sha3("doubleIt(uint256)")); BOOST_CHECK(callContractFunction("receive(uint256)", 7) == bytes());
BOOST_CHECK(callContractFunction("save()", innerHash.asBytes(), 7) == bytes()); BOOST_CHECK(callContractFunction("val()") == encodeArgs(0));
BOOST_CHECK(callContractFunction("val()") == bytes(0));
BOOST_CHECK(callContractFunction("forward(bool)", true) == bytes()); BOOST_CHECK(callContractFunction("forward(bool)", true) == bytes());
BOOST_CHECK(callContractFunction("val()") == bytes(14)); BOOST_CHECK(callContractFunction("val()") == encodeArgs(8));
BOOST_CHECK(callContractFunction("forward(bool)", false) == bytes()); BOOST_CHECK(callContractFunction("forward(bool)", false) == bytes());
BOOST_CHECK(callContractFunction("val()") == bytes(28)); BOOST_CHECK(callContractFunction("val()") == encodeArgs(16));
BOOST_CHECK(callContractFunction("forward(bool)", true) == bytes());
BOOST_CHECK(callContractFunction("val()") == encodeArgs(0x80));
} }
// TODO test that "delete" also clears the values
BOOST_AUTO_TEST_SUITE_END() BOOST_AUTO_TEST_SUITE_END()
} }