mirror of https://github.com/embarklabs/embark.git
some progress with new tests
This commit is contained in:
parent
0f14c247b0
commit
95615d14a7
|
@ -1,32 +1,43 @@
|
||||||
var assert = require('assert');
|
var assert = require('assert');
|
||||||
var Embark = require('embark-framework');
|
//var Embark = require('embark-framework');
|
||||||
var EmbarkSpec = Embark.initTests();
|
|
||||||
var web3 = EmbarkSpec.web3;
|
var SimpleStorage;
|
||||||
|
|
||||||
describe("SimpleStorage", function() {
|
describe("SimpleStorage", function() {
|
||||||
before(function(done) {
|
before(function(done) {
|
||||||
EmbarkSpec.sim.createAccounts(10, function() {
|
var self = this;
|
||||||
EmbarkSpec.sim.setBalance(web3.eth.accounts[0], 1000000000000000000000, function() {
|
|
||||||
EmbarkSpec.deployAll(done);
|
var Embark = require('../../lib/index.js');
|
||||||
// or
|
var EmbarkSpec = Embark.initTests();
|
||||||
// EmbarkSpec.deployContract('SimpleStorage', [100], done);
|
//var web3 = EmbarkSpec.web3;
|
||||||
});
|
|
||||||
|
//var contracts = EmbarkSpec.deployAll(done);
|
||||||
|
//var SimpleStorage = contracts.SimpleStorage;
|
||||||
|
// or
|
||||||
|
EmbarkSpec.deployContract('SimpleStorage', [100], function(contract) {
|
||||||
|
SimpleStorage = contract;
|
||||||
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should set constructor value", function(done) {
|
it("should set constructor value", function(done) {
|
||||||
SimpleStorage.storedData(function(err, result) {
|
SimpleStorage.storedData()
|
||||||
assert.equal(result.toNumber(), 100);
|
.then(function(value) {
|
||||||
|
assert.equal(value.toNumber(), 100);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it("set storage value", function(done) {
|
it("set storage value", function(done) {
|
||||||
SimpleStorage.set(150, function() {
|
var self = this;
|
||||||
SimpleStorage.get(function(err, result) {
|
//console.log(SimpleStorage);
|
||||||
assert.equal(result.toNumber(), 150);
|
SimpleStorage.set(150)
|
||||||
|
.then(function() {
|
||||||
|
return SimpleStorage.get();
|
||||||
|
})
|
||||||
|
.then(function(value) {
|
||||||
|
assert.equal(value.toNumber(), 150);
|
||||||
done();
|
done();
|
||||||
});
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
14
js/embark.js
14
js/embark.js
|
@ -1,3 +1,6 @@
|
||||||
|
if (typeof module !== 'undefined') {
|
||||||
|
var Promise = require('bluebird');
|
||||||
|
}
|
||||||
|
|
||||||
var EmbarkJS = {
|
var EmbarkJS = {
|
||||||
};
|
};
|
||||||
|
@ -23,7 +26,7 @@ EmbarkJS.Contract = function(options) {
|
||||||
this.code = options.code;
|
this.code = options.code;
|
||||||
this.web3 = options.web3 || web3;
|
this.web3 = options.web3 || web3;
|
||||||
|
|
||||||
var ContractClass = web3.eth.contract(this.abi);
|
var ContractClass = this.web3.eth.contract(this.abi);
|
||||||
|
|
||||||
this._originalContractObject = ContractClass.at(this.address);
|
this._originalContractObject = ContractClass.at(this.address);
|
||||||
this._methods = Object.getOwnPropertyNames(this._originalContractObject).filter(function (p) {
|
this._methods = Object.getOwnPropertyNames(this._originalContractObject).filter(function (p) {
|
||||||
|
@ -34,7 +37,6 @@ EmbarkJS.Contract = function(options) {
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
EmbarkJS.Contract.prototype.deploy = function(args) {
|
EmbarkJS.Contract.prototype.deploy = function(args) {
|
||||||
|
@ -44,13 +46,13 @@ EmbarkJS.Contract.prototype.deploy = function(args) {
|
||||||
contractParams = args;
|
contractParams = args;
|
||||||
|
|
||||||
contractParams.push({
|
contractParams.push({
|
||||||
from: web3.eth.accounts[0],
|
from: this.web3.eth.accounts[0],
|
||||||
data: this.code,
|
data: this.code,
|
||||||
gasLimit: 500000,
|
gasLimit: 500000,
|
||||||
gasPrice: 10000000000000
|
gasPrice: 10000000000000
|
||||||
});
|
});
|
||||||
|
|
||||||
var contractObject = web3.eth.contract(this.abi);
|
var contractObject = this.web3.eth.contract(this.abi);
|
||||||
|
|
||||||
var promise = new Promise(function(resolve, reject) {
|
var promise = new Promise(function(resolve, reject) {
|
||||||
contractParams.push(function(err, transaction) {
|
contractParams.push(function(err, transaction) {
|
||||||
|
@ -97,4 +99,6 @@ EmbarkJS.Messages.Whisper.listenTo = function(options) {
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
if (typeof module !== 'undefined') {
|
||||||
|
module.exports = EmbarkJS;
|
||||||
|
}
|
||||||
|
|
|
@ -16,6 +16,7 @@ var Blockchain = require('./blockchain.js');
|
||||||
var Server = require('./server.js');
|
var Server = require('./server.js');
|
||||||
var Watch = require('./watch.js');
|
var Watch = require('./watch.js');
|
||||||
var Pipeline = require('./pipeline.js');
|
var Pipeline = require('./pipeline.js');
|
||||||
|
var Test = require('./test.js');
|
||||||
|
|
||||||
var Embark = {
|
var Embark = {
|
||||||
|
|
||||||
|
@ -108,6 +109,10 @@ var Embark = {
|
||||||
], function(err, result) {
|
], function(err, result) {
|
||||||
done(result);
|
done(result);
|
||||||
});
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
initTests: function(options) {
|
||||||
|
return new Test(options);
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -0,0 +1,73 @@
|
||||||
|
var Web3 = require('web3');
|
||||||
|
var Deploy = require('./deploy.js');
|
||||||
|
var ContractsManager = require('./contracts.js');
|
||||||
|
var EmbarkJS = require('../js/embark.js');
|
||||||
|
|
||||||
|
var initAccounts = function(sim, web3, done) {
|
||||||
|
sim.createAccounts(10, function() {
|
||||||
|
sim.setBalance(web3.eth.accounts[0], 1000000000000000000000, function() {
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
var Test = function(options) {
|
||||||
|
try {
|
||||||
|
this.EtherSim = require('ethersim');
|
||||||
|
} catch(e) {
|
||||||
|
this.EtherSim = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.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();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
//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();
|
||||||
|
// });
|
||||||
|
//};
|
||||||
|
|
||||||
|
Test.prototype.deployContract = function(className, args, cb) {
|
||||||
|
var self = this;
|
||||||
|
this.web3 = new Web3();
|
||||||
|
this.sim = new this.EtherSim.init();
|
||||||
|
this.web3.setProvider(this.sim.provider);
|
||||||
|
|
||||||
|
var contractsManager = new ContractsManager('./config/', ['app/contracts/*.sol'], 'development');
|
||||||
|
contractsManager.init();
|
||||||
|
contractsManager.build();
|
||||||
|
|
||||||
|
var deploy = new Deploy(this.web3, contractsManager);
|
||||||
|
var contract = contractsManager.contracts[className];
|
||||||
|
|
||||||
|
initAccounts(this.sim, this.web3, function() {
|
||||||
|
deploy.deployContract(contract, args, function(err, address) {
|
||||||
|
console.log("deployed");
|
||||||
|
console.log(address);
|
||||||
|
|
||||||
|
console.log(contract);
|
||||||
|
|
||||||
|
var deployedContract = new EmbarkJS.Contract({
|
||||||
|
abi: contract.abiDefinition,
|
||||||
|
address: address,
|
||||||
|
code: contract.code,
|
||||||
|
web3: self.web3
|
||||||
|
});
|
||||||
|
|
||||||
|
cb(deployedContract);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
module.exports = Test;
|
|
@ -15,6 +15,7 @@
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"async": "^2.0.1",
|
"async": "^2.0.1",
|
||||||
"bignumber.js": "debris/bignumber.js#master",
|
"bignumber.js": "debris/bignumber.js#master",
|
||||||
|
"bluebird": "^3.4.1",
|
||||||
"chokidar": "^1.6.0",
|
"chokidar": "^1.6.0",
|
||||||
"colors": "^1.1.2",
|
"colors": "^1.1.2",
|
||||||
"commander": "^2.8.1",
|
"commander": "^2.8.1",
|
||||||
|
|
Loading…
Reference in New Issue