refactor modules; update grunt tasks
This commit is contained in:
parent
e43c0a38d6
commit
b7bdd841c9
|
@ -1,4 +1,12 @@
|
||||||
EmbarkSpec = require('embark-framework').Tests;
|
var Embark = require('embark-framework');
|
||||||
|
Embark.init();
|
||||||
|
Embark.blockchainConfig.loadConfigFile('config/blockchain.yml');
|
||||||
|
Embark.contractsConfig.loadConfigFile('config/contracts.yml');
|
||||||
|
|
||||||
|
var files = ["app/contracts/simple_storage.sol"];
|
||||||
|
|
||||||
|
Embark.contractsConfig.init(files);
|
||||||
|
var EmbarkSpec = Embark.tests(files);
|
||||||
|
|
||||||
describe("SimpleStorage", function() {
|
describe("SimpleStorage", function() {
|
||||||
beforeAll(function() {
|
beforeAll(function() {
|
||||||
|
|
|
@ -16,6 +16,10 @@ ContractsConfig.prototype.init = function(files) {
|
||||||
this.contractFiles = files;
|
this.contractFiles = files;
|
||||||
this.contractDependencies = {};
|
this.contractDependencies = {};
|
||||||
|
|
||||||
|
if (this.blockchainConfig.config != undefined) {
|
||||||
|
this.blockchainConfig = this.blockchainConfig.config('development');
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
this.web3.setProvider(new this.web3.providers.HttpProvider("http://" + this.blockchainConfig.rpcHost + ":" + this.blockchainConfig.rpcPort));
|
this.web3.setProvider(new this.web3.providers.HttpProvider("http://" + this.blockchainConfig.rpcHost + ":" + this.blockchainConfig.rpcPort));
|
||||||
primaryAddress = this.web3.eth.coinbase;
|
primaryAddress = this.web3.eth.coinbase;
|
||||||
|
|
24
lib/index.js
24
lib/index.js
|
@ -20,9 +20,27 @@ var Config = require('./config/config.js');
|
||||||
|
|
||||||
Embark = {
|
Embark = {
|
||||||
init: function() {
|
init: function() {
|
||||||
this.blockchainConfig = (new Config.BlockchainConfig());
|
this.blockchainConfig = (new Config.Blockchain());
|
||||||
this.contractsConfig = (new Config.ContractsConfig(this.blockchainConfig, web3));
|
this.contractsConfig = (new Config.Contracts(this.blockchainConfig, web3));
|
||||||
}
|
},
|
||||||
|
|
||||||
|
tests: function(contractFiles) {
|
||||||
|
return new Tests(this.contractsConfig, contractFiles);
|
||||||
|
},
|
||||||
|
|
||||||
|
startBlockchain: function(env) {
|
||||||
|
var chain = new Blockchain(this.blockchainConfig.config(env));
|
||||||
|
chain.startChain();
|
||||||
|
},
|
||||||
|
|
||||||
|
deployContracts: function(env, contractFiles) {
|
||||||
|
this.contractsConfig.init(env, contractFiles);
|
||||||
|
var deploy = new Deploy(env, contractFiles, this.blockchainConfig.config(env), this.contractsConfig);
|
||||||
|
deploy.deploy_contracts(env);
|
||||||
|
return deploy.generate_abi_file();
|
||||||
|
},
|
||||||
|
|
||||||
|
release: Release
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = Embark;
|
module.exports = Embark;
|
||||||
|
|
|
@ -7,7 +7,7 @@ ipfs = function() {
|
||||||
|
|
||||||
cmd = ipfs_path + "/ipfs add -r " + build_dir;
|
cmd = ipfs_path + "/ipfs add -r " + build_dir;
|
||||||
|
|
||||||
grunt.log.writeln("=== adding " + cmd + " to ipfs");
|
console.log("=== adding " + cmd + " to ipfs");
|
||||||
|
|
||||||
result = exec(cmd);
|
result = exec(cmd);
|
||||||
|
|
||||||
|
|
25
lib/test.js
25
lib/test.js
|
@ -59,27 +59,18 @@ TestContract = function(contract, className, args) {
|
||||||
return Obj;
|
return Obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
request = function(className, args) {
|
test = function(contractsConfig, contractFiles) {
|
||||||
py_exec("from ethertdd import EvmContract")
|
contractsConfig.init(contractFiles);
|
||||||
|
|
||||||
web3.setProvider(new web3.providers.HttpProvider('http://localhost:8101'));
|
|
||||||
web3.eth.defaultAccount = web3.eth.accounts[0];
|
|
||||||
|
|
||||||
//TODO: get the files from the config
|
|
||||||
contractFiles = grunt.file.expand("./app/contracts/**/*.sol")
|
|
||||||
blockchainConfig = (new Config.Blockchain()).loadConfigFile('config/blockchain.yml').config(env);
|
|
||||||
contractsConfig = new Config.Contracts(contractFiles, blockchainConfig);
|
|
||||||
|
|
||||||
contractsConfig.compileContracts();
|
contractsConfig.compileContracts();
|
||||||
contractDB = contractsConfig.contractDB;
|
this.contractDB = contractsConfig.contractDB;
|
||||||
|
}
|
||||||
|
|
||||||
var contract = contractDB[className];
|
test.prototype.request = function(className, args) {
|
||||||
|
var contract = this.contractDB[className];
|
||||||
|
py_exec("from ethertdd import EvmContract")
|
||||||
return TestContract(contract, className, args)
|
return TestContract(contract, className, args)
|
||||||
}
|
}
|
||||||
|
|
||||||
Test = {
|
module.exports = test;
|
||||||
request: request
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = Test;
|
|
||||||
|
|
||||||
|
|
|
@ -3,5 +3,7 @@ module.exports = (grunt) ->
|
||||||
grunt.registerTask "blockchain", "deploy ethereum node", (env_) =>
|
grunt.registerTask "blockchain", "deploy ethereum node", (env_) =>
|
||||||
env = env_ || "development"
|
env = env_ || "development"
|
||||||
Embark = require('embark-framework')
|
Embark = require('embark-framework')
|
||||||
Embark.Blockchain.startChain(env)
|
Embark.init()
|
||||||
|
Embark.blockchainConfig.loadConfigFile('config/blockchain.yml')
|
||||||
|
Embark.startBlockchain(env)
|
||||||
|
|
||||||
|
|
|
@ -8,5 +8,9 @@ module.exports = (grunt) ->
|
||||||
destFile = grunt.config.get("deploy.dest");
|
destFile = grunt.config.get("deploy.dest");
|
||||||
|
|
||||||
Embark = require('embark-framework')
|
Embark = require('embark-framework')
|
||||||
Embark.Deploy.deployContracts(env, contractFiles, destFile)
|
Embark.init()
|
||||||
|
Embark.blockchainConfig.loadConfigFile('config/blockchain.yml')
|
||||||
|
Embark.contractsConfig.loadConfigFile('config/contracts.yml')
|
||||||
|
abi = Embark.deployContracts(env, contractFiles, destFile)
|
||||||
|
grunt.file.write(destFile, abi);
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
module.exports = (grunt) ->
|
module.exports = (grunt) ->
|
||||||
|
|
||||||
grunt.registerTask "ipfs", "distribute into ipfs", (env_) =>
|
grunt.registerTask "ipfs", "distribute into ipfs", (env_) =>
|
||||||
|
env = env_ || "development"
|
||||||
Embark = require('embark-framework')
|
Embark = require('embark-framework')
|
||||||
Embark.Release.ipfs()
|
Embark.release.ipfs()
|
||||||
|
|
||||||
|
|
27
test/test.js
27
test/test.js
|
@ -1,2 +1,27 @@
|
||||||
EmbarkSpec = require('../lib/test.js').Tests;
|
var Config = require('../lib/config/config.js');
|
||||||
|
var Test = require('../lib/test.js');
|
||||||
|
var assert = require('assert');
|
||||||
|
var web3 = require('web3');
|
||||||
|
|
||||||
|
//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').config("development");
|
||||||
|
var contractsConfig = new Config.Contracts(blockchainConfig, web3);
|
||||||
|
contractsConfig.loadConfigFile('test/support/contracts.yml');
|
||||||
|
contractsConfig.init(files);
|
||||||
|
|
||||||
|
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');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
Loading…
Reference in New Issue