embark/old_lib/test.js

47 lines
1.2 KiB
JavaScript
Raw Normal View History

2016-05-23 20:00:54 +00:00
try {
2016-05-30 00:14:27 +00:00
var EtherSim = require('ethersim');
2016-05-23 20:00:54 +00:00
} catch(e) {
2016-05-30 00:14:27 +00:00
var EtherSim = false;
2016-05-23 20:00:54 +00:00
}
2016-05-30 00:14:27 +00:00
var Web3 = require('web3');
var web3
2015-10-09 14:57:30 +00:00
Test = function(contractFiles, blockchainFile, contractFile, _env) {
2016-05-30 00:14:27 +00:00
if (EtherSim === false) {
2016-05-23 20:00:54 +00:00
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();
}
2015-10-12 14:50:52 +00:00
this.env = _env || 'development';
2016-05-30 00:14:27 +00:00
this.web3 = new Web3();
this.sim = new EtherSim.init();
this.web3.setProvider(this.sim.provider);
2015-10-12 14:50:52 +00:00
this.contractFiles = contractFiles;
2015-10-09 14:57:30 +00:00
2015-10-12 14:50:52 +00:00
Embark.init(this.web3);
Embark.blockchainConfig.loadConfigFile(blockchainFile);
Embark.contractsConfig.loadConfigFile(contractFile);
2015-10-09 14:57:30 +00:00
2015-10-12 14:50:52 +00:00
Embark.contractsConfig.init(this.contractFiles, this.env);
}
2015-10-09 14:57:30 +00:00
2015-10-12 14:50:52 +00:00
Test.prototype.deployAll = function(cb) {
2016-05-30 00:14:27 +00:00
var web3 = this.web3;
2015-10-12 14:50:52 +00:00
Embark.deployContracts('development', this.contractFiles, "/tmp/abi.js", "chains.json", false, false, function(abi) {
2015-10-09 14:57:30 +00:00
eval(abi);
cb();
});
}
Test.prototype.deployContract = function(className, args, cb) {
var web3 = this.web3;
Embark.deployContract(this.contractFiles, className, args, function(abi) {
eval(abi);
cb();
});
};
2015-10-09 14:57:30 +00:00
module.exports = Test;
2016-05-30 00:14:27 +00:00