mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Force running abi coder v1 instead of v2.
This commit is contained in:
+1
-1
@@ -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");
|
||||
}
|
||||
|
||||
+1
-1
@@ -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;
|
||||
|
||||
|
||||
@@ -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)));
|
||||
}
|
||||
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -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);
|
||||
callContractFunction("f()");
|
||||
REQUIRE_LOG_DATA(encodeArgs(10, 0x60, 11, 3, u256(-2), u256(-1), u256(0)));
|
||||
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)
|
||||
|
||||
@@ -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) \
|
||||
}
|
||||
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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"));
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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:
|
||||
|
||||
|
||||
Reference in New Issue
Block a user