Force running abi coder v1 instead of v2.

This commit is contained in:
chriseth 2020-11-19 16:58:41 +01:00
parent d525a8bccb
commit a5bd22795e
14 changed files with 46 additions and 58 deletions

View File

@ -11,7 +11,7 @@
#
# EVM=version_string Specifies EVM version to compile for (such as homestead, etc)
# OPTIMIZE=1 Enables backend optimizer
# ABI_ENCODER_V2=1 Enables ABI encoder version 2
# ABI_ENCODER_V1=1 Forcibly enables ABI coder version 1
# SOLTEST_FLAGS=<flags> Appends <flags> to default SOLTEST_ARGS
#
# ------------------------------------------------------------------------------
@ -49,7 +49,7 @@ ulimit -s 16384
get_logfile_basename() {
local filename="${EVM}"
test "${OPTIMIZE}" = "1" && filename="${filename}_opt"
test "${ABI_ENCODER_V2}" = "1" && filename="${filename}_abiv2"
test "${ABI_ENCODER_V1}" = "1" && filename="${filename}_abiv1"
echo -ne "${filename}"
}
@ -57,7 +57,7 @@ get_logfile_basename() {
BOOST_TEST_ARGS="--color_output=no --show_progress=yes --logger=JUNIT,error,test_results/`get_logfile_basename`.xml ${BOOST_TEST_ARGS}"
SOLTEST_ARGS="--evm-version=$EVM $SOLTEST_FLAGS"
test "${OPTIMIZE}" = "1" && SOLTEST_ARGS="${SOLTEST_ARGS} --optimize"
test "${ABI_ENCODER_V2}" = "1" && SOLTEST_ARGS="${SOLTEST_ARGS} --abiencoderv2"
test "${ABI_ENCODER_V1}" = "1" && SOLTEST_ARGS="${SOLTEST_ARGS} --abiencoderv1"
echo "Running ${REPODIR}/build/test/soltest ${BOOST_TEST_ARGS} -- ${SOLTEST_ARGS}"

View File

@ -58,11 +58,11 @@ echo "Running steps $RUN_STEPS..."
STEP=1
# Run SMTChecker tests separately, as the heaviest expected run.
[[ " $RUN_STEPS " =~ " $STEP " ]] && EVM=istanbul OPTIMIZE=1 ABI_ENCODER_V2=1 BOOST_TEST_ARGS="-t smtCheckerTests/*" "${REPODIR}/.circleci/soltest.sh"
[[ " $RUN_STEPS " =~ " $STEP " ]] && EVM=istanbul OPTIMIZE=1 ABI_ENCODER_V1=1 BOOST_TEST_ARGS="-t smtCheckerTests/*" "${REPODIR}/.circleci/soltest.sh"
STEP=$(($STEP + 1))
# Run without SMTChecker tests.
[[ " $RUN_STEPS " =~ " $STEP " ]] && EVM=istanbul OPTIMIZE=1 ABI_ENCODER_V2=1 BOOST_TEST_ARGS="-t !smtCheckerTests" "${REPODIR}/.circleci/soltest.sh"
[[ " $RUN_STEPS " =~ " $STEP " ]] && EVM=istanbul OPTIMIZE=1 ABI_ENCODER_V1=1 BOOST_TEST_ARGS="-t !smtCheckerTests" "${REPODIR}/.circleci/soltest.sh"
STEP=$(($STEP + 1))
for OPTIMIZE in ${OPTIMIZE_VALUES[@]}

View File

@ -90,19 +90,19 @@ for optimize in "" "--optimize"
do
for vm in $EVM_VERSIONS
do
FORCE_ABIV2_RUNS="no"
FORCE_ABIV1_RUNS="no"
if [[ "$vm" == "istanbul" ]]
then
FORCE_ABIV2_RUNS="no yes" # run both in istanbul
FORCE_ABIV1_RUNS="no yes" # run both in istanbul
fi
for abiv2 in $FORCE_ABIV2_RUNS
for abiv1 in $FORCE_ABIV1_RUNS
do
force_abiv2_flag=""
if [[ "$abiv2" == "yes" ]]
force_abiv1_flag=""
if [[ "$abiv1" == "yes" ]]
then
force_abiv2_flag="--abiencoderv2"
force_abiv1_flag="--abiencoderv1"
fi
printTask "--> Running tests using "$optimize" --evm-version "$vm" $force_abiv2_flag..."
printTask "--> Running tests using "$optimize" --evm-version "$vm" $force_abiv1_flag..."
log=""
if [ -n "$log_directory" ]
@ -119,7 +119,7 @@ do
[ "${vm}" = "byzantium" ] && [ "${optimize}" = "" ] && EWASM_ARGS="--ewasm"
set +e
"${SOLIDITY_BUILD_DIR}"/test/soltest --show-progress $log -- ${EWASM_ARGS} --testpath "$REPO_ROOT"/test "$optimize" --evm-version "$vm" $SMT_FLAGS $force_abiv2_flag
"${SOLIDITY_BUILD_DIR}"/test/soltest --show-progress $log -- ${EWASM_ARGS} --testpath "$REPO_ROOT"/test "$optimize" --evm-version "$vm" $SMT_FLAGS $force_abiv1_flag
if test "0" -ne "$?"; then
exit 1

View File

@ -98,7 +98,7 @@ CommonOptions::CommonOptions(std::string _caption):
("no-smt", po::bool_switch(&disableSMT), "disable SMT checker")
("optimize", po::bool_switch(&optimize), "enables optimization")
("enforce-via-yul", po::bool_switch(&enforceViaYul), "Enforce compiling all tests via yul to see if additional tests can be activated.")
("abiencoderv2", po::bool_switch(&useABIEncoderV2), "enables abi encoder v2")
("abiencoderv1", po::bool_switch(&useABIEncoderV1), "enables abi encoder v1")
("show-messages", po::bool_switch(&showMessages), "enables message output")
("show-metadata", po::bool_switch(&showMetadata), "enables metadata output");
}

