I'm using the Truffle testing framework (v4.0.1) for Ethereum. I can't figure out why the transaction fees aren't adding up to gasPrice*gasUsed
for the following simple contract:
contract MinTest {
function run() public returns(bool) {
return true;
}
}
The mocha test I'm using is:
contract('Minimum Test', function (accounts) {
it("min test", function () {
var initial = web3.eth.getBalance(accounts[1]);
var final;
return MinTest.deployed().then(function(instance) {
return instance.run({from: accounts[1]});
}).then(function(result) {
final = web3.eth.getBalance(accounts[1]);
var gasPrice = new BigNumber(web3.eth.gasPrice);
var gasUsed = new BigNumber(result.receipt.gasUsed);
var gasCost = gasPrice.times(gasUsed);
console.log("gasPrice : " + gasPrice);
console.log("gasUsed : " + gasUsed);
console.log("gasCost : " + gasCost);
console.log("initial : " + initial);
console.log("initial-gasCost: " + initial.minus(gasCost));
console.log("final : " + final);
console.log("unaccounted : " + initial.minus(gasCost).minus(final));
});
});
});
The test above produces the following output:
gasPrice : 20000000000
gasUsed : 21478
gasCost : 429560000000000
initial : 100000000000000000000
initial-gasCost: 99999570440000000000
final : 99997852200000000000
unaccounted : 1718240000000000
I expected that the call to the MinTest.run
function of the contract to cause accounts[1]
to be debited an amount exactly equal to gasPrice*gasUsed
, but that isn't the case in this example. There is a an additional 1718240000000000
wei debited that I can't account for. Why is an additional 1718240000000000
wei debited here?