aboutsummaryrefslogtreecommitdiffstats
path: root/test/libsolidity
diff options
context:
space:
mode:
authorchriseth <chris@ethereum.org>2017-08-03 21:06:59 +0800
committerAlex Beregszaszi <alex@rtfs.hu>2017-08-14 20:11:38 +0800
commit38446a9669b3ddeadb3a088bad98ef948fa5adc6 (patch)
tree08d51c5cf89b4c66ea8c3a2657ca90ece5d713ad /test/libsolidity
parent4630b3315aa249508036998e4ed122b5ba260ba1 (diff)
downloaddexon-solidity-38446a9669b3ddeadb3a088bad98ef948fa5adc6.tar.gz
dexon-solidity-38446a9669b3ddeadb3a088bad98ef948fa5adc6.tar.zst
dexon-solidity-38446a9669b3ddeadb3a088bad98ef948fa5adc6.zip
ABI encoder tests.
Diffstat (limited to 'test/libsolidity')
-rw-r--r--test/libsolidity/ABIEncoderTests.cpp86
-rw-r--r--test/libsolidity/SolidityEndToEndTest.cpp21
2 files changed, 105 insertions, 2 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()
}
diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp
index 166c4660..73dd7d22 100644
--- a/test/libsolidity/SolidityEndToEndTest.cpp
+++ b/test/libsolidity/SolidityEndToEndTest.cpp
@@ -3128,7 +3128,7 @@ BOOST_AUTO_TEST_CASE(event_really_lots_of_data)
callContractFunction("deposit()");
BOOST_REQUIRE_EQUAL(m_logs.size(), 1);
BOOST_CHECK_EQUAL(m_logs[0].address, m_contractAddress);
- BOOST_CHECK(m_logs[0].data == encodeArgs(10, 0x60, 15, 4) + FixedHash<4>(dev::keccak256("deposit()")).asBytes());
+ BOOST_CHECK_EQUAL(toHex(m_logs[0].data), toHex(encodeArgs(10, 0x60, 15, 4) + FixedHash<4>(dev::keccak256("deposit()")).asBytes()));
BOOST_REQUIRE_EQUAL(m_logs[0].topics.size(), 1);
BOOST_CHECK_EQUAL(m_logs[0].topics[0], dev::keccak256(string("Deposit(uint256,bytes,uint256)")));
}
@@ -3152,7 +3152,7 @@ BOOST_AUTO_TEST_CASE(event_really_lots_of_data_from_storage)
callContractFunction("deposit()");
BOOST_REQUIRE_EQUAL(m_logs.size(), 1);
BOOST_CHECK_EQUAL(m_logs[0].address, m_contractAddress);
- BOOST_CHECK(m_logs[0].data == encodeArgs(10, 0x60, 15, 3, string("ABC")));
+ BOOST_CHECK_EQUAL(toHex(m_logs[0].data), toHex(encodeArgs(10, 0x60, 15, 3, string("ABC"))));
BOOST_REQUIRE_EQUAL(m_logs[0].topics.size(), 1);
BOOST_CHECK_EQUAL(m_logs[0].topics[0], dev::keccak256(string("Deposit(uint256,bytes,uint256)")));
}
@@ -4432,10 +4432,12 @@ BOOST_AUTO_TEST_CASE(array_copy_storage_abi)
// NOTE: This does not really test copying from storage to ABI directly,
// because it will always copy to memory first.
char const* sourceCode = R"(
+ pragma experimental ABIEncoderV2;
contract c {
uint8[] x;
uint16[] y;
uint24[] z;
+ uint24[][] w;
function test1() returns (uint8[]) {
for (uint i = 0; i < 101; ++i)
x.push(uint8(i));
@@ -4451,6 +4453,13 @@ BOOST_AUTO_TEST_CASE(array_copy_storage_abi)
z.push(uint24(i));
return z;
}
+ function test4() returns (uint24[][]) {
+ w.length = 5;
+ for (uint i = 0; i < 5; ++i)
+ for (uint j = 0; j < 101; ++j)
+ w[i].push(uint24(j));
+ return w;
+ }
}
)";
compileAndRun(sourceCode);
@@ -4460,6 +4469,14 @@ BOOST_AUTO_TEST_CASE(array_copy_storage_abi)
BOOST_CHECK(callContractFunction("test1()") == encodeArgs(0x20, 101) + valueSequence);
BOOST_CHECK(callContractFunction("test2()") == encodeArgs(0x20, 101) + valueSequence);
BOOST_CHECK(callContractFunction("test3()") == encodeArgs(0x20, 101) + valueSequence);
+ BOOST_CHECK(callContractFunction("test4()") ==
+ encodeArgs(0x20, 5, 0xa0, 0xa0 + 102 * 32 * 1, 0xa0 + 102 * 32 * 2, 0xa0 + 102 * 32 * 3, 0xa0 + 102 * 32 * 4) +
+ encodeArgs(101) + valueSequence +
+ encodeArgs(101) + valueSequence +
+ encodeArgs(101) + valueSequence +
+ encodeArgs(101) + valueSequence +
+ encodeArgs(101) + valueSequence
+ );
}
BOOST_AUTO_TEST_CASE(array_copy_storage_abi_signed)