Merge pull request #7081 from ethereum/EndToEndTest-extractions-3

Extracting more end-to-end tests.
This commit is contained in:
Christian Parpart 2019-07-23 14:04:45 +02:00 committed by GitHub
commit 146993409a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 114 additions and 220 deletions

View File

@ -1195,212 +1195,6 @@ BOOST_AUTO_TEST_CASE(now)
)
}
BOOST_AUTO_TEST_CASE(type_conversions_cleanup)
{
// 22-byte integer converted to a contract (i.e. address, 20 bytes), converted to a 32 byte
// integer should drop the first two bytes
char const* sourceCode = R"(
contract Test {
function test() public returns (uint ret) { return uint(address(Test(address(0x11223344556677889900112233445566778899001122)))); }
}
)";
ALSO_VIA_YUL(
compileAndRun(sourceCode);
BOOST_REQUIRE(callContractFunction("test()") == bytes({0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0x00, 0x11, 0x22,
0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0x00, 0x11, 0x22}));
)
}
// fixed bytes to fixed bytes conversion tests
BOOST_AUTO_TEST_CASE(convert_fixed_bytes_to_fixed_bytes_smaller_size)
{
char const* sourceCode = R"(
contract Test {
function bytesToBytes(bytes4 input) public returns (bytes2 ret) {
return bytes2(input);
}
}
)";
ALSO_VIA_YUL(
compileAndRun(sourceCode);
ABI_CHECK(callContractFunction("bytesToBytes(bytes4)", "abcd"), encodeArgs("ab"));
)
}
BOOST_AUTO_TEST_CASE(convert_fixed_bytes_to_fixed_bytes_greater_size)
{
char const* sourceCode = R"(
contract Test {
function bytesToBytes(bytes2 input) public returns (bytes4 ret) {
return bytes4(input);
}
}
)";
ALSO_VIA_YUL(
compileAndRun(sourceCode);
ABI_CHECK(callContractFunction("bytesToBytes(bytes2)", "ab"), encodeArgs("ab"));
)
}
BOOST_AUTO_TEST_CASE(convert_fixed_bytes_to_fixed_bytes_same_size)
{
char const* sourceCode = R"(
contract Test {
function bytesToBytes(bytes4 input) public returns (bytes4 ret) {
return bytes4(input);
}
}
)";
ALSO_VIA_YUL(
compileAndRun(sourceCode);
ABI_CHECK(callContractFunction("bytesToBytes(bytes4)", "abcd"), encodeArgs("abcd"));
)
}
// fixed bytes to uint conversion tests
BOOST_AUTO_TEST_CASE(convert_fixed_bytes_to_uint_same_size)
{
char const* sourceCode = R"(
contract Test {
function bytesToUint(bytes32 s) public returns (uint256 h) {
return uint(s);
}
}
)";
ALSO_VIA_YUL(
compileAndRun(sourceCode);
ABI_CHECK(
callContractFunction("bytesToUint(bytes32)", string("abc2")),
encodeArgs(u256("0x6162633200000000000000000000000000000000000000000000000000000000"))
);
)
}
BOOST_AUTO_TEST_CASE(convert_fixed_bytes_to_uint_same_min_size)
{
char const* sourceCode = R"(
contract Test {
function bytesToUint(bytes1 s) public returns (uint8 h) {
return uint8(s);
}
}
)";
ALSO_VIA_YUL(
compileAndRun(sourceCode);
ABI_CHECK(
callContractFunction("bytesToUint(bytes1)", string("a")),
encodeArgs(u256("0x61"))
);
)
}
BOOST_AUTO_TEST_CASE(convert_fixed_bytes_to_uint_smaller_size)
{
char const* sourceCode = R"(
contract Test {
function bytesToUint(bytes4 s) public returns (uint16 h) {
return uint16(uint32(s));
}
}
)";
ALSO_VIA_YUL(
compileAndRun(sourceCode);
ABI_CHECK(
callContractFunction("bytesToUint(bytes4)", string("abcd")),
encodeArgs(u256("0x6364"))
);
)
}
BOOST_AUTO_TEST_CASE(convert_fixed_bytes_to_uint_greater_size)
{
char const* sourceCode = R"(
contract Test {
function bytesToUint(bytes4 s) public returns (uint64 h) {
return uint64(uint32(s));
}
}
)";
ALSO_VIA_YUL(
compileAndRun(sourceCode);
ABI_CHECK(
callContractFunction("bytesToUint(bytes4)", string("abcd")),
encodeArgs(u256("0x61626364"))
);
)
}
// uint fixed bytes conversion tests
BOOST_AUTO_TEST_CASE(convert_uint_to_fixed_bytes_same_size)
{
char const* sourceCode = R"(
contract Test {
function uintToBytes(uint256 h) public returns (bytes32 s) {
return bytes32(h);
}
}
)";
ALSO_VIA_YUL(
compileAndRun(sourceCode);
u256 a("0x6162630000000000000000000000000000000000000000000000000000000000");
ABI_CHECK(callContractFunction("uintToBytes(uint256)", a), encodeArgs(a));
)
}
BOOST_AUTO_TEST_CASE(convert_uint_to_fixed_bytes_same_min_size)
{
char const* sourceCode = R"(
contract Test {
function UintToBytes(uint8 h) public returns (bytes1 s) {
return bytes1(h);
}
}
)";
ALSO_VIA_YUL(
compileAndRun(sourceCode);
ABI_CHECK(
callContractFunction("UintToBytes(uint8)", u256("0x61")),
encodeArgs(string("a"))
);
)
}
BOOST_AUTO_TEST_CASE(convert_uint_to_fixed_bytes_smaller_size)
{
char const* sourceCode = R"(
contract Test {
function uintToBytes(uint32 h) public returns (bytes2 s) {
return bytes2(uint16(h));
}
}
)";
ALSO_VIA_YUL(
compileAndRun(sourceCode);
ABI_CHECK(
callContractFunction("uintToBytes(uint32)", u160("0x61626364")),
encodeArgs(string("cd"))
);
)
}
BOOST_AUTO_TEST_CASE(convert_uint_to_fixed_bytes_greater_size)
{
char const* sourceCode = R"(
contract Test {
function UintToBytes(uint16 h) public returns (bytes8 s) {
return bytes8(uint64(h));
}
}
)";
ALSO_VIA_YUL(
compileAndRun(sourceCode);
ABI_CHECK(
callContractFunction("UintToBytes(uint16)", u256("0x6162")),
encodeArgs(string("\0\0\0\0\0\0ab", 8))
);
)
}
BOOST_AUTO_TEST_CASE(send_ether)
{
char const* sourceCode = R"(
@ -1471,20 +1265,6 @@ BOOST_AUTO_TEST_CASE(uncalled_blockhash)
BOOST_CHECK(result[0] != 0 || result[1] != 0 || result[2] != 0);
}
BOOST_AUTO_TEST_CASE(blockhash_shadow_resolution)
{
char const* code = R"(
contract C {
function blockhash(uint256 blockNumber) public returns(bytes32) { bytes32 x; return x; }
function f() public returns(bytes32) { return blockhash(3); }
}
)";
ALSO_VIA_YUL(
compileAndRun(code, 0, "C");
ABI_CHECK(callContractFunction("f()"), encodeArgs(0));
)
}
BOOST_AUTO_TEST_CASE(log0)
{
char const* sourceCode = R"(

View File

@ -0,0 +1,8 @@
contract C {
function blockhash(uint256 blockNumber) public returns(bytes32) { bytes32 x; return x; }
function f() public returns(bytes32) { return blockhash(3); }
}
// ====
// compileViaYul: also
// ----
// f() -> 0

View File

@ -0,0 +1,9 @@
contract Test {
function bytesToBytes(bytes2 input) public returns (bytes4 ret) {
return bytes4(input);
}
}
// ====
// compileViaYul: also
// ----
// bytesToBytes(bytes2): "ab" -> "ab"

View File

@ -0,0 +1,9 @@
contract Test {
function bytesToBytes(bytes4 input) public returns (bytes4 ret) {
return bytes4(input);
}
}
// ====
// compileViaYul: also
// ----
// bytesToBytes(bytes4): "abcd" -> "abcd"

View File

@ -0,0 +1,9 @@
contract Test {
function bytesToBytes(bytes4 input) public returns (bytes2 ret) {
return bytes2(input);
}
}
// ====
// compileViaYul: also
// ----
// bytesToBytes(bytes4): "abcd" -> "ab"

View File

@ -0,0 +1,9 @@
contract Test {
function bytesToUint(bytes4 s) public returns (uint64 h) {
return uint64(uint32(s));
}
}
// ====
// compileViaYul: also
// ----
// bytesToUint(bytes4): "abcd" -> 0x61626364

View File

@ -0,0 +1,9 @@
contract Test {
function bytesToUint(bytes1 s) public returns (uint8 h) {
return uint8(s);
}
}
// ====
// compileViaYul: also
// ----
// bytesToUint(bytes1): "a" -> 0x61

View File

@ -0,0 +1,9 @@
contract Test {
function bytesToUint(bytes32 s) public returns (uint256 h) {
return uint(s);
}
}
// ====
// compileViaYul: also
// ----
// bytesToUint(bytes32): "abc2" -> left(0x61626332)

View File

@ -0,0 +1,9 @@
contract Test {
function bytesToUint(bytes4 s) public returns (uint16 h) {
return uint16(uint32(s));
}
}
// ====
// compileViaYul: also
// ----
// bytesToUint(bytes4): "abcd" -> 0x6364

View File

@ -0,0 +1,9 @@
contract Test {
function UintToBytes(uint16 h) public returns (bytes8 s) {
return bytes8(uint64(h));
}
}
// ====
// compileViaYul: also
// ----
// UintToBytes(uint16): 0x6162 -> "\0\0\0\0\0\0ab"

View File

@ -0,0 +1,9 @@
contract Test {
function UintToBytes(uint8 h) public returns (bytes1 s) {
return bytes1(h);
}
}
// ====
// compileViaYul: also
// ----
// UintToBytes(uint8): 0x61 -> "a"

View File

@ -0,0 +1,9 @@
contract Test {
function uintToBytes(uint256 h) public returns (bytes32 s) {
return bytes32(h);
}
}
// ====
// compileViaYul: also
// ----
// uintToBytes(uint256): left(0x616263) -> left(0x616263)

View File

@ -0,0 +1,9 @@
contract Test {
function uintToBytes(uint32 h) public returns (bytes2 s) {
return bytes2(uint16(h));
}
}
// ====
// compileViaYul: also
// ----
// uintToBytes(uint32): 0x61626364 -> "cd"

View File

@ -0,0 +1,7 @@
contract Test {
function test() public returns (uint ret) { return uint(address(Test(address(0x11223344556677889900112233445566778899001122)))); }
}
// ====
// compileViaYul: also
// ----
// test() -> 0x0000000000000000000000003344556677889900112233445566778899001122