diff options
Diffstat (limited to 'test/libsolidity/GasMeter.cpp')
-rw-r--r-- | test/libsolidity/GasMeter.cpp | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/test/libsolidity/GasMeter.cpp b/test/libsolidity/GasMeter.cpp index 601948bc..d765d440 100644 --- a/test/libsolidity/GasMeter.cpp +++ b/test/libsolidity/GasMeter.cpp @@ -44,7 +44,6 @@ namespace test class GasMeterTestFramework: public SolidityExecutionFramework { public: - GasMeterTestFramework() { } void compile(string const& _sourceCode) { m_compiler.reset(false); @@ -62,7 +61,7 @@ public: ); } - void testCreationTimeGas(string const& _sourceCode) + void testCreationTimeGas(string const& _sourceCode, u256 const& _tolerance = u256(0)) { compileAndRun(_sourceCode); auto state = make_shared<KnownState>(); @@ -75,12 +74,13 @@ public: gas += gasForTransaction(m_compiler.object(m_compiler.lastContractName()).bytecode, true); BOOST_REQUIRE(!gas.isInfinite); - BOOST_CHECK_EQUAL(gas.value, m_gasUsed); + 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) /// against the actual gas usage computed by the VM on the given set of argument variants. - void testRunTimeGas(string const& _sig, vector<bytes> _argumentVariants) + void testRunTimeGas(string const& _sig, vector<bytes> _argumentVariants, u256 const& _tolerance = u256(0)) { u256 gasUsed = 0; GasMeter::GasConsumption gas; @@ -98,7 +98,8 @@ public: _sig ); BOOST_REQUIRE(!gas.isInfinite); - BOOST_CHECK_EQUAL(gas.value, m_gasUsed); + BOOST_CHECK_LE(m_gasUsed, gas.value); + BOOST_CHECK_LE(gas.value - _tolerance, m_gasUsed); } static GasMeter::GasConsumption gasForTransaction(bytes const& _data, bool _isCreation) @@ -138,8 +139,7 @@ BOOST_AUTO_TEST_CASE(non_overlapping_filtered_costs) if (first->first->location().intersects(second->first->location())) { BOOST_CHECK_MESSAGE(false, "Source locations should not overlap!"); - auto scannerFromSource = [&](string const& _sourceName) -> Scanner const& { return m_compiler.scanner(_sourceName); }; - SourceReferenceFormatter formatter(cout, scannerFromSource); + SourceReferenceFormatter formatter(cout); formatter.printSourceLocation(&first->first->location()); formatter.printSourceLocation(&second->first->location()); @@ -187,7 +187,7 @@ BOOST_AUTO_TEST_CASE(updating_store) } } )"; - testCreationTimeGas(sourceCode); + testCreationTimeGas(sourceCode, m_evmVersion < EVMVersion::constantinople() ? u256(0) : u256(9600)); } BOOST_AUTO_TEST_CASE(branches) |