Commit 82a999f6 authored by aniket-engg's avatar aniket-engg Committed by Aniket

double the gas if deployment fails with OOG error

parent 92636aa5
......@@ -142,7 +142,6 @@ export function compileFileOrFiles(filename: string, isDirectory: boolean, opts:
/**
* @dev Compile contract source before running tests (used for IDE tests execution)
* @param sources sources
* @param versionUrl url of selected compiler version to load
* @param compilerConfig current compiler configuration
* @param importFileCb Import file callback
* @param opts Options
......
......@@ -2,7 +2,7 @@ import async from 'async'
var remixLib = require('remix-lib')
import Web3 from 'web3';
export function deployAll(compileResult: object, web3: Web3, callback) {
export function deployAll(compileResult: object, web3: Web3, isAgain: boolean, callback) {
let compiledObject = {}
let contracts = {}
let accounts: string[] = []
......@@ -56,9 +56,12 @@ export function deployAll(compileResult: object, web3: Web3, callback) {
function deployContracts(contractsToDeploy: string[], next: Function) {
const deployRunner = (deployObject, contractObject, contractName, filename, callback) => {
deployObject.estimateGas().then((gasValue) => {
let gas = Math.ceil(gasValue * 1.2)
if(isAgain)
gas = gas * 2
deployObject.send({
from: accounts[0],
gas: Math.ceil(gasValue * 1.2)
gas: gas
}).on('receipt', function (receipt) {
contractObject.options.address = receipt.contractAddress
contractObject.options.from = accounts[0]
......
......@@ -60,7 +60,7 @@ export function runTestFiles(filepath: string, isDirectory: boolean, web3: Web3,
if(filename.endsWith('_test.sol'))
sourceASTs[filename] = asts[filename].ast
}
deployAll(compilationResult, web3, (err, contracts) => {
deployAll(compilationResult, web3, false, (err, contracts) => {
if (err) {
next(err)
}
......
......@@ -49,11 +49,19 @@ export async function runTestSources(contractSources: SrcIfc, compilerConfig: Co
if(filename.endsWith('_test.sol'))
sourceASTs[filename] = asts[filename].ast
}
deployAll(compilationResult, web3, (err, contracts) => {
deployAll(compilationResult, web3, false, (err, contracts) => {
if (err) {
// If contract deployment fails because of 'Out of Gas' error, try again with double gas
// This is temporary, should be removed when remix-tests will have a dedicated UI to
// accept deployment params from UI
if(err.message.includes('The contract code couldn\'t be stored, please check your gas limit')) {
deployAll(compilationResult, web3, true, (error, contracts) => {
if (error) next([{message: 'contract deployment failed after trying twice: ' + error.message, severity: 'error'}]) // IDE expects errors in array
else next(null, compilationResult, contracts)
})
} else
next([{message: 'contract deployment failed: ' + err.message, severity: 'error'}]) // IDE expects errors in array
}
} else
next(null, compilationResult, contracts)
})
},
......
......@@ -67,7 +67,7 @@ async function compileAndDeploy(filename: string, callback: Function) {
}
try {
compilationData = compilationResult
deployAll(compilationResult, web3, next)
deployAll(compilationResult, web3, false, next)
} catch (e) {
throw e
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment