mirror of https://github.com/embarklabs/embark.git
support embarkjs in the tests
This commit is contained in:
parent
e119007f76
commit
c4ca4e52b8
20
js/embark.js
20
js/embark.js
|
@ -1,9 +1,14 @@
|
||||||
var EmbarkJS = {
|
var EmbarkJS = {
|
||||||
onReady: __embarkContext.execWhenReady
|
onReady: function(cb) {
|
||||||
|
if (typeof (__embarkContext) === 'undefined') {
|
||||||
|
return cb();
|
||||||
|
}
|
||||||
|
return __embarkContext.execWhenReady(cb);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
EmbarkJS.isNewWeb3 = function() {
|
EmbarkJS.isNewWeb3 = function(web3Obj) {
|
||||||
var _web3 = new Web3();
|
var _web3 = web3Obj || (new Web3());
|
||||||
if (typeof(_web3.version) === "string") {
|
if (typeof(_web3.version) === "string") {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -17,22 +22,24 @@ EmbarkJS.Contract = function(options) {
|
||||||
|
|
||||||
this.abi = options.abi;
|
this.abi = options.abi;
|
||||||
this.address = options.address;
|
this.address = options.address;
|
||||||
|
this.gas = options.gas;
|
||||||
this.code = '0x' + options.code;
|
this.code = '0x' + options.code;
|
||||||
//this.web3 = options.web3 || web3;
|
//this.web3 = options.web3 || web3;
|
||||||
this.web3 = options.web3;
|
this.web3 = options.web3;
|
||||||
if (!this.web3 && typeof ('web3') !== 'undefined') {
|
if (!this.web3 && typeof ('web3') !== 'undefined') {
|
||||||
this.web3 = web3;
|
this.web3 = web3;
|
||||||
} else {
|
} else if (!this.web3) {
|
||||||
this.web3 = window.web3;
|
this.web3 = window.web3;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (EmbarkJS.isNewWeb3()) {
|
if (EmbarkJS.isNewWeb3(this.web3)) {
|
||||||
ContractClass = new this.web3.eth.Contract(this.abi, this.address);
|
ContractClass = new this.web3.eth.Contract(this.abi, this.address);
|
||||||
ContractClass.setProvider(this.web3.currentProvider);
|
ContractClass.setProvider(this.web3.currentProvider);
|
||||||
ContractClass.options.data = this.code;
|
ContractClass.options.data = this.code;
|
||||||
ContractClass.options.from = this.from;
|
ContractClass.options.from = this.from;
|
||||||
ContractClass.abi = ContractClass.options.abi;
|
ContractClass.abi = ContractClass.options.abi;
|
||||||
ContractClass.address = this.address;
|
ContractClass.address = this.address;
|
||||||
|
ContractClass.gas = this.gas;
|
||||||
|
|
||||||
let originalMethods = Object.keys(ContractClass);
|
let originalMethods = Object.keys(ContractClass);
|
||||||
|
|
||||||
|
@ -386,4 +393,5 @@ EmbarkJS.Utils = {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export default EmbarkJS;
|
//export default EmbarkJS;
|
||||||
|
module.exports = EmbarkJS;
|
||||||
|
|
|
@ -8,6 +8,8 @@ const cloneDeep = require('clone-deep');
|
||||||
const AccountParser = require('../contracts/accountParser');
|
const AccountParser = require('../contracts/accountParser');
|
||||||
const Provider = require('../contracts/provider');
|
const Provider = require('../contracts/provider');
|
||||||
|
|
||||||
|
const EmbarkJS = require('../../js/embark');
|
||||||
|
|
||||||
function getSimulator() {
|
function getSimulator() {
|
||||||
try {
|
try {
|
||||||
return require('ganache-cli');
|
return require('ganache-cli');
|
||||||
|
@ -241,8 +243,10 @@ class Test {
|
||||||
} else {
|
} else {
|
||||||
data = self.contracts[contractName].options.data;
|
data = self.contracts[contractName].options.data;
|
||||||
}
|
}
|
||||||
Object.assign(self.contracts[contractName], new self.web3.eth.Contract(contract.abiDefinition, contract.deployedAddress,
|
//Object.assign(self.contracts[contractName], new self.web3.eth.Contract(contract.abiDefinition, contract.deployedAddress,
|
||||||
{from: self.web3.eth.defaultAccount, gas: 6000000}));
|
// {from: self.web3.eth.defaultAccount, gas: 6000000}));
|
||||||
|
Object.assign(self.contracts[contractName], new EmbarkJS.Contract({abi: contract.abiDefinition, address: contract.deployedAddress, from: self.web3.eth.defaultAccount, gas: 6000000, web3: self.web3}));
|
||||||
|
|
||||||
self.contracts[contractName].address = contract.deployedAddress;
|
self.contracts[contractName].address = contract.deployedAddress;
|
||||||
if (self.contracts[contractName].options) {
|
if (self.contracts[contractName].options) {
|
||||||
self.contracts[contractName].options.from = self.contracts[contractName].options.from || self.web3.eth.defaultAccount;
|
self.contracts[contractName].options.from = self.contracts[contractName].options.from || self.web3.eth.defaultAccount;
|
||||||
|
@ -288,8 +292,9 @@ class Test {
|
||||||
contract = this.engine.contractsManager.contracts[contractNames[0]];
|
contract = this.engine.contractsManager.contracts[contractNames[0]];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.contracts[contractName] = new this.web3.eth.Contract(contract.abiDefinition, contract.address,
|
//this.contracts[contractName] = new this.web3.eth.Contract(contract.abiDefinition, contract.address,
|
||||||
{from: this.web3.eth.defaultAccount, gas: 6000000});
|
// {from: this.web3.eth.defaultAccount, gas: 6000000});
|
||||||
|
this.contracts[contractName] = new EmbarkJS.Contract({abi: contract.abiDefinition, address: contract.address, from: this.web3.eth.defaultAccount, gas: 6000000, web3: this.web3});
|
||||||
this.contracts[contractName].address = contract.address;
|
this.contracts[contractName].address = contract.address;
|
||||||
this.contracts[contractName].options.data = contract.code;
|
this.contracts[contractName].options.data = contract.code;
|
||||||
this.web3.eth.getAccounts().then((accounts) => {
|
this.web3.eth.getAccounts().then((accounts) => {
|
||||||
|
|
|
@ -40,6 +40,11 @@ contract("AnotherStorage", function() {
|
||||||
assert.equal(result.toString(), SimpleStorage.options.address);
|
assert.equal(result.toString(), SimpleStorage.options.address);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("set SimpleStorage address with alternative syntax", async function() {
|
||||||
|
let result = await AnotherStorage.simpleStorageAddress();
|
||||||
|
assert.equal(result.toString(), SimpleStorage.options.address);
|
||||||
|
});
|
||||||
|
|
||||||
it('should set the balance correctly', async function () {
|
it('should set the balance correctly', async function () {
|
||||||
const balance = await web3.eth.getBalance(accounts[0]);
|
const balance = await web3.eth.getBalance(accounts[0]);
|
||||||
assert.ok(balance < 5000000000000000000);
|
assert.ok(balance < 5000000000000000000);
|
||||||
|
|
Loading…
Reference in New Issue