Merge pull request #528 from embark-framework/cached_gas_issue

fix cached gas issue
This commit is contained in:
Iuri Matias 2018-06-14 11:17:54 -04:00 committed by GitHub
commit 502788c7e0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 115 additions and 79 deletions

View File

@ -27,8 +27,6 @@ class TemplateGenerator {
console.log('-------------------'.yellow);
console.log(__('Next steps:').green);
console.log(('-> ' + ('cd ' + fspath).bold.cyan).green);
console.log('-> '.green + 'embark blockchain'.bold.cyan + ' or '.green + 'embark simulator'.bold.cyan);
console.log(__('open another console in the same directory and run').green);
console.log('-> '.green + 'embark run'.bold.cyan);
console.log(__('For more info go to http://embark.status.im').green);
}

View File

@ -216,10 +216,13 @@ class ContractDeployer {
},
function estimateCorrectGas(next) {
if (contract.gas === 'auto') {
return deployObject.estimateGas().then((gasValue) => {
return self.blockchain.estimateDeployContractGas(deployObject, (err, gasValue) => {
if (err) {
return next(err);
}
contract.gas = gasValue;
next();
}).catch(next);
});
}
next();
},

View File

@ -1,8 +1,8 @@
let toposort = require('toposort');
let async = require('async');
const cloneDeep = require('clone-deep');
let utils = require('../utils/utils.js');
const constants = require('../constants');
// TODO: create a contract object
@ -10,7 +10,7 @@ class ContractsManager {
constructor(options) {
const self = this;
this.contractFiles = options.contractFiles;
this.contractsConfig = options.contractsConfig;
this.contractsConfig = cloneDeep(options.contractsConfig || {});
this.contracts = {};
this.logger = options.logger;
this.plugins = options.plugins;
@ -20,13 +20,6 @@ class ContractsManager {
this.events = options.events;
this.compileError = false;
self.events.on(constants.events.contractFilesChanged, (newContractFiles) => {
self.contractFiles = newContractFiles;
});
self.events.on(constants.events.contractConfigChanged, (newContracts) => {
self.contractsConfig = newContracts;
});
self.events.setCommandHandler('contracts:list', (cb) => {
cb(self.compileError, self.listContracts());
});
@ -58,7 +51,20 @@ class ContractsManager {
build(done) {
let self = this;
self.contracts = {};
async.waterfall([
function loadContractFiles(callback) {
self.events.request("config:contractsFiles", (contractsFiles) => {
self.contractsFiles = contractsFiles;
callback();
});
},
function loadContractConfigs(callback) {
self.events.request("config:contractsConfig", (contractsConfig) => {
self.contractsConfig = cloneDeep(contractsConfig);
callback();
});
},
function compileContracts(callback) {
self.events.emit("status", __("Compiling..."));
if (process.env.isTest && self.compiledContracts && Object.keys(self.compiledContracts).length) {

View File

@ -7,6 +7,7 @@ const deepEqual = require('deep-equal');
const constants = require('../constants');
var Config = function(options) {
const self = this;
this.env = options.env;
this.blockchainConfig = {};
this.contractsConfig = {};
@ -22,6 +23,14 @@ var Config = function(options) {
this.events = options.events;
this.embarkConfig = {};
this.context = options.context || [constants.contexts.any];
self.events.setCommandHandler("config:contractsConfig", (cb) => {
cb(self.contractsConfig);
});
self.events.setCommandHandler("config:contractsFiles", (cb) => {
cb(self.contractsFiles);
});
};
Config.prototype.loadConfigFiles = function(options) {

View File

@ -43,6 +43,43 @@ describe('embark.Contracts', function() {
compiler.compile_contracts(contractFiles, cb);
});
events.setCommandHandler("config:contractsConfig", function(cb) {
cb(contractsConfig);
});
events.setCommandHandler("config:contractsFiles", (cb) => {
cb([]);
});
let contractsConfig = {
"versions": {
"web3.js": "1.0.0-beta",
"solc": "0.4.17"
},
"deployment": {
"host": "localhost",
"port": 8545,
"type": "rpc"
},
"dappConnection": [
"$WEB3",
"localhost:8545"
],
"gas": "auto",
"contracts": {
"Token": {
"args": [
100
]
},
"SimpleStorage": {
"args": [
200
]
}
}
};
let contractsManager = new ContractsManager({
plugins: plugins,
contractFiles: [
@ -50,34 +87,7 @@ describe('embark.Contracts', function() {
readFile('test/contracts/token.sol')
],
contractDirectories: ['app/contracts'],
contractsConfig: {
"versions": {
"web3.js": "1.0.0-beta",
"solc": "0.4.17"
},
"deployment": {
"host": "localhost",
"port": 8545,
"type": "rpc"
},
"dappConnection": [
"$WEB3",
"localhost:8545"
],
"gas": "auto",
"contracts": {
"Token": {
"args": [
100
]
},
"SimpleStorage": {
"args": [
200
]
}
}
},
contractsConfig: contractsConfig,
logger: new Logger({}),
events: events
});
@ -138,6 +148,53 @@ describe('embark.Contracts', function() {
compiler.compile_contracts(contractFiles, cb);
});
events.setCommandHandler("config:contractsConfig", function(cb) {
cb(contractsConfig);
});
events.setCommandHandler("config:contractsFiles", (cb) => {
cb([]);
});
let contractsConfig = {
"versions": {
"web3.js": "1.0.0-beta",
"solc": "0.4.17"
},
"deployment": {
"host": "localhost",
"port": 8545,
"type": "rpc"
},
"dappConnection": [
"$WEB3",
"localhost:8545"
],
"gas": "auto",
"contracts": {
"TokenStorage": {
"args": [
100,
"$SimpleStorage"
]
},
"MySimpleStorage": {
"instanceOf": "SimpleStorage",
"args": [
300
]
},
"SimpleStorage": {
"args": [
200
]
},
"AnotherSimpleStorage": {
"instanceOf": "SimpleStorage"
}
}
}
let contractsManager = new ContractsManager({
plugins: plugins,
contractFiles: [
@ -145,44 +202,7 @@ describe('embark.Contracts', function() {
readFile('test/contracts/token_storage.sol')
],
contractDirectories: ['app/contracts'],
contractsConfig: {
"versions": {
"web3.js": "1.0.0-beta",
"solc": "0.4.17"
},
"deployment": {
"host": "localhost",
"port": 8545,
"type": "rpc"
},
"dappConnection": [
"$WEB3",
"localhost:8545"
],
"gas": "auto",
"contracts": {
"TokenStorage": {
"args": [
100,
"$SimpleStorage"
]
},
"MySimpleStorage": {
"instanceOf": "SimpleStorage",
"args": [
300
]
},
"SimpleStorage": {
"args": [
200
]
},
"AnotherSimpleStorage": {
"instanceOf": "SimpleStorage"
}
}
},
contractsConfig: contractsConfig,
logger: new Logger({}),
events: events
});