mirror of
https://github.com/embarklabs/embark.git
synced 2025-02-20 17:38:28 +00:00
Merge pull request #498 from embark-framework/single_test
fix from and data options; add single test support
This commit is contained in:
commit
33de740fff
@ -81,7 +81,8 @@ module.exports = {
|
|||||||
mocha.addFile(file);
|
mocha.addFile(file);
|
||||||
|
|
||||||
mocha.suite.timeout(0);
|
mocha.suite.timeout(0);
|
||||||
mocha.suite.beforeEach('Wait for deploy', (done) => {
|
|
||||||
|
mocha.suite.beforeAll('Wait for deploy', (done) => {
|
||||||
global.embark.onReady(() => {
|
global.embark.onReady(() => {
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
@ -121,12 +121,16 @@ class Test {
|
|||||||
|
|
||||||
config(options, callback) {
|
config(options, callback) {
|
||||||
const self = this;
|
const self = this;
|
||||||
|
if (typeof (options) === 'function') {
|
||||||
|
callback = options;
|
||||||
|
options = {};
|
||||||
|
}
|
||||||
if (!callback) {
|
if (!callback) {
|
||||||
callback = function () {
|
callback = function () {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
if (!options.contracts) {
|
if (!options.contracts) {
|
||||||
throw new Error(__('No contracts specified in the options'));
|
options.contracts = {};
|
||||||
}
|
}
|
||||||
self.ready = false;
|
self.ready = false;
|
||||||
|
|
||||||
@ -211,12 +215,20 @@ class Test {
|
|||||||
function createContractObject(accounts, next) {
|
function createContractObject(accounts, next) {
|
||||||
async.each(Object.keys(self.engine.contractsManager.contracts), (contractName, eachCb) => {
|
async.each(Object.keys(self.engine.contractsManager.contracts), (contractName, eachCb) => {
|
||||||
const contract = self.engine.contractsManager.contracts[contractName];
|
const contract = self.engine.contractsManager.contracts[contractName];
|
||||||
|
let data;
|
||||||
if (!self.contracts[contractName]) {
|
if (!self.contracts[contractName]) {
|
||||||
self.contracts[contractName] = {};
|
self.contracts[contractName] = {};
|
||||||
|
data = "";
|
||||||
|
} else {
|
||||||
|
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}));
|
||||||
self.contracts[contractName].address = contract.deployedAddress;
|
self.contracts[contractName].address = contract.deployedAddress;
|
||||||
|
if (self.contracts[contractName].options) {
|
||||||
|
self.contracts[contractName].options.from = self.contracts[contractName].options.from || self.web3.eth.defaultAccount;
|
||||||
|
self.contracts[contractName].options.data = data;
|
||||||
|
}
|
||||||
eachCb();
|
eachCb();
|
||||||
}, (err) => {
|
}, (err) => {
|
||||||
next(err, accounts);
|
next(err, accounts);
|
||||||
@ -260,6 +272,10 @@ class Test {
|
|||||||
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].address = contract.address;
|
this.contracts[contractName].address = contract.address;
|
||||||
|
this.contracts[contractName].options.data = contract.code;
|
||||||
|
this.web3.eth.getAccounts().then((accounts) => {
|
||||||
|
this.contracts[contractName].options.from = contract.from || accounts[0];
|
||||||
|
});
|
||||||
return this.contracts[contractName];
|
return this.contracts[contractName];
|
||||||
}
|
}
|
||||||
throw new Error(__('Unknown module %s', module));
|
throw new Error(__('Unknown module %s', module));
|
||||||
|
23
test_apps/test_app/test/simple_storage_deploy_spec.js
Normal file
23
test_apps/test_app/test/simple_storage_deploy_spec.js
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
/*global contract, config, it, embark, assert, web3*/
|
||||||
|
const SimpleStorage = embark.require('Embark/contracts/SimpleStorage');
|
||||||
|
let accounts;
|
||||||
|
|
||||||
|
contract("SimpleStorage Deploy", function () {
|
||||||
|
let SimpleStorageInstance;
|
||||||
|
|
||||||
|
before(async function() {
|
||||||
|
SimpleStorageInstance = await SimpleStorage.deploy({arguments: [150]}).send();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should set constructor value", async function () {
|
||||||
|
let result = await SimpleStorageInstance.methods.storedData().call();
|
||||||
|
assert.strictEqual(parseInt(result, 10), 150);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("set storage value", async function () {
|
||||||
|
await SimpleStorageInstance.methods.set(150).send();
|
||||||
|
let result = await SimpleStorageInstance.methods.get().call();
|
||||||
|
assert.strictEqual(parseInt(result, 10), 499650);
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
Loading…
x
Reference in New Issue
Block a user