aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorchriseth <chris@ethereum.org>2018-08-16 04:31:01 +0800
committerGitHub <noreply@github.com>2018-08-16 04:31:01 +0800
commitc164f80ba6b1c6753450b59365d1e0f1633688db (patch)
tree202778bf484063adaac39bf73bb546eecf53baf6 /test
parente95901d86103a75ac1eebcf8b497432282da275c (diff)
parentc00db3c247dd2aa296650045b995cbfa87ba2324 (diff)
downloaddexon-solidity-c164f80ba6b1c6753450b59365d1e0f1633688db.tar
dexon-solidity-c164f80ba6b1c6753450b59365d1e0f1633688db.tar.gz
dexon-solidity-c164f80ba6b1c6753450b59365d1e0f1633688db.tar.bz2
dexon-solidity-c164f80ba6b1c6753450b59365d1e0f1633688db.tar.lz
dexon-solidity-c164f80ba6b1c6753450b59365d1e0f1633688db.tar.xz
dexon-solidity-c164f80ba6b1c6753450b59365d1e0f1633688db.tar.zst
dexon-solidity-c164f80ba6b1c6753450b59365d1e0f1633688db.zip
Merge pull request #4820 from ethereum/disallow_indexed_ref_v2
Disallow indexed reference types in events when using ABIEncoderV2
Diffstat (limited to 'test')
-rw-r--r--test/libsolidity/SolidityEndToEndTest.cpp203
-rw-r--r--test/libsolidity/syntaxTests/events/event_array_indexed_v2.sol7
-rw-r--r--test/libsolidity/syntaxTests/events/event_array_v2.sol6
-rw-r--r--test/libsolidity/syntaxTests/events/event_nested_array_indexed_v2.sol7
-rw-r--r--test/libsolidity/syntaxTests/events/event_nested_array_v2.sol6
-rw-r--r--test/libsolidity/syntaxTests/events/event_struct_indexed_v2.sol8
-rw-r--r--test/libsolidity/syntaxTests/events/event_struct_v2.sol7
7 files changed, 244 insertions, 0 deletions
diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp
index 8a334e5e..ce3c4324 100644
--- a/test/libsolidity/SolidityEndToEndTest.cpp
+++ b/test/libsolidity/SolidityEndToEndTest.cpp
@@ -3937,6 +3937,209 @@ BOOST_AUTO_TEST_CASE(event_really_really_lots_of_data_from_storage)
BOOST_CHECK_EQUAL(m_logs[0].topics[0], dev::keccak256(string("Deposit(uint256,bytes,uint256)")));
}
+BOOST_AUTO_TEST_CASE(event_struct_memory_v2)
+{
+ char const* sourceCode = R"(
+ pragma experimental ABIEncoderV2;
+ contract C {
+ struct S { uint a; }
+ event E(S);
+ function createEvent(uint x) public {
+ emit E(S(x));
+ }
+ }
+ )";
+ compileAndRun(sourceCode);
+ u256 x(42);
+ callContractFunction("createEvent(uint256)", x);
+ BOOST_REQUIRE_EQUAL(m_logs.size(), 1);
+ BOOST_CHECK_EQUAL(m_logs[0].address, m_contractAddress);
+ BOOST_CHECK(m_logs[0].data == encodeArgs(x));
+ BOOST_REQUIRE_EQUAL(m_logs[0].topics.size(), 1);
+ BOOST_CHECK_EQUAL(m_logs[0].topics[0], dev::keccak256(string("E((uint256))")));
+}
+
+BOOST_AUTO_TEST_CASE(event_struct_storage_v2)
+{
+ char const* sourceCode = R"(
+ pragma experimental ABIEncoderV2;
+ contract C {
+ struct S { uint a; }
+ event E(S);
+ S s;
+ function createEvent(uint x) public {
+ s.a = x;
+ emit E(s);
+ }
+ }
+ )";
+ compileAndRun(sourceCode);
+ u256 x(42);
+ callContractFunction("createEvent(uint256)", x);
+ BOOST_REQUIRE_EQUAL(m_logs.size(), 1);
+ BOOST_CHECK_EQUAL(m_logs[0].address, m_contractAddress);
+ BOOST_CHECK(m_logs[0].data == encodeArgs(x));
+ BOOST_REQUIRE_EQUAL(m_logs[0].topics.size(), 1);
+ BOOST_CHECK_EQUAL(m_logs[0].topics[0], dev::keccak256(string("E((uint256))")));
+}
+
+BOOST_AUTO_TEST_CASE(event_dynamic_array_memory)
+{
+ char const* sourceCode = R"(
+ contract C {
+ event E(uint[]);
+ function createEvent(uint x) public {
+ uint[] memory arr = new uint[](3);
+ arr[0] = x;
+ arr[1] = x + 1;
+ arr[2] = x + 2;
+ emit E(arr);
+ }
+ }
+ )";
+ compileAndRun(sourceCode);
+ u256 x(42);
+ callContractFunction("createEvent(uint256)", x);
+ BOOST_REQUIRE_EQUAL(m_logs.size(), 1);
+ BOOST_CHECK_EQUAL(m_logs[0].address, m_contractAddress);
+ BOOST_CHECK(m_logs[0].data == encodeArgs(0x20, 3, x, x + 1, x + 2));
+ BOOST_REQUIRE_EQUAL(m_logs[0].topics.size(), 1);
+ BOOST_CHECK_EQUAL(m_logs[0].topics[0], dev::keccak256(string("E(uint256[])")));
+}
+
+BOOST_AUTO_TEST_CASE(event_dynamic_array_memory_v2)
+{
+ char const* sourceCode = R"(
+ pragma experimental ABIEncoderV2;
+ contract C {
+ event E(uint[]);
+ function createEvent(uint x) public {
+ uint[] memory arr = new uint[](3);
+ arr[0] = x;
+ arr[1] = x + 1;
+ arr[2] = x + 2;
+ emit E(arr);
+ }
+ }
+ )";
+ compileAndRun(sourceCode);
+ u256 x(42);
+ callContractFunction("createEvent(uint256)", x);
+ BOOST_REQUIRE_EQUAL(m_logs.size(), 1);
+ BOOST_CHECK_EQUAL(m_logs[0].address, m_contractAddress);
+ BOOST_CHECK(m_logs[0].data == encodeArgs(0x20, 3, x, x + 1, x + 2));
+ BOOST_REQUIRE_EQUAL(m_logs[0].topics.size(), 1);
+ BOOST_CHECK_EQUAL(m_logs[0].topics[0], dev::keccak256(string("E(uint256[])")));
+}
+
+BOOST_AUTO_TEST_CASE(event_dynamic_nested_array_memory_v2)
+{
+ char const* sourceCode = R"(
+ pragma experimental ABIEncoderV2;
+ contract C {
+ event E(uint[][]);
+ function createEvent(uint x) public {
+ uint[][] memory arr = new uint[][](2);
+ arr[0] = new uint[](2);
+ arr[1] = new uint[](2);
+ arr[0][0] = x;
+ arr[0][1] = x + 1;
+ arr[1][0] = x + 2;
+ arr[1][1] = x + 3;
+ emit E(arr);
+ }
+ }
+ )";
+ compileAndRun(sourceCode);
+ u256 x(42);
+ callContractFunction("createEvent(uint256)", x);
+ BOOST_REQUIRE_EQUAL(m_logs.size(), 1);
+ BOOST_CHECK_EQUAL(m_logs[0].address, m_contractAddress);
+ BOOST_CHECK(m_logs[0].data == encodeArgs(0x20, 2, 0x40, 0xa0, 2, x, x + 1, 2, x + 2, x + 3));
+ BOOST_REQUIRE_EQUAL(m_logs[0].topics.size(), 1);
+ BOOST_CHECK_EQUAL(m_logs[0].topics[0], dev::keccak256(string("E(uint256[][])")));
+}
+
+BOOST_AUTO_TEST_CASE(event_dynamic_array_storage)
+{
+ char const* sourceCode = R"(
+ contract C {
+ event E(uint[]);
+ uint[] arr;
+ function createEvent(uint x) public {
+ arr.length = 3;
+ arr[0] = x;
+ arr[1] = x + 1;
+ arr[2] = x + 2;
+ emit E(arr);
+ }
+ }
+ )";
+ compileAndRun(sourceCode);
+ u256 x(42);
+ callContractFunction("createEvent(uint256)", x);
+ BOOST_REQUIRE_EQUAL(m_logs.size(), 1);
+ BOOST_CHECK_EQUAL(m_logs[0].address, m_contractAddress);
+ BOOST_CHECK(m_logs[0].data == encodeArgs(0x20, 3, x, x + 1, x + 2));
+ BOOST_REQUIRE_EQUAL(m_logs[0].topics.size(), 1);
+ BOOST_CHECK_EQUAL(m_logs[0].topics[0], dev::keccak256(string("E(uint256[])")));
+}
+
+BOOST_AUTO_TEST_CASE(event_dynamic_array_storage_v2)
+{
+ char const* sourceCode = R"(
+ pragma experimental ABIEncoderV2;
+ contract C {
+ event E(uint[]);
+ uint[] arr;
+ function createEvent(uint x) public {
+ arr.length = 3;
+ arr[0] = x;
+ arr[1] = x + 1;
+ arr[2] = x + 2;
+ emit E(arr);
+ }
+ }
+ )";
+ compileAndRun(sourceCode);
+ u256 x(42);
+ callContractFunction("createEvent(uint256)", x);
+ BOOST_REQUIRE_EQUAL(m_logs.size(), 1);
+ BOOST_CHECK_EQUAL(m_logs[0].address, m_contractAddress);
+ BOOST_CHECK(m_logs[0].data == encodeArgs(0x20, 3, x, x + 1, x + 2));
+ BOOST_REQUIRE_EQUAL(m_logs[0].topics.size(), 1);
+ BOOST_CHECK_EQUAL(m_logs[0].topics[0], dev::keccak256(string("E(uint256[])")));
+}
+
+BOOST_AUTO_TEST_CASE(event_dynamic_nested_array_storage_v2)
+{
+ char const* sourceCode = R"(
+ pragma experimental ABIEncoderV2;
+ contract C {
+ event E(uint[][]);
+ uint[][] arr;
+ function createEvent(uint x) public {
+ arr.length = 2;
+ arr[0].length = 2;
+ arr[1].length = 2;
+ arr[0][0] = x;
+ arr[0][1] = x + 1;
+ arr[1][0] = x + 2;
+ arr[1][1] = x + 3;
+ emit E(arr);
+ }
+ }
+ )";
+ compileAndRun(sourceCode);
+ u256 x(42);
+ callContractFunction("createEvent(uint256)", x);
+ BOOST_REQUIRE_EQUAL(m_logs.size(), 1);
+ BOOST_CHECK_EQUAL(m_logs[0].address, m_contractAddress);
+ BOOST_CHECK(m_logs[0].data == encodeArgs(0x20, 2, 0x40, 0xa0, 2, x, x + 1, 2, x + 2, x + 3));
+ BOOST_REQUIRE_EQUAL(m_logs[0].topics.size(), 1);
+ BOOST_CHECK_EQUAL(m_logs[0].topics[0], dev::keccak256(string("E(uint256[][])")));
+}
+
BOOST_AUTO_TEST_CASE(event_indexed_string)
{
char const* sourceCode = R"(
diff --git a/test/libsolidity/syntaxTests/events/event_array_indexed_v2.sol b/test/libsolidity/syntaxTests/events/event_array_indexed_v2.sol
new file mode 100644
index 00000000..aaf6028a
--- /dev/null
+++ b/test/libsolidity/syntaxTests/events/event_array_indexed_v2.sol
@@ -0,0 +1,7 @@
+pragma experimental ABIEncoderV2;
+contract c {
+ event E(uint[] indexed);
+}
+// ----
+// Warning: (0-33): Experimental features are turned on. Do not use experimental features on live deployments.
+// TypeError: (59-65): Indexed reference types cannot yet be used with ABIEncoderV2.
diff --git a/test/libsolidity/syntaxTests/events/event_array_v2.sol b/test/libsolidity/syntaxTests/events/event_array_v2.sol
new file mode 100644
index 00000000..9ccd9fc9
--- /dev/null
+++ b/test/libsolidity/syntaxTests/events/event_array_v2.sol
@@ -0,0 +1,6 @@
+pragma experimental ABIEncoderV2;
+contract c {
+ event E(uint[]);
+}
+// ----
+// Warning: (0-33): Experimental features are turned on. Do not use experimental features on live deployments.
diff --git a/test/libsolidity/syntaxTests/events/event_nested_array_indexed_v2.sol b/test/libsolidity/syntaxTests/events/event_nested_array_indexed_v2.sol
new file mode 100644
index 00000000..ffae5b9c
--- /dev/null
+++ b/test/libsolidity/syntaxTests/events/event_nested_array_indexed_v2.sol
@@ -0,0 +1,7 @@
+pragma experimental ABIEncoderV2;
+contract c {
+ event E(uint[][] indexed);
+}
+// ----
+// Warning: (0-33): Experimental features are turned on. Do not use experimental features on live deployments.
+// TypeError: (59-67): Indexed reference types cannot yet be used with ABIEncoderV2.
diff --git a/test/libsolidity/syntaxTests/events/event_nested_array_v2.sol b/test/libsolidity/syntaxTests/events/event_nested_array_v2.sol
new file mode 100644
index 00000000..efc7439e
--- /dev/null
+++ b/test/libsolidity/syntaxTests/events/event_nested_array_v2.sol
@@ -0,0 +1,6 @@
+pragma experimental ABIEncoderV2;
+contract c {
+ event E(uint[][]);
+}
+// ----
+// Warning: (0-33): Experimental features are turned on. Do not use experimental features on live deployments.
diff --git a/test/libsolidity/syntaxTests/events/event_struct_indexed_v2.sol b/test/libsolidity/syntaxTests/events/event_struct_indexed_v2.sol
new file mode 100644
index 00000000..a8e0837f
--- /dev/null
+++ b/test/libsolidity/syntaxTests/events/event_struct_indexed_v2.sol
@@ -0,0 +1,8 @@
+pragma experimental ABIEncoderV2;
+contract c {
+ struct S { uint a ; }
+ event E(S indexed);
+}
+// ----
+// Warning: (0-33): Experimental features are turned on. Do not use experimental features on live deployments.
+// TypeError: (85-86): Indexed reference types cannot yet be used with ABIEncoderV2.
diff --git a/test/libsolidity/syntaxTests/events/event_struct_v2.sol b/test/libsolidity/syntaxTests/events/event_struct_v2.sol
new file mode 100644
index 00000000..97ca61b6
--- /dev/null
+++ b/test/libsolidity/syntaxTests/events/event_struct_v2.sol
@@ -0,0 +1,7 @@
+pragma experimental ABIEncoderV2;
+contract c {
+ struct S { uint a ; }
+ event E(S);
+}
+// ----
+// Warning: (0-33): Experimental features are turned on. Do not use experimental features on live deployments.