aboutsummaryrefslogtreecommitdiffstats
path: root/test/libsolidity/SolidityEndToEndTest.cpp
diff options
context:
space:
mode:
authorDaniel Kirchner <daniel@ekpyron.org>2018-08-06 20:59:37 +0800
committerDaniel Kirchner <daniel@ekpyron.org>2018-08-13 20:27:01 +0800
commit7d7abeb1496dddfab7eb8705dbfc3d06284cf25d (patch)
tree2909fe73439256e0f77231ec219b1b9af6fefd5a /test/libsolidity/SolidityEndToEndTest.cpp
parent43db88b8363d73ee2f5ffa094ff506414261bd11 (diff)
downloaddexon-solidity-7d7abeb1496dddfab7eb8705dbfc3d06284cf25d.tar.gz
dexon-solidity-7d7abeb1496dddfab7eb8705dbfc3d06284cf25d.tar.zst
dexon-solidity-7d7abeb1496dddfab7eb8705dbfc3d06284cf25d.zip
Disallow ambiguous conversions between number literals and bytesXX types.
Diffstat (limited to 'test/libsolidity/SolidityEndToEndTest.cpp')
-rw-r--r--test/libsolidity/SolidityEndToEndTest.cpp106
1 files changed, 53 insertions, 53 deletions
diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp
index e487f0ae..2c7e3947 100644
--- a/test/libsolidity/SolidityEndToEndTest.cpp
+++ b/test/libsolidity/SolidityEndToEndTest.cpp
@@ -2211,7 +2211,7 @@ BOOST_AUTO_TEST_CASE(log0)
char const* sourceCode = R"(
contract test {
function a() public {
- log0(1);
+ log0(bytes32(uint256(1)));
}
}
)";
@@ -2228,7 +2228,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 +2246,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 +2265,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 +2284,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 +2303,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 +5017,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 +5076,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 +5274,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 +5453,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 +5490,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 +5538,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 +5560,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 +5582,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 +5672,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 +5703,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 +6060,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;
}
}
)";
@@ -8062,17 +8062,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 +8888,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 +9383,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 +9404,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 +9736,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 +9754,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)