aboutsummaryrefslogtreecommitdiffstats
path: root/test/libsolidity/ABIEncoderTests.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'test/libsolidity/ABIEncoderTests.cpp')
-rw-r--r--test/libsolidity/ABIEncoderTests.cpp86
1 files changed, 86 insertions, 0 deletions
diff --git a/test/libsolidity/ABIEncoderTests.cpp b/test/libsolidity/ABIEncoderTests.cpp
index 44c673c5..24205069 100644
--- a/test/libsolidity/ABIEncoderTests.cpp
+++ b/test/libsolidity/ABIEncoderTests.cpp
@@ -126,6 +126,73 @@ BOOST_AUTO_TEST_CASE(conversion)
));
}
+BOOST_AUTO_TEST_CASE(memory_array_one_dim)
+{
+ char const* sourceCode = R"(
+ contract C {
+ event E(uint a, int16[] b, uint c);
+ function f() {
+ int16[] memory x = new int16[](3);
+ assembly {
+ for { let i := 0 } lt(i, 3) { i := add(i, 1) } {
+ mstore(add(x, mul(add(i, 1), 0x20)), add(0xfffffffe, i))
+ }
+ }
+ E(10, x, 11);
+ }
+ }
+ )";
+ compileAndRun(sourceCode);
+ callContractFunction("f()");
+ REQUIRE_LOG_DATA(encodeArgs(10, 0x60, 11, 3, u256(-2), u256(-1), u256(0)));
+}
+
+BOOST_AUTO_TEST_CASE(memory_array_two_dim)
+{
+ char const* sourceCode = R"(
+ contract C {
+ event E(uint a, int16[][2] b, uint c);
+ function f() {
+ int16[][2] memory x;
+ x[0] = new int16[](3);
+ x[1] = new int16[](2);
+ x[0][0] = 7;
+ x[0][1] = int16(0x010203040506);
+ x[0][2] = -1;
+ x[1][0] = 4;
+ x[1][1] = 5;
+ E(10, x, 11);
+ }
+ }
+ )";
+ compileAndRun(sourceCode);
+ callContractFunction("f()");
+ REQUIRE_LOG_DATA(encodeArgs(10, 0x60, 11, 0x40, 0xc0, 3, 7, 0x0506, u256(-1), 2, 4, 5));
+}
+
+BOOST_AUTO_TEST_CASE(memory_byte_array)
+{
+ char const* sourceCode = R"(
+ contract C {
+ event E(uint a, bytes[] b, uint c);
+ function f() {
+ bytes[] memory x = new bytes[](2);
+ x[0] = "abcabcdefghjklmnopqrsuvwabcdefgijklmnopqrstuwabcdefgijklmnoprstuvw";
+ x[1] = "abcdefghijklmnopqrtuvwabcfghijklmnopqstuvwabcdeghijklmopqrstuvw";
+ E(10, x, 11);
+ }
+ }
+ )";
+ compileAndRun(sourceCode);
+ callContractFunction("f()");
+ REQUIRE_LOG_DATA(encodeArgs(
+ 10, 0x60, 11,
+ 2, 0x40, 0xc0,
+ 66, string("abcabcdefghjklmnopqrsuvwabcdefgijklmnopqrstuwabcdefgijklmnoprstuvw"),
+ 63, string("abcdefghijklmnopqrtuvwabcfghijklmnopqstuvwabcdeghijklmopqrstuvw")
+ ));
+}
+
BOOST_AUTO_TEST_CASE(storage_byte_array)
{
char const* sourceCode = R"(
@@ -252,6 +319,25 @@ BOOST_AUTO_TEST_CASE(external_function_cleanup)
REQUIRE_LOG_DATA(encodeArgs(string(24, char(-1)), string(24, char(-1))));
}
+BOOST_AUTO_TEST_CASE(calldata)
+{
+ char const* sourceCode = R"(
+ contract C {
+ event E(bytes);
+ function f(bytes a) external {
+ E(a);
+ }
+ }
+ )";
+ compileAndRun(sourceCode);
+ string s("abcdef");
+ string t("abcdefgggggggggggggggggggggggggggggggggggggggghhheeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeggg");
+ callContractFunction("f(bytes)", 0x20, s.size(), s);
+ REQUIRE_LOG_DATA(encodeArgs(0x20, s.size(), s));
+ callContractFunction("f(bytes)", 0x20, t.size(), t);
+ REQUIRE_LOG_DATA(encodeArgs(0x20, t.size(), t));
+}
+
BOOST_AUTO_TEST_SUITE_END()
}