mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Merge remote-tracking branch 'upstream/develop' into blockTests
This commit is contained in:
commit
6d5d7b5124
@ -2424,6 +2424,66 @@ BOOST_AUTO_TEST_CASE(bytes_length_member)
|
||||
BOOST_CHECK(callContractFunction("getLength()") == encodeArgs(4+32+32));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(struct_copy)
|
||||
{
|
||||
char const* sourceCode = R"(
|
||||
contract c {
|
||||
struct Nested { uint x; uint y; }
|
||||
struct Struct { uint a; mapping(uint => Struct) b; Nested nested; uint c; }
|
||||
mapping(uint => Struct) public data;
|
||||
function set(uint k) returns (bool) {
|
||||
data[k].a = 1;
|
||||
data[k].nested.x = 3;
|
||||
data[k].nested.y = 4;
|
||||
data[k].c = 2;
|
||||
return true;
|
||||
}
|
||||
function copy(uint from, uint to) returns (bool) {
|
||||
data[to] = data[from];
|
||||
return true;
|
||||
}
|
||||
function retrieve(uint k) returns (uint a, uint x, uint y, uint c)
|
||||
{
|
||||
a = data[k].a;
|
||||
x = data[k].nested.x;
|
||||
y = data[k].nested.y;
|
||||
c = data[k].c;
|
||||
}
|
||||
}
|
||||
)";
|
||||
compileAndRun(sourceCode);
|
||||
BOOST_CHECK(callContractFunction("set(uint256)", 7) == encodeArgs(true));
|
||||
BOOST_CHECK(callContractFunction("retrieve(uint256)", 7) == encodeArgs(1, 3, 4, 2));
|
||||
BOOST_CHECK(callContractFunction("copy(uint256,uint256)", 7, 8) == encodeArgs(true));
|
||||
BOOST_CHECK(callContractFunction("retrieve(uint256)", 7) == encodeArgs(1, 3, 4, 2));
|
||||
BOOST_CHECK(callContractFunction("retrieve(uint256)", 8) == encodeArgs(1, 3, 4, 2));
|
||||
BOOST_CHECK(callContractFunction("copy(uint256,uint256)", 0, 7) == encodeArgs(true));
|
||||
BOOST_CHECK(callContractFunction("retrieve(uint256)", 7) == encodeArgs(0, 0, 0, 0));
|
||||
BOOST_CHECK(callContractFunction("retrieve(uint256)", 8) == encodeArgs(1, 3, 4, 2));
|
||||
BOOST_CHECK(callContractFunction("copy(uint256,uint256)", 7, 8) == encodeArgs(true));
|
||||
BOOST_CHECK(callContractFunction("retrieve(uint256)", 8) == encodeArgs(0, 0, 0, 0));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(struct_copy_via_local)
|
||||
{
|
||||
char const* sourceCode = R"(
|
||||
contract c {
|
||||
struct Struct { uint a; uint b; }
|
||||
Struct data1;
|
||||
Struct data2;
|
||||
function test() returns (bool) {
|
||||
data1.a = 1;
|
||||
data1.b = 2;
|
||||
var x = data1;
|
||||
data2 = x;
|
||||
return data2.a == data1.a && data2.b == data1.b;
|
||||
}
|
||||
}
|
||||
)";
|
||||
compileAndRun(sourceCode);
|
||||
BOOST_CHECK(callContractFunction("test()") == encodeArgs(true));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END()
|
||||
|
||||
}
|
||||
|
@ -332,7 +332,7 @@ BOOST_AUTO_TEST_CASE(assignment_to_struct)
|
||||
" data = a;\n"
|
||||
" }\n"
|
||||
"}\n";
|
||||
BOOST_CHECK_THROW(parseTextAndResolveNames(text), TypeError);
|
||||
BOOST_CHECK_NO_THROW(parseTextAndResolveNames(text));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(returns_in_constructor)
|
||||
|
Loading…
Reference in New Issue
Block a user