fix deployment for tests

This commit is contained in:
Iuri Matias 2016-05-29 20:14:27 -04:00
parent b78b742ab4
commit 00543f3830
4 changed files with 62 additions and 12 deletions

View File

@ -0,0 +1,33 @@
var assert = require('assert');
var Embark = require('embark-framework');
var EmbarkSpec = Embark.initTests();
var web3 = EmbarkSpec.web3;
describe("MyContract", function() {
// Deploy all contrats using the development config
before(function(done) {
EmbarkSpec.sim.createAccounts(10, function() {
EmbarkSpec.sim.setBalance(web3.eth.accounts[0], 1000000000000000000000, function() {
EmbarkSpec.deployAll(done);
});
});
});
//it("should set constructor value", function(done) {
// SimpleStorage.storedData(function(err, result) {
// assert.equal(result.toNumber(), 100);
// done();
// });
//});
//it("set storage value", function(done) {
// SimpleStorage.set(150, function() {
// SimpleStorage.get(function(err, result) {
// assert.equal(result.toNumber(), 150);
// done();
// });
// });
//});
})

View File

@ -1,10 +1,15 @@
var assert = require('assert'); var assert = require('assert');
var Embark = require('embark-framework'); var Embark = require('embark-framework');
var EmbarkSpec = Embark.initTests(); var EmbarkSpec = Embark.initTests();
var web3 = EmbarkSpec.web3;
describe("SimpleStorage", function(done) { describe("SimpleStorage", function() {
before(function(done) { before(function(done) {
EmbarkSpec.deployAll(done); EmbarkSpec.sim.createAccounts(10, function() {
EmbarkSpec.sim.setBalance(web3.eth.accounts[0], 1000000000000000000000, function() {
EmbarkSpec.deployAll(done);
});
});
}); });
it("should set constructor value", function(done) { it("should set constructor value", function(done) {

View File

@ -31,20 +31,28 @@ Deploy = function(env, contractFiles, blockchainConfig, contractsConfig, chainMa
console.log("primary account address is : " + primaryAddress); console.log("primary account address is : " + primaryAddress);
}; };
Deploy.waitForContract = function(transactionHash, cb) {
web3.eth.getTransactionReceipt(transactionHash, function(e, receipt) {
if (!e && receipt && receipt.contractAddress !== undefined) {
cb(receipt.contractAddress);
}
else {
Deploy.waitForContract(transactionHash, cb);
}
});
};
Deploy.prototype.deploy_contract = function(contractObject, contractParams, cb) { Deploy.prototype.deploy_contract = function(contractObject, contractParams, cb) {
var callback = function(e, contract) { var callback = function(e, contract) {
if(!e && contract.address !== undefined) { if(!e && contract.address !== undefined) {
cb(contract.address); cb(contract.address);
} }
else { else {
console.log("error deploying"); Deploy.waitForContract(contract.transactionHash, cb);
console.log(e)
//exit();
} }
}; };
contractParams.push(callback); contractParams.push(callback);
contractObject["new"].apply(contractObject, contractParams); contractObject["new"].apply(contractObject, contractParams);
} }

View File

@ -1,20 +1,22 @@
try { try {
var ethersim = require('ethersim'); var EtherSim = require('ethersim');
} catch(e) { } catch(e) {
var ethersim = false; var EtherSim = false;
} }
var web3 = require('web3'); var Web3 = require('web3');
var web3
Test = function(contractFiles, blockchainFile, contractFile, _env) { Test = function(contractFiles, blockchainFile, contractFile, _env) {
if (ethersim === false) { if (EtherSim === false) {
console.log('EtherSim not found; Please install it with "npm install ethersim --save"'); console.log('EtherSim not found; Please install it with "npm install ethersim --save"');
console.log('For more information see https://github.com/iurimatias/ethersim'); console.log('For more information see https://github.com/iurimatias/ethersim');
exit(); exit();
} }
this.env = _env || 'development'; this.env = _env || 'development';
this.web3 = web3; this.web3 = new Web3();
this.web3.setProvider(ethersim.web3Provider()); this.sim = new EtherSim.init();
this.web3.setProvider(this.sim.provider);
this.contractFiles = contractFiles; this.contractFiles = contractFiles;
Embark.init(this.web3); Embark.init(this.web3);
@ -25,6 +27,7 @@ Test = function(contractFiles, blockchainFile, contractFile, _env) {
} }
Test.prototype.deployAll = function(cb) { Test.prototype.deployAll = function(cb) {
var web3 = this.web3;
Embark.deployContracts('development', this.contractFiles, "/tmp/abi.js", "chains.json", false, false, function(abi) { Embark.deployContracts('development', this.contractFiles, "/tmp/abi.js", "chains.json", false, false, function(abi) {
eval(abi); eval(abi);
cb(); cb();
@ -32,3 +35,4 @@ Test.prototype.deployAll = function(cb) {
} }
module.exports = Test; module.exports = Test;