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 Embark = require('embark-framework');
var EmbarkSpec = Embark.initTests();
var web3 = EmbarkSpec.web3;
describe("SimpleStorage", function(done) {
describe("SimpleStorage", function() {
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) {

View File

@ -31,20 +31,28 @@ Deploy = function(env, contractFiles, blockchainConfig, contractsConfig, chainMa
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) {
var callback = function(e, contract) {
if(!e && contract.address !== undefined) {
cb(contract.address);
}
else {
console.log("error deploying");
console.log(e)
//exit();
Deploy.waitForContract(contract.transactionHash, cb);
}
};
contractParams.push(callback);
contractObject["new"].apply(contractObject, contractParams);
}

View File

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