herge branch 'refactor_e' into develop

This commit is contained in:
Iuri Matias 2017-02-25 23:32:08 -05:00
commit a153859caf
12 changed files with 417 additions and 340 deletions

View File

@ -150,6 +150,7 @@ Cmd.prototype.otherCommands = function() {
.action(function(env){
console.log('unknown command "%s"'.red, env);
console.log("type embark --help to see the available commands");
process.exit(0);
});
};

View File

@ -108,8 +108,10 @@ ABIGenerator.prototype.generateABI = function(options) {
result += this.generateProvider();
result += this.generateContracts(options.useEmbarkJS);
result += this.generateStorageInitialization(options.useEmbarkJS);
result += this.generateCommunicationInitialization(options.useEmbarkJS);
// TODO: disable this for now until refactor is over
//result += this.generateStorageInitialization(options.useEmbarkJS);
//result += this.generateCommunicationInitialization(options.useEmbarkJS);
return result;
};

View File

@ -1,6 +1,6 @@
/*jshint esversion: 6, loopfunc: true */
var solc = require('solc');
var async = require('async');
var SolcW = require('./solcW.js');
function asyncEachObject(object, iterator, callback) {
async.each(
@ -15,13 +15,14 @@ async.eachObject = asyncEachObject;
var Compiler = function(options) {
this.plugins = options.plugins;
this.logger = options.logger;
};
Compiler.prototype.compile_contracts = function(contractFiles, cb) {
var available_compilers = {
//".se": this.compile_serpent
".sol": this.compile_solidity
".sol": this.compile_solidity.bind(this)
};
if (this.plugins) {
@ -56,36 +57,60 @@ Compiler.prototype.compile_contracts = function(contractFiles, cb) {
};
Compiler.prototype.compile_solidity = function(contractFiles, cb) {
var self = this;
var input = {};
var solcW;
async.waterfall([
function prepareInput(callback) {
for (var i = 0; i < contractFiles.length; i++){
// TODO: this depends on the config
var filename = contractFiles[i].filename.replace('app/contracts/','');
input[filename] = contractFiles[i].content.toString();
}
callback();
},
function loadCompiler(callback) {
// TODO: there ino need to load this twice
solcW = new SolcW();
if (solcW.isCompilerLoaded()) {
callback();
} else {
self.logger.info("loading solc compiler..");
solcW.load_compiler(function(){
callback();
});
}
},
function compileContracts(callback) {
self.logger.info("compiling contracts...");
solcW.compile({sources: input}, 1, function(output) {
// TODO: check error is handled properly
//if (output.errors) {
// throw new Error ("Solidity errors: " + output.errors);
//}
callback(null, output);
});
},
function createCompiledObject(output, callback) {
var json = output.contracts;
for (var i = 0; i < contractFiles.length; i++){
// TODO: this depends on the config
var filename = contractFiles[i].filename.replace('app/contracts/','');
input[filename] = contractFiles[i].content.toString();
}
compiled_object = {};
var output = solc.compile({sources: input}, 1);
for (var className in json) {
var contract = json[className];
if (output.errors) {
throw new Error ("Solidity errors: " + output.errors);
}
var json = output.contracts;
compiled_object = {};
for (var className in json) {
var contract = json[className];
compiled_object[className] = {};
compiled_object[className].code = contract.bytecode;
compiled_object[className].runtimeBytecode = contract.runtimeBytecode;
compiled_object[className].gasEstimates = contract.gasEstimates;
compiled_object[className].functionHashes = contract.functionHashes;
compiled_object[className].abiDefinition = JSON.parse(contract.interface);
}
cb(compiled_object);
compiled_object[className] = {};
compiled_object[className].code = contract.bytecode;
compiled_object[className].runtimeBytecode = contract.runtimeBytecode;
compiled_object[className].gasEstimates = contract.gasEstimates;
compiled_object[className].functionHashes = contract.functionHashes;
compiled_object[className].abiDefinition = JSON.parse(contract.interface);
}
callback(null, compiled_object);
}
], function(err, result) {
cb(result);
});
};
module.exports = Compiler;

View File

@ -39,16 +39,16 @@ ContractsManager.prototype.build = function(done) {
var self = this;
async.waterfall([
function compileContracts(callback) {
var compiler = new Compiler({plugins: self.plugins});
var compiler = new Compiler({plugins: self.plugins, logger: self.logger});
// TODO: check if try is still needed
try {
//try {
compiler.compile_contracts(self.contractFiles, function(compiledObject) {
self.compiledContracts = compiledObject;
callback();
});
} catch(err) {
return callback(new Error(err.message));
}
//} catch(err) {
// return callback(new Error(err.message));
//}
},
function prepareContractsFromConfig(callback) {
var className, contract;

View File

@ -0,0 +1,84 @@
var async = require('async');
var Web3 = require('web3');
var Deploy = require('./deploy.js');
var ContractsManager = require('./contracts.js');
var ABIGenerator = require('./abi.js');
var DeployManager = function(options) {
this.config = options.config;
this.logger = options.logger;
this.plugins = options.plugins;
this.events = options.events;
};
DeployManager.prototype.deployContracts = function(done) {
var self = this;
async.waterfall([
function buildContracts(callback) {
var contractsManager = new ContractsManager({
contractFiles: self.config.contractsFiles,
contractsConfig: self.config.contractsConfig,
logger: self.logger,
plugins: self.plugins
});
contractsManager.build(callback);
},
function deployContracts(contractsManager, callback) {
//TODO: figure out where to put this since the web3 can be passed along if needed
// perhaps it should go into the deploy object itself
// TODO: should come from the config object
var web3 = new Web3();
var web3Endpoint = 'http://' + self.config.blockchainConfig.rpcHost + ':' + self.config.blockchainConfig.rpcPort;
web3.setProvider(new web3.providers.HttpProvider(web3Endpoint));
if (!web3.isConnected()) {
console.log(("Couldn't connect to " + web3Endpoint.underline + " are you sure it's on?").red);
console.log("make sure you have an ethereum node or simulator running. e.g 'embark blockchain'".magenta);
// ===================================
// TODO: should throw exception instead
// ===================================
process.exit();
}
web3.eth.getAccounts(function(err, accounts) {
if (err) {
return callback(new Error(err));
}
web3.eth.defaultAccount = accounts[0];
var deploy = new Deploy({
web3: web3,
contractsManager: contractsManager,
logger: self.logger,
chainConfig: self.config.chainTracker,
env: self.config.env
});
deploy.deployAll(function() {
callback(null, contractsManager);
self.events.emit('contractsDeployed');
});
});
},
function generateABI(contractsManager, callback) {
var abiGenerator = new ABIGenerator({blockchainConfig: self.config.blockchainConfig, contractsManager: contractsManager, plugins: self.plugins, storageConfig: self.config.storageConfig});
var embarkJSABI = abiGenerator.generateABI({useEmbarkJS: true});
var vanillaABI = abiGenerator.generateABI({useEmbarkJS: false});
self.events.emit('abi-vanila', vanillaABI);
self.events.emit('abi', embarkJSABI);
callback(null, embarkJSABI);
}
], function(err, result) {
if (err) {
done(err, null);
} else {
done(null, result);
}
});
};
module.exports = DeployManager;

18
lib/contracts/solcP.js Normal file
View File

@ -0,0 +1,18 @@
var solc;
process.on('message', function(msg) {
if (msg.action === 'loadCompiler') {
solc = require('solc');
process.send({result: "loadedCompiler"});
}
if (msg.action === 'compile') {
var output = solc.compile(msg.obj, msg.optimize);
process.send({result: "compilation", output: output});
}
});
process.on('exit', function() {
process.exit(0);
});

35
lib/contracts/solcW.js Normal file
View File

@ -0,0 +1,35 @@
var solcProcess;
var compilerLoaded = false;
var SolcW = function() {
};
SolcW.prototype.load_compiler = function(done) {
if (compilerLoaded) { done(); }
solcProcess = require('child_process').fork(__dirname + '/solcP.js');
solcProcess.once('message', function(msg) {
if (msg.result !== 'loadedCompiler') {
return;
}
compilerLoaded = true;
done();
});
solcProcess.send({action: 'loadCompiler'});
};
SolcW.prototype.isCompilerLoaded = function() {
return (compilerLoaded === true);
};
SolcW.prototype.compile = function(obj, optimize, done) {
solcProcess.once('message', function(msg) {
if (msg.result !== 'compilation') {
return;
}
done(msg.output);
});
solcProcess.send({action: 'compile', obj: obj, optimize: optimize});
};
module.exports = SolcW;

5
lib/core/core.js Normal file
View File

@ -0,0 +1,5 @@
var Core = function() {};
module.exports = Core;

View File

@ -7,9 +7,7 @@ var Blockchain = require('./cmds/blockchain/blockchain.js');
var Simulator = require('./cmds/simulator.js');
var TemplateGenerator = require('./cmds/template_generator.js');
var Deploy = require('./contracts/deploy.js');
var ContractsManager = require('./contracts/contracts.js');
var ABIGenerator = require('./contracts/abi.js');
var DeployManager = require('./contracts/deploy_manager.js');
var Test = require('./core/test.js');
var Logger = require('./core/logger.js');
@ -62,126 +60,38 @@ var Embark = {
templateGenerator.generate(destinationFolder, name);
},
redeploy: function(env) {
var self = this;
async.waterfall([
function reloadFiles(callback) {
self.config.reloadConfig();
callback();
},
self.buildDeployGenerate.bind(self),
function buildPipeline(abi, callback) {
self.logger.setStatus("Building Assets");
var pipeline = new Pipeline({
buildDir: self.config.buildDir,
contractsFiles: self.config.contractsFiles,
assetFiles: self.config.assetFiles,
logger: self.logger,
plugins: self.plugins
});
pipeline.build(abi);
callback();
}
], function(err, result) {
if (err) {
self.logger.error(err.message);
} else {
self.logger.trace("finished".underline);
}
});
},
run: function(options) {
var self = this;
var env = options.env;
async.waterfall([
function welcome(callback) {
if (!options.useDashboard) {
console.log('========================'.bold.green);
console.log(('Welcome to Embark ' + Embark.version).yellow.bold);
console.log('========================'.bold.green);
}
callback();
},
if (!options.useDashboard) {
console.log('========================'.bold.green);
console.log(('Welcome to Embark ' + Embark.version).yellow.bold);
console.log('========================'.bold.green);
}
async.parallel([
function startDashboard(callback) {
if (!options.useDashboard) {
return callback();
}
Embark.dashboard = new Dashboard({
var dashboard = new Dashboard({
logger: Embark.logger,
plugins: self.plugins,
version: self.version,
env: env
});
Embark.dashboard.start(callback);
},
function displayLoadedPlugins(callback) {
var pluginList = self.plugins.listPlugins();
if (pluginList.length > 0) {
self.logger.info("loaded plugins: " + pluginList.join(", "));
}
callback();
},
function monitorServices(callback) {
if (!options.useDashboard) {
return callback();
}
Embark.servicesMonitor = new ServicesMonitor({
logger: Embark.logger,
config: Embark.config,
serverHost: options.serverHost,
serverPort: options.serverPort,
runWebserver: options.runWebserver,
version: Embark.version
dashboard.start(function() {
self.events.on('abi-vanila', function(abi) {
dashboard.console.runCode(abi);
});
callback();
});
Embark.servicesMonitor.startMonitor();
callback();
},
self.buildDeployGenerate.bind(self),
function buildPipeline(abi, callback) {
self.logger.setStatus("Building Assets");
var pipeline = new Pipeline({
buildDir: self.config.buildDir,
contractsFiles: self.config.contractsFiles,
assetFiles: self.config.assetFiles,
logger: self.logger,
plugins: self.plugins
});
pipeline.build(abi);
callback();
},
function watchFilesForChanges(callback) {
self.logger.setStatus("Watching for changes");
var watch = new Watch({logger: self.logger, events: self.events});
watch.start();
self.events.on('file-event', function(fileType, path) {
if (fileType === 'contract' || fileType === 'config') {
self.logger.info("received redeploy event");
Embark.redeploy();
}
});
self.events.on('rebuildAssets', function(fileType, path) {
if (fileType === 'asset') {
self.logger.info("received rebuildAssets event");
// TODO: can just rebuild pipeline, no need to deploy contracts
// again
Embark.redeploy();
}
});
callback();
},
function startAssetServer(callback) {
if (!options.runWebserver) {
return callback();
}
self.logger.setStatus("Starting Server");
var server = new Server({
logger: self.logger,
host: options.serverHost,
port: options.serverPort
});
server.start(callback);
function (callback) {
Embark.startEmbark(options, callback);
}
], function(err, result) {
if (err) {
@ -194,14 +104,128 @@ var Embark = {
});
},
startEmbark: function(options, done) {
var self = this;
var env = options.env;
async.waterfall([
function displayLoadedPlugins(callback) {
var pluginList = self.plugins.listPlugins();
if (pluginList.length > 0) {
self.logger.info("loaded plugins: " + pluginList.join(", "));
}
callback();
},
// can be done in paralell
function monitorServices(callback) {
if (!options.useDashboard) {
return callback();
}
var servicesMonitor = new ServicesMonitor({
logger: Embark.logger,
config: Embark.config,
serverHost: options.serverHost,
serverPort: options.serverPort,
runWebserver: options.runWebserver,
version: Embark.version
});
servicesMonitor.startMonitor();
callback();
},
function buildPipeline(callback) {
self.logger.setStatus("Building Assets");
var pipeline = new Pipeline({
buildDir: self.config.buildDir,
contractsFiles: self.config.contractsFiles,
assetFiles: self.config.assetFiles,
logger: self.logger,
plugins: self.plugins
});
self.events.on('abi', function(abi) {
pipeline.build(abi);
});
callback();
},
function deploy(callback) {
var deployManager = new DeployManager({
config: Embark.config,
logger: Embark.logger,
plugins: self.plugins,
events: self.events
});
deployManager.deployContracts(function() {
callback();
});
self.events.on('file-event', function(fileType, path) {
if (fileType === 'contract' || fileType === 'config') {
self.config.reloadConfig();
deployManager.deployContracts(function() {});
}
});
self.events.on('file-event', function(fileType, path) {
if (fileType === 'asset') {
// TODO: can just rebuild pipeline, no need to deploy contracts
// again
self.config.reloadConfig();
deployManager.deployContracts(function() {});
}
});
},
function watchFilesForChanges(callback) {
self.logger.setStatus("Watching for changes");
var watch = new Watch({logger: self.logger, events: self.events});
watch.start();
callback();
},
function startAssetServer(callback) {
if (!options.runWebserver) {
return callback();
}
self.logger.setStatus("Starting Server");
var server = new Server({
logger: self.logger,
host: options.serverHost,
port: options.serverPort
});
server.start(callback);
}
], function(err, result) {
if (err) {
self.logger.error(err.message);
}
done();
});
},
build: function(env) {
var self = this;
async.waterfall([
function displayLoadedPlugins(callback) {
var pluginList = self.plugins.listPlugins();
if (pluginList.length > 0) {
self.logger.info("loaded plugins: " + pluginList.join(", "));
}
callback();
},
function deployAndGenerateABI(callback) {
Embark.deploy(function(abi) {
var deployManager = new DeployManager({
config: Embark.config,
logger: Embark.logger,
plugins: self.plugins,
events: self.events
});
deployManager.deployContracts(function(error, abi) {
callback(null, abi);
});
},
function buildPipeline(abi, callback) {
self.logger.trace("Building Assets");
var pipeline = new Pipeline({
@ -218,131 +242,10 @@ var Embark = {
if (err) {
self.logger.error(err.message);
} else {
self.logger.trace("finished".underline);
self.logger.info("finished building".underline);
}
});
},
buildAndDeploy: function(done) {
var self = this;
async.waterfall([
function buildContracts(callback) {
var contractsManager = new ContractsManager({
contractFiles: self.config.contractsFiles,
contractsConfig: self.config.contractsConfig,
logger: Embark.logger,
plugins: self.plugins
});
contractsManager.build(callback);
},
function deployContracts(contractsManager, callback) {
//TODO: figure out where to put this since the web3 can be passed along if needed
// perhaps it should go into the deploy object itself
// TODO: should come from the config object
var web3 = new Web3();
var web3Endpoint = 'http://' + self.config.blockchainConfig.rpcHost + ':' + self.config.blockchainConfig.rpcPort;
web3.setProvider(new web3.providers.HttpProvider(web3Endpoint));
if (!web3.isConnected()) {
console.log(("Couldn't connect to " + web3Endpoint.underline + " are you sure it's on?").red);
console.log("make sure you have an ethereum node or simulator running. e.g 'embark blockchain'".magenta);
// ===================================
// TODO: should throw exception instead
// ===================================
process.exit();
}
web3.eth.getAccounts(function(err, accounts) {
if (err) {
return callback(new Error(err));
}
web3.eth.defaultAccount = accounts[0];
var deploy = new Deploy({
web3: web3,
contractsManager: contractsManager,
logger: Embark.logger,
chainConfig: self.config.chainTracker,
env: self.config.env
});
deploy.deployAll(function() {
callback(null, contractsManager);
});
});
}
], function(err, result) {
if (err) {
done(err, null);
} else {
done(null, result);
}
});
},
deploy: function(done) {
var self = this;
async.waterfall([
function buildAndDeploy(callback) {
Embark.buildAndDeploy(function(err, contractsManager) {
callback(err, contractsManager);
});
},
function generateABI(contractsManager, callback) {
var abiGenerator = new ABIGenerator({blockchainConfig: self.config.blockchainConfig, contractsManager: contractsManager, plugins: self.plugins, storageConfig: self.config.storageConfig});
callback(null, abiGenerator.generateABI({useEmbarkJS: true}));
}
], function(err, result) {
if (err) {
self.logger.error(err.message);
}
done(result);
});
},
buildDeployGenerate: function(done) {
var self = this;
if (self.config.blockchainConfig.enabled === false) {
self.logger.info('== blockchain is disabled in this environment in config/blockchain.json'.underline);
return done(null, "");
}
self.logger.setStatus("Deploying...".magenta.underline);
async.waterfall([
function deployAndBuildContractsManager(callback) {
Embark.buildAndDeploy(function(err, contractsManager) {
if (err) {
return callback(err);
}
return callback(null, contractsManager);
});
},
function generateConsoleABI(contractsManager, callback) {
var abiGenerator = new ABIGenerator({blockchainConfig: self.config.blockchainConfig, contractsManager: contractsManager, storageConfig: self.config.storageConfig, communicationConfig: self.config.communicationConfig});
var consoleABI = abiGenerator.generateABI({useEmbarkJS: false});
// not good, better generate events when deployment is done and do this
// through a listener
if (Embark.dashboard) {
Embark.dashboard.console.runCode(consoleABI);
}
callback(null, contractsManager);
},
function generateABI(contractsManager, callback) {
var abiGenerator = new ABIGenerator({blockchainConfig: self.config.blockchainConfig, contractsManager: contractsManager, plugins: self.plugins, storageConfig: self.config.storageConfig, communicationConfig: self.config.communicationConfig});
callback(null, abiGenerator.generateABI({useEmbarkJS: true}));
}
], function(err, result) {
if (err) {
self.logger.error("error deploying");
self.logger.error(err.message);
self.logger.setStatus("Deployment Error".red);
} else {
self.logger.setStatus("Ready".green);
}
done(null, result);
// needed due to child processes
process.exit();
});
},

View File

@ -1,5 +1,6 @@
/*globals describe, it*/
var Compiler = require('../lib/contracts/compiler.js');
var TestLogger = require('../lib/core/test_logger.js');
var assert = require('assert');
var fs = require('fs');
@ -8,7 +9,7 @@ var readFile = function(file) {
};
describe('embark.Compiler', function() {
var compiler = new Compiler({});
var compiler = new Compiler({logger: new TestLogger({})});
describe('#compile_solidity', function() {
var expectedObject = {};

View File

@ -34,35 +34,36 @@ describe('embark.Contratcs', function() {
});
describe('#build', function() {
it('generate contracts', function() {
it('generate contracts', function(done) {
contractsManager.build(function(err, result) {
if (err) {
throw err;
}
var contracts = contractsManager.listContracts();
assert.equal(contracts.length, 2);
assert.equal(contracts[0].deploy, true);
assert.deepEqual(contracts[0].args, [100]);
assert.equal(contracts[0].className, "Token");
assert.deepEqual(contracts[0].gas, 725000);
//assert.equal(contracts[0].gasPrice, []); // TODO: test this one
assert.equal(contracts[0].type, 'file');
//assert.equal(contracts[0].abiDefinition, '');
//assert.equal(contracts[0].code, '');
//assert.equal(contracts[0].runtimeBytecode, '');
assert.equal(contracts[1].deploy, true);
assert.deepEqual(contracts[1].args, [200]);
assert.equal(contracts[1].className, "SimpleStorage");
assert.deepEqual(contracts[1].gas, 725000);
//assert.equal(contracts[1].gasPrice, []); // TODO: test this one
assert.equal(contracts[1].type, 'file');
//assert.equal(contracts[1].abiDefinition, '');
//assert.equal(contracts[1].code, '');
//assert.equal(contracts[1].runtimeBytecode, '');
done();
});
var contracts = contractsManager.listContracts();
assert.equal(contracts.length, 2);
assert.equal(contracts[0].deploy, true);
assert.deepEqual(contracts[0].args, [100]);
assert.equal(contracts[0].className, "Token");
assert.deepEqual(contracts[0].gas, 725000);
//assert.equal(contracts[0].gasPrice, []); // TODO: test this one
assert.equal(contracts[0].type, 'file');
//assert.equal(contracts[0].abiDefinition, '');
//assert.equal(contracts[0].code, '');
//assert.equal(contracts[0].runtimeBytecode, '');
assert.equal(contracts[1].deploy, true);
assert.deepEqual(contracts[1].args, [200]);
assert.equal(contracts[1].className, "SimpleStorage");
assert.deepEqual(contracts[1].gas, 725000);
//assert.equal(contracts[1].gasPrice, []); // TODO: test this one
assert.equal(contracts[1].type, 'file');
//assert.equal(contracts[1].abiDefinition, '');
//assert.equal(contracts[1].code, '');
//assert.equal(contracts[1].runtimeBytecode, '');
});
});
});
@ -102,58 +103,59 @@ describe('embark.Contratcs', function() {
});
describe('#build', function() {
it('generate contracts', function() {
it('generate contracts', function(done) {
contractsManager.build(function(err, result) {
if (err) {
throw err;
}
var contracts = contractsManager.listContracts();
assert.equal(contracts.length, 4);
assert.equal(contracts[0].className, "MySimpleStorage");
assert.equal(contracts[1].className, "AnotherSimpleStorage");
assert.equal(contracts[2].className, "SimpleStorage");
assert.equal(contracts[3].className, "TokenStorage");
// TokenStorage
assert.equal(contracts[3].deploy, true);
assert.deepEqual(contracts[3].args, [100, '$SimpleStorage']);
assert.deepEqual(contracts[3].gas, 725000);
assert.equal(contracts[3].type, 'file');
//assert.equal(contracts[3].abiDefinition, '');
//assert.equal(contracts[3].code, '');
//assert.equal(contracts[3].runtimeBytecode, '');
var parentContract = contracts[2];
//MySimpleStorage
assert.equal(contracts[0].deploy, true);
assert.deepEqual(contracts[0].args, [300]);
assert.deepEqual(contracts[0].gas, 725000);
assert.equal(contracts[0].type, 'instance');
assert.equal(contracts[0].abiDefinition, parentContract.abiDefinition);
assert.equal(contracts[0].code, parentContract.code);
assert.equal(contracts[0].runtimeBytecode, parentContract.runtimeBytecode);
// SimpleStorage
assert.equal(contracts[2].deploy, true);
assert.deepEqual(contracts[2].args, [200]);
assert.deepEqual(contracts[2].gas, 725000);
assert.equal(contracts[2].type, 'file');
//assert.equal(contracts[2].abiDefinition, '');
//assert.equal(contracts[2].code, '');
//assert.equal(contracts[2].runtimeBytecode, '');
// AnotherSimpleStorage
assert.equal(contracts[1].deploy, true);
assert.deepEqual(contracts[1].args, [200]);
assert.deepEqual(contracts[1].gas, 725000);
assert.equal(contracts[1].type, 'instance');
assert.equal(contracts[1].abiDefinition, parentContract.abiDefinition);
assert.equal(contracts[1].code, parentContract.code);
assert.equal(contracts[1].runtimeBytecode, parentContract.runtimeBytecode);
done();
});
var contracts = contractsManager.listContracts();
assert.equal(contracts.length, 4);
assert.equal(contracts[0].className, "MySimpleStorage");
assert.equal(contracts[1].className, "AnotherSimpleStorage");
assert.equal(contracts[2].className, "SimpleStorage");
assert.equal(contracts[3].className, "TokenStorage");
// TokenStorage
assert.equal(contracts[3].deploy, true);
assert.deepEqual(contracts[3].args, [100, '$SimpleStorage']);
assert.deepEqual(contracts[3].gas, 725000);
assert.equal(contracts[3].type, 'file');
//assert.equal(contracts[3].abiDefinition, '');
//assert.equal(contracts[3].code, '');
//assert.equal(contracts[3].runtimeBytecode, '');
var parentContract = contracts[2];
//MySimpleStorage
assert.equal(contracts[0].deploy, true);
assert.deepEqual(contracts[0].args, [300]);
assert.deepEqual(contracts[0].gas, 725000);
assert.equal(contracts[0].type, 'instance');
assert.equal(contracts[0].abiDefinition, parentContract.abiDefinition);
assert.equal(contracts[0].code, parentContract.code);
assert.equal(contracts[0].runtimeBytecode, parentContract.runtimeBytecode);
// SimpleStorage
assert.equal(contracts[2].deploy, true);
assert.deepEqual(contracts[2].args, [200]);
assert.deepEqual(contracts[2].gas, 725000);
assert.equal(contracts[2].type, 'file');
//assert.equal(contracts[2].abiDefinition, '');
//assert.equal(contracts[2].code, '');
//assert.equal(contracts[2].runtimeBytecode, '');
// AnotherSimpleStorage
assert.equal(contracts[1].deploy, true);
assert.deepEqual(contracts[1].args, [200]);
assert.deepEqual(contracts[1].gas, 725000);
assert.equal(contracts[1].type, 'instance');
assert.equal(contracts[1].abiDefinition, parentContract.abiDefinition);
assert.equal(contracts[1].code, parentContract.code);
assert.equal(contracts[1].runtimeBytecode, parentContract.runtimeBytecode);
});
});
});

View File

@ -9,6 +9,7 @@ contract Token {
mapping( address => uint ) _balances;
mapping( address => mapping( address => uint ) ) _approvals;
uint public _supply;
//uint public _supply2;
function Token( uint initial_balance ) {
_balances[msg.sender] = initial_balance;
_supply = initial_balance;