From 312c631f86ec616da03434f79d021ab8d8c1f6f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Medeiros?= Date: Tue, 4 Jun 2019 13:12:43 -0400 Subject: [PATCH] fix: gas estimates in test (#1650) --- packages/embark-deployment/src/contract_deployer.js | 9 ++++++++- packages/embark-deployment/src/index.js | 2 ++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/packages/embark-deployment/src/contract_deployer.js b/packages/embark-deployment/src/contract_deployer.js index eb3a60976..a2a03aebd 100644 --- a/packages/embark-deployment/src/contract_deployer.js +++ b/packages/embark-deployment/src/contract_deployer.js @@ -316,7 +316,14 @@ class ContractDeployer { next(); }, function estimateCorrectGas(next) { - if (contract.gas === 'auto' || !contract.gas) { + if (contract._skipGasEstimations) { + // This is Ganache's gas limit. We subtract 1 so we don't reach the limit. + // + // We do this because Ganache's gas estimates are wrong (contract creation + // has a base cost of 53k, not 21k, so it sometimes results in out of gas + // errors.) + contract.gas = 6721975 - 1; + } else if (contract.gas === 'auto' || !contract.gas) { return self.blockchain.estimateDeployContractGas(deployObject, (err, gasValue) => { if (err) { return next(err); diff --git a/packages/embark-deployment/src/index.js b/packages/embark-deployment/src/index.js index de58e15c4..e40812f8b 100644 --- a/packages/embark-deployment/src/index.js +++ b/packages/embark-deployment/src/index.js @@ -36,6 +36,7 @@ class DeployManager { this.events.setCommandHandler('deploy:contracts:test', (cb) => { self.fatalErrors = true; self.deployOnlyOnConfig = true; + self.skipGasEstimations = true; self.deployContracts(cb); }); } @@ -70,6 +71,7 @@ class DeployManager { callback = result; } contract._gasLimit = self.gasLimit; + contract._skipGasEstimations = self.skipGasEstimations; self.events.request('deploy:contract', contract, (err) => { if (err) { contract.error = err.message || err;