Making order of gas expectations deterministic.

This commit is contained in:
Djordje Mijovic 2021-02-01 10:37:03 +01:00
parent aed3832b27
commit cf59d7fc13
2 changed files with 7 additions and 9 deletions

View File

@ -323,11 +323,9 @@ string TestFunctionCall::formatRawParameters(
string TestFunctionCall::formatGasExpectations(string const& _linePrefix) const string TestFunctionCall::formatGasExpectations(string const& _linePrefix) const
{ {
stringstream os; stringstream os;
for (auto const& [runType, gasUsed]: m_call.expectations.gasUsed) for (auto const& [runType, gasUsed]: m_gasCosts)
if (runType != get<0>(m_gasCost)) if (!runType.empty())
os << endl << _linePrefix << "// gas " << runType << ": " << gasUsed.str(); os << endl << _linePrefix << "// gas " << runType << ": " << (gasUsed.str());
if (!get<0>(m_gasCost).empty())
os << endl << _linePrefix << "// gas " << get<0>(m_gasCost) << ": " << get<1>(m_gasCost).str();
return os.str(); return os.str();
} }

View File

@ -42,7 +42,7 @@ namespace solidity::frontend::test
class TestFunctionCall class TestFunctionCall
{ {
public: public:
TestFunctionCall(FunctionCall _call): m_call(std::move(_call)) {} TestFunctionCall(FunctionCall _call): m_call(std::move(_call)), m_gasCosts(m_call.expectations.gasUsed) {}
/// Formats this function call test and applies the format that was detected during parsing. /// Formats this function call test and applies the format that was detected during parsing.
/// If _renderResult is false, the expected result of the call will be used, if it's true /// If _renderResult is false, the expected result of the call will be used, if it's true
@ -79,7 +79,7 @@ public:
void calledNonExistingFunction() { m_calledNonExistingFunction = true; } void calledNonExistingFunction() { m_calledNonExistingFunction = true; }
void setFailure(const bool _failure) { m_failure = _failure; } void setFailure(const bool _failure) { m_failure = _failure; }
void setRawBytes(const bytes _rawBytes) { m_rawBytes = _rawBytes; } void setRawBytes(const bytes _rawBytes) { m_rawBytes = _rawBytes; }
void setGasCost(std::string _runType, u256 _gasCost) { m_gasCost = {std::move(_runType), std::move(_gasCost)}; } void setGasCost(std::string const& _runType, u256 const& _gasCost) { m_gasCosts[_runType] = _gasCost; }
void setContractABI(Json::Value _contractABI) { m_contractABI = std::move(_contractABI); } void setContractABI(Json::Value _contractABI) { m_contractABI = std::move(_contractABI); }
private: private:
@ -128,8 +128,8 @@ private:
FunctionCall m_call; FunctionCall m_call;
/// Result of the actual call been made. /// Result of the actual call been made.
bytes m_rawBytes = bytes{}; bytes m_rawBytes = bytes{};
/// Actual gas cost for the type of the run /// Actual gas costs
std::tuple<std::string, u256> m_gasCost; std::map<std::string, u256> m_gasCosts;
/// Transaction status of the actual call. False in case of a REVERT or any other failure. /// Transaction status of the actual call. False in case of a REVERT or any other failure.
bool m_failure = true; bool m_failure = true;
/// JSON object which holds the contract ABI and that is used to set the output formatting /// JSON object which holds the contract ABI and that is used to set the output formatting