This commit is contained in:
Iuri Matias 2015-07-03 22:41:39 -04:00
parent b7bdd841c9
commit 3f86244fbd
4 changed files with 35 additions and 42 deletions

View File

@ -9,12 +9,12 @@ BlockchainConfig.prototype.loadConfigFile = function(filename) {
throw new Error("error reading " + filename); throw new Error("error reading " + filename);
} }
return this; return this;
} };
BlockchainConfig.prototype.loadConfig = function(config) { BlockchainConfig.prototype.loadConfig = function(config) {
this.blockchainConfig = config; this.blockchainConfig = config;
return this; return this;
} };
BlockchainConfig.prototype.config = function(env) { BlockchainConfig.prototype.config = function(env) {
if (this.blockchainConfig === null) { if (this.blockchainConfig === null) {
@ -25,10 +25,10 @@ BlockchainConfig.prototype.config = function(env) {
var networkId; var networkId;
if (config.network_id === undefined) { if (config.network_id === undefined) {
networkId = Math.floor((Math.random() * 100000) + 1000) networkId = Math.floor((Math.random() * 100000) + 1000);
} }
else { else {
networkId = config.network_id networkId = config.network_id;
} }
config = { config = {
@ -47,7 +47,7 @@ BlockchainConfig.prototype.config = function(env) {
} }
return config; return config;
} };
module.exports = BlockchainConfig module.exports = BlockchainConfig;

View File

@ -1,7 +1,5 @@
indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };
var readYaml = require('read-yaml'); var readYaml = require('read-yaml');
var fs = require('fs'); var fs = require('fs');
var Blockchain = require('./blockchain.js');
var toposort = require('toposort'); var toposort = require('toposort');
ContractsConfig = function(blockchainConfig, web3) { ContractsConfig = function(blockchainConfig, web3) {
@ -39,16 +37,16 @@ ContractsConfig.prototype.loadConfigFile = function(filename) {
throw new Error("error reading " + filename); throw new Error("error reading " + filename);
} }
return this; return this;
} };
ContractsConfig.prototype.loadConfig = function(config) { ContractsConfig.prototype.loadConfig = function(config) {
this.contractConfig = config; this.contractConfig = config;
return this; return this;
} };
ContractsConfig.prototype.config = function(env) { ContractsConfig.prototype.config = function(env) {
return this.contractConfig[env]; return this.contractConfig[env];
} };
ContractsConfig.prototype.compileContracts = function(env) { ContractsConfig.prototype.compileContracts = function(env) {
var contractFile, source, j; var contractFile, source, j;
@ -86,7 +84,7 @@ ContractsConfig.prototype.compileContracts = function(env) {
} }
this.sortContracts(); this.sortContracts();
} };
ContractsConfig.prototype.sortContracts = function() { ContractsConfig.prototype.sortContracts = function() {
var converted_dependencies = [], i; var converted_dependencies = [], i;
@ -105,7 +103,7 @@ ContractsConfig.prototype.sortContracts = function() {
var order_b = orderedDependencies.indexOf(b); var order_b = orderedDependencies.indexOf(b);
return order_a - order_b; return order_a - order_b;
});; });;
} };
module.exports = ContractsConfig module.exports = ContractsConfig;

View File

