aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorchriseth <c@ethdev.com>2016-06-22 00:13:07 +0800
committerchriseth <c@ethdev.com>2016-06-29 05:18:55 +0800
commit05e5bdf780cba4d198066d6f26353fd25d8ff553 (patch)
treee27d1a7d61770956f35c376817725694d7e3140a
parentc0bbd1cfe592144df5769f0313a2b0d418ef720f (diff)
downloaddexon-solidity-05e5bdf780cba4d198066d6f26353fd25d8ff553.tar.gz
dexon-solidity-05e5bdf780cba4d198066d6f26353fd25d8ff553.tar.zst
dexon-solidity-05e5bdf780cba4d198066d6f26353fd25d8ff553.zip
Fixes for gas tests.
-rw-r--r--test/libsolidity/GasMeter.cpp17
1 files changed, 16 insertions, 1 deletions
diff --git a/test/libsolidity/GasMeter.cpp b/test/libsolidity/GasMeter.cpp
index 1ff2e0f9..fc7a033f 100644
--- a/test/libsolidity/GasMeter.cpp
+++ b/test/libsolidity/GasMeter.cpp
@@ -66,7 +66,11 @@ public:
PathGasMeter meter(*m_compiler.assemblyItems());
GasMeter::GasConsumption gas = meter.estimateMax(0, state);
u256 bytecodeSize(m_compiler.runtimeObject().bytecode.size());
+ // costs for deployment
gas += bytecodeSize * schedule.createDataGas;
+ // costs for transaction
+ gas += gasForTransaction(m_compiler.object().bytecode, true);
+
BOOST_REQUIRE(!gas.isInfinite);
BOOST_CHECK(gas.value == m_gasUsed);
}
@@ -76,14 +80,16 @@ public:
void testRunTimeGas(string const& _sig, vector<bytes> _argumentVariants)
{
u256 gasUsed = 0;
+ GasMeter::GasConsumption gas;
FixedHash<4> hash(dev::sha3(_sig));
for (bytes const& arguments: _argumentVariants)
{
sendMessage(hash.asBytes() + arguments, false, 0);
gasUsed = max(gasUsed, m_gasUsed);
+ gas = max(gas, gasForTransaction(hash.asBytes() + arguments, false));
}
- GasMeter::GasConsumption gas = GasEstimator::functionalEstimation(
+ gas += GasEstimator::functionalEstimation(
*m_compiler.runtimeAssemblyItems(),
_sig
);
@@ -91,6 +97,15 @@ public:
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:
map<ASTNode const*, eth::GasMeter::GasConsumption> m_gasCosts;
};