Skip to content

Commit

Permalink
Update EndToEnd tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
chriseth committed Oct 14, 2020
1 parent 484e482 commit 5a8df54
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 15 deletions.
8 changes: 8 additions & 0 deletions test/ExecutionFramework.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include <test/evmc/evmc.hpp>

#include <libsolutil/CommonIO.h>
#include <libsolutil/FunctionSelector.h>

#include <liblangutil/Exceptions.h>

Expand Down Expand Up @@ -112,6 +113,13 @@ std::pair<bool, string> 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};
Expand Down
2 changes: 2 additions & 0 deletions test/ExecutionFramework.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@

#include <libsolutil/FixedHash.h>
#include <libsolutil/Keccak256.h>
#include <libsolutil/ErrorCodes.h>

#include <functional>

Expand Down Expand Up @@ -200,6 +201,7 @@ class ExecutionFramework
{
return bytes();
}
static bytes panicData(util::PanicCode _code);

//@todo might be extended in the future
template <class Arg>
Expand Down
25 changes: 10 additions & 15 deletions test/libsolidity/SolidityEndToEndTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include <libevmasm/Assembly.h>

#include <libsolutil/Keccak256.h>
#include <libsolutil/ErrorCodes.h>

#include <boost/range/adaptor/transformed.hpp>
#include <boost/test/unit_test.hpp>
Expand Down Expand Up @@ -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));
}
}

Expand Down Expand Up @@ -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)
Expand All @@ -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);
}

Expand Down Expand Up @@ -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)
);
}

Expand Down Expand Up @@ -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));
}
}

Expand Down Expand Up @@ -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));
}
}

Expand Down

0 comments on commit 5a8df54

Please sign in to comment.