@ -17,14 +17,12 @@ Deploy = function(env, contractFiles, blockchainConfig, contractsConfig) {
web3.setProvider(new web3.providers.HttpProvider("http://" + this.blockchainConfig.rpcHost + ":" + this.blockchainConfig.rpcPort)); web3.setProvider(new web3.providers.HttpProvider("http://" + this.blockchainConfig.rpcHost + ":" + this.blockchainConfig.rpcPort));
primaryAddress = web3.eth.coinbase; primaryAddress = web3.eth.coinbase;
web3.eth.defaultAccount = primaryAddress; web3.eth.defaultAccount = primaryAddress;
} catch (_error) { } catch (e) {
e = _error; throw new Error("==== can't connect to " + this.blockchainConfig.rpcHost + ":" + this.blockchainConfig.rpcPort + " check if an ethereum node is running");
console.log("==== can't connect to " + this.blockchainConfig.rpcHost + ":" + this.blockchainConfig.rpcPort + " check if an ethereum node is running");
exit;
} }
console.log("address is : " + primaryAddress); console.log("address is : " + primaryAddress);
} };
Deploy.prototype.deploy_contracts = function(env) { Deploy.prototype.deploy_contracts = function(env) {
this.contractsManager.compileContracts(env); this.contractsManager.compileContracts(env);
@ -70,7 +68,7 @@ Deploy.prototype.deploy_contracts = function(env) {
console.log("deployed " + className + " at " + contractAddress); console.log("deployed " + className + " at " + contractAddress);
} }
} };
Deploy.prototype.generate_abi_file = function() { Deploy.prototype.generate_abi_file = function() {
var result; var result;
@ -90,12 +88,12 @@ Deploy.prototype.generate_abi_file = function() {
} }
return result; return result;
} };
Deploy.prototype.generate_and_write_abi_file = function(destFile) { Deploy.prototype.generate_and_write_abi_file = function(destFile) {
var result = this.generate_abi_file(); var result = this.generate_abi_file();
grunt.file.write(destFile, result); grunt.file.write(destFile, result);
} };
module.exports = Deploy module.exports = Deploy;

View File

@ -1,13 +1,10 @@
var python = require('python').shell; var python = require('python').shell;
var web3 = require('web3');
var fs = require('fs');
var mm = require('methodmissing'); var mm = require('methodmissing');
var sync = require('sync-me'); var sync = require('sync-me');
var grunt = require('grunt');
py_exec = function(cmd) { py_exec = function(cmd) {
return sync(python, cmd)[1].trim(); return sync(python, cmd)[1].trim();
} };
TestContractWrapper = (function() { TestContractWrapper = (function() {
function TestContractWrapper(contract, className, args) { function TestContractWrapper(contract, className, args) {
@ -18,28 +15,28 @@ TestContractWrapper = (function() {
} }
TestContractWrapper.prototype.initializeContract = function() { TestContractWrapper.prototype.initializeContract = function() {
example_abi = JSON.stringify(this.contract.info.abiDefinition) example_abi = JSON.stringify(this.contract.info.abiDefinition);
example_binary = this.contract.code.slice(2) example_binary = this.contract.code.slice(2);
py_exec("example_abi = '" + example_abi + "'") py_exec("example_abi = '" + example_abi + "'");
py_exec("example_abi") py_exec("example_abi");
py_exec("example_binary = '" + example_binary + "'.decode('hex')") py_exec("example_binary = '" + example_binary + "'.decode('hex')");
py_exec("example_binary") py_exec("example_binary");
if (this.args == undefined) { if (this.args === undefined) {
py_exec(this.className + "_contract = EvmContract(example_abi, example_binary, '" + this.className + "')") py_exec(this.className + "_contract = EvmContract(example_abi, example_binary, '" + this.className + "')");
} }
else { else {
py_exec(this.className + "_contract = EvmContract(example_abi, example_binary, '" + this.className + "', [" + this.args.join(",") + "])") py_exec(this.className + "_contract = EvmContract(example_abi, example_binary, '" + this.className + "', [" + this.args.join(",") + "])");
} }
this.contractVariable = this.className + "_contract" this.contractVariable = this.className + "_contract";
}; };
TestContractWrapper.prototype.execCmd = function(method, args) { TestContractWrapper.prototype.execCmd = function(method, args) {
arg_list = []; var arg_list = [];
for (key in args) { for (var key in args) {
value = args[key]; var value = args[key];
arg_list.push(value); arg_list.push(value);
} }
@ -68,8 +65,8 @@ test = function(contractsConfig, contractFiles) {
test.prototype.request = function(className, args) { test.prototype.request = function(className, args) {
var contract = this.contractDB[className]; var contract = this.contractDB[className];
py_exec("from ethertdd import EvmContract") py_exec("from ethertdd import EvmContract");
return TestContract(contract, className, args) return TestContract(contract, className, args);
} }
module.exports = test; module.exports = test;