Merge branch 'mds' into develop
This commit is contained in:
commit
65ae827350
|
@ -1,21 +1,14 @@
|
||||||
/*jshint esversion: 6, loopfunc: true */
|
/*jshint esversion: 6, loopfunc: true */
|
||||||
let async = require('../utils/async_extend.js');
|
let async = require('../utils/async_extend.js');
|
||||||
let SolcW = require('./solcW.js');
|
|
||||||
|
|
||||||
class Compiler {
|
class Compiler {
|
||||||
constructor(options) {
|
constructor(options) {
|
||||||
this.plugins = options.plugins;
|
this.plugins = options.plugins;
|
||||||
this.logger = options.logger;
|
this.logger = options.logger;
|
||||||
this.solcVersion = options.solcVersion;
|
|
||||||
this.contractDirectories = options.contractDirectories;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
compile_contracts(contractFiles, cb) {
|
compile_contracts(contractFiles, cb) {
|
||||||
|
let available_compilers = {};
|
||||||
let available_compilers = {
|
|
||||||
//".se": this.compile_serpent
|
|
||||||
".sol": this.compile_solidity.bind(this)
|
|
||||||
};
|
|
||||||
|
|
||||||
if (this.plugins) {
|
if (this.plugins) {
|
||||||
let compilerPlugins = this.plugins.getPluginsFor('compilers');
|
let compilerPlugins = this.plugins.getPluginsFor('compilers');
|
||||||
|
@ -48,90 +41,6 @@ class Compiler {
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
compile_solidity(contractFiles, cb) {
|
|
||||||
let self = this;
|
|
||||||
let input = {};
|
|
||||||
let solcW;
|
|
||||||
async.waterfall([
|
|
||||||
function prepareInput(callback) {
|
|
||||||
async.each(contractFiles,
|
|
||||||
function(file, fileCb) {
|
|
||||||
let filename = file.filename;
|
|
||||||
|
|
||||||
for (let directory of self.contractDirectories) {
|
|
||||||
filename = filename.replace(directory, '');
|
|
||||||
}
|
|
||||||
|
|
||||||
file.content(function(fileContent) {
|
|
||||||
input[filename] = fileContent;
|
|
||||||
fileCb();
|
|
||||||
});
|
|
||||||
},
|
|
||||||
function (err) {
|
|
||||||
callback(err);
|
|
||||||
}
|
|
||||||
);
|
|
||||||
},
|
|
||||||
function loadCompiler(callback) {
|
|
||||||
// TODO: there ino need to load this twice
|
|
||||||
solcW = new SolcW({logger: self.logger, solcVersion: self.solcVersion});
|
|
||||||
if (solcW.isCompilerLoaded()) {
|
|
||||||
return callback();
|
|
||||||
}
|
|
||||||
|
|
||||||
self.logger.info("loading solc compiler..");
|
|
||||||
solcW.load_compiler(function (err) {
|
|
||||||
callback(err);
|
|
||||||
});
|
|
||||||
},
|
|
||||||
function compileContracts(callback) {
|
|
||||||
self.logger.info("compiling contracts...");
|
|
||||||
solcW.compile({sources: input}, 1, function (output) {
|
|
||||||
if (output.errors) {
|
|
||||||
for (let i=0; i<output.errors; i++) {
|
|
||||||
if (output.errors[i].indexOf('Warning:') >= 0) {
|
|
||||||
return callback(new Error("Solidity errors: " + output.errors).message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
self.logger.warn(output.errors.join('\n'));
|
|
||||||
}
|
|
||||||
callback(null, output);
|
|
||||||
});
|
|
||||||
},
|
|
||||||
function createCompiledObject(output, callback) {
|
|
||||||
let json = output.contracts;
|
|
||||||
|
|
||||||
let compiled_object = {};
|
|
||||||
|
|
||||||
for (let contractName in json) {
|
|
||||||
let contract = json[contractName];
|
|
||||||
|
|
||||||
// Pull out filename:classname
|
|
||||||
// [0] filename:classname
|
|
||||||
// [1] filename
|
|
||||||
// [2] classname
|
|
||||||
const regex = /(.*):(.*)/;
|
|
||||||
const className = contractName.match(regex)[2];
|
|
||||||
const filename = contractName.match(regex)[1];
|
|
||||||
|
|
||||||
compiled_object[className] = {};
|
|
||||||
compiled_object[className].code = contract.bytecode;
|
|
||||||
compiled_object[className].runtimeBytecode = contract.runtimeBytecode;
|
|
||||||
compiled_object[className].realRuntimeBytecode = contract.runtimeBytecode.slice(0, -68);
|
|
||||||
compiled_object[className].swarmHash = contract.runtimeBytecode.slice(-68).slice(0, 64);
|
|
||||||
compiled_object[className].gasEstimates = contract.gasEstimates;
|
|
||||||
compiled_object[className].functionHashes = contract.functionHashes;
|
|
||||||
compiled_object[className].abiDefinition = JSON.parse(contract.interface);
|
|
||||||
compiled_object[className].filename = filename;
|
|
||||||
}
|
|
||||||
|
|
||||||
callback(null, compiled_object);
|
|
||||||
}
|
|
||||||
], function (err, result) {
|
|
||||||
cb(err, result);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = Compiler;
|
module.exports = Compiler;
|
||||||
|
|
|
@ -8,17 +8,10 @@ let Compiler = require('./compiler.js');
|
||||||
class ContractsManager {
|
class ContractsManager {
|
||||||
constructor(options) {
|
constructor(options) {
|
||||||
this.contractFiles = options.contractFiles;
|
this.contractFiles = options.contractFiles;
|
||||||
this.contractDirectories = options.contractDirectories;
|
|
||||||
this.contractsConfig = options.contractsConfig;
|
this.contractsConfig = options.contractsConfig;
|
||||||
this.contracts = {};
|
this.contracts = {};
|
||||||
this.logger = options.logger;
|
this.logger = options.logger;
|
||||||
this.plugins = options.plugins;
|
this.plugins = options.plugins;
|
||||||
if (!options.contractsConfig.versions) {
|
|
||||||
this.solcVersion = "0.4.17";
|
|
||||||
} else {
|
|
||||||
this.solcVersion = options.contractsConfig.versions.solc;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.contractDependencies = {};
|
this.contractDependencies = {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,7 +19,7 @@ class ContractsManager {
|
||||||
let self = this;
|
let self = this;
|
||||||
async.waterfall([
|
async.waterfall([
|
||||||
function compileContracts(callback) {
|
function compileContracts(callback) {
|
||||||
let compiler = new Compiler({plugins: self.plugins, logger: self.logger, solcVersion: self.solcVersion, contractDirectories: self.contractDirectories});
|
let compiler = new Compiler({plugins: self.plugins, logger: self.logger});
|
||||||
compiler.compile_contracts(self.contractFiles, function (err, compiledObject) {
|
compiler.compile_contracts(self.contractFiles, function (err, compiledObject) {
|
||||||
self.compiledContracts = compiledObject;
|
self.compiledContracts = compiledObject;
|
||||||
callback(err);
|
callback(err);
|
||||||
|
|
|
@ -26,7 +26,6 @@ class DeployManager {
|
||||||
function buildContracts(callback) {
|
function buildContracts(callback) {
|
||||||
let contractsManager = new ContractsManager({
|
let contractsManager = new ContractsManager({
|
||||||
contractFiles: self.config.contractsFiles,
|
contractFiles: self.config.contractsFiles,
|
||||||
contractDirectories: self.config.contractDirectories,
|
|
||||||
contractsConfig: self.config.contractsConfig,
|
contractsConfig: self.config.contractsConfig,
|
||||||
logger: self.logger,
|
logger: self.logger,
|
||||||
plugins: self.plugins
|
plugins: self.plugins
|
||||||
|
|
|
@ -46,6 +46,10 @@ class Engine {
|
||||||
this.servicesMonitor.startMonitor();
|
this.servicesMonitor.startMonitor();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
registerModule(moduleName, options) {
|
||||||
|
this.plugins.loadInternalPlugin(moduleName, options);
|
||||||
|
}
|
||||||
|
|
||||||
startService(serviceName, _options) {
|
startService(serviceName, _options) {
|
||||||
let options = _options || {};
|
let options = _options || {};
|
||||||
|
|
||||||
|
@ -124,6 +128,12 @@ class Engine {
|
||||||
|
|
||||||
deploymentService(options) {
|
deploymentService(options) {
|
||||||
let self = this;
|
let self = this;
|
||||||
|
|
||||||
|
this.registerModule('solidity', {
|
||||||
|
solcVersion: self.config.contractsConfig.versions.solc,
|
||||||
|
contractDirectories: self.config.contractDirectories
|
||||||
|
});
|
||||||
|
|
||||||
this.deployManager = new DeployManager({
|
this.deployManager = new DeployManager({
|
||||||
web3: options.web3 || self.web3,
|
web3: options.web3 || self.web3,
|
||||||
trackContracts: options.trackContracts,
|
trackContracts: options.trackContracts,
|
||||||
|
|
|
@ -5,6 +5,7 @@ var utils = require('../utils/utils.js');
|
||||||
// TODO: pass other params like blockchainConfig, contract files, etc..
|
// TODO: pass other params like blockchainConfig, contract files, etc..
|
||||||
var Plugin = function(options) {
|
var Plugin = function(options) {
|
||||||
this.name = options.name;
|
this.name = options.name;
|
||||||
|
this.isInternal = options.isInternal;
|
||||||
this.pluginModule = options.pluginModule;
|
this.pluginModule = options.pluginModule;
|
||||||
this.pluginPath = options.pluginPath;
|
this.pluginPath = options.pluginPath;
|
||||||
this.pluginConfig = options.pluginConfig;
|
this.pluginConfig = options.pluginConfig;
|
||||||
|
@ -31,6 +32,10 @@ Plugin.prototype.loadPlugin = function() {
|
||||||
(this.pluginModule.call(this, this));
|
(this.pluginModule.call(this, this));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Plugin.prototype.loadInternalPlugin = function() {
|
||||||
|
new this.pluginModule(this, this.pluginConfig); /*eslint no-new: "off"*/
|
||||||
|
};
|
||||||
|
|
||||||
Plugin.prototype.loadPluginFile = function(filename) {
|
Plugin.prototype.loadPluginFile = function(filename) {
|
||||||
return fs.readFileSync(this.pathToFile(filename)).toString();
|
return fs.readFileSync(this.pathToFile(filename)).toString();
|
||||||
};
|
};
|
||||||
|
|
|
@ -27,11 +27,20 @@ Plugins.prototype.listPlugins = function() {
|
||||||
return list;
|
return list;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Plugins.prototype.loadInternalPlugin = function(pluginName, pluginConfig) {
|
||||||
|
var pluginPath = utils.joinPath('../modules/', pluginName, 'index.js');
|
||||||
|
var plugin = require(pluginPath);
|
||||||
|
|
||||||
|
var pluginWrapper = new Plugin({name: pluginName, pluginModule: plugin, pluginConfig: pluginConfig, logger: this.logger, pluginPath: pluginPath, interceptLogs: this.interceptLogs, events: this.events, config: this.config, isInternal: true});
|
||||||
|
pluginWrapper.loadInternalPlugin();
|
||||||
|
this.plugins.push(pluginWrapper);
|
||||||
|
};
|
||||||
|
|
||||||
Plugins.prototype.loadPlugin = function(pluginName, pluginConfig) {
|
Plugins.prototype.loadPlugin = function(pluginName, pluginConfig) {
|
||||||
var pluginPath = utils.joinPath(process.env.PWD, 'node_modules', pluginName);
|
var pluginPath = utils.joinPath(process.env.PWD, 'node_modules', pluginName);
|
||||||
var plugin = require(pluginPath);
|
var plugin = require(pluginPath);
|
||||||
|
|
||||||
var pluginWrapper = new Plugin({name: pluginName, pluginModule: plugin, pluginConfig: pluginConfig, logger: this.logger, pluginPath: pluginPath, interceptLogs: this.interceptLogs, events: this.events, config: this.config});
|
var pluginWrapper = new Plugin({name: pluginName, pluginModule: plugin, pluginConfig: pluginConfig, logger: this.logger, pluginPath: pluginPath, interceptLogs: this.interceptLogs, events: this.events, config: this.config, isInternal: false});
|
||||||
pluginWrapper.loadPlugin();
|
pluginWrapper.loadPlugin();
|
||||||
this.plugins.push(pluginWrapper);
|
this.plugins.push(pluginWrapper);
|
||||||
};
|
};
|
||||||
|
|
|
@ -51,7 +51,8 @@ Test.prototype.deployAll = function(contractsConfig, cb) {
|
||||||
|
|
||||||
async.waterfall([
|
async.waterfall([
|
||||||
function getConfig(callback) {
|
function getConfig(callback) {
|
||||||
self.engine.config.contractsConfig = {contracts: contractsConfig};
|
let _versions_default = self.engine.config.contractsConfig.versions;
|
||||||
|
self.engine.config.contractsConfig = {contracts: contractsConfig, versions: _versions_default};
|
||||||
callback();
|
callback();
|
||||||
},
|
},
|
||||||
function startServices(callback) {
|
function startServices(callback) {
|
||||||
|
|
|
@ -0,0 +1,100 @@
|
||||||
|
let async = require('../../utils/async_extend.js');
|
||||||
|
let SolcW = require('./solcW.js');
|
||||||
|
|
||||||
|
class Solidity {
|
||||||
|
|
||||||
|
constructor(embark, options) {
|
||||||
|
this.logger = embark.logger;
|
||||||
|
this.solcVersion = options.solcVersion;
|
||||||
|
this.contractDirectories = options.contractDirectories;
|
||||||
|
|
||||||
|
embark.registerCompiler(".sol", this.compile_solidity.bind(this));
|
||||||
|
}
|
||||||
|
|
||||||
|
compile_solidity(contractFiles, cb) {
|
||||||
|
let self = this;
|
||||||
|
let input = {};
|
||||||
|
let solcW;
|
||||||
|
async.waterfall([
|
||||||
|
function prepareInput(callback) {
|
||||||
|
async.each(contractFiles,
|
||||||
|
function(file, fileCb) {
|
||||||
|
let filename = file.filename;
|
||||||
|
|
||||||
|
for (let directory of self.contractDirectories) {
|
||||||
|
filename = filename.replace(directory, '');
|
||||||
|
}
|
||||||
|
|
||||||
|
file.content(function(fileContent) {
|
||||||
|
input[filename] = fileContent;
|
||||||
|
fileCb();
|
||||||
|
});
|
||||||
|
},
|
||||||
|
function (err) {
|
||||||
|
callback(err);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
},
|
||||||
|
function loadCompiler(callback) {
|
||||||
|
// TODO: there ino need to load this twice
|
||||||
|
solcW = new SolcW({logger: self.logger, solcVersion: self.solcVersion});
|
||||||
|
if (solcW.isCompilerLoaded()) {
|
||||||
|
return callback();
|
||||||
|
}
|
||||||
|
|
||||||
|
self.logger.info("loading solc compiler..");
|
||||||
|
solcW.load_compiler(function (err) {
|
||||||
|
callback(err);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
function compileContracts(callback) {
|
||||||
|
self.logger.info("compiling contracts...");
|
||||||
|
solcW.compile({sources: input}, 1, function (output) {
|
||||||
|
if (output.errors) {
|
||||||
|
for (let i=0; i<output.errors; i++) {
|
||||||
|
if (output.errors[i].indexOf('Warning:') >= 0) {
|
||||||
|
return callback(new Error("Solidity errors: " + output.errors).message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
self.logger.warn(output.errors.join('\n'));
|
||||||
|
}
|
||||||
|
callback(null, output);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
function createCompiledObject(output, callback) {
|
||||||
|
let json = output.contracts;
|
||||||
|
|
||||||
|
let compiled_object = {};
|
||||||
|
|
||||||
|
for (let contractName in json) {
|
||||||
|
let contract = json[contractName];
|
||||||
|
|
||||||
|
// Pull out filename:classname
|
||||||
|
// [0] filename:classname
|
||||||
|
// [1] filename
|
||||||
|
// [2] classname
|
||||||
|
const regex = /(.*):(.*)/;
|
||||||
|
const className = contractName.match(regex)[2];
|
||||||
|
const filename = contractName.match(regex)[1];
|
||||||
|
|
||||||
|
compiled_object[className] = {};
|
||||||
|
compiled_object[className].code = contract.bytecode;
|
||||||
|
compiled_object[className].runtimeBytecode = contract.runtimeBytecode;
|
||||||
|
compiled_object[className].realRuntimeBytecode = contract.runtimeBytecode.slice(0, -68);
|
||||||
|
compiled_object[className].swarmHash = contract.runtimeBytecode.slice(-68).slice(0, 64);
|
||||||
|
compiled_object[className].gasEstimates = contract.gasEstimates;
|
||||||
|
compiled_object[className].functionHashes = contract.functionHashes;
|
||||||
|
compiled_object[className].abiDefinition = JSON.parse(contract.interface);
|
||||||
|
compiled_object[className].filename = filename;
|
||||||
|
}
|
||||||
|
|
||||||
|
callback(null, compiled_object);
|
||||||
|
}
|
||||||
|
], function (err, result) {
|
||||||
|
cb(err, result);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = Solidity;
|
|
@ -1,9 +1,8 @@
|
||||||
let utils = require('../utils/utils.js');
|
let utils = require('../../utils/utils.js');
|
||||||
let solcProcess;
|
let solcProcess;
|
||||||
let compilerLoaded = false;
|
let compilerLoaded = false;
|
||||||
var Npm = require('../pipeline/npm.js');
|
var Npm = require('../../pipeline/npm.js');
|
||||||
let path = require('path');
|
let currentSolcVersion = require('../../../package.json').dependencies.solc;
|
||||||
let currentSolcVersion = require('../../package.json').dependencies.solc;
|
|
||||||
|
|
||||||
class SolcW {
|
class SolcW {
|
||||||
|
|
||||||
|
@ -33,7 +32,7 @@ class SolcW {
|
||||||
if (err) {
|
if (err) {
|
||||||
return done(err);
|
return done(err);
|
||||||
}
|
}
|
||||||
let requirePath = path.join(process.env.PWD, location);
|
let requirePath = utils.joinPath(process.env.PWD, location);
|
||||||
solcProcess.send({action: 'loadCompiler', solcLocation: requirePath});
|
solcProcess.send({action: 'loadCompiler', solcLocation: requirePath});
|
||||||
});
|
});
|
||||||
}
|
}
|
|
@ -1,46 +0,0 @@
|
||||||
var Config = require('../lib/config/config.js');
|
|
||||||
var Blockchain = require('../lib/blockchain.js');
|
|
||||||
var assert = require('assert');
|
|
||||||
var sinon = require('sinon');
|
|
||||||
|
|
||||||
describe('embark.blockchain', function() {
|
|
||||||
var blockchainConfig = (new Config.Blockchain()).loadConfigFile('test/support/blockchain.yml').config("development");
|
|
||||||
|
|
||||||
describe('#generate_basic_command', function() {
|
|
||||||
var blockchain = new Blockchain(blockchainConfig);
|
|
||||||
|
|
||||||
it('should return correct cmd', function() {
|
|
||||||
assert.strictEqual(blockchain.generate_basic_command(), "geth --datadir=\"/tmp/embark\" --password config/password --port 30303 --rpc --rpcport 8101 --rpcaddr localhost --networkid "+blockchainConfig.networkId+" --rpccorsdomain=\"*\" --minerthreads \"1\" --mine --rpcapi \"eth,web3\" --maxpeers 4 ");
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('#list_command', function() {
|
|
||||||
var blockchain = new Blockchain(blockchainConfig);
|
|
||||||
blockchain.generate_basic_command = sinon.stub().returns("geth ");
|
|
||||||
|
|
||||||
it('should generate command to list accounts', function() {
|
|
||||||
assert.equal(blockchain.list_command(), "geth --datadir=\"/tmp/embark\" --password config/password account list ");
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('#init_command', function() {
|
|
||||||
var blockchain = new Blockchain(blockchainConfig);
|
|
||||||
blockchain.generate_basic_command = sinon.stub().returns("geth ");
|
|
||||||
|
|
||||||
it('should generate command to create an account', function() {
|
|
||||||
assert.equal(blockchain.init_command(), "geth --datadir=\"/tmp/embark\" --password config/password account new ");
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('#run_command', function() {
|
|
||||||
describe('with mine when needed config set', function() {
|
|
||||||
var blockchain = new Blockchain(blockchainConfig);
|
|
||||||
blockchain.generate_basic_command = sinon.stub().returns("geth ");
|
|
||||||
|
|
||||||
it('should generate run command with script ', function() {
|
|
||||||
assert.equal(blockchain.run_command(), "geth js node_modules/embark-framework/js/mine.js");
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
});
|
|
|
@ -1,66 +0,0 @@
|
||||||
var ChainManager = require('../lib/chain_manager.js');
|
|
||||||
var Config = require('../lib/config/config.js');
|
|
||||||
var Blockchain = require('../lib/blockchain.js');
|
|
||||||
var assert = require('assert');
|
|
||||||
var fs = require('fs');
|
|
||||||
|
|
||||||
// TODO: replace with ethersim
|
|
||||||
var Web3 = require('web3');
|
|
||||||
var web3 = new Web3();
|
|
||||||
web3.setProvider(new web3.providers.HttpProvider("http://localhost:8101"));
|
|
||||||
|
|
||||||
describe('embark.chain_manager', function() {
|
|
||||||
var chainFile = './test/support/chain_manager.json';
|
|
||||||
fs.writeFileSync(chainFile, '{}');
|
|
||||||
|
|
||||||
var chainManager = (new ChainManager()).loadConfigFile(chainFile);
|
|
||||||
var blockchainConfig = (new Config.Blockchain()).loadConfigFile('test/support/blockchain.yml').config('development');
|
|
||||||
|
|
||||||
describe('#init', function() {
|
|
||||||
chainManager.init('development', blockchainConfig, web3);
|
|
||||||
|
|
||||||
it('should initialize chain', function() {
|
|
||||||
var chain = chainManager.chainManagerConfig['0x245a1b878a79ee9d0fd46e19c89d0cefbaa475e74e45fa133e022da45943b111']
|
|
||||||
assert.equal(chain != undefined, true);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('#addContract', function() {
|
|
||||||
|
|
||||||
it('should register a contract in the chain', function() {
|
|
||||||
chainManager.addContract("Foo", "123456", [], "0x123");
|
|
||||||
|
|
||||||
console.log(chainManager.chainManagerConfig);
|
|
||||||
var chain = chainManager.chainManagerConfig['0x245a1b878a79ee9d0fd46e19c89d0cefbaa475e74e45fa133e022da45943b111']
|
|
||||||
var contract = chain.contracts["d5d91a8825c5c253dff531ddda2354c4014f5699b7bcbea70207cfdcb37b6c8b"]
|
|
||||||
|
|
||||||
assert.equal(contract.name, "Foo");
|
|
||||||
assert.equal(contract.address, "0x123");
|
|
||||||
});
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('#getContract', function() {
|
|
||||||
|
|
||||||
it('should a contract in the chain', function() {
|
|
||||||
var contract = chainManager.getContract("Foo", "123456", []);
|
|
||||||
|
|
||||||
assert.equal(contract.name, "Foo");
|
|
||||||
assert.equal(contract.address, "0x123");
|
|
||||||
});
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('#save', function() {
|
|
||||||
|
|
||||||
it('should save changes in the chain', function() {
|
|
||||||
chainManager.save();
|
|
||||||
|
|
||||||
var chainFile = './test/support/chain_manager.json';
|
|
||||||
var content = fs.readFileSync(chainFile).toString();
|
|
||||||
assert.equal(content, '{"0x245a1b878a79ee9d0fd46e19c89d0cefbaa475e74e45fa133e022da45943b111\":{"contracts":{"d5d91a8825c5c253dff531ddda2354c4014f5699b7bcbea70207cfdcb37b6c8b\":{"name":"Foo","address":"0x123"}}}}');
|
|
||||||
});
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
});
|
|
|
@ -1,69 +0,0 @@
|
||||||
var Compiler = require('../lib/compiler.js');
|
|
||||||
var assert = require('assert');
|
|
||||||
|
|
||||||
describe('embark.compiler', function() {
|
|
||||||
|
|
||||||
describe('compile a file', function() {
|
|
||||||
var files = [
|
|
||||||
'test/support/contracts/simple_storage.sol'
|
|
||||||
];
|
|
||||||
|
|
||||||
it("should build a correct compiled object", function() {
|
|
||||||
var compiler = new Compiler();
|
|
||||||
|
|
||||||
var compiledFile = compiler.compile(files);
|
|
||||||
|
|
||||||
assert.equal(compiledFile.SimpleStorage.code, '60606040526040516020806075833950608060405251600081905550604e8060276000396000f3606060405260e060020a60003504632a1afcd98114602e57806360fe47b11460365780636d4ce63c146040575b005b604460005481565b600435600055602c565b6000545b6060908152602090f3');
|
|
||||||
|
|
||||||
assert.equal(JSON.stringify(compiledFile.SimpleStorage.info.abiDefinition), '[{"constant":true,"inputs":[],"name":"storedData","outputs":[{"name":"","type":"uint256"}],"type":"function"},{"constant":false,"inputs":[{"name":"x","type":"uint256"}],"name":"set","outputs":[],"type":"function"},{"constant":true,"inputs":[],"name":"get","outputs":[{"name":"retVal","type":"uint256"}],"type":"function"},{"inputs":[{"name":"initialValue","type":"uint256"}],"type":"constructor"}]');
|
|
||||||
});
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('compile a file with an error', function() {
|
|
||||||
var files = [
|
|
||||||
'test/support/contracts/error.sol'
|
|
||||||
];
|
|
||||||
|
|
||||||
it("throw an error", function() {
|
|
||||||
var compiler = new Compiler();
|
|
||||||
|
|
||||||
assert.throws(function() { compiler.compile(files) }, Error);
|
|
||||||
});
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('compile a serpent file', function() {
|
|
||||||
var files = [
|
|
||||||
'test/support/contracts/cash.se'
|
|
||||||
];
|
|
||||||
|
|
||||||
it("should build a correct compiled object", function() {
|
|
||||||
var compiler = new Compiler();
|
|
||||||
|
|
||||||
var compiledFile = compiler.compile(files);
|
|
||||||
|
|
||||||
assert.equal(compiledFile.cash.code, '6000603f536a0186a000000000000000006040604059905901600090526000815232816020015280905020556103658061003a60003961039f56600061047f537c010000000000000000000000000000000000000000000000000000000060003504638357984f81141561005f57600435604052604060405990590160009052600081526040518160200152809050205460605260206060f35b63693200ce8114156101465760043560a05260243560c0523260e0526040604059905901600090526000815260e051816020015280905020546101005260c051610100511215156101385760c0516040604059905901600090526000815260e05181602001528090502054036040604059905901600090526000815260e0518160200152809050205560c0516040604059905901600090526000815260a05181602001528090502054016040604059905901600090526000815260a0518160200152809050205560c0516101c05260206101c0f3610145565b60006101e05260206101e0f35b5b6380b97fc081141561024c5760043560a05260243560c05260443561020052326102005114151561017e576000610220526020610220f35b6040604059905901600090526000815261020051816020015280905020546101005260c0516101005112151561023e5760c0516040604059905901600090526000815261020051816020015280905020540360406040599059016000905260008152610200518160200152809050205560c0516040604059905901600090526000815260a05181602001528090502054016040604059905901600090526000815260a0518160200152809050205560c0516102e05260206102e0f361024b565b6000610300526020610300f35b5b634c764abc8114156102b4576004356103205260243561034052610340516040604059905901600090526000815261032051816020015280905020540360406040599059016000905260008152610320518160200152809050205560016103a05260206103a0f35b63a92c9b8381141561031c57600435610320526024356103405261034051604060405990590160009052600081526103205181602001528090502054016040604059905901600090526000815261032051816020015280905020556001610400526020610400f35b631d62e92281141561036357600435604052602435610420526104205160406040599059016000905260008152604051816020015280905020556001610460526020610460f35b505b6000f3');
|
|
||||||
|
|
||||||
assert.equal(JSON.stringify(compiledFile.cash.info.abiDefinition), '[{\"name\":\"addCash(int256,int256)\",\"type\":\"function\",\"inputs\":[{\"name\":\"ID\",\"type\":\"int256\"},{\"name\":\"amount\",\"type\":\"int256\"}],\"outputs\":[{\"name\":\"out\",\"type\":\"int256\"}],\"constant\":true},{\"name\":\"balance(int256)\",\"type\":\"function\",\"inputs\":[{\"name\":\"address\",\"type\":\"int256\"}],\"outputs\":[{\"name\":\"out\",\"type\":\"int256\"}],\"constant\":true},{\"name\":\"send(int256,int256)\",\"type\":\"function\",\"inputs\":[{\"name\":\"recver\",\"type\":\"int256\"},{\"name\":\"value\",\"type\":\"int256\"}],\"outputs\":[{\"name\":\"out\",\"type\":\"int256\"}],\"constant\":true},{\"name\":\"sendFrom(int256,int256,int256)\",\"type\":\"function\",\"inputs\":[{\"name\":\"recver\",\"type\":\"int256\"},{\"name\":\"value\",\"type\":\"int256\"},{\"name\":\"from\",\"type\":\"int256\"}],\"outputs\":[{\"name\":\"out\",\"type\":\"int256\"}],\"constant\":true},{\"name\":\"setCash(int256,int256)\",\"type\":\"function\",\"inputs\":[{\"name\":\"address\",\"type\":\"int256\"},{\"name\":\"balance\",\"type\":\"int256\"}],\"outputs\":[{\"name\":\"out\",\"type\":\"int256\"}],\"constant\":true},{\"name\":\"subtractCash(int256,int256)\",\"type\":\"function\",\"inputs\":[{\"name\":\"ID\",\"type\":\"int256\"},{\"name\":\"amount\",\"type\":\"int256\"}],\"outputs\":[{\"name\":\"out\",\"type\":\"int256\"}],\"constant\":true}]');
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('compile a file with an error', function() {
|
|
||||||
var files = [
|
|
||||||
'test/support/contracts/error.sol'
|
|
||||||
];
|
|
||||||
|
|
||||||
it("throw an error", function() {
|
|
||||||
var compiler = new Compiler();
|
|
||||||
|
|
||||||
assert.throws(function() { compiler.compile(files) }, Error);
|
|
||||||
});
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
|
@ -1,150 +0,0 @@
|
||||||
var Config = require('../lib/config/config.js');
|
|
||||||
var assert = require('assert');
|
|
||||||
|
|
||||||
describe('embark.config.blockchain', function() {
|
|
||||||
var blockchainConfig = new Config.Blockchain();
|
|
||||||
|
|
||||||
describe('#loadConfigFile', function() {
|
|
||||||
it('should read and load yml file', function() {
|
|
||||||
blockchainConfig.loadConfigFile('test/support/blockchain.yml');
|
|
||||||
|
|
||||||
assert.equal(blockchainConfig.blockchainConfig.hasOwnProperty('development'), true)
|
|
||||||
assert.equal(blockchainConfig.blockchainConfig.hasOwnProperty('staging'), true)
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should throw exception reading invalid file', function() {
|
|
||||||
assert.throws(function() { blockchainConfig.loadConfigFile('test/support/invalid.yml') }, Error);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('#loadConfig', function() {
|
|
||||||
it('should load config', function() {
|
|
||||||
var hsh = {
|
|
||||||
development: {},
|
|
||||||
staging: {}
|
|
||||||
};
|
|
||||||
|
|
||||||
blockchainConfig.loadConfig(hsh);
|
|
||||||
|
|
||||||
assert.equal(blockchainConfig.blockchainConfig.hasOwnProperty('development'), true)
|
|
||||||
assert.equal(blockchainConfig.blockchainConfig.hasOwnProperty('staging'), true)
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('#config', function() {
|
|
||||||
|
|
||||||
it('should load environment', function() {
|
|
||||||
var hsh = {
|
|
||||||
development: {
|
|
||||||
rpc_host: 'localhost',
|
|
||||||
rpc_port: 8101,
|
|
||||||
rpc_whitelist: "*",
|
|
||||||
network_id: 0,
|
|
||||||
minerthreads: 1,
|
|
||||||
genesis_block: 'config/genesis.json',
|
|
||||||
datadir: '/tmp/embark',
|
|
||||||
chains: 'chains_development.json',
|
|
||||||
deploy_timeout: 45,
|
|
||||||
mine_when_needed: true,
|
|
||||||
gas_limit: 123,
|
|
||||||
gas_price: 100,
|
|
||||||
console: false,
|
|
||||||
account: {
|
|
||||||
init: true,
|
|
||||||
password: 'config/password'
|
|
||||||
}
|
|
||||||
},
|
|
||||||
staging: {}
|
|
||||||
};
|
|
||||||
|
|
||||||
blockchainConfig.loadConfig(hsh);
|
|
||||||
|
|
||||||
assert.deepEqual(blockchainConfig.config('development'), {
|
|
||||||
rpcHost: 'localhost',
|
|
||||||
rpcPort: 8101,
|
|
||||||
gasLimit: 123,
|
|
||||||
gasPrice: 100,
|
|
||||||
rpcWhitelist: "*",
|
|
||||||
testnet: false,
|
|
||||||
bootNodes: [],
|
|
||||||
whisper: false,
|
|
||||||
minerthreads: 1,
|
|
||||||
nat: [],
|
|
||||||
genesisBlock: 'config/genesis.json',
|
|
||||||
datadir: '/tmp/embark',
|
|
||||||
chains: 'chains_development.json',
|
|
||||||
deployTimeout: 45,
|
|
||||||
deploy_synchronously: false,
|
|
||||||
networkId: 0,
|
|
||||||
maxPeers: 4,
|
|
||||||
mine: false,
|
|
||||||
port: "30303",
|
|
||||||
console_toggle: false,
|
|
||||||
mine_when_needed: true,
|
|
||||||
geth_extra_opts: [],
|
|
||||||
account: {
|
|
||||||
init: true,
|
|
||||||
password: 'config/password'
|
|
||||||
}
|
|
||||||
})
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should return defaults', function() {
|
|
||||||
var hsh = {
|
|
||||||
development: {
|
|
||||||
rpc_host: 'localhost',
|
|
||||||
rpc_port: 8101,
|
|
||||||
rpc_whitelist: "*",
|
|
||||||
network_id: 0,
|
|
||||||
minerthreads: 1,
|
|
||||||
datadir: '/tmp/embark',
|
|
||||||
chains: undefined,
|
|
||||||
mine_when_needed: true,
|
|
||||||
console: false,
|
|
||||||
account: {
|
|
||||||
init: true,
|
|
||||||
password: 'config/password'
|
|
||||||
},
|
|
||||||
},
|
|
||||||
staging: {}
|
|
||||||
};
|
|
||||||
|
|
||||||
blockchainConfig.loadConfig(hsh);
|
|
||||||
|
|
||||||
assert.deepEqual(blockchainConfig.config('development'), {
|
|
||||||
rpcHost: 'localhost',
|
|
||||||
rpcPort: 8101,
|
|
||||||
gasLimit: 500000,
|
|
||||||
gasPrice: 10000000000000,
|
|
||||||
rpcWhitelist: "*",
|
|
||||||
testnet: false,
|
|
||||||
bootNodes: [],
|
|
||||||
whisper: false,
|
|
||||||
minerthreads: 1,
|
|
||||||
nat: [],
|
|
||||||
genesisBlock: undefined,
|
|
||||||
datadir: '/tmp/embark',
|
|
||||||
chains: undefined,
|
|
||||||
deployTimeout: 20,
|
|
||||||
deploy_synchronously: false,
|
|
||||||
networkId: 0,
|
|
||||||
maxPeers: 4,
|
|
||||||
mine: false,
|
|
||||||
port: "30303",
|
|
||||||
console_toggle: false,
|
|
||||||
mine_when_needed: true,
|
|
||||||
geth_extra_opts: [],
|
|
||||||
account: {
|
|
||||||
init: true,
|
|
||||||
password: 'config/password'
|
|
||||||
}
|
|
||||||
})
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should load environment', function() {
|
|
||||||
var blockchainConfig = new Config.Blockchain();
|
|
||||||
assert.throws(function() { blockchainConfig.config('development') }, Error);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
});
|
|
|
@ -1,115 +0,0 @@
|
||||||
var Config = require('../lib/config/config.js');
|
|
||||||
var Compiler = require('../lib/compiler.js');
|
|
||||||
var assert = require('assert');
|
|
||||||
var sinon = require('sinon');
|
|
||||||
require('mocha-sinon');
|
|
||||||
|
|
||||||
describe('embark.config.contracts', function() {
|
|
||||||
var _blockchainConfig = (new Config.Blockchain()).loadConfigFile('test/support/blockchain.yml');
|
|
||||||
var blockchainConfig = _blockchainConfig.config("development");
|
|
||||||
var compiler = new Compiler(_blockchainConfig);
|
|
||||||
|
|
||||||
describe('#loadConfigFile', function() {
|
|
||||||
it('should read and load yml file', function() {
|
|
||||||
var contractsConfig = new Config.Contracts(blockchainConfig, compiler);
|
|
||||||
contractsConfig.loadConfigFile('test/support/contracts.yml');
|
|
||||||
|
|
||||||
assert.equal(contractsConfig.contractConfig.hasOwnProperty('development'), true)
|
|
||||||
assert.equal(contractsConfig.contractConfig.hasOwnProperty('staging'), true)
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should throw exception reading invalid file', function() {
|
|
||||||
assert.throws(function() { contractsConfig.loadConfigFile('test/support/invalid.yml') }, Error);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('#loadConfig', function() {
|
|
||||||
it('should load config', function() {
|
|
||||||
var contractsConfig = new Config.Contracts([], blockchainConfig, compiler);
|
|
||||||
var hsh = {
|
|
||||||
development: {},
|
|
||||||
staging: {}
|
|
||||||
};
|
|
||||||
|
|
||||||
contractsConfig.loadConfig(hsh);
|
|
||||||
|
|
||||||
assert.equal(contractsConfig.contractConfig.hasOwnProperty('development'), true)
|
|
||||||
assert.equal(contractsConfig.contractConfig.hasOwnProperty('staging'), true)
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('#compileContracts', function() {
|
|
||||||
context("simple contracts", function() {
|
|
||||||
before(function() {
|
|
||||||
files = [
|
|
||||||
'test/support/contracts/simple_storage.sol',
|
|
||||||
'test/support/contracts/another_storage.sol'
|
|
||||||
]
|
|
||||||
contractsConfig = new Config.Contracts(blockchainConfig, compiler);
|
|
||||||
contractsConfig.loadConfigFile('test/support/contracts.yml');
|
|
||||||
contractsConfig.init(files, 'development');
|
|
||||||
contractsConfig.compileContracts();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('add contracts to a list', function() {
|
|
||||||
//assert.deepEqual(contractsConfig.all_contracts, [ "SimpleStorage", "AnotherStorage" ]);
|
|
||||||
assert.deepEqual(contractsConfig.all_contracts, [ "AnotherStorage", "SimpleStorage" ]);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
context("contracts as arguments to other contracts", function() {
|
|
||||||
before(function() {
|
|
||||||
files = [
|
|
||||||
'test/support/contracts/wallet.sol',
|
|
||||||
'test/support/contracts/simple_storage.sol',
|
|
||||||
'test/support/contracts/another_storage.sol',
|
|
||||||
'test/support/contracts/wallets.sol'
|
|
||||||
]
|
|
||||||
contractsConfig = new Config.Contracts(blockchainConfig, compiler);
|
|
||||||
contractsConfig.loadConfigFile('test/support/arguments.yml');
|
|
||||||
contractsConfig.init(files, 'development');
|
|
||||||
contractsConfig.compileContracts('development');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('add contracts to a list', function() {
|
|
||||||
assert.deepEqual(contractsConfig.all_contracts, [ "SimpleStorage", "AnotherStorage", "Wallet", "Wallets" ]);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
context("contracts instances", function() {
|
|
||||||
before(function() {
|
|
||||||
files = [
|
|
||||||
'test/support/contracts/simple_storage.sol'
|
|
||||||
]
|
|
||||||
contractsConfig = new Config.Contracts(blockchainConfig, compiler);
|
|
||||||
contractsConfig.loadConfigFile('test/support/instances.yml');
|
|
||||||
contractsConfig.init(files, 'development');
|
|
||||||
contractsConfig.compileContracts('development');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('add contracts to a list', function() {
|
|
||||||
assert.deepEqual(contractsConfig.all_contracts, [ "SimpleStorage", "BarStorage", "FooStorage" ]);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
context("contracts as arguments to other contracts with stubs", function() {
|
|
||||||
before(function() {
|
|
||||||
files = [
|
|
||||||
'test/support/contracts/crowdsale.sol',
|
|
||||||
'test/support/contracts/token.sol'
|
|
||||||
]
|
|
||||||
contractsConfig = new Config.Contracts(blockchainConfig, compiler);
|
|
||||||
contractsConfig.loadConfigFile('test/support/arguments2.yml');
|
|
||||||
contractsConfig.init(files, 'development');
|
|
||||||
contractsConfig.compileContracts('development');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('add contracts to a list', function() {
|
|
||||||
assert.deepEqual(contractsConfig.all_contracts, [ "token", "Crowdsale" ]);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
|
@ -1,261 +0,0 @@
|
||||||
var Config = require('../lib/config/config.js');
|
|
||||||
var Deploy = require('../lib/deploy.js');
|
|
||||||
var Compiler = require('../lib/compiler.js');
|
|
||||||
var ChainManager = require('../lib/chain_manager.js');
|
|
||||||
var assert = require('assert');
|
|
||||||
var web3 = require('web3');
|
|
||||||
|
|
||||||
// TODO: replace with ethersim
|
|
||||||
var Web3 = require('web3');
|
|
||||||
var web3 = new Web3();
|
|
||||||
web3.setProvider(new web3.providers.HttpProvider("http://localhost:8101"));
|
|
||||||
|
|
||||||
setDeployConfig = function(config) {
|
|
||||||
var _blockchainConfig = (new Config.Blockchain()).loadConfigFile(config.blockchain);
|
|
||||||
var blockchainConfig = _blockchainConfig.config("development");
|
|
||||||
var compiler = new Compiler(_blockchainConfig);
|
|
||||||
var contractsConfig = new Config.Contracts(blockchainConfig, compiler);
|
|
||||||
var chainManager = (new ChainManager()).loadConfigFile('./test/support/chain_manager.json');
|
|
||||||
contractsConfig.loadConfigFile(config.contracts);
|
|
||||||
contractsConfig.init(config.files, 'development');
|
|
||||||
compiler.init('development');
|
|
||||||
return new Deploy('development', config.files, blockchainConfig, contractsConfig, chainManager, true, false, web3);
|
|
||||||
}
|
|
||||||
|
|
||||||
function Done(fn) {
|
|
||||||
var self = this;
|
|
||||||
var called = false;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @param {*} params...
|
|
||||||
*/
|
|
||||||
this.trigger = function (params) {
|
|
||||||
if(called) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
fn.apply(self, arguments);
|
|
||||||
called = true;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
describe('embark.deploy', function() {
|
|
||||||
|
|
||||||
describe('contracts as arguments to other contracts', function() {
|
|
||||||
var files = [
|
|
||||||
'test/support/contracts/wallet.sol',
|
|
||||||
'test/support/contracts/simple_storage.sol',
|
|
||||||
'test/support/contracts/another_storage.sol',
|
|
||||||
'test/support/contracts/wallets.sol'
|
|
||||||
];
|
|
||||||
|
|
||||||
describe('#deploy_contracts', function() {
|
|
||||||
var deploy = setDeployConfig({
|
|
||||||
files: files,
|
|
||||||
blockchain: 'test/support/blockchain.yml',
|
|
||||||
contracts: 'test/support/arguments.yml'
|
|
||||||
});
|
|
||||||
|
|
||||||
it("should deploy contracts", function(fn) {
|
|
||||||
var doneWrap = new Done(fn);
|
|
||||||
|
|
||||||
deploy.deploy_contracts("development", function() {
|
|
||||||
var all_contracts = ['Wallet', 'SimpleStorage', 'AnotherStorage', 'Wallets'];
|
|
||||||
for(var i=0; i < all_contracts.length; i++) {
|
|
||||||
var className = all_contracts[i];
|
|
||||||
|
|
||||||
assert.equal(deploy.deployedContracts.hasOwnProperty(className), true);
|
|
||||||
}
|
|
||||||
|
|
||||||
doneWrap.trigger();
|
|
||||||
});
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('#generate_abi_file', function() {
|
|
||||||
var deploy = setDeployConfig({
|
|
||||||
files: files,
|
|
||||||
blockchain: 'test/support/blockchain.yml',
|
|
||||||
contracts: 'test/support/arguments.yml'
|
|
||||||
});
|
|
||||||
deploy.deployedContracts = {
|
|
||||||
"SimpleStorage": "0x123",
|
|
||||||
"AnotherStorage": "0x234"
|
|
||||||
}
|
|
||||||
deploy.contractDB = {
|
|
||||||
"SimpleStorage": {compiled: {info: {abiDefinition: 123}}},
|
|
||||||
"AnotherStorage": {compiled: {info: {abiDefinition: 234}}}
|
|
||||||
}
|
|
||||||
|
|
||||||
it("should deploy contracts", function() {
|
|
||||||
var result = "";
|
|
||||||
|
|
||||||
result += deploy.generate_provider_file();
|
|
||||||
result += deploy.generate_abi_file();
|
|
||||||
|
|
||||||
assert.strictEqual(result, "var web3 = new Web3();web3.setProvider(new web3.providers.HttpProvider('http://localhost:8101'));web3.eth.defaultAccount = web3.eth.accounts[0];blockchain = {\"testnet\":false,\"rpcHost\":\"localhost\",\"rpcPort\":8101,\"gasLimit\":1000000,\"gasPrice\":10000000000000,\"rpcWhitelist\":\"*\",\"nat\":[],\"minerthreads\":1,\"genesisBlock\":\"config/genesis.json\",\"datadir\":\"/tmp/embark\",\"bootNodes\":[],\"deployTimeout\":20,\"networkId\":"+deploy.blockchainConfig.networkId+",\"maxPeers\":4,\"mine\":false,\"port\":\"30303\",\"console_toggle\":false,\"mine_when_needed\":true,\"whisper\":false,\"account\":{\"init\":true,\"password\":\"config/password\"},\"geth_extra_opts\":[],\"deploy_synchronously\":false};SimpleStorageAbi = 123;SimpleStorageContract = web3.eth.contract(SimpleStorageAbi);SimpleStorage = SimpleStorageContract.at('0x123');AnotherStorageAbi = 234;AnotherStorageContract = web3.eth.contract(AnotherStorageAbi);AnotherStorage = AnotherStorageContract.at('0x234');contractDB = {\"SimpleStorage\":{\"compiled\":{\"info\":{\"abiDefinition\":123}}},\"AnotherStorage\":{\"compiled\":{\"info\":{\"abiDefinition\":234}}}};");
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('contracts as arguments to other contracts with stubs', function() {
|
|
||||||
var files = [
|
|
||||||
'test/support/contracts/crowdsale.sol',
|
|
||||||
'test/support/contracts/token.sol'
|
|
||||||
];
|
|
||||||
|
|
||||||
describe('#deploy_contracts', function() {
|
|
||||||
var deploy = setDeployConfig({
|
|
||||||
files: files,
|
|
||||||
blockchain: 'test/support/blockchain.yml',
|
|
||||||
contracts: 'test/support/arguments2.yml'
|
|
||||||
});
|
|
||||||
|
|
||||||
it("should deploy contracts", function(fn) {
|
|
||||||
var doneWrap = new Done(fn);
|
|
||||||
|
|
||||||
deploy.deploy_contracts("development", function() {
|
|
||||||
|
|
||||||
var all_contracts = ['token', 'Crowdsale'];
|
|
||||||
for(var i=0; i < all_contracts.length; i++) {
|
|
||||||
var className = all_contracts[i];
|
|
||||||
|
|
||||||
assert.equal(deploy.deployedContracts.hasOwnProperty(className), true);
|
|
||||||
}
|
|
||||||
|
|
||||||
doneWrap.trigger();
|
|
||||||
});
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('contracts instances', function() {
|
|
||||||
var files = [
|
|
||||||
'test/support/contracts/simple_storage.sol'
|
|
||||||
];
|
|
||||||
|
|
||||||
describe('#deploy_contracts', function() {
|
|
||||||
var deploy = setDeployConfig({
|
|
||||||
files: files,
|
|
||||||
blockchain: 'test/support/blockchain.yml',
|
|
||||||
contracts: 'test/support/instances.yml'
|
|
||||||
});
|
|
||||||
|
|
||||||
it("should deploy contracts", function(fn) {
|
|
||||||
var doneWrap = new Done(fn);
|
|
||||||
|
|
||||||
deploy.deploy_contracts("development", function() {
|
|
||||||
|
|
||||||
var all_contracts = ['BarStorage', 'FooStorage'];
|
|
||||||
for(var i=0; i < all_contracts.length; i++) {
|
|
||||||
var className = all_contracts[i];
|
|
||||||
|
|
||||||
assert.equal(deploy.deployedContracts.hasOwnProperty(className), true);
|
|
||||||
}
|
|
||||||
assert.notEqual(deploy.deployedContracts.hasOwnProperty('SimpleStorage'), true);
|
|
||||||
|
|
||||||
doneWrap.trigger();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('contracts deploy script', function() {
|
|
||||||
var files = [
|
|
||||||
'test/support/contracts/data_source.sol',
|
|
||||||
'test/support/contracts/manager.sol'
|
|
||||||
];
|
|
||||||
|
|
||||||
describe('#deploy_contracts', function() {
|
|
||||||
var deploy = setDeployConfig({
|
|
||||||
files: files,
|
|
||||||
blockchain: 'test/support/blockchain.yml',
|
|
||||||
contracts: 'test/support/arguments3.yml'
|
|
||||||
});
|
|
||||||
|
|
||||||
it("should deploy contracts", function(fn) {
|
|
||||||
var doneWrap = new Done(fn);
|
|
||||||
|
|
||||||
deploy.deploy_contracts("development", function() {
|
|
||||||
var all_contracts = ['DataSource', 'MyDataSource', 'Manager'];
|
|
||||||
for(var i=0; i < all_contracts.length; i++) {
|
|
||||||
var className = all_contracts[i];
|
|
||||||
|
|
||||||
assert.equal(deploy.deployedContracts.hasOwnProperty(className), true);
|
|
||||||
}
|
|
||||||
|
|
||||||
doneWrap.trigger();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it("should execute deploy changes", function(fn) {
|
|
||||||
var doneWrap = new Done(fn);
|
|
||||||
|
|
||||||
web3.setProvider(new web3.providers.HttpProvider('http://localhost:8101'));
|
|
||||||
web3.eth.defaultAccount = web3.eth.accounts[0];
|
|
||||||
|
|
||||||
data_source_abi = deploy.contractDB['DataSource'].compiled.info.abiDefinition;
|
|
||||||
data_source_address = deploy.deployedContracts['DataSource'];
|
|
||||||
my_data_source_abi = deploy.contractDB['MyDataSource'].compiled.info.abiDefinition;
|
|
||||||
my_data_source_address = deploy.deployedContracts['MyDataSource'];
|
|
||||||
manager_abi = deploy.contractDB['Manager'].compiled.info.abiDefinition;
|
|
||||||
manager_address = deploy.deployedContracts['Manager'];
|
|
||||||
|
|
||||||
DataSource = web3.eth.contract(data_source_abi).at(data_source_address);
|
|
||||||
MyDataSource = web3.eth.contract(my_data_source_abi).at(my_data_source_address);
|
|
||||||
ManagerSource = web3.eth.contract(manager_abi).at(manager_address);
|
|
||||||
|
|
||||||
assert.equal(DataSource.storeData().toNumber(), 5);
|
|
||||||
assert.equal(Manager.data().toString(), my_data_source_address);
|
|
||||||
|
|
||||||
doneWrap.trigger();
|
|
||||||
});
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('contracts with addresses defined', function() {
|
|
||||||
var files = [
|
|
||||||
'test/support/contracts/simple_storage.sol'
|
|
||||||
];
|
|
||||||
|
|
||||||
describe('#deploy_contracts', function() {
|
|
||||||
var deploy = setDeployConfig({
|
|
||||||
files: files,
|
|
||||||
blockchain: 'test/support/blockchain.yml',
|
|
||||||
contracts: 'test/support/address.yml'
|
|
||||||
});
|
|
||||||
|
|
||||||
it("should not deploy contracts with addresses defined", function(fn) {
|
|
||||||
var doneWrap = new Done(fn);
|
|
||||||
|
|
||||||
deploy.deploy_contracts("development", function() {
|
|
||||||
var expected_deploys = ['SimpleStorage', 'BarStorage', 'FooStorage'];
|
|
||||||
|
|
||||||
for(var i=0; i < expected_deploys.length; i++) {
|
|
||||||
var className = expected_deploys[i];
|
|
||||||
|
|
||||||
assert.equal(deploy.deployedContracts.hasOwnProperty(className), true);
|
|
||||||
}
|
|
||||||
|
|
||||||
assert.equal(deploy.deployedContracts['SimpleStorage'], '0x123');
|
|
||||||
assert.equal(deploy.deployedContracts['BarStorage'], '0x234');
|
|
||||||
|
|
||||||
doneWrap.trigger();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
});
|
|
|
@ -1,13 +0,0 @@
|
||||||
development:
|
|
||||||
SimpleStorage:
|
|
||||||
address: 0x123
|
|
||||||
args:
|
|
||||||
- 100
|
|
||||||
BarStorage:
|
|
||||||
address: 0x234
|
|
||||||
instanceOf: SimpleStorage
|
|
||||||
FooStorage:
|
|
||||||
instanceOf: SimpleStorage
|
|
||||||
args:
|
|
||||||
- 200
|
|
||||||
staging:
|
|
|
@ -1,14 +0,0 @@
|
||||||
development:
|
|
||||||
Wallet:
|
|
||||||
args:
|
|
||||||
- $AnotherStorage
|
|
||||||
SimpleStorage:
|
|
||||||
args:
|
|
||||||
- 100
|
|
||||||
AnotherStorage:
|
|
||||||
args:
|
|
||||||
- 100
|
|
||||||
Wallets:
|
|
||||||
args:
|
|
||||||
- $Wallet
|
|
||||||
staging:
|
|
|
@ -1,13 +0,0 @@
|
||||||
development:
|
|
||||||
token:
|
|
||||||
args:
|
|
||||||
Crowdsale:
|
|
||||||
stubs:
|
|
||||||
- token
|
|
||||||
args:
|
|
||||||
- 0x123
|
|
||||||
- 100000000000000000000
|
|
||||||
- 30
|
|
||||||
- 20000000000000000
|
|
||||||
- $token
|
|
||||||
staging:
|
|
|
@ -1,15 +0,0 @@
|
||||||
development:
|
|
||||||
DataSource:
|
|
||||||
args:
|
|
||||||
MyDataSource:
|
|
||||||
args:
|
|
||||||
instanceOf: DataSource
|
|
||||||
Manager:
|
|
||||||
stubs:
|
|
||||||
- DataSource
|
|
||||||
args:
|
|
||||||
- $DataSource
|
|
||||||
onDeploy:
|
|
||||||
- DataSource.set(5)
|
|
||||||
- Manager.update($MyDataSource)
|
|
||||||
staging:
|
|
|
@ -1,24 +0,0 @@
|
||||||
development:
|
|
||||||
rpc_host: localhost
|
|
||||||
rpc_port: 8101
|
|
||||||
rpc_whitelist: "*"
|
|
||||||
minerthreads: 1
|
|
||||||
genesis_block: config/genesis.json
|
|
||||||
datadir: /tmp/embark
|
|
||||||
mine_when_needed: true
|
|
||||||
gas_limit: 1000000
|
|
||||||
gas_price: 10000000000000
|
|
||||||
console: false
|
|
||||||
account:
|
|
||||||
init: true
|
|
||||||
password: config/password
|
|
||||||
staging:
|
|
||||||
rpc_host: localhost
|
|
||||||
rpc_port: 8101
|
|
||||||
rpc_whitelist: "*"
|
|
||||||
datadir: default
|
|
||||||
network_id: 0
|
|
||||||
console: true
|
|
||||||
account:
|
|
||||||
init: false
|
|
||||||
address:
|
|
|
@ -1 +0,0 @@
|
||||||
{"0x245a1b878a79ee9d0fd46e19c89d0cefbaa475e74e45fa133e022da45943b111":{"contracts":{"d5d91a8825c5c253dff531ddda2354c4014f5699b7bcbea70207cfdcb37b6c8b":{"name":"Foo","address":"0x123"}}}}
|
|
|
@ -1,2 +0,0 @@
|
||||||
development:
|
|
||||||
staging:
|
|
|
@ -1,14 +0,0 @@
|
||||||
contract AnotherStorage {
|
|
||||||
uint public storedData;
|
|
||||||
|
|
||||||
function SimpleStorage(uint initialValue) {
|
|
||||||
storedData = initialValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
function set(uint x) {
|
|
||||||
storedData = x;
|
|
||||||
}
|
|
||||||
function get() constant returns (uint retVal) {
|
|
||||||
return storedData;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,75 +0,0 @@
|
||||||
# This software (Augur) allows buying && selling event outcomes in ethereum
|
|
||||||
# Copyright (C) 2015 Forecast Foundation
|
|
||||||
# This program is free software; you can redistribute it &&/or modify
|
|
||||||
# it under the terms of the GNU General Public License as published by
|
|
||||||
# the Free Software Foundation; either version 2 of the License, or
|
|
||||||
# (at your option) any later version.
|
|
||||||
#
|
|
||||||
# This program is free software: you can redistribute it &&/or modify
|
|
||||||
# it under the terms of the GNU General Public License as published by
|
|
||||||
# the Free Software Foundation, either version 3 of the License, or
|
|
||||||
# (at your option) any later version.
|
|
||||||
#
|
|
||||||
# This program is distributed in the hope that it will be useful,
|
|
||||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
# GNU General Public License for more details.
|
|
||||||
#
|
|
||||||
# You should have received a copy of the GNU General Public License
|
|
||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
# Any questions please contact joey@augur.net
|
|
||||||
|
|
||||||
data cashcoinBalances[]
|
|
||||||
|
|
||||||
def init():
|
|
||||||
# test initial funds
|
|
||||||
self.cashcoinBalances[tx.origin] = 100000*2^64
|
|
||||||
|
|
||||||
# @return: cash balance of address
|
|
||||||
def balance(address):
|
|
||||||
return(self.cashcoinBalances[address])
|
|
||||||
|
|
||||||
# should send values as fixed point in UI (1 is 2^64, 4 is 4*2^64, .5 is 2^63, etc.)
|
|
||||||
# so cashcoin fees could just go to root branch, or we could not have fees besides
|
|
||||||
# gas fee to do a send transaction
|
|
||||||
# @return: value sent, 0 if fails
|
|
||||||
def send(recver, value):
|
|
||||||
sender = tx.origin
|
|
||||||
senderBalance = self.cashcoinBalances[sender]
|
|
||||||
if(senderBalance >= value):
|
|
||||||
self.cashcoinBalances[sender] -= value
|
|
||||||
self.cashcoinBalances[recver] += value
|
|
||||||
return(value)
|
|
||||||
else:
|
|
||||||
return(0)
|
|
||||||
|
|
||||||
# @return value of cash sent; fail is 0
|
|
||||||
def sendFrom(recver, value, from):
|
|
||||||
if(from!=tx.origin):
|
|
||||||
return(0)
|
|
||||||
senderBalance = self.cashcoinBalances[from]
|
|
||||||
if(senderBalance >= value):
|
|
||||||
self.cashcoinBalances[from] -= value
|
|
||||||
self.cashcoinBalances[recver] += value
|
|
||||||
return(value)
|
|
||||||
else:
|
|
||||||
return(0)
|
|
||||||
|
|
||||||
# make sure only coming from specific contracts
|
|
||||||
def subtractCash(ID, amount):
|
|
||||||
#if(!self.whitelist.check(msg.sender)):
|
|
||||||
# return(-1)
|
|
||||||
self.cashcoinBalances[ID] -= amount
|
|
||||||
return(1)
|
|
||||||
|
|
||||||
def addCash(ID, amount):
|
|
||||||
#if(!self.whitelist.check(msg.sender)):
|
|
||||||
# return(-1)
|
|
||||||
self.cashcoinBalances[ID] += amount
|
|
||||||
return(1)
|
|
||||||
|
|
||||||
def setCash(address, balance):
|
|
||||||
#if !self.whitelist.check(msg.sender):
|
|
||||||
# return(-1)
|
|
||||||
self.cashcoinBalances[address] = balance
|
|
||||||
return(1)
|
|
|
@ -1,51 +0,0 @@
|
||||||
contract token { mapping (address => uint) public coinBalanceOf; function token() {} function sendCoin(address receiver, uint amount) returns(bool sufficient) { } }
|
|
||||||
|
|
||||||
contract Crowdsale {
|
|
||||||
|
|
||||||
address public beneficiary;
|
|
||||||
uint public fundingGoal; uint public amountRaised; uint public deadline; uint public price;
|
|
||||||
token public tokenReward;
|
|
||||||
Funder[] public funders;
|
|
||||||
event FundTransfer(address backer, uint amount, bool isContribution);
|
|
||||||
|
|
||||||
/* data structure to hold information about campaign contributors */
|
|
||||||
struct Funder {
|
|
||||||
address addr;
|
|
||||||
uint amount;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* at initialization, setup the owner */
|
|
||||||
function Crowdsale(address _beneficiary, uint _fundingGoal, uint _duration, uint _price, token _reward) {
|
|
||||||
beneficiary = _beneficiary;
|
|
||||||
fundingGoal = _fundingGoal;
|
|
||||||
deadline = now + _duration * 1 minutes;
|
|
||||||
price = _price;
|
|
||||||
tokenReward = token(_reward);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* The function without name is the default function that is called whenever anyone sends funds to a contract */
|
|
||||||
function () {
|
|
||||||
uint amount = msg.value;
|
|
||||||
funders[funders.length++] = Funder({addr: msg.sender, amount: amount});
|
|
||||||
amountRaised += amount;
|
|
||||||
tokenReward.sendCoin(msg.sender, amount / price);
|
|
||||||
FundTransfer(msg.sender, amount, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
modifier afterDeadline() { if (now >= deadline) _ }
|
|
||||||
|
|
||||||
/* checks if the goal or time limit has been reached and ends the campaign */
|
|
||||||
function checkGoalReached() afterDeadline {
|
|
||||||
if (amountRaised >= fundingGoal){
|
|
||||||
beneficiary.send(amountRaised);
|
|
||||||
FundTransfer(beneficiary, amountRaised, false);
|
|
||||||
} else {
|
|
||||||
FundTransfer(0, 11, false);
|
|
||||||
for (uint i = 0; i < funders.length; ++i) {
|
|
||||||
funders[i].addr.send(funders[i].amount);
|
|
||||||
FundTransfer(funders[i].addr, funders[i].amount, false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
suicide(beneficiary);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,11 +0,0 @@
|
||||||
contract DataSource {
|
|
||||||
uint public storeData;
|
|
||||||
|
|
||||||
function DataSource() {
|
|
||||||
}
|
|
||||||
|
|
||||||
function set(uint num) {
|
|
||||||
storeData = num;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,14 +0,0 @@
|
||||||
contract SimpleStorage {
|
|
||||||
uint public storedData;
|
|
||||||
|
|
||||||
function SimpleStorage(uint initialValue) {
|
|
||||||
storedData2 = initialValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
function set(uint x) {
|
|
||||||
storedData = x;
|
|
||||||
}
|
|
||||||
function get() constant returns (uint retVal) {
|
|
||||||
return storedData;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,11 +0,0 @@
|
||||||
contract Manager {
|
|
||||||
address public data;
|
|
||||||
|
|
||||||
function Manager(address dataAddress) {
|
|
||||||
data = dataAddress;
|
|
||||||
}
|
|
||||||
|
|
||||||
function update(address _addr) {
|
|
||||||
data = _addr;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,75 +0,0 @@
|
||||||
# This software (Augur) allows buying && selling event outcomes in ethereum
|
|
||||||
# Copyright (C) 2015 Forecast Foundation
|
|
||||||
# This program is free software; you can redistribute it &&/or modify
|
|
||||||
# it under the terms of the GNU General Public License as published by
|
|
||||||
# the Free Software Foundation; either version 2 of the License, or
|
|
||||||
# (at your option) any later version.
|
|
||||||
#
|
|
||||||
# This program is free software: you can redistribute it &&/or modify
|
|
||||||
# it under the terms of the GNU General Public License as published by
|
|
||||||
# the Free Software Foundation, either version 3 of the License, or
|
|
||||||
# (at your option) any later version.
|
|
||||||
#
|
|
||||||
# This program is distributed in the hope that it will be useful,
|
|
||||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
# GNU General Public License for more details.
|
|
||||||
#
|
|
||||||
# You should have received a copy of the GNU General Public License
|
|
||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
# Any questions please contact joey@augur.net
|
|
||||||
|
|
||||||
data cashcoinBalances[]
|
|
||||||
|
|
||||||
def init():
|
|
||||||
# test initial funds
|
|
||||||
self.cashcoinBalances[tx.origin] = 100000*2^64
|
|
||||||
|
|
||||||
# @return: cash balance of address
|
|
||||||
def balance(address):
|
|
||||||
return(self.cashcoinBalances[address])
|
|
||||||
|
|
||||||
# should send values as fixed point in UI (1 is 2^64, 4 is 4*2^64, .5 is 2^63, etc.)
|
|
||||||
# so cashcoin fees could just go to root branch, or we could not have fees besides
|
|
||||||
# gas fee to do a send transaction
|
|
||||||
# @return: value sent, 0 if fails
|
|
||||||
def send(recver, value):
|
|
||||||
sender = tx.origin
|
|
||||||
senderBalance = self.cashcoinBalances[sender]
|
|
||||||
if(senderBalance >= value):
|
|
||||||
self.cashcoinBalances[sender] -= value
|
|
||||||
self.cashcoinBalances[recver] += value
|
|
||||||
return(value)
|
|
||||||
else:
|
|
||||||
return(0)
|
|
||||||
|
|
||||||
# @return value of cash sent; fail is 0
|
|
||||||
def sendFrom(recver, value, from):
|
|
||||||
if(from!=tx.origin):
|
|
||||||
return(0)
|
|
||||||
senderBalance = self.cashcoinBalances[from]
|
|
||||||
if(senderBalance >= value):
|
|
||||||
self.cashcoinBalances[from] -= value
|
|
||||||
self.cashcoinBalances[recver] += value
|
|
||||||
return(value)
|
|
||||||
else:
|
|
||||||
return(0)
|
|
||||||
|
|
||||||
# make sure only coming from specific contracts
|
|
||||||
def subtractCash(ID, amount):
|
|
||||||
#if(!self.whitelist.check(msg.sender)):
|
|
||||||
# return(-1)
|
|
||||||
self.cashcoinBalances[ID] -= amount
|
|
||||||
return(1)
|
|
||||||
|
|
||||||
def addCash(ID, amount):
|
|
||||||
#if(!self.whitelist.check(msg.sender)):
|
|
||||||
# return(-1)
|
|
||||||
self.cashcoinBalances[ID] += amount
|
|
||||||
return(1)
|
|
||||||
|
|
||||||
def setCash(address, balance):
|
|
||||||
#if !self.whitelist.check(msg.sender):
|
|
||||||
# return(-1)
|
|
||||||
self.cashcoinBalances[address] = balance
|
|
||||||
return(1)
|
|
|
@ -1,14 +0,0 @@
|
||||||
contract SimpleStorage {
|
|
||||||
uint public storedData;
|
|
||||||
|
|
||||||
function SimpleStorage(uint initialValue) {
|
|
||||||
storedData = initialValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
function set(uint x) {
|
|
||||||
storedData = x;
|
|
||||||
}
|
|
||||||
function get() constant returns (uint retVal) {
|
|
||||||
return storedData;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,19 +0,0 @@
|
||||||
contract token {
|
|
||||||
mapping (address => uint) public coinBalanceOf;
|
|
||||||
event CoinTransfer(address sender, address receiver, uint amount);
|
|
||||||
|
|
||||||
/* Initializes contract with initial supply tokens to the creator of the contract */
|
|
||||||
function token(uint supply) {
|
|
||||||
//coinBalanceOf[msg.sender] = (supply || 10000);
|
|
||||||
coinBalanceOf[msg.sender] = 10000;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Very simple trade function */
|
|
||||||
function sendCoin(address receiver, uint amount) returns(bool sufficient) {
|
|
||||||
if (coinBalanceOf[msg.sender] < amount) return false;
|
|
||||||
coinBalanceOf[msg.sender] -= amount;
|
|
||||||
coinBalanceOf[receiver] += amount;
|
|
||||||
CoinTransfer(msg.sender, receiver, amount);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,8 +0,0 @@
|
||||||
contract Wallet {
|
|
||||||
address currency;
|
|
||||||
|
|
||||||
function Wallet(address c) {
|
|
||||||
currency = c;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,9 +0,0 @@
|
||||||
contract Wallets {
|
|
||||||
address wallet;
|
|
||||||
|
|
||||||
function Wallet(address w) {
|
|
||||||
wallet = w;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,12 +0,0 @@
|
||||||
development:
|
|
||||||
SimpleStorage:
|
|
||||||
deploy: false
|
|
||||||
args:
|
|
||||||
- 100
|
|
||||||
BarStorage:
|
|
||||||
instanceOf: SimpleStorage
|
|
||||||
FooStorage:
|
|
||||||
instanceOf: SimpleStorage
|
|
||||||
args:
|
|
||||||
- 200
|
|
||||||
staging:
|
|
|
@ -1,29 +0,0 @@
|
||||||
var Config = require('../lib/config/config.js');
|
|
||||||
var Test = require('../lib/test.js');
|
|
||||||
var Compiler = require('../lib/compiler.js');
|
|
||||||
var assert = require('assert');
|
|
||||||
|
|
||||||
//var contractFiles = grunt.file.expand("./app/contracts/**/*.sol")
|
|
||||||
|
|
||||||
describe('embark.test', function() {
|
|
||||||
//var files = [
|
|
||||||
// 'test/support/contracts/simple_storage.sol'
|
|
||||||
//]
|
|
||||||
//var _blockchainConfig = (new Config.Blockchain()).loadConfigFile('test/support/blockchain.yml');
|
|
||||||
//var blockchainConfig = _blockchainConfig.config("development");
|
|
||||||
//var compiler = new Compiler(_blockchainConfig);
|
|
||||||
//var contractsConfig = new Config.Contracts(blockchainConfig, compiler);
|
|
||||||
//contractsConfig.loadConfigFile('test/support/contracts.yml');
|
|
||||||
//contractsConfig.init(files, 'development');
|
|
||||||
|
|
||||||
//describe('simple test', function() {
|
|
||||||
// var embarkSpec = new Test(contractsConfig, files);
|
|
||||||
|
|
||||||
// it('execute simple test', function() {
|
|
||||||
// var SimpleStorage = embarkSpec.request('SimpleStorage', [100])
|
|
||||||
|
|
||||||
// assert.equal(SimpleStorage.storedData(), '100');
|
|
||||||
// });
|
|
||||||
//});
|
|
||||||
|
|
||||||
});
|
|
|
@ -1,5 +1,6 @@
|
||||||
/*globals describe, it*/
|
/*globals describe, it*/
|
||||||
let Compiler = require('../lib/contracts/compiler.js');
|
let Compiler = require('../lib/contracts/compiler.js');
|
||||||
|
let SolidityCompiler = require('../lib/modules/solidity');
|
||||||
let TestLogger = require('../lib/core/test_logger.js');
|
let TestLogger = require('../lib/core/test_logger.js');
|
||||||
let File = require('../lib/core/file.js');
|
let File = require('../lib/core/file.js');
|
||||||
let assert = require('assert');
|
let assert = require('assert');
|
||||||
|
@ -9,8 +10,14 @@ let readFile = function(file) {
|
||||||
return new File({filename: file, type: 'dapp_file', path: file});
|
return new File({filename: file, type: 'dapp_file', path: file});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
var apiObject = {
|
||||||
|
registerCompiler: function() {},
|
||||||
|
logger: new TestLogger({})
|
||||||
|
};
|
||||||
|
|
||||||
describe('embark.Compiler', function() {
|
describe('embark.Compiler', function() {
|
||||||
let compiler = new Compiler({logger: new TestLogger({}), solcVersion: '0.4.17', contractDirectories: ['app/contracts/']});
|
//let compiler = new Compiler({logger: new TestLogger({})});
|
||||||
|
let compiler = new SolidityCompiler(apiObject, {solcVersion: '0.4.17', contractDirectories: ['app/contracts/']});
|
||||||
|
|
||||||
describe('#compile_solidity', function() {
|
describe('#compile_solidity', function() {
|
||||||
this.timeout(0);
|
this.timeout(0);
|
||||||
|
|
|
@ -2,17 +2,27 @@
|
||||||
let ContractsManager = require('../lib/contracts/contracts.js');
|
let ContractsManager = require('../lib/contracts/contracts.js');
|
||||||
let Logger = require('../lib/core/logger.js');
|
let Logger = require('../lib/core/logger.js');
|
||||||
let File = require('../lib/core/file.js');
|
let File = require('../lib/core/file.js');
|
||||||
|
let TestLogger = require('../lib/core/test_logger.js');
|
||||||
let assert = require('assert');
|
let assert = require('assert');
|
||||||
let fs = require('fs');
|
let fs = require('fs');
|
||||||
|
|
||||||
|
//let SolidityCompiler = require('../lib/modules/solidity');
|
||||||
|
let Plugins = require('../lib/core/plugins.js');
|
||||||
|
|
||||||
let readFile = function(file) {
|
let readFile = function(file) {
|
||||||
return new File({filename: file, type: 'dapp_file', path: file});
|
return new File({filename: file, type: 'dapp_file', path: file});
|
||||||
};
|
};
|
||||||
|
|
||||||
describe('embark.Contratcs', function() {
|
describe('embark.Contracts', function() {
|
||||||
this.timeout(0);
|
this.timeout(0);
|
||||||
describe('simple', function() {
|
describe('simple', function() {
|
||||||
|
let plugins = new Plugins({
|
||||||
|
logger: new TestLogger({})
|
||||||
|
});
|
||||||
|
plugins.loadInternalPlugin('Solidity', {solcVersion: '0.4.17', contractDirectories: ['app/contracts/']});
|
||||||
|
|
||||||
let contractsManager = new ContractsManager({
|
let contractsManager = new ContractsManager({
|
||||||
|
plugins: plugins,
|
||||||
contractFiles: [
|
contractFiles: [
|
||||||
readFile('test/contracts/simple_storage.sol'),
|
readFile('test/contracts/simple_storage.sol'),
|
||||||
readFile('test/contracts/token.sol')
|
readFile('test/contracts/token.sol')
|
||||||
|
@ -85,7 +95,13 @@ describe('embark.Contratcs', function() {
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('config with contract instances', function() {
|
describe('config with contract instances', function() {
|
||||||
|
let plugins = new Plugins({
|
||||||
|
logger: new TestLogger({})
|
||||||
|
});
|
||||||
|
plugins.loadInternalPlugin('Solidity', {solcVersion: '0.4.17', contractDirectories: ['app/contracts/']});
|
||||||
|
|
||||||
let contractsManager = new ContractsManager({
|
let contractsManager = new ContractsManager({
|
||||||
|
plugins: plugins,
|
||||||
contractFiles: [
|
contractFiles: [
|
||||||
readFile('test/contracts/simple_storage.sol'),
|
readFile('test/contracts/simple_storage.sol'),
|
||||||
readFile('test/contracts/token_storage.sol')
|
readFile('test/contracts/token_storage.sol')
|
||||||
|
|
Loading…
Reference in New Issue