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.cpp69
1 files changed, 22 insertions, 47 deletions
diff --git a/test/libsolidity/ABIEncoderTests.cpp b/test/libsolidity/ABIEncoderTests.cpp
index 49db9ce1..d2125cc7 100644
--- a/test/libsolidity/ABIEncoderTests.cpp
+++ b/test/libsolidity/ABIEncoderTests.cpp
@@ -68,7 +68,7 @@ BOOST_AUTO_TEST_CASE(value_types)
assembly { b := 7 }
C c;
assembly { c := sub(0, 5) }
- E(10, uint16(uint256(-2)), uint24(0x12121212), int24(int256(-1)), bytes3(x), b, c);
+ emit E(10, uint16(uint256(-2)), uint24(0x12121212), int24(int256(-1)), bytes3(x), b, c);
}
}
)";
@@ -87,7 +87,7 @@ BOOST_AUTO_TEST_CASE(string_literal)
contract C {
event E(string, bytes20, string);
function f() public {
- E("abcdef", "abcde", "abcdefabcdefgehabcabcasdfjklabcdefabcedefghabcabcasdfjklabcdefabcdefghabcabcasdfjklabcdeefabcdefghabcabcasdefjklabcdefabcdefghabcabcasdfjkl");
+ emit E("abcdef", "abcde", "abcdefabcdefgehabcabcasdfjklabcdefabcedefghabcabcasdfjklabcdefabcdefghabcabcasdfjklabcdeefabcdefghabcabcasdefjklabcdefabcdefghabcabcasdfjkl");
}
}
)";
@@ -133,7 +133,7 @@ BOOST_AUTO_TEST_CASE(conversion)
int8 c;
int16 d;
assembly { a := sub(0, 1) c := 0x0101ff d := 0xff01 }
- E(10, x, a, uint8(b), c, int8(d));
+ emit E(bytes4(uint32(10)), x, a, uint8(b), c, int8(d));
}
}
)";
@@ -159,7 +159,7 @@ BOOST_AUTO_TEST_CASE(memory_array_one_dim)
mstore(add(x, mul(add(i, 1), 0x20)), add(0xfffffffe, i))
}
}
- E(10, x, 11);
+ emit E(10, x, 11);
}
}
)";
@@ -188,7 +188,7 @@ BOOST_AUTO_TEST_CASE(memory_array_two_dim)
x[0][2] = -1;
x[1][0] = 4;
x[1][1] = 5;
- E(10, x, 11);
+ emit E(10, x, 11);
}
}
)";
@@ -208,7 +208,7 @@ BOOST_AUTO_TEST_CASE(memory_byte_array)
bytes[] memory x = new bytes[](2);
x[0] = "abcabcdefghjklmnopqrsuvwabcdefgijklmnopqrstuwabcdefgijklmnoprstuvw";
x[1] = "abcdefghijklmnopqrtuvwabcfghijklmnopqstuvwabcdeghijklmopqrstuvw";
- E(10, x, 11);
+ emit E(10, x, 11);
}
}
)";
@@ -234,7 +234,7 @@ BOOST_AUTO_TEST_CASE(storage_byte_array)
function f() public {
short = "123456789012345678901234567890a";
long = "ffff123456789012345678901234567890afffffffff123456789012345678901234567890a";
- E(short, long);
+ emit E(short, long);
}
}
)";
@@ -261,7 +261,7 @@ BOOST_AUTO_TEST_CASE(storage_array)
sstore(1, sub(0, 2))
sstore(2, sub(0, 3))
}
- E(addr);
+ emit E(addr);
}
}
)";
@@ -279,10 +279,10 @@ BOOST_AUTO_TEST_CASE(storage_array_dyn)
address[] addr;
event E(address[] a);
function f() public {
- addr.push(1);
- addr.push(2);
- addr.push(3);
- E(addr);
+ addr.push(0x0000000000000000000000000000000000000001);
+ addr.push(0x0000000000000000000000000000000000000002);
+ addr.push(0x0000000000000000000000000000000000000003);
+ emit E(addr);
}
}
)";
@@ -308,7 +308,7 @@ BOOST_AUTO_TEST_CASE(storage_array_compact)
x.push(6);
x.push(-7);
x.push(8);
- E(x);
+ emit E(x);
}
}
)";
@@ -329,7 +329,7 @@ BOOST_AUTO_TEST_CASE(external_function)
function(uint) external returns (uint) g;
function f(uint) public returns (uint) {
g = this.f;
- E(this.f, g);
+ emit E(this.f, g);
}
}
)";
@@ -351,7 +351,7 @@ BOOST_AUTO_TEST_CASE(external_function_cleanup)
function f(uint) public returns (uint) {
function(uint) external returns (uint)[1] memory h;
assembly { sstore(0, sub(0, 1)) mstore(h, sub(0, 1)) }
- E(h[0], g);
+ emit E(h[0], g);
}
}
)";
@@ -367,22 +367,19 @@ BOOST_AUTO_TEST_CASE(calldata)
string sourceCode = R"(
contract C {
event E(bytes);
- function f(bytes a) external {
- E(a);
+ function f(bytes calldata a) external {
+ emit E(a);
}
}
)";
string s("abcdef");
string t("abcdefgggggggggggggggggggggggggggggggggggggggghhheeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeggg");
- bool newEncoder = false;
BOTH_ENCODERS(
compileAndRun(sourceCode);
callContractFunction("f(bytes)", 0x20, s.size(), s);
- // The old encoder did not pad to multiples of 32 bytes
- REQUIRE_LOG_DATA(encodeArgs(0x20, s.size()) + (newEncoder ? encodeArgs(s) : asBytes(s)));
+ REQUIRE_LOG_DATA(encodeArgs(0x20, s.size(), s));
callContractFunction("f(bytes)", 0x20, t.size(), t);
- REQUIRE_LOG_DATA(encodeArgs(0x20, t.size()) + (newEncoder ? encodeArgs(t) : asBytes(t)));
- newEncoder = true;
+ REQUIRE_LOG_DATA(encodeArgs(0x20, t.size(), t));
)
}
@@ -420,7 +417,7 @@ BOOST_AUTO_TEST_CASE(structs)
struct T { uint64[2] x; }
S s;
event e(uint16, S);
- function f() public returns (uint, S) {
+ function f() public returns (uint, S memory) {
uint16 x = 7;
s.a = 8;
s.b = 9;
@@ -429,7 +426,7 @@ BOOST_AUTO_TEST_CASE(structs)
s.sub[0].x[0] = 11;
s.sub[1].x[0] = 12;
s.sub[2].x[1] = 13;
- e(x, s);
+ emit e(x, s);
return (x, s);
}
}
@@ -450,28 +447,6 @@ BOOST_AUTO_TEST_CASE(structs)
)
}
-BOOST_AUTO_TEST_CASE(empty_struct)
-{
- string sourceCode = R"(
- contract C {
- struct S { }
- S s;
- event e(uint16, S, uint16);
- function f() returns (uint, S, uint) {
- e(7, s, 8);
- return (7, s, 8);
- }
- }
- )";
-
- NEW_ENCODER(
- compileAndRun(sourceCode, 0, "C");
- bytes encoded = encodeArgs(7, 8);
- BOOST_CHECK(callContractFunction("f()") == encoded);
- REQUIRE_LOG_DATA(encoded);
- )
-}
-
BOOST_AUTO_TEST_CASE(structs2)
{
string sourceCode = R"(
@@ -479,7 +454,7 @@ BOOST_AUTO_TEST_CASE(structs2)
enum E {A, B, C}
struct T { uint x; E e; uint8 y; }
struct S { C c; T[] t;}
- function f() public returns (uint a, S[2] s1, S[] s2, uint b) {
+ function f() public returns (uint a, S[2] memory s1, S[] memory s2, uint b) {
a = 7;
b = 8;
s1[0].c = this;