Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

Commit

Permalink
Per comments in #412, make eth_call use block gas limit by default
Browse files Browse the repository at this point in the history
  • Loading branch information
benjamincburns committed Jan 30, 2018
1 parent a695c54 commit 2421f4a
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/subproviders/geth_api_double.js
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,9 @@ GethApiDouble.prototype.eth_sendRawTransaction = function(rawTx, callback) {
};

GethApiDouble.prototype.eth_call = function(tx_data, block_number, callback) {
if (!tx_data.gas) {
tx_data.gas = this.state.blockchain.blockGasLimit;
}
this.state.queueTransaction("eth_call", tx_data, callback);
};

Expand Down
71 changes: 71 additions & 0 deletions test/call.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
var Web3 = require('web3');
var assert = require('assert');
var Ganache = require("../index.js");
var fs = require("fs");
var path = require("path");
var solc = require("solc");
var to = require("../lib/utils/to.js");

// Thanks solc. At least this works!
// This removes solc's overzealous uncaughtException event handler.
process.removeAllListeners("uncaughtException");

describe("eth_call", function() {
var web3 = new Web3(Ganache.provider({}));
var accounts;
var estimateGasContractData;
var estimateGasContractAbi;
var EstimateGasContract;
var estimateGasInstance;
var deploymentReceipt;
var source = fs.readFileSync(path.join(__dirname, "EstimateGas.sol"), "utf8");

before("get accounts", function(done) {
web3.eth.getAccounts(function(err, accs) {
if (err) return done(err);
accounts = accs;
done();
});
});

before("compile source and deploy", function() {
this.timeout(10000);
var result = solc.compile({sources: {"EstimateGas.sol": source}}, 1);

estimateGasContractData = "0x" + result.contracts["EstimateGas.sol:EstimateGas"].bytecode;
estimateGasContractAbi = JSON.parse(result.contracts["EstimateGas.sol:EstimateGas"].interface);

EstimateGasContract = new web3.eth.Contract(estimateGasContractAbi);
return EstimateGasContract.deploy({data: estimateGasContractData})
.send({from: accounts[0], gas: 3141592})
.on('receipt', function (receipt) {
deploymentReceipt = receipt;
})
.then(function(instance) {
// TODO: ugly workaround - not sure why this is necessary.
if (!instance._requestManager.provider) {
instance._requestManager.setProvider(web3.eth._provider);
}
estimateGasInstance = instance;
});
});

it("should use the block gas limit if no gas limit is specified", function() {
// this call uses more than the default transaction gas limit and will
// therefore fail if the block gas limit isn't used for calls
return estimateGasInstance.methods.add(toBytes("Tim"), toBytes("A great guy"), 5)
.call({from: accounts[0]})
.then(result => {
assert.equal(result, true)
})
})

function toBytes(s) {
let bytes = Array.prototype.map.call(s, function(c) {
return c.codePointAt(0)
})

return to.hex(Buffer.from(bytes))
}

});

0 comments on commit 2421f4a

Please sign in to comment.