aboutsummaryrefslogtreecommitdiffstats
path: root/test/libsolidity/GasMeter.cpp
diff options
context:
space:
mode:
authorchriseth <c@ethdev.com>2016-07-01 19:50:07 +0800
committerGitHub <noreply@github.com>2016-07-01 19:50:07 +0800
commit48238c9f1452b1326851af053c782734d0f67101 (patch)
treec7eac99e657d71851186c75a1bc15abf49f25681 /test/libsolidity/GasMeter.cpp
parent2ccfea8b54699d7ecc4e790aa962d0eed58ed3fc (diff)
parenta15b533323ffeb2e4ef4875367b3ef2877f8b786 (diff)
downloaddexon-solidity-48238c9f1452b1326851af053c782734d0f67101.tar
dexon-solidity-48238c9f1452b1326851af053c782734d0f67101.tar.gz
dexon-solidity-48238c9f1452b1326851af053c782734d0f67101.tar.bz2
dexon-solidity-48238c9f1452b1326851af053c782734d0f67101.tar.lz
dexon-solidity-48238c9f1452b1326851af053c782734d0f67101.tar.xz
dexon-solidity-48238c9f1452b1326851af053c782734d0f67101.tar.zst
dexon-solidity-48238c9f1452b1326851af053c782734d0f67101.zip
Merge pull request #608 from chriseth/testViaIPC
Test via IPC.
Diffstat (limited to 'test/libsolidity/GasMeter.cpp')
-rw-r--r--test/libsolidity/GasMeter.cpp19
1 files changed, 17 insertions, 2 deletions
diff --git a/test/libsolidity/GasMeter.cpp b/test/libsolidity/GasMeter.cpp
index ebd5d774..fc7a033f 100644
--- a/test/libsolidity/GasMeter.cpp
+++ b/test/libsolidity/GasMeter.cpp
@@ -20,7 +20,7 @@
* Unit tests for the gas estimator.
*/
-#include <test/libsolidity/solidityExecutionFramework.h>
+#include <test/libsolidity/SolidityExecutionFramework.h>
#include <libevmasm/GasMeter.h>
#include <libevmasm/KnownState.h>
#include <libevmasm/PathGasMeter.h>
@@ -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;
};