double the gas if deployment fails with OOG error

pull/7/head
aniket-engg 5 years ago committed by Aniket
parent 92636aa53f
commit 82a999f6db
  1. 1
      remix-tests/src/compiler.ts
  2. 7
      remix-tests/src/deployer.ts
  3. 2
      remix-tests/src/runTestFiles.ts
  4. 16
      remix-tests/src/runTestSources.ts
  5. 2
      remix-tests/tests/testRunner.ts

@ -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) {
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)
})
},

@ -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
}

Loading…
Cancel
Save