aboutsummaryrefslogtreecommitdiffstats
path: root/test/libsolidity/SolidityEndToEndTest.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'test/libsolidity/SolidityEndToEndTest.cpp')
-rw-r--r--test/libsolidity/SolidityEndToEndTest.cpp348
1 files changed, 295 insertions, 53 deletions
diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp
index e487f0ae..5ffdf6af 100644
--- a/test/libsolidity/SolidityEndToEndTest.cpp
+++ b/test/libsolidity/SolidityEndToEndTest.cpp
@@ -1543,6 +1543,92 @@ BOOST_AUTO_TEST_CASE(mapping_local_compound_assignment)
ABI_CHECK(callContractFunction("f()"), encodeArgs(byte(42), byte(0), byte(0), byte(21)));
}
+BOOST_AUTO_TEST_CASE(mapping_internal_argument)
+{
+ char const* sourceCode = R"(
+ contract test {
+ mapping(uint8 => uint8) a;
+ mapping(uint8 => uint8) b;
+ function set_internal(mapping(uint8 => uint8) storage m, uint8 key, uint8 value) internal returns (uint8) {
+ uint8 oldValue = m[key];
+ m[key] = value;
+ return oldValue;
+ }
+ function set(uint8 key, uint8 value_a, uint8 value_b) public returns (uint8 old_a, uint8 old_b) {
+ old_a = set_internal(a, key, value_a);
+ old_b = set_internal(b, key, value_b);
+ }
+ function get(uint8 key) public returns (uint8, uint8) {
+ return (a[key], b[key]);
+ }
+ }
+ )";
+ compileAndRun(sourceCode);
+
+ ABI_CHECK(callContractFunction("set(uint8,uint8,uint8)", byte(1), byte(21), byte(42)), encodeArgs(byte(0), byte(0)));
+ ABI_CHECK(callContractFunction("get(uint8)", byte(1)), encodeArgs(byte(21), byte(42)));
+ ABI_CHECK(callContractFunction("set(uint8,uint8,uint8)", byte(1), byte(10), byte(11)), encodeArgs(byte(21), byte(42)));
+ ABI_CHECK(callContractFunction("get(uint8)", byte(1)), encodeArgs(byte(10), byte(11)));
+}
+
+BOOST_AUTO_TEST_CASE(mapping_array_internal_argument)
+{
+ char const* sourceCode = R"(
+ contract test {
+ mapping(uint8 => uint8)[2] a;
+ mapping(uint8 => uint8)[2] b;
+ function set_internal(mapping(uint8 => uint8)[2] storage m, uint8 key, uint8 value1, uint8 value2) internal returns (uint8, uint8) {
+ uint8 oldValue1 = m[0][key];
+ uint8 oldValue2 = m[1][key];
+ m[0][key] = value1;
+ m[1][key] = value2;
+ return (oldValue1, oldValue2);
+ }
+ function set(uint8 key, uint8 value_a1, uint8 value_a2, uint8 value_b1, uint8 value_b2) public returns (uint8 old_a1, uint8 old_a2, uint8 old_b1, uint8 old_b2) {
+ (old_a1, old_a2) = set_internal(a, key, value_a1, value_a2);
+ (old_b1, old_b2) = set_internal(b, key, value_b1, value_b2);
+ }
+ function get(uint8 key) public returns (uint8, uint8, uint8, uint8) {
+ return (a[0][key], a[1][key], b[0][key], b[1][key]);
+ }
+ }
+ )";
+ compileAndRun(sourceCode);
+
+ ABI_CHECK(callContractFunction("set(uint8,uint8,uint8,uint8,uint8)", byte(1), byte(21), byte(22), byte(42), byte(43)), encodeArgs(byte(0), byte(0), byte(0), byte(0)));
+ ABI_CHECK(callContractFunction("get(uint8)", byte(1)), encodeArgs(byte(21), byte(22), byte(42), byte(43)));
+ ABI_CHECK(callContractFunction("set(uint8,uint8,uint8,uint8,uint8)", byte(1), byte(10), byte(30), byte(11), byte(31)), encodeArgs(byte(21), byte(22), byte(42), byte(43)));
+ ABI_CHECK(callContractFunction("get(uint8)", byte(1)), encodeArgs(byte(10), byte(30), byte(11), byte(31)));
+}
+
+BOOST_AUTO_TEST_CASE(mapping_internal_return)
+{
+ char const* sourceCode = R"(
+ contract test {
+ mapping(uint8 => uint8) a;
+ mapping(uint8 => uint8) b;
+ function f() internal returns (mapping(uint8 => uint8) storage r) {
+ r = a;
+ r[1] = 42;
+ r = b;
+ r[1] = 84;
+ }
+ function g() public returns (uint8, uint8, uint8, uint8, uint8, uint8) {
+ f()[2] = 21;
+ return (a[0], a[1], a[2], b[0], b[1], b[2]);
+ }
+ function h() public returns (uint8, uint8, uint8, uint8, uint8, uint8) {
+ mapping(uint8 => uint8) storage m = f();
+ m[2] = 17;
+ return (a[0], a[1], a[2], b[0], b[1], b[2]);
+ }
+ }
+ )";
+ compileAndRun(sourceCode);
+
+ ABI_CHECK(callContractFunction("g()"), encodeArgs(byte(0), byte(42), byte(0), byte(0), byte(84), byte (21)));
+ ABI_CHECK(callContractFunction("h()"), encodeArgs(byte(0), byte(42), byte(0), byte(0), byte(84), byte (17)));
+}
BOOST_AUTO_TEST_CASE(structs)
{
@@ -2211,7 +2297,7 @@ BOOST_AUTO_TEST_CASE(log0)
char const* sourceCode = R"(
contract test {
function a() public {
- log0(1);
+ log0(bytes32(uint256(1)));
}
}
)";
@@ -2228,7 +2314,7 @@ BOOST_AUTO_TEST_CASE(log1)
char const* sourceCode = R"(
contract test {
function a() public {
- log1(1, 2);
+ log1(bytes32(uint256(1)), bytes32(uint256(2)));
}
}
)";
@@ -2246,7 +2332,7 @@ BOOST_AUTO_TEST_CASE(log2)
char const* sourceCode = R"(
contract test {
function a() public {
- log2(1, 2, 3);
+ log2(bytes32(uint256(1)), bytes32(uint256(2)), bytes32(uint256(3)));
}
}
)";
@@ -2265,7 +2351,7 @@ BOOST_AUTO_TEST_CASE(log3)
char const* sourceCode = R"(
contract test {
function a() public {
- log3(1, 2, 3, 4);
+ log3(bytes32(uint256(1)), bytes32(uint256(2)), bytes32(uint256(3)), bytes32(uint256(4)));
}
}
)";
@@ -2284,7 +2370,7 @@ BOOST_AUTO_TEST_CASE(log4)
char const* sourceCode = R"(
contract test {
function a() public {
- log4(1, 2, 3, 4, 5);
+ log4(bytes32(uint256(1)), bytes32(uint256(2)), bytes32(uint256(3)), bytes32(uint256(4)), bytes32(uint256(5)));
}
}
)";
@@ -2303,7 +2389,7 @@ BOOST_AUTO_TEST_CASE(log_in_constructor)
char const* sourceCode = R"(
contract test {
constructor() public {
- log1(1, 2);
+ log1(bytes32(uint256(1)), bytes32(uint256(2)));
}
}
)";
@@ -5017,7 +5103,7 @@ BOOST_AUTO_TEST_CASE(array_copy_target_simple)
function test() public returns (bytes17 a, bytes17 b, bytes17 c, bytes17 d, bytes17 e) {
for (uint i = 0; i < data1.length; ++i)
data1[i] = bytes8(uint64(i));
- data2[8] = data2[9] = 2;
+ data2[8] = data2[9] = bytes8(uint64(2));
data2 = data1;
a = data2[1];
b = data2[2];
@@ -5076,10 +5162,10 @@ BOOST_AUTO_TEST_CASE(array_copy_target_leftover2)
bytes8[4] data1; // fits into one slot
bytes10[6] data2; // 4 elements need two slots
function test() public returns (bytes10 r1, bytes10 r2, bytes10 r3) {
- data1[0] = 1;
- data1[1] = 2;
- data1[2] = 3;
- data1[3] = 4;
+ data1[0] = bytes8(uint64(1));
+ data1[1] = bytes8(uint64(2));
+ data1[2] = bytes8(uint64(3));
+ data1[3] = bytes8(uint64(4));
for (uint i = 0; i < data2.length; ++i)
data2[i] = bytes10(uint80(0xffff00 | (1 + i)));
data2 = data1;
@@ -5274,13 +5360,13 @@ BOOST_AUTO_TEST_CASE(byte_array_push)
contract c {
bytes data;
function test() public returns (bool x) {
- if (data.push(5) != 1) return true;
- if (data[0] != 5) return true;
- data.push(4);
- if (data[1] != 4) return true;
- uint l = data.push(3);
- if (data[2] != 3) return true;
- if (l != 3) return true;
+ if (data.push(0x05) != 1) return true;
+ if (data[0] != 0x05) return true;
+ data.push(0x04);
+ if (data[1] != 0x04) return true;
+ uint l = data.push(0x03);
+ if (data[2] != 0x03) return true;
+ if (l != 0x03) return true;
}
}
)";
@@ -5453,11 +5539,11 @@ BOOST_AUTO_TEST_CASE(byte_array_pop)
contract c {
bytes data;
function test() public returns (uint x, uint y, uint l) {
- data.push(7);
- x = data.push(3);
+ data.push(0x07);
+ x = data.push(0x03);
data.pop();
data.pop();
- y = data.push(2);
+ y = data.push(0x02);
l = data.length;
}
}
@@ -5490,9 +5576,9 @@ BOOST_AUTO_TEST_CASE(byte_array_pop_storage_empty)
contract c {
bytes data;
function test() public {
- data.push(7);
- data.push(5);
- data.push(3);
+ data.push(0x07);
+ data.push(0x05);
+ data.push(0x03);
data.pop();
data.pop();
data.pop();
@@ -5538,7 +5624,7 @@ BOOST_AUTO_TEST_CASE(byte_array_pop_long_storage_empty_garbage_ref)
bytes data;
function test() public {
for (uint8 i = 0; i <= 40; i++)
- data.push(3);
+ data.push(0x03);
for (uint8 j = 0; j <= 40; j++) {
assembly {
mstore(0, "garbage")
@@ -5560,7 +5646,7 @@ BOOST_AUTO_TEST_CASE(byte_array_pop_masking_long)
bytes data;
function test() public returns (bytes memory) {
for (uint i = 0; i < 34; i++)
- data.push(3);
+ data.push(0x03);
data.pop();
return data;
}
@@ -5582,7 +5668,7 @@ BOOST_AUTO_TEST_CASE(byte_array_pop_copy_long)
bytes data;
function test() public returns (bytes memory) {
for (uint i = 0; i < 33; i++)
- data.push(3);
+ data.push(0x03);
for (uint j = 0; j < 4; j++)
data.pop();
return data;
@@ -5672,10 +5758,10 @@ BOOST_AUTO_TEST_CASE(bytes_index_access)
data[31] = 0x77;
data[32] = 0x14;
- data[31] = 1;
- data[31] |= 8;
- data[30] = 1;
- data[32] = 3;
+ data[31] = 0x01;
+ data[31] |= 0x08;
+ data[30] = 0x01;
+ data[32] = 0x03;
return uint(uint8(data[30])) * 0x100 | uint(uint8(data[31])) * 0x10 | uint(uint8(data[32]));
}
}
@@ -5703,7 +5789,7 @@ BOOST_AUTO_TEST_CASE(bytes_delete_element)
delete data[94];
delete data[96];
delete data[98];
- return data[94] == 0 && data[95] == 95 && data[96] == 0 && data[97] == 97;
+ return data[94] == 0 && uint8(data[95]) == 95 && data[96] == 0 && uint8(data[97]) == 97;
}
}
)";
@@ -6060,19 +6146,19 @@ BOOST_AUTO_TEST_CASE(packed_storage_structs_bytes)
s2 data;
byte y;
function test() public returns (bool) {
- x = 1;
- data.a = 2;
- data.inner.a = 3;
- data.inner.b = 4;
+ x = 0x01;
+ data.a = 0x02;
+ data.inner.a = 0x03;
+ data.inner.b = 0x04;
data.inner.c = "1234567890";
data.inner.d = "123456789";
data.inner.e = "abcdefghij";
- data.b = 5;
- data.c = 6;
- y = 7;
- return x == 1 && data.a == 2 && data.inner.a == 3 && data.inner.b == 4 &&
+ data.b = 0x05;
+ data.c = byte(0x06);
+ y = 0x07;
+ return x == 0x01 && data.a == 0x02 && data.inner.a == 0x03 && data.inner.b == 0x04 &&
data.inner.c == "1234567890" && data.inner.d == "123456789" &&
- data.inner.e == "abcdefghij" && data.b == 5 && data.c == 6 && y == 7;
+ data.inner.e == "abcdefghij" && data.b == 0x05 && data.c == byte(0x06) && y == 0x07;
}
}
)";
@@ -7961,6 +8047,162 @@ BOOST_AUTO_TEST_CASE(internal_types_in_library)
ABI_CHECK(callContractFunction("f()"), encodeArgs(u256(4), u256(17)));
}
+BOOST_AUTO_TEST_CASE(mapping_arguments_in_library)
+{
+ char const* sourceCode = R"(
+ library Lib {
+ function set(mapping(uint => uint) storage m, uint key, uint value) internal
+ {
+ m[key] = value;
+ }
+ function get(mapping(uint => uint) storage m, uint key) internal view returns (uint)
+ {
+ return m[key];
+ }
+ }
+ contract Test {
+ mapping(uint => uint) m;
+ function set(uint256 key, uint256 value) public returns (uint)
+ {
+ uint oldValue = Lib.get(m, key);
+ Lib.set(m, key, value);
+ return oldValue;
+ }
+ function get(uint256 key) public view returns (uint) {
+ return Lib.get(m, key);
+ }
+ }
+ )";
+ compileAndRun(sourceCode, 0, "Lib");
+ compileAndRun(sourceCode, 0, "Test", bytes(), map<string, Address>{{"Lib", m_contractAddress}});
+ ABI_CHECK(callContractFunction("set(uint256,uint256)", u256(1), u256(42)), encodeArgs(u256(0)));
+ ABI_CHECK(callContractFunction("set(uint256,uint256)", u256(2), u256(84)), encodeArgs(u256(0)));
+ ABI_CHECK(callContractFunction("set(uint256,uint256)", u256(21), u256(7)), encodeArgs(u256(0)));
+ ABI_CHECK(callContractFunction("get(uint256)", u256(0)), encodeArgs(u256(0)));
+ ABI_CHECK(callContractFunction("get(uint256)", u256(1)), encodeArgs(u256(42)));
+ ABI_CHECK(callContractFunction("get(uint256)", u256(2)), encodeArgs(u256(84)));
+ ABI_CHECK(callContractFunction("get(uint256)", u256(21)), encodeArgs(u256(7)));
+ ABI_CHECK(callContractFunction("set(uint256,uint256)", u256(1), u256(21)), encodeArgs(u256(42)));
+ ABI_CHECK(callContractFunction("set(uint256,uint256)", u256(2), u256(42)), encodeArgs(u256(84)));
+ ABI_CHECK(callContractFunction("set(uint256,uint256)", u256(21), u256(14)), encodeArgs(u256(7)));
+ ABI_CHECK(callContractFunction("get(uint256)", u256(0)), encodeArgs(u256(0)));
+ ABI_CHECK(callContractFunction("get(uint256)", u256(1)), encodeArgs(u256(21)));
+ ABI_CHECK(callContractFunction("get(uint256)", u256(2)), encodeArgs(u256(42)));
+ ABI_CHECK(callContractFunction("get(uint256)", u256(21)), encodeArgs(u256(14)));
+}
+
+BOOST_AUTO_TEST_CASE(mapping_returns_in_library)
+{
+ char const* sourceCode = R"(
+ library Lib {
+ function choose_mapping(mapping(uint => uint) storage a, mapping(uint => uint) storage b, bool c) internal pure returns(mapping(uint=>uint) storage)
+ {
+ return c ? a : b;
+ }
+ }
+ contract Test {
+ mapping(uint => uint) a;
+ mapping(uint => uint) b;
+ function set(bool choice, uint256 key, uint256 value) public returns (uint)
+ {
+ mapping(uint => uint) storage m = Lib.choose_mapping(a, b, choice);
+ uint oldValue = m[key];
+ m[key] = value;
+ return oldValue;
+ }
+ function get(bool choice, uint256 key) public view returns (uint) {
+ return Lib.choose_mapping(a, b, choice)[key];
+ }
+ function get_a(uint256 key) public view returns (uint) {
+ return a[key];
+ }
+ function get_b(uint256 key) public view returns (uint) {
+ return b[key];
+ }
+ }
+ )";
+ compileAndRun(sourceCode, 0, "Lib");
+ compileAndRun(sourceCode, 0, "Test", bytes(), map<string, Address>{{"Lib", m_contractAddress}});
+ ABI_CHECK(callContractFunction("set(bool,uint256,uint256)", true, u256(1), u256(42)), encodeArgs(u256(0)));
+ ABI_CHECK(callContractFunction("set(bool,uint256,uint256)", true, u256(2), u256(84)), encodeArgs(u256(0)));
+ ABI_CHECK(callContractFunction("set(bool,uint256,uint256)", true, u256(21), u256(7)), encodeArgs(u256(0)));
+ ABI_CHECK(callContractFunction("set(bool,uint256,uint256)", false, u256(1), u256(10)), encodeArgs(u256(0)));
+ ABI_CHECK(callContractFunction("set(bool,uint256,uint256)", false, u256(2), u256(11)), encodeArgs(u256(0)));
+ ABI_CHECK(callContractFunction("set(bool,uint256,uint256)", false, u256(21), u256(12)), encodeArgs(u256(0)));
+ ABI_CHECK(callContractFunction("get(bool,uint256)", true, u256(0)), encodeArgs(u256(0)));
+ ABI_CHECK(callContractFunction("get(bool,uint256)", true, u256(1)), encodeArgs(u256(42)));
+ ABI_CHECK(callContractFunction("get(bool,uint256)", true, u256(2)), encodeArgs(u256(84)));
+ ABI_CHECK(callContractFunction("get(bool,uint256)", true, u256(21)), encodeArgs(u256(7)));
+ ABI_CHECK(callContractFunction("get_a(uint256)", u256(0)), encodeArgs(u256(0)));
+ ABI_CHECK(callContractFunction("get_a(uint256)", u256(1)), encodeArgs(u256(42)));
+ ABI_CHECK(callContractFunction("get_a(uint256)", u256(2)), encodeArgs(u256(84)));
+ ABI_CHECK(callContractFunction("get_a(uint256)", u256(21)), encodeArgs(u256(7)));
+ ABI_CHECK(callContractFunction("get(bool,uint256)", false, u256(0)), encodeArgs(u256(0)));
+ ABI_CHECK(callContractFunction("get(bool,uint256)", false, u256(1)), encodeArgs(u256(10)));
+ ABI_CHECK(callContractFunction("get(bool,uint256)", false, u256(2)), encodeArgs(u256(11)));
+ ABI_CHECK(callContractFunction("get(bool,uint256)", false, u256(21)), encodeArgs(u256(12)));
+ ABI_CHECK(callContractFunction("get_b(uint256)", u256(0)), encodeArgs(u256(0)));
+ ABI_CHECK(callContractFunction("get_b(uint256)", u256(1)), encodeArgs(u256(10)));
+ ABI_CHECK(callContractFunction("get_b(uint256)", u256(2)), encodeArgs(u256(11)));
+ ABI_CHECK(callContractFunction("get_b(uint256)", u256(21)), encodeArgs(u256(12)));
+ ABI_CHECK(callContractFunction("set(bool,uint256,uint256)", true, u256(1), u256(21)), encodeArgs(u256(42)));
+ ABI_CHECK(callContractFunction("set(bool,uint256,uint256)", true, u256(2), u256(42)), encodeArgs(u256(84)));
+ ABI_CHECK(callContractFunction("set(bool,uint256,uint256)", true, u256(21), u256(14)), encodeArgs(u256(7)));
+ ABI_CHECK(callContractFunction("set(bool,uint256,uint256)", false, u256(1), u256(30)), encodeArgs(u256(10)));
+ ABI_CHECK(callContractFunction("set(bool,uint256,uint256)", false, u256(2), u256(31)), encodeArgs(u256(11)));
+ ABI_CHECK(callContractFunction("set(bool,uint256,uint256)", false, u256(21), u256(32)), encodeArgs(u256(12)));
+ ABI_CHECK(callContractFunction("get_a(uint256)", u256(0)), encodeArgs(u256(0)));
+ ABI_CHECK(callContractFunction("get_a(uint256)", u256(1)), encodeArgs(u256(21)));
+ ABI_CHECK(callContractFunction("get_a(uint256)", u256(2)), encodeArgs(u256(42)));
+ ABI_CHECK(callContractFunction("get_a(uint256)", u256(21)), encodeArgs(u256(14)));
+ ABI_CHECK(callContractFunction("get(bool,uint256)", true, u256(0)), encodeArgs(u256(0)));
+ ABI_CHECK(callContractFunction("get(bool,uint256)", true, u256(1)), encodeArgs(u256(21)));
+ ABI_CHECK(callContractFunction("get(bool,uint256)", true, u256(2)), encodeArgs(u256(42)));
+ ABI_CHECK(callContractFunction("get(bool,uint256)", true, u256(21)), encodeArgs(u256(14)));
+ ABI_CHECK(callContractFunction("get_b(uint256)", u256(0)), encodeArgs(u256(0)));
+ ABI_CHECK(callContractFunction("get_b(uint256)", u256(1)), encodeArgs(u256(30)));
+ ABI_CHECK(callContractFunction("get_b(uint256)", u256(2)), encodeArgs(u256(31)));
+ ABI_CHECK(callContractFunction("get_b(uint256)", u256(21)), encodeArgs(u256(32)));
+ ABI_CHECK(callContractFunction("get(bool,uint256)", false, u256(0)), encodeArgs(u256(0)));
+ ABI_CHECK(callContractFunction("get(bool,uint256)", false, u256(1)), encodeArgs(u256(30)));
+ ABI_CHECK(callContractFunction("get(bool,uint256)", false, u256(2)), encodeArgs(u256(31)));
+ ABI_CHECK(callContractFunction("get(bool,uint256)", false, u256(21)), encodeArgs(u256(32)));
+}
+
+BOOST_AUTO_TEST_CASE(mapping_returns_in_library_named)
+{
+ char const* sourceCode = R"(
+ library Lib {
+ function f(mapping(uint => uint) storage a, mapping(uint => uint) storage b) internal returns(mapping(uint=>uint) storage r)
+ {
+ r = a;
+ r[1] = 42;
+ r = b;
+ r[1] = 21;
+ }
+ }
+ contract Test {
+ mapping(uint => uint) a;
+ mapping(uint => uint) b;
+ function f() public returns (uint, uint, uint, uint, uint, uint)
+ {
+ Lib.f(a, b)[2] = 84;
+ return (a[0], a[1], a[2], b[0], b[1], b[2]);
+ }
+ function g() public returns (uint, uint, uint, uint, uint, uint)
+ {
+ mapping(uint => uint) storage m = Lib.f(a, b);
+ m[2] = 17;
+ return (a[0], a[1], a[2], b[0], b[1], b[2]);
+ }
+ }
+ )";
+ compileAndRun(sourceCode, 0, "Lib");
+ compileAndRun(sourceCode, 0, "Test", bytes(), map<string, Address>{{"Lib", m_contractAddress}});
+ ABI_CHECK(callContractFunction("f()"), encodeArgs(u256(0), u256(42), u256(0), u256(0), u256(21), u256(84)));
+ ABI_CHECK(callContractFunction("g()"), encodeArgs(u256(0), u256(42), u256(0), u256(0), u256(21), u256(17)));
+}
+
BOOST_AUTO_TEST_CASE(using_library_structs)
{
char const* sourceCode = R"(
@@ -8062,17 +8304,17 @@ BOOST_AUTO_TEST_CASE(short_strings)
if (data1[4] != "4") return 11;
for (uint i = 0; i < data1.length; i ++)
data1[i] = byte(uint8(i * 3));
- if (data1[4] != 4 * 3) return 12;
- if (data1[67] != 67 * 3) return 13;
+ if (uint8(data1[4]) != 4 * 3) return 12;
+ if (uint8(data1[67]) != 67 * 3) return 13;
// change length: long -> short
data1.length = 22;
if (data1.length != 22) return 14;
- if (data1[21] != byte(21 * 3)) return 15;
- if (data1[2] != 2 * 3) return 16;
+ if (uint8(data1[21]) != 21 * 3) return 15;
+ if (uint8(data1[2]) != 2 * 3) return 16;
// change length: short -> shorter
data1.length = 19;
if (data1.length != 19) return 17;
- if (data1[7] != byte(7 * 3)) return 18;
+ if (uint8(data1[7]) != 7 * 3) return 18;
// and now again to original size
data1.length = 22;
if (data1.length != 22) return 19;
@@ -8888,7 +9130,7 @@ BOOST_AUTO_TEST_CASE(fixed_bytes_length_access)
contract C {
byte a;
function f(bytes32 x) public returns (uint, uint, uint) {
- return (x.length, bytes16(2).length, a.length + 7);
+ return (x.length, bytes16(uint128(2)).length, a.length + 7);
}
}
)";
@@ -9383,9 +9625,9 @@ BOOST_AUTO_TEST_CASE(iszero_bnot_correct)
char const* sourceCode = R"(
contract C {
function f() public returns (bool) {
- bytes32 x = 1;
+ bytes32 x = bytes32(uint256(1));
assembly { x := not(x) }
- if (x != ~bytes32(1)) return false;
+ if (x != ~bytes32(uint256(1))) return false;
assembly { x := iszero(x) }
if (x != bytes32(0)) return false;
return true;
@@ -9404,7 +9646,7 @@ BOOST_AUTO_TEST_CASE(cleanup_bytes_types)
function f(bytes2 a, uint16 x) public returns (uint) {
if (a != "ab") return 1;
if (x != 0x0102) return 2;
- if (bytes3(uint24(x)) != 0x0102) return 3;
+ if (bytes3(uint24(x)) != 0x000102) return 3;
return 0;
}
}
@@ -9736,7 +9978,7 @@ BOOST_AUTO_TEST_CASE(failing_ecrecover_invalid_input)
char const* sourceCode = R"(
contract C {
function f() public returns (address) {
- return ecrecover(bytes32(uint(-1)), 1, 2, 3);
+ return ecrecover(bytes32(uint(-1)), 1, bytes32(uint(2)), bytes32(uint(3)));
}
}
)";
@@ -9754,8 +9996,8 @@ BOOST_AUTO_TEST_CASE(failing_ecrecover_invalid_input_proper)
0, // invalid v value
0x6944c77849b18048f6abe0db8084b0d0d0689cdddb53d2671c36967b58691ad4,
0xef4f06ba4f78319baafd0424365777241af4dfd3da840471b4b4b087b7750d0d,
- 0x00ca35b7d915458ef540ade6068dfe2f44e8fa733c,
- 0x00ca35b7d915458ef540ade6068dfe2f44e8fa733c
+ 0x000000000000000000000000ca35b7d915458ef540ade6068dfe2f44e8fa733c,
+ 0x000000000000000000000000ca35b7d915458ef540ade6068dfe2f44e8fa733c
);
}
function recover(bytes32 hash, uint8 v, bytes32 r, bytes32 s, uint blockExpired, bytes32 salt)