Fixes for gas tests.

This commit is contained in:
chriseth 2016-06-21 18:13:07 +02:00
parent c0bbd1cfe5
commit 05e5bdf780

View File

@ -66,7 +66,11 @@ public:
PathGasMeter meter(*m_compiler.assemblyItems()); PathGasMeter meter(*m_compiler.assemblyItems());
GasMeter::GasConsumption gas = meter.estimateMax(0, state); GasMeter::GasConsumption gas = meter.estimateMax(0, state);
u256 bytecodeSize(m_compiler.runtimeObject().bytecode.size()); u256 bytecodeSize(m_compiler.runtimeObject().bytecode.size());
// costs for deployment
gas += bytecodeSize * schedule.createDataGas; gas += bytecodeSize * schedule.createDataGas;
// costs for transaction
gas += gasForTransaction(m_compiler.object().bytecode, true);
BOOST_REQUIRE(!gas.isInfinite); BOOST_REQUIRE(!gas.isInfinite);
BOOST_CHECK(gas.value == m_gasUsed); BOOST_CHECK(gas.value == m_gasUsed);
} }
@ -76,14 +80,16 @@ public:
void testRunTimeGas(string const& _sig, vector<bytes> _argumentVariants) void testRunTimeGas(string const& _sig, vector<bytes> _argumentVariants)
{ {
u256 gasUsed = 0; u256 gasUsed = 0;
GasMeter::GasConsumption gas;
FixedHash<4> hash(dev::sha3(_sig)); FixedHash<4> hash(dev::sha3(_sig));
for (bytes const& arguments: _argumentVariants) for (bytes const& arguments: _argumentVariants)
{ {
sendMessage(hash.asBytes() + arguments, false, 0); sendMessage(hash.asBytes() + arguments, false, 0);
gasUsed = max(gasUsed, m_gasUsed); gasUsed = max(gasUsed, m_gasUsed);
gas = max(gas, gasForTransaction(hash.asBytes() + arguments, false));
} }
GasMeter::GasConsumption gas = GasEstimator::functionalEstimation( gas += GasEstimator::functionalEstimation(
*m_compiler.runtimeAssemblyItems(), *m_compiler.runtimeAssemblyItems(),
_sig _sig
); );
@ -91,6 +97,15 @@ public:
BOOST_CHECK(gas.value == m_gasUsed); BOOST_CHECK(gas.value == m_gasUsed);
} }
static GasMeter::GasConsumption gasForTransaction(bytes const& _data, bool _isCreation)
{
EVMSchedule schedule;
GasMeter::GasConsumption gas = _isCreation ? schedule.txCreateGas : schedule.txGas;
for (auto i: _data)
gas += i != 0 ? schedule.txDataNonZeroGas : schedule.txDataZeroGas;
return gas;
}
protected: protected:
map<ASTNode const*, eth::GasMeter::GasConsumption> m_gasCosts; map<ASTNode const*, eth::GasMeter::GasConsumption> m_gasCosts;
}; };