Fix for copying arrays to storage.

This commit is contained in:
chriseth 2015-06-30 21:03:23 +02:00
parent fc8f83b84e
commit 3350f1d304

View File

@ -4879,7 +4879,7 @@ BOOST_AUTO_TEST_CASE(memory_structs_as_function_args)
BOOST_CHECK(callContractFunction("test()") == encodeArgs(u256(1), u256(2), u256(3))); BOOST_CHECK(callContractFunction("test()") == encodeArgs(u256(1), u256(2), u256(3)));
} }
BOOST_AUTO_TEST_CASE(memory_structs_wrapped) BOOST_AUTO_TEST_CASE(memory_structs_nested)
{ {
char const* sourceCode = R"( char const* sourceCode = R"(
contract Test { contract Test {
@ -4911,42 +4911,51 @@ BOOST_AUTO_TEST_CASE(memory_structs_wrapped)
BOOST_CHECK(callContractFunction("test()") == encodeArgs(u256(1), u256(2), u256(3), u256(4))); BOOST_CHECK(callContractFunction("test()") == encodeArgs(u256(1), u256(2), u256(3), u256(4)));
} }
BOOST_AUTO_TEST_CASE(memory_structs_wrapped_load) BOOST_AUTO_TEST_CASE(memory_structs_nested_load)
{ {
char const* sourceCode = R"( char const* sourceCode = R"(
contract Test { contract Test {
struct S { uint8 x; uint16 y; uint z; } struct S { uint8 x; uint16 y; uint z; }
struct X { uint8 x; S s; } struct X { uint8 x; S s; uint8[2] a; }
X m_x; X m_x;
function load() returns (uint a, uint x, uint y, uint z) { function load() returns (uint a, uint x, uint y, uint z, uint a1, uint a2) {
m_x.x = 1; m_x.x = 1;
m_x.s.x = 2; m_x.s.x = 2;
m_x.s.y = 3; m_x.s.y = 3;
m_x.s.z = 4; m_x.s.z = 4;
m_x.a[0] = 5;
m_x.a[1] = 6;
X memory d = m_x; X memory d = m_x;
a = d.x; a = d.x;
x = d.s.x; x = d.s.x;
y = d.s.y; y = d.s.y;
z = d.s.z; z = d.s.z;
a1 = d.a[0];
a2 = d.a[1];
} }
function store() returns (uint a, uint x, uint y, uint z) { function store() returns (uint a, uint x, uint y, uint z, uint a1, uint a2) {
X memory d = m_x; X memory d;
d.x = 1; d.x = 1;
d.s.x = 2; d.s.x = 2;
d.s.y = 3; d.s.y = 3;
d.s.z = 4; d.s.z = 4;
d.a[0] = 5;
d.a[1] = 6;
m_x = d; m_x = d;
a = m_x.x; a = m_x.x;
x = m_x.s.x; x = m_x.s.x;
y = m_x.s.y; y = m_x.s.y;
z = m_x.s.z; z = m_x.s.z;
a1 = m_x.a[0];
a2 = m_x.a[1];
} }
} }
)"; )";
compileAndRun(sourceCode, 0, "Test"); compileAndRun(sourceCode, 0, "Test");
BOOST_CHECK(callContractFunction("load()") == encodeArgs(u256(1), u256(2), u256(3), u256(4))); auto out = encodeArgs(u256(1), u256(2), u256(3), u256(4), u256(5), u256(6));
BOOST_CHECK(callContractFunction("store()") == encodeArgs(u256(1), u256(2), u256(3), u256(4))); BOOST_CHECK(callContractFunction("load()") == out);
BOOST_CHECK(callContractFunction("store()") == out);
} }
BOOST_AUTO_TEST_SUITE_END() BOOST_AUTO_TEST_SUITE_END()