From 5a8df54a185a4cbc36d9c03c0d68cfd9885d048d Mon Sep 17 00:00:00 2001 From: chriseth Date: Wed, 14 Oct 2020 17:20:33 +0200 Subject: [PATCH] Update EndToEnd tests. --- test/ExecutionFramework.cpp | 8 ++++++++ test/ExecutionFramework.h | 2 ++ test/libsolidity/SolidityEndToEndTest.cpp | 25 +++++++++-------------- 3 files changed, 20 insertions(+), 15 deletions(-) diff --git a/test/ExecutionFramework.cpp b/test/ExecutionFramework.cpp index a17f65f3cd4f..c96fdc01b645 100644 --- a/test/ExecutionFramework.cpp +++ b/test/ExecutionFramework.cpp @@ -28,6 +28,7 @@ #include #include +#include #include @@ -112,6 +113,13 @@ std::pair ExecutionFramework::compareAndCreateMessage( return make_pair(false, message); } +bytes ExecutionFramework::panicData(util::PanicCode _code) +{ + return + toCompactBigEndian(selectorFromSignature32("Panic(uint256)"), 4) + + encode(u256(_code)); +} + u256 ExecutionFramework::gasLimit() const { return {m_evmcHost->tx_context.block_gas_limit}; diff --git a/test/ExecutionFramework.h b/test/ExecutionFramework.h index 9b01d9a91cfd..4768629dcad0 100644 --- a/test/ExecutionFramework.h +++ b/test/ExecutionFramework.h @@ -33,6 +33,7 @@ #include #include +#include #include @@ -200,6 +201,7 @@ class ExecutionFramework { return bytes(); } + static bytes panicData(util::PanicCode _code); //@todo might be extended in the future template diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp index f8161c9ea755..6dad6ebc2117 100644 --- a/test/libsolidity/SolidityEndToEndTest.cpp +++ b/test/libsolidity/SolidityEndToEndTest.cpp @@ -33,6 +33,7 @@ #include #include +#include #include #include @@ -2616,7 +2617,7 @@ BOOST_AUTO_TEST_CASE(generic_staticcall) ABI_CHECK(callContractFunction("g(address)", c_addressA), encodeArgs(true, 0x40, 0x20, 23 + 42)); ABI_CHECK(callContractFunction("h(address)", c_addressA), encodeArgs(false, 0x40, 0x00)); ABI_CHECK(callContractFunction("i(address,uint256)", c_addressA, 42), encodeArgs(true, 0x40, 0x20, 42)); - ABI_CHECK(callContractFunction("i(address,uint256)", c_addressA, 23), encodeArgs(false, 0x40, 0x00)); + ABI_CHECK(callContractFunction("i(address,uint256)", c_addressA, 23), encodeArgs(false, 0x40, 0x24) + panicData(PanicCode::Assert) + bytes(32 - 4, 0)); } } @@ -3740,8 +3741,7 @@ BOOST_AUTO_TEST_CASE(invalid_enum_logged) BOOST_REQUIRE_EQUAL(logTopic(0, 0), util::keccak256(string("Log(uint8)"))); BOOST_CHECK_EQUAL(h256(logData(0)), h256(u256(0))); - // should throw - ABI_CHECK(callContractFunction("test_log()"), encodeArgs()); + ABI_CHECK(callContractFunction("test_log()"), panicData(PanicCode::EnumConversionError)); } BOOST_AUTO_TEST_CASE(evm_exceptions_in_constructor_out_of_baund) @@ -3758,7 +3758,7 @@ BOOST_AUTO_TEST_CASE(evm_exceptions_in_constructor_out_of_baund) } } )"; - ABI_CHECK(compileAndRunWithoutCheck({{"", sourceCode}}, 0, "A"), encodeArgs()); + ABI_CHECK(compileAndRunWithoutCheck({{"", sourceCode}}, 0, "A"), panicData(PanicCode::ArrayOutOfBounds)); BOOST_CHECK(!m_transactionSuccessful); } @@ -4238,7 +4238,7 @@ BOOST_AUTO_TEST_CASE(calldata_bytes_array_bounds) ); ABI_CHECK( callContractFunction("f(bytes[],uint256)", 0x40, 2, 1, 0x20, 2, bytes{'a', 'b'} + bytes(30, 0)), - encodeArgs() + panicData(PanicCode::ArrayOutOfBounds) ); } @@ -4288,11 +4288,9 @@ BOOST_AUTO_TEST_CASE(calldata_array_two_dimensional) ABI_CHECK(callContractFunction("test(" + arrayType + ",uint256,uint256)", 0x60, i, j, encoding), encodeArgs(data[i][j])); ABI_CHECK(callContractFunction("reenc(" + arrayType + ",uint256,uint256)", 0x60, i, j, encoding), encodeArgs(data[i][j])); } - // out of bounds access - ABI_CHECK(callContractFunction("test(" + arrayType + ",uint256,uint256)", 0x60, i, data[i].size(), encoding), encodeArgs()); + ABI_CHECK(callContractFunction("test(" + arrayType + ",uint256,uint256)", 0x60, i, data[i].size(), encoding), panicData(PanicCode::ArrayOutOfBounds)); } - // out of bounds access - ABI_CHECK(callContractFunction("test(" + arrayType + ",uint256)", 0x40, data.size(), encoding), encodeArgs()); + ABI_CHECK(callContractFunction("test(" + arrayType + ",uint256)", 0x40, data.size(), encoding), panicData(PanicCode::ArrayOutOfBounds)); } } @@ -4370,14 +4368,11 @@ BOOST_AUTO_TEST_CASE(calldata_array_dynamic_three_dimensional) ABI_CHECK(callContractFunction("test(" + arrayType + ",uint256,uint256,uint256)", 0x80, i, j, k, encoding), encodeArgs(data[i][j][k])); ABI_CHECK(callContractFunction("reenc(" + arrayType + ",uint256,uint256,uint256)", 0x80, i, j, k, encoding), encodeArgs(data[i][j][k])); } - // out of bounds access - ABI_CHECK(callContractFunction("test(" + arrayType + ",uint256,uint256,uint256)", 0x80, i, j, data[i][j].size(), encoding), encodeArgs()); + ABI_CHECK(callContractFunction("test(" + arrayType + ",uint256,uint256,uint256)", 0x80, i, j, data[i][j].size(), encoding), panicData(PanicCode::ArrayOutOfBounds)); } - // out of bounds access - ABI_CHECK(callContractFunction("test(" + arrayType + ",uint256,uint256)", 0x60, i, data[i].size(), encoding), encodeArgs()); + ABI_CHECK(callContractFunction("test(" + arrayType + ",uint256,uint256)", 0x60, i, data[i].size(), encoding), panicData(PanicCode::ArrayOutOfBounds)); } - // out of bounds access - ABI_CHECK(callContractFunction("test(" + arrayType + ",uint256)", 0x40, data.size(), encoding), encodeArgs()); + ABI_CHECK(callContractFunction("test(" + arrayType + ",uint256)", 0x40, data.size(), encoding), panicData(PanicCode::ArrayOutOfBounds)); } }