mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Merge pull request #9252 from ethereum/develop
Merge develop into breaking.
This commit is contained in:
@@ -777,7 +777,7 @@ BOOST_AUTO_TEST_CASE(struct_in_constructor_data_short)
|
||||
|
||||
NEW_ENCODER(
|
||||
BOOST_CHECK(
|
||||
compileAndRunWithoutCheck(sourceCode, 0, "C", encodeArgs(0x20, 0x60, 0x03, 0x80, 0x00)).empty()
|
||||
compileAndRunWithoutCheck({{"", sourceCode}}, 0, "C", encodeArgs(0x20, 0x60, 0x03, 0x80, 0x00)).empty()
|
||||
);
|
||||
)
|
||||
}
|
||||
|
||||
@@ -42,11 +42,10 @@ namespace fs = boost::filesystem;
|
||||
SemanticTest::SemanticTest(string const& _filename, langutil::EVMVersion _evmVersion, bool enforceViaYul):
|
||||
SolidityExecutionFramework(_evmVersion),
|
||||
EVMVersionRestrictedTestCase(_filename),
|
||||
m_sources(m_reader.sources()),
|
||||
m_lineOffset(m_reader.lineNumber()),
|
||||
m_enforceViaYul(enforceViaYul)
|
||||
{
|
||||
m_source = m_reader.source();
|
||||
m_lineOffset = m_reader.lineNumber();
|
||||
|
||||
string choice = m_reader.stringSetting("compileViaYul", "false");
|
||||
if (choice == "also")
|
||||
{
|
||||
@@ -239,12 +238,48 @@ TestCase::TestResult SemanticTest::run(ostream& _stream, string const& _linePref
|
||||
return TestResult::Success;
|
||||
}
|
||||
|
||||
void SemanticTest::printSource(ostream& _stream, string const& _linePrefix, bool) const
|
||||
void SemanticTest::printSource(ostream& _stream, string const& _linePrefix, bool _formatted) const
|
||||
{
|
||||
stringstream stream(m_source);
|
||||
string line;
|
||||
while (getline(stream, line))
|
||||
_stream << _linePrefix << line << endl;
|
||||
if (m_sources.sources.empty())
|
||||
return;
|
||||
|
||||
bool outputNames = (m_sources.sources.size() != 1 || !m_sources.sources.begin()->first.empty());
|
||||
|
||||
for (auto const& [name, source]: m_sources.sources)
|
||||
if (_formatted)
|
||||
{
|
||||
if (source.empty())
|
||||
continue;
|
||||
|
||||
if (outputNames)
|
||||
_stream << _linePrefix << formatting::CYAN << "==== Source: " << name << " ====" << formatting::RESET << endl;
|
||||
vector<char const*> sourceFormatting(source.length(), formatting::RESET);
|
||||
|
||||
_stream << _linePrefix << sourceFormatting.front() << source.front();
|
||||
for (size_t i = 1; i < source.length(); i++)
|
||||
{
|
||||
if (sourceFormatting[i] != sourceFormatting[i - 1])
|
||||
_stream << sourceFormatting[i];
|
||||
if (source[i] != '\n')
|
||||
_stream << source[i];
|
||||
else
|
||||
{
|
||||
_stream << formatting::RESET << endl;
|
||||
if (i + 1 < source.length())
|
||||
_stream << _linePrefix << sourceFormatting[i];
|
||||
}
|
||||
}
|
||||
_stream << formatting::RESET;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (outputNames)
|
||||
_stream << _linePrefix << "==== Source: " + name << " ====" << endl;
|
||||
stringstream stream(source);
|
||||
string line;
|
||||
while (getline(stream, line))
|
||||
_stream << _linePrefix << line << endl;
|
||||
}
|
||||
}
|
||||
|
||||
void SemanticTest::printUpdatedExpectations(ostream& _stream, string const&) const
|
||||
@@ -276,6 +311,6 @@ void SemanticTest::parseExpectations(istream& _stream)
|
||||
|
||||
bool SemanticTest::deploy(string const& _contractName, u256 const& _value, bytes const& _arguments, map<string, solidity::test::Address> const& _libraries)
|
||||
{
|
||||
auto output = compileAndRunWithoutCheck(m_source, _value, _contractName, _arguments, _libraries);
|
||||
auto output = compileAndRunWithoutCheck(m_sources.sources, _value, _contractName, _arguments, _libraries);
|
||||
return !output.empty() && m_transactionSuccessful;
|
||||
}
|
||||
|
||||
@@ -58,9 +58,8 @@ public:
|
||||
/// Compiles and deploys currently held source.
|
||||
/// Returns true if deployment was successful, false otherwise.
|
||||
bool deploy(std::string const& _contractName, u256 const& _value, bytes const& _arguments, std::map<std::string, solidity::test::Address> const& _libraries = {});
|
||||
|
||||
private:
|
||||
std::string m_source;
|
||||
SourceMap m_sources;
|
||||
std::size_t m_lineOffset;
|
||||
std::vector<TestFunctionCall> m_tests;
|
||||
bool m_runWithYul = false;
|
||||
|
||||
@@ -1723,7 +1723,7 @@ BOOST_AUTO_TEST_CASE(internal_constructor)
|
||||
constructor() internal {}
|
||||
}
|
||||
)";
|
||||
BOOST_CHECK(compileAndRunWithoutCheck(sourceCode, 0, "C").empty());
|
||||
BOOST_CHECK(compileAndRunWithoutCheck({{"", sourceCode}}, 0, "C").empty());
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(default_fallback_throws)
|
||||
@@ -3618,7 +3618,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"), encodeArgs());
|
||||
BOOST_CHECK(!m_transactionSuccessful);
|
||||
}
|
||||
|
||||
|
||||
@@ -31,22 +31,18 @@ using namespace solidity::frontend;
|
||||
using namespace solidity::frontend::test;
|
||||
using namespace std;
|
||||
|
||||
bytes SolidityExecutionFramework::compileContract(
|
||||
string const& _sourceCode,
|
||||
bytes SolidityExecutionFramework::multiSourceCompileContract(
|
||||
map<string, string> const& _sourceCode,
|
||||
string const& _contractName,
|
||||
map<string, Address> const& _libraryAddresses
|
||||
)
|
||||
{
|
||||
// Silence compiler version warning
|
||||
std::string sourceCode = "pragma solidity >=0.0;\n";
|
||||
if (
|
||||
solidity::test::CommonOptions::get().useABIEncoderV2 &&
|
||||
_sourceCode.find("pragma experimental ABIEncoderV2;") == std::string::npos
|
||||
)
|
||||
sourceCode += "pragma experimental ABIEncoderV2;\n";
|
||||
sourceCode += _sourceCode;
|
||||
map<string, string> sourcesWithPreamble = _sourceCode;
|
||||
for (auto& entry: sourcesWithPreamble)
|
||||
entry.second = addPreamble(entry.second);
|
||||
|
||||
m_compiler.reset();
|
||||
m_compiler.setSources({{"", sourceCode}});
|
||||
m_compiler.setSources(sourcesWithPreamble);
|
||||
m_compiler.setLibraries(_libraryAddresses);
|
||||
m_compiler.setRevertStringBehaviour(m_revertStrings);
|
||||
m_compiler.setEVMVersion(m_evmVersion);
|
||||
@@ -85,3 +81,28 @@ bytes SolidityExecutionFramework::compileContract(
|
||||
cout << "metadata: " << m_compiler.metadata(contractName) << endl;
|
||||
return obj.bytecode;
|
||||
}
|
||||
|
||||
bytes SolidityExecutionFramework::compileContract(
|
||||
string const& _sourceCode,
|
||||
string const& _contractName,
|
||||
map<string, Address> const& _libraryAddresses
|
||||
)
|
||||
{
|
||||
return multiSourceCompileContract(
|
||||
{{"", _sourceCode}},
|
||||
_contractName,
|
||||
_libraryAddresses
|
||||
);
|
||||
}
|
||||
|
||||
string SolidityExecutionFramework::addPreamble(string const& _sourceCode)
|
||||
{
|
||||
// Silence compiler version warning
|
||||
string preamble = "pragma solidity >=0.0;\n";
|
||||
if (
|
||||
solidity::test::CommonOptions::get().useABIEncoderV2 &&
|
||||
_sourceCode.find("pragma experimental ABIEncoderV2;") == string::npos
|
||||
)
|
||||
preamble += "pragma experimental ABIEncoderV2;\n";
|
||||
return preamble + _sourceCode;
|
||||
}
|
||||
|
||||
@@ -47,14 +47,14 @@ public:
|
||||
{}
|
||||
|
||||
bytes const& compileAndRunWithoutCheck(
|
||||
std::string const& _sourceCode,
|
||||
std::map<std::string, std::string> const& _sourceCode,
|
||||
u256 const& _value = 0,
|
||||
std::string const& _contractName = "",
|
||||
bytes const& _arguments = bytes(),
|
||||
std::map<std::string, solidity::test::Address> const& _libraryAddresses = std::map<std::string, solidity::test::Address>()
|
||||
bytes const& _arguments = {},
|
||||
std::map<std::string, solidity::test::Address> const& _libraryAddresses = {}
|
||||
) override
|
||||
{
|
||||
bytes bytecode = compileContract(_sourceCode, _contractName, _libraryAddresses);
|
||||
bytes bytecode = multiSourceCompileContract(_sourceCode, _contractName, _libraryAddresses);
|
||||
sendMessage(bytecode + _arguments, true, _value);
|
||||
return m_output;
|
||||
}
|
||||
@@ -62,16 +62,23 @@ public:
|
||||
bytes compileContract(
|
||||
std::string const& _sourceCode,
|
||||
std::string const& _contractName = "",
|
||||
std::map<std::string, solidity::test::Address> const& _libraryAddresses = std::map<std::string, solidity::test::Address>()
|
||||
std::map<std::string, solidity::test::Address> const& _libraryAddresses = {}
|
||||
);
|
||||
|
||||
bytes multiSourceCompileContract(
|
||||
std::map<std::string, std::string> const& _sources,
|
||||
std::string const& _contractName = "",
|
||||
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.
|
||||
static std::string addPreamble(std::string const& _sourceCode);
|
||||
protected:
|
||||
solidity::frontend::CompilerStack m_compiler;
|
||||
bool m_compileViaYul = false;
|
||||
bool m_showMetadata = false;
|
||||
RevertStrings m_revertStrings = RevertStrings::Default;
|
||||
|
||||
};
|
||||
|
||||
} // end namespaces
|
||||
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
==== Source: A ====
|
||||
contract A {
|
||||
function g(uint256 x) public view returns(uint256) { return x + 1; }
|
||||
}
|
||||
==== Source: B ====
|
||||
import "A";
|
||||
contract B is A {
|
||||
function f(uint256 x) public view returns(uint256) { return x; }
|
||||
}
|
||||
// ----
|
||||
// f(uint256): 1337 -> 1337
|
||||
// g(uint256): 1337 -> 1338
|
||||
@@ -4,4 +4,3 @@ contract C {
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// TypeError 7128: (96-97): External function arguments of reference type are read-only.
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
// SPDX-License-Identifier: GPL-3.0
|
||||
pragma solidity < 142857;
|
||||
pragma solidity >= 0.0;
|
||||
pragma solidity >= 0.0.0;
|
||||
|
||||
contract C {
|
||||
}
|
||||
@@ -5,7 +5,5 @@ contract Test {
|
||||
function g(S calldata s) external { S memory m; s = m; }
|
||||
}
|
||||
// ----
|
||||
// TypeError 7128: (114-115): External function arguments of reference type are read-only.
|
||||
// TypeError 7407: (118-122): Type struct Test.S memory is not implicitly convertible to expected type struct Test.S calldata.
|
||||
// TypeError 7128: (178-179): External function arguments of reference type are read-only.
|
||||
// TypeError 7407: (182-183): Type struct Test.S memory is not implicitly convertible to expected type struct Test.S calldata.
|
||||
|
||||
Reference in New Issue
Block a user