From 219406f45b611a5f5ff54fed7389874e822631f5 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Wed, 26 Sep 2018 18:06:35 +0100 Subject: [PATCH 1/3] Add CLI option to soltest to always use ABIEncoderV2 --- test/Options.cpp | 2 ++ test/Options.h | 1 + test/libsolidity/SolidityExecutionFramework.h | 5 ++++- 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/test/Options.cpp b/test/Options.cpp index 9f0d6752e..8389d853b 100644 --- a/test/Options.cpp +++ b/test/Options.cpp @@ -55,6 +55,8 @@ Options::Options() } else if (string(suite.argv[i]) == "--optimize") optimize = true; + else if (string(suite.argv[i]) == "--abiencoderv2") + useABIEncoderV2 = true; else if (string(suite.argv[i]) == "--evm-version") { evmVersionString = i + 1 < suite.argc ? suite.argv[i + 1] : "INVALID"; diff --git a/test/Options.h b/test/Options.h index af6f06ee4..f510aade0 100644 --- a/test/Options.h +++ b/test/Options.h @@ -41,6 +41,7 @@ struct Options: boost::noncopyable bool optimize = false; bool disableIPC = false; bool disableSMT = false; + bool useABIEncoderV2 = false; void validate() const; solidity::EVMVersion evmVersion() const; diff --git a/test/libsolidity/SolidityExecutionFramework.h b/test/libsolidity/SolidityExecutionFramework.h index bda1c2486..37adbdf4e 100644 --- a/test/libsolidity/SolidityExecutionFramework.h +++ b/test/libsolidity/SolidityExecutionFramework.h @@ -65,7 +65,10 @@ public: ) { // Silence compiler version warning - std::string sourceCode = "pragma solidity >=0.0;\n" + _sourceCode; + std::string sourceCode = "pragma solidity >=0.0;\n"; + if (dev::test::Options::get().useABIEncoderV2 && _sourceCode.find("pragma experimental ABIEncoderV2;") == std::string::npos) + sourceCode += "pragma experimental ABIEncoderV2;\n"; + sourceCode += _sourceCode; m_compiler.reset(false); m_compiler.addSource("", sourceCode); m_compiler.setLibraries(_libraryAddresses); From 5bbd65c5caa12ff2b89a16e44fd279eaf9788a7b Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Wed, 26 Sep 2018 18:09:10 +0100 Subject: [PATCH 2/3] Run constantinople in regular and in force-abiv2 mode. --- scripts/tests.sh | 35 +++++++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/scripts/tests.sh b/scripts/tests.sh index 27cad6e32..553454583 100755 --- a/scripts/tests.sh +++ b/scripts/tests.sh @@ -190,18 +190,33 @@ for optimize in "" "--optimize" do for vm in $EVM_VERSIONS do - printTask "--> Running tests using "$optimize" --evm-version "$vm"..." - log="" - if [ -n "$log_directory" ] + FORCE_ABIV2_RUNS="no" + if [[ "$vm" == "constantinople" ]] then - if [ -n "$optimize" ] - then - log=--logger=JUNIT,test_suite,$log_directory/opt_$vm.xml $testargs - else - log=--logger=JUNIT,test_suite,$log_directory/noopt_$vm.xml $testargs_no_opt - fi + FORCE_ABIV2_RUNS="no yes" # run both in constantinople fi - "$REPO_ROOT"/build/test/soltest $progress $log -- --testpath "$REPO_ROOT"/test "$optimize" --evm-version "$vm" $SMT_FLAGS $IPC_FLAGS --ipcpath "${WORKDIR}/geth.ipc" + for abiv2 in $FORCE_ABIV2_RUNS + do + force_abiv2_flag="" + if [[ "$abiv2" == "yes" ]] + then + force_abiv2_flag="--abiencoderv2" + fi + printTask "--> Running tests using "$optimize" --evm-version "$vm" $force_abiv2_flag..." + + log="" + if [ -n "$log_directory" ] + then + if [ -n "$optimize" ] + then + log=--logger=JUNIT,test_suite,$log_directory/opt_$vm.xml $testargs + else + log=--logger=JUNIT,test_suite,$log_directory/noopt_$vm.xml $testargs_no_opt + fi + fi + + "$REPO_ROOT"/build/test/soltest $progress $log -- --testpath "$REPO_ROOT"/test "$optimize" --evm-version "$vm" $SMT_FLAGS $IPC_FLAGS $force_abiv2_flag --ipcpath "${WORKDIR}/geth.ipc" + done done done From 8ace2c5b1136e1f2aa54ee59910cd7ef219e75c9 Mon Sep 17 00:00:00 2001 From: chriseth Date: Tue, 19 Feb 2019 18:55:36 +0100 Subject: [PATCH 3/3] Special treatment for differences between ABI encoders. --- test/libsolidity/ABIDecoderTests.cpp | 2 +- test/libsolidity/ABIEncoderTests.cpp | 11 +++++++---- test/libsolidity/GasCosts.cpp | 6 ++++++ test/libsolidity/GasMeter.cpp | 22 ++++++++++++++++------ test/libsolidity/SolidityEndToEndTest.cpp | 15 ++++++++++----- 5 files changed, 40 insertions(+), 16 deletions(-) diff --git a/test/libsolidity/ABIDecoderTests.cpp b/test/libsolidity/ABIDecoderTests.cpp index 291ed15aa..ce6afcf35 100644 --- a/test/libsolidity/ABIDecoderTests.cpp +++ b/test/libsolidity/ABIDecoderTests.cpp @@ -86,7 +86,7 @@ BOOST_AUTO_TEST_CASE(enums) } } )"; - bool newDecoder = false; + bool newDecoder = dev::test::Options::get().useABIEncoderV2; BOTH_ENCODERS( compileAndRun(sourceCode); ABI_CHECK(callContractFunction("f(uint8)", 0), encodeArgs(u256(0))); diff --git a/test/libsolidity/ABIEncoderTests.cpp b/test/libsolidity/ABIEncoderTests.cpp index f56b8ad1f..a8f175543 100644 --- a/test/libsolidity/ABIEncoderTests.cpp +++ b/test/libsolidity/ABIEncoderTests.cpp @@ -164,10 +164,13 @@ BOOST_AUTO_TEST_CASE(memory_array_one_dim) } )"; - compileAndRun(sourceCode); - callContractFunction("f()"); - // The old encoder does not clean array elements. - REQUIRE_LOG_DATA(encodeArgs(10, 0x60, 11, 3, u256("0xfffffffe"), u256("0xffffffff"), u256("0x100000000"))); + if (!dev::test::Options::get().useABIEncoderV2) + { + compileAndRun(sourceCode); + callContractFunction("f()"); + // The old encoder does not clean array elements. + REQUIRE_LOG_DATA(encodeArgs(10, 0x60, 11, 3, u256("0xfffffffe"), u256("0xffffffff"), u256("0x100000000"))); + } compileAndRun(NewEncoderPragma + sourceCode); callContractFunction("f()"); diff --git a/test/libsolidity/GasCosts.cpp b/test/libsolidity/GasCosts.cpp index c7da3ca04..44fd5bf77 100644 --- a/test/libsolidity/GasCosts.cpp +++ b/test/libsolidity/GasCosts.cpp @@ -70,6 +70,9 @@ BOOST_AUTO_TEST_CASE(string_storage) if (Options::get().evmVersion() <= EVMVersion::byzantium()) CHECK_GAS(134435, 130591, 100); + // This is only correct on >=Constantinople. + else if (Options::get().useABIEncoderV2) + CHECK_GAS(151819, 142753, 100); else CHECK_GAS(127225, 124873, 100); if (Options::get().evmVersion() >= EVMVersion::byzantium()) @@ -77,6 +80,9 @@ BOOST_AUTO_TEST_CASE(string_storage) callContractFunction("f()"); if (Options::get().evmVersion() == EVMVersion::byzantium()) CHECK_GAS(21551, 21526, 20); + // This is only correct on >=Constantinople. + else if (Options::get().useABIEncoderV2) + CHECK_GAS(21713, 21635, 20); else CHECK_GAS(21546, 21526, 20); } diff --git a/test/libsolidity/GasMeter.cpp b/test/libsolidity/GasMeter.cpp index d765d440b..54d3c247c 100644 --- a/test/libsolidity/GasMeter.cpp +++ b/test/libsolidity/GasMeter.cpp @@ -73,9 +73,14 @@ public: // costs for transaction gas += gasForTransaction(m_compiler.object(m_compiler.lastContractName()).bytecode, true); - BOOST_REQUIRE(!gas.isInfinite); - BOOST_CHECK_LE(m_gasUsed, gas.value); - BOOST_CHECK_LE(gas.value - _tolerance, m_gasUsed); + // Skip the tests when we force ABIEncoderV2. + // TODO: We should enable this again once the yul optimizer is activated. + if (!dev::test::Options::get().useABIEncoderV2) + { + BOOST_REQUIRE(!gas.isInfinite); + BOOST_CHECK_LE(m_gasUsed, gas.value); + BOOST_CHECK_LE(gas.value - _tolerance, m_gasUsed); + } } /// Compares the gas computed by PathGasMeter for the given signature (but unknown arguments) @@ -97,9 +102,14 @@ public: *m_compiler.runtimeAssemblyItems(m_compiler.lastContractName()), _sig ); - BOOST_REQUIRE(!gas.isInfinite); - BOOST_CHECK_LE(m_gasUsed, gas.value); - BOOST_CHECK_LE(gas.value - _tolerance, m_gasUsed); + // Skip the tests when we force ABIEncoderV2. + // TODO: We should enable this again once the yul optimizer is activated. + if (!dev::test::Options::get().useABIEncoderV2) + { + BOOST_REQUIRE(!gas.isInfinite); + BOOST_CHECK_LE(m_gasUsed, gas.value); + BOOST_CHECK_LE(gas.value - _tolerance, m_gasUsed); + } } static GasMeter::GasConsumption gasForTransaction(bytes const& _data, bool _isCreation) diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp index c540ef320..ee3cc626b 100644 --- a/test/libsolidity/SolidityEndToEndTest.cpp +++ b/test/libsolidity/SolidityEndToEndTest.cpp @@ -14317,12 +14317,17 @@ BOOST_AUTO_TEST_CASE(abi_encode_empty_string) } } )"; + compileAndRun(sourceCode, 0, "C"); - ABI_CHECK(callContractFunction("f()"), encodeArgs( - 0x40, 0xc0, - 0x60, 0x20, 0x00, 0x00, - 0x00 - )); + if (!dev::test::Options::get().useABIEncoderV2) + { + // ABI Encoder V2 has slightly different padding, tested below. + ABI_CHECK(callContractFunction("f()"), encodeArgs( + 0x40, 0xc0, + 0x60, 0x20, 0x00, 0x00, + 0x00 + )); + } } BOOST_AUTO_TEST_CASE(abi_encode_empty_string_v2)