make running config() without callback work

This commit is contained in:
Jonathan Rainville 2018-05-30 16:17:17 -04:00
parent 756d77a9b1
commit 827a3b309f
3 changed files with 35 additions and 19 deletions

View File

@ -53,6 +53,11 @@ module.exports = {
// TODO: this global here might not be necessary at all // TODO: this global here might not be necessary at all
global.web3 = global.embark.web3; global.web3 = global.embark.web3;
mocha.suite.beforeAll('Wait for deploy', (done) => {
test.onReady(() => {
done();
});
});
global.contract = function (describeName, callback) { global.contract = function (describeName, callback) {
return Mocha.describe(describeName, callback); return Mocha.describe(describeName, callback);
}; };

View File

@ -4,6 +4,7 @@ const TestLogger = require('./test_logger.js');
const Web3 = require('web3'); const Web3 = require('web3');
const utils = require('../utils/utils'); const utils = require('../utils/utils');
const constants = require('../constants'); const constants = require('../constants');
const Events = require('../core/events');
function getSimulator() { function getSimulator() {
try { try {
@ -28,6 +29,8 @@ class Test {
this.options = options || {}; this.options = options || {};
this.simOptions = this.options.simulatorOptions || {}; this.simOptions = this.options.simulatorOptions || {};
this.contracts = {}; this.contracts = {};
this.events = new Events();
this.ready = true;
this.web3 = new Web3(); this.web3 = new Web3();
if (this.simOptions.node) { if (this.simOptions.node) {
@ -65,11 +68,26 @@ class Test {
}); });
} }
onReady(callback) {
if (this.ready) {
return callback();
}
this.events.once('ready', () => {
callback();
});
}
config(options, callback) { config(options, callback) {
if (!callback) {
callback = function () {};
}
this.options = utils.recursiveMerge(this.options, options); this.options = utils.recursiveMerge(this.options, options);
this.simOptions = this.options.simulatorOptions || {}; this.simOptions = this.options.simulatorOptions || {};
this.ready = false;
this._deploy(options, (err, accounts) => { this._deploy(options, (err, accounts) => {
this.ready = true;
this.events.emit('ready');
if (err) { if (err) {
console.error(err); console.error(err);
return callback(err); return callback(err);

View File

@ -1,33 +1,26 @@
/*global contract, before, it, embark, web3*/ /*global contract, config, it, embark*/
const assert = require('assert'); const assert = require('assert');
const SimpleStorage = embark.require('contracts/SimpleStorage'); const SimpleStorage = embark.require('contracts/SimpleStorage');
contract("SimpleStorage", function () { config({
this.timeout(0);
before(function (done) {
const contractsConfig = {
contracts: { contracts: {
"SimpleStorage": { "SimpleStorage": {
args: [100] args: [100]
} }
} }
};
embark.config(contractsConfig, () => {
done();
});
}); });
contract("SimpleStorage", function () {
this.timeout(0);
it("should set constructor value", async function () { it("should set constructor value", async function () {
let result = await SimpleStorage.methods.storedData().call(); let result = await SimpleStorage.methods.storedData().call();
assert.strictEqual(parseInt(result, 10), 100); assert.strictEqual(parseInt(result, 10), 100);
}); });
it("set storage value", async function () { it("set storage value", async function () {
// TODO Solve from
await SimpleStorage.methods.set(150).send(); await SimpleStorage.methods.set(150).send();
let result = await SimpleStorage.methods.get().call(); let result = await SimpleStorage.methods.get().call();
assert.strictEqual(parseInt(result, 10), 499650); assert.strictEqual(parseInt(result, 10), 499650);
}); });
}); });