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: ...@@ -142,7 +142,6 @@ export function compileFileOrFiles(filename: string, isDirectory: boolean, opts:
/** /**
* @dev Compile contract source before running tests (used for IDE tests execution) * @dev Compile contract source before running tests (used for IDE tests execution)
* @param sources sources * @param sources sources
* @param versionUrl url of selected compiler version to load
* @param compilerConfig current compiler configuration * @param compilerConfig current compiler configuration
* @param importFileCb Import file callback * @param importFileCb Import file callback
* @param opts Options * @param opts Options
......
...@@ -2,7 +2,7 @@ import async from 'async' ...@@ -2,7 +2,7 @@ import async from 'async'
var remixLib = require('remix-lib') var remixLib = require('remix-lib')
import Web3 from 'web3'; 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 compiledObject = {}
let contracts = {} let contracts = {}
let accounts: string[] = [] let accounts: string[] = []
...@@ -56,9 +56,12 @@ export function deployAll(compileResult: object, web3: Web3, callback) { ...@@ -56,9 +56,12 @@ export function deployAll(compileResult: object, web3: Web3, callback) {
function deployContracts(contractsToDeploy: string[], next: Function) { function deployContracts(contractsToDeploy: string[], next: Function) {
const deployRunner = (deployObject, contractObject, contractName, filename, callback) => { const deployRunner = (deployObject, contractObject, contractName, filename, callback) => {
deployObject.estimateGas().then((gasValue) => { deployObject.estimateGas().then((gasValue) => {
let gas = Math.ceil(gasValue * 1.2)
if(isAgain)
gas = gas * 2
deployObject.send({ deployObject.send({
from: accounts[0], from: accounts[0],
gas: Math.ceil(gasValue * 1.2) gas: gas
}).on('receipt', function (receipt) { }).on('receipt', function (receipt) {
contractObject.options.address = receipt.contractAddress contractObject.options.address = receipt.contractAddress
contractObject.options.from = accounts[0] contractObject.options.from = accounts[0]
......
...@@ -60,7 +60,7 @@ export function runTestFiles(filepath: string, isDirectory: boolean, web3: Web3, ...@@ -60,7 +60,7 @@ export function runTestFiles(filepath: string, isDirectory: boolean, web3: Web3,
if(filename.endsWith('_test.sol')) if(filename.endsWith('_test.sol'))
sourceASTs[filename] = asts[filename].ast sourceASTs[filename] = asts[filename].ast
} }
deployAll(compilationResult, web3, (err, contracts) => { deployAll(compilationResult, web3, false, (err, contracts) => {
if (err) { if (err) {
next(err) next(err)
} }
......
...@@ -49,11 +49,19 @@ export async function runTestSources(contractSources: SrcIfc, compilerConfig: Co ...@@ -49,11 +49,19 @@ export async function runTestSources(contractSources: SrcIfc, compilerConfig: Co
if(filename.endsWith('_test.sol')) if(filename.endsWith('_test.sol'))
sourceASTs[filename] = asts[filename].ast sourceASTs[filename] = asts[filename].ast
} }
deployAll(compilationResult, web3, (err, contracts) => { deployAll(compilationResult, web3, false, (err, contracts) => {
if (err) { if (err) {
next([{message: 'contract deployment failed: ' + err.message, severity: 'error'}]) // IDE expects errors in array // 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) next(null, compilationResult, contracts)
}) })
}, },
......
...@@ -67,7 +67,7 @@ async function compileAndDeploy(filename: string, callback: Function) { ...@@ -67,7 +67,7 @@ async function compileAndDeploy(filename: string, callback: Function) {
} }
try { try {
compilationData = compilationResult compilationData = compilationResult
deployAll(compilationResult, web3, next) deployAll(compilationResult, web3, false, next)
} catch (e) { } catch (e) {
throw 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