View File

@ -57,7 +57,7 @@ struct CommonOptions: boost::noncopyable
bool optimize = false;
bool enforceViaYul = false;
bool disableSMT = false;
bool useABIEncoderV2 = false;
bool useABIEncoderV1 = false;
bool showMessages = false;
bool showMetadata = false;

View File

@ -468,7 +468,7 @@ BOOST_AUTO_TEST_CASE(creation)
{
deployWallet(200);
BOOST_REQUIRE(callContractFunction("isOwner(address)", m_sender) == encodeArgs(true));
bool v2 = solidity::test::CommonOptions::get().useABIEncoderV2;
bool v2 = !solidity::test::CommonOptions::get().useABIEncoderV1;
BOOST_REQUIRE(callContractFunction("isOwner(address)", h256(~0)) == (v2 ? encodeArgs() : encodeArgs(false)));
}

View File

@ -37,17 +37,6 @@ namespace solidity::frontend::test
BOOST_FIXTURE_TEST_SUITE(ABIDecoderTest, SolidityExecutionFramework)
BOOST_AUTO_TEST_CASE(both_encoders_macro)
{
// This tests that the "both decoders macro" at least runs twice and
// modifies the source.
string sourceCode;
int runs = 0;
BOTH_ENCODERS(runs++;)
BOOST_CHECK(sourceCode == NewEncoderPragma);
BOOST_CHECK_EQUAL(runs, 2);
}
BOOST_AUTO_TEST_CASE(value_types)
{
string sourceCode = R"(
@ -334,7 +323,7 @@ BOOST_AUTO_TEST_CASE(validation_function_type)
function i(function () external[] calldata a) external pure returns (uint r) { a[0]; r = 4; }
}
)";
bool newDecoder = solidity::test::CommonOptions::get().useABIEncoderV2;
bool newDecoder = false;
string validFun{"01234567890123456789abcd"};
string invalidFun{"01234567890123456789abcdX"};
BOTH_ENCODERS(

View File

@ -48,17 +48,6 @@ namespace solidity::frontend::test
BOOST_FIXTURE_TEST_SUITE(ABIEncoderTest, SolidityExecutionFramework)
BOOST_AUTO_TEST_CASE(both_encoders_macro)
{
// This tests that the "both encoders macro" at least runs twice and
// modifies the source.
string sourceCode;
int runs = 0;
BOTH_ENCODERS(runs++;)
BOOST_CHECK(sourceCode == NewEncoderPragma);
BOOST_CHECK_EQUAL(runs, 2);
}
BOOST_AUTO_TEST_CASE(value_types)
{
string sourceCode = R"(
@ -166,7 +155,7 @@ BOOST_AUTO_TEST_CASE(memory_array_one_dim)
}
)";
if (!solidity::test::CommonOptions::get().useABIEncoderV2)
if (solidity::test::CommonOptions::get().useABIEncoderV1)
{
compileAndRun(sourceCode);
callContractFunction("f()");
@ -174,9 +163,11 @@ BOOST_AUTO_TEST_CASE(memory_array_one_dim)
REQUIRE_LOG_DATA(encodeArgs(10, 0x60, 11, 3, u256("0xfffffffe"), u256("0xffffffff"), u256("0x100000000")));
}
compileAndRun(NewEncoderPragma + sourceCode);
NEW_ENCODER(
compileAndRun(sourceCode);
callContractFunction("f()");
REQUIRE_LOG_DATA(encodeArgs(10, 0x60, 11, 3, u256(-2), u256(-1), u256(0)));
)
}
BOOST_AUTO_TEST_CASE(memory_array_two_dim)

