refactor modules; update grunt tasks

This commit is contained in:
Iuri Matias 2015-07-03 22:27:17 -04:00
parent e43c0a38d6
commit b7bdd841c9
9 changed files with 79 additions and 26 deletions

View File

@ -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() {
beforeAll(function() {

View File

@ -16,6 +16,10 @@ ContractsConfig.prototype.init = function(files) {
this.contractFiles = files;
this.contractDependencies = {};
if (this.blockchainConfig.config != undefined) {
this.blockchainConfig = this.blockchainConfig.config('development');
}
try {
this.web3.setProvider(new this.web3.providers.HttpProvider("http://" + this.blockchainConfig.rpcHost + ":" + this.blockchainConfig.rpcPort));
primaryAddress = this.web3.eth.coinbase;

View File

@ -20,9 +20,27 @@ var Config = require('./config/config.js');
Embark = {
init: function() {
this.blockchainConfig = (new Config.BlockchainConfig());
this.contractsConfig = (new Config.ContractsConfig(this.blockchainConfig, web3));
}
this.blockchainConfig = (new Config.Blockchain());
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;

View File

@ -7,7 +7,7 @@ ipfs = function() {
cmd = ipfs_path + "/ipfs add -r " + build_dir;
grunt.log.writeln("=== adding " + cmd + " to ipfs");
console.log("=== adding " + cmd + " to ipfs");
result = exec(cmd);

View File

@ -59,27 +59,18 @@ TestContract = function(contract, className, args) {
return Obj;
}
request = function(className, args) {
py_exec("from ethertdd import EvmContract")
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);
test = function(contractsConfig, contractFiles) {
contractsConfig.init(contractFiles);
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)
}
Test = {
request: request
}
module.exports = Test;
module.exports = test;

View File

@ -3,5 +3,7 @@ module.exports = (grunt) ->
grunt.registerTask "blockchain", "deploy ethereum node", (env_) =>
env = env_ || "development"
Embark = require('embark-framework')
Embark.Blockchain.startChain(env)
Embark.init()
Embark.blockchainConfig.loadConfigFile('config/blockchain.yml')
Embark.startBlockchain(env)

View File

@ -8,5 +8,9 @@ module.exports = (grunt) ->
destFile = grunt.config.get("deploy.dest");
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);

View File

@ -1,6 +1,7 @@
module.exports = (grunt) ->
grunt.registerTask "ipfs", "distribute into ipfs", (env_) =>
env = env_ || "development"
Embark = require('embark-framework')
Embark.Release.ipfs()
Embark.release.ipfs()

View File

@ -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');
});
});
});