mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Implement struct encoder.
This commit is contained in:
committed by
Alex Beregszaszi
parent
6385641f6e
commit
70d70e7816
@@ -424,7 +424,43 @@ BOOST_AUTO_TEST_CASE(function_name_collision)
|
||||
)
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(structs)
|
||||
{
|
||||
string sourceCode = R"(
|
||||
contract C {
|
||||
struct S { uint16 a; uint16 b; T[] sub; uint16 c; }
|
||||
struct T { uint64[2] x; }
|
||||
S s;
|
||||
event e(uint16, S);
|
||||
function f() returns (uint, S) {
|
||||
uint16 x = 7;
|
||||
s.a = 8;
|
||||
s.b = 9;
|
||||
s.c = 10;
|
||||
s.sub.length = 3;
|
||||
s.sub[0].x[0] = 11;
|
||||
s.sub[1].x[0] = 12;
|
||||
s.sub[2].x[1] = 13;
|
||||
e(x, s);
|
||||
return (x, s);
|
||||
}
|
||||
}
|
||||
)";
|
||||
|
||||
NEW_ENCODER(
|
||||
compileAndRun(sourceCode, 0, "C");
|
||||
bytes encoded = encodeArgs(
|
||||
u256(7), 0x40,
|
||||
8, 9, 0x80, 10,
|
||||
3,
|
||||
11, 0,
|
||||
12, 0,
|
||||
0, 13
|
||||
);
|
||||
BOOST_CHECK(callContractFunction("f()") == encoded);
|
||||
REQUIRE_LOG_DATA(encoded);
|
||||
)
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END()
|
||||
|
||||
|
||||
@@ -9682,50 +9682,6 @@ BOOST_AUTO_TEST_CASE(contracts_separated_with_comment)
|
||||
compileAndRun(sourceCode, 0, "C2");
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(return_structs)
|
||||
{
|
||||
char const* sourceCode = R"(
|
||||
pragma experimental ABIEncoderV2;
|
||||
contract C {
|
||||
struct S { uint a; T[] sub; }
|
||||
struct T { uint[2] x; }
|
||||
function f() returns (uint x, S s) {
|
||||
x = 7;
|
||||
s.a = 8;
|
||||
s.sub = new T[](3);
|
||||
s.sub[0].x[0] = 9;
|
||||
s.sub[1].x[0] = 10;
|
||||
s.sub[2].x[1] = 11;
|
||||
}
|
||||
}
|
||||
)";
|
||||
// This will throw "unimplemented" until it is implemented.
|
||||
BOOST_CHECK_THROW(
|
||||
compileAndRun(sourceCode, 0, "C"),
|
||||
Exception);
|
||||
|
||||
// Will calculate the exact encoding later.
|
||||
// BOOST_CHECK(callContractFunction("f()") == encodeArgs(
|
||||
// u256(7), u256(0x40),
|
||||
// u256(8), u256(0x40),
|
||||
// u256(3),
|
||||
// // s.sub[0]
|
||||
// u256(9), u256(0xc0),
|
||||
// // s.sub[1]
|
||||
// u256(10), u256(0xe0),
|
||||
// // s.sub[2]
|
||||
// u256(11), u256(0x100),
|
||||
// // s.sub[0].sub
|
||||
// u256(2)
|
||||
// // s.sub[0].sub[0].a
|
||||
// u256(8),
|
||||
// u256()
|
||||
// // s.sub[1].sub
|
||||
// u256(0)
|
||||
// // s.sub[2].sub
|
||||
// u256(2)
|
||||
// ));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(include_creation_bytecode_only_once)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user