View File

@ -21,17 +21,25 @@
namespace solidity::frontend::test
{
static std::string const NewEncoderPragma = "pragma experimental ABIEncoderV2;\n";
#define NEW_ENCODER(CODE) \
{ \
sourceCode = NewEncoderPragma + sourceCode; \
string sourceCodeTmp = sourceCode; \
sourceCode = "pragma abicoder v2;\n" + sourceCode; \
{ CODE } \
sourceCode = sourceCodeTmp; \
}
#define OLD_ENCODER(CODE) \
{ \
string sourceCodeTmp = sourceCode; \
sourceCode = "pragma abicoder v1;\n" + sourceCode; \
{ CODE } \
sourceCode = sourceCodeTmp; \
}
#define BOTH_ENCODERS(CODE) \
{ \
{ CODE } \
OLD_ENCODER(CODE) \
NEW_ENCODER(CODE) \
}

View File

@ -99,7 +99,7 @@ BOOST_AUTO_TEST_CASE(string_storage)
if (evmVersion <= EVMVersion::byzantium())
CHECK_DEPLOY_GAS(133045, 129731, evmVersion);
// This is only correct on >=Constantinople.
else if (CommonOptions::get().useABIEncoderV2)
else if (!CommonOptions::get().useABIEncoderV1)
{
if (CommonOptions::get().optimize)
{
@ -128,7 +128,7 @@ BOOST_AUTO_TEST_CASE(string_storage)
if (evmVersion == EVMVersion::byzantium())
CHECK_GAS(21545, 21526, 20);
// This is only correct on >=Constantinople.
else if (CommonOptions::get().useABIEncoderV2)
else if (!CommonOptions::get().useABIEncoderV1)
{
if (CommonOptions::get().optimize)
{

View File

@ -62,9 +62,9 @@ public:
// costs for transaction
gas += gasForTransaction(m_compiler.object(m_compiler.lastContractName()).bytecode, true);
// Skip the tests when we force ABIEncoderV2.
// Skip the tests when we use ABIEncoderV2.
// TODO: We should enable this again once the yul optimizer is activated.
if (!solidity::test::CommonOptions::get().useABIEncoderV2)
if (solidity::test::CommonOptions::get().useABIEncoderV1)
{
BOOST_REQUIRE(!gas.isInfinite);
BOOST_CHECK_LE(m_gasUsed, gas.value);
@ -91,9 +91,9 @@ public:
*m_compiler.runtimeAssemblyItems(m_compiler.lastContractName()),
_sig
);
// Skip the tests when we force ABIEncoderV2.
// Skip the tests when we use ABIEncoderV2.
// TODO: We should enable this again once the yul optimizer is activated.
if (!solidity::test::CommonOptions::get().useABIEncoderV2)
if (solidity::test::CommonOptions::get().useABIEncoderV1)
{
BOOST_REQUIRE(!gas.isInfinite);
BOOST_CHECK_LE(m_gasUsed, gas.value);

View File

@ -88,7 +88,7 @@ SemanticTest::SemanticTest(string const& _filename, langutil::EVMVersion _evmVer
m_runWithEwasm = false;
m_runWithABIEncoderV1Only = m_reader.boolSetting("ABIEncoderV1Only", false);
if (m_runWithABIEncoderV1Only && solidity::test::CommonOptions::get().useABIEncoderV2)
if (m_runWithABIEncoderV1Only && !solidity::test::CommonOptions::get().useABIEncoderV1)
m_shouldRun = false;
auto revertStrings = revertStringsFromString(m_reader.stringSetting("revertStrings", "default"));

View File

@ -136,10 +136,10 @@ string SolidityExecutionFramework::addPreamble(string const& _sourceCode)
// Silence compiler version warning
string preamble = "pragma solidity >=0.0;\n// SPDX-License-Identifier: unlicensed\n";
if (
solidity::test::CommonOptions::get().useABIEncoderV2 &&
solidity::test::CommonOptions::get().useABIEncoderV1 &&
_sourceCode.find("pragma experimental ABIEncoderV2;") == string::npos &&
_sourceCode.find("pragma abicoder") == string::npos
)
preamble += "pragma abicoder v2;\n";
preamble += "pragma abicoder v1;\n";
return preamble + _sourceCode;
}

View File

@ -69,8 +69,8 @@ public:
std::map<std::string, solidity::test::Address> const& _libraryAddresses = {}
);
/// Returns @param _sourceCode prefixed with the version pragma and the ABIEncoderV2 pragma,
/// the latter only if it is required.
/// Returns @param _sourceCode prefixed with the version pragma and the abi coder v1 pragma,
/// the latter only if it is forced.
static std::string addPreamble(std::string const& _sourceCode);
protected: