Skip to content

Commit

Permalink
Merge pull request #460 from MaciejBaj/400-tests-stabilization
Browse files Browse the repository at this point in the history
Fix stability of dapps test, fix waitUntilBlockchainReady function - Closes #400
  • Loading branch information
karmacoma committed Mar 7, 2017
2 parents 5ab70ef + 1b7b2bc commit 69e46f9
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 7 deletions.
30 changes: 25 additions & 5 deletions test/api/dapps.js
@@ -1,6 +1,8 @@
'use strict';

var node = require('./../node.js');
var clearDatabaseTable = require('../common/globalBefore').clearDatabaseTable;
var modulesLoader = require('../common/initModule').modulesLoader;

var dapp = {};
var account = node.randomTxAccount();
Expand Down Expand Up @@ -28,6 +30,18 @@ function putTransaction (params, done) {
});
}

before(function (done) {
modulesLoader.getDbConnection(function (err, db) {
if (err) {
return done(err);
}

node.async.every(['dapps', 'outtransfer', 'intransfer'], function (table, cb) {
clearDatabaseTable(db, modulesLoader.logger, table, cb);
}, done);
});
});

before(function (done) {
// Send to LISK to account 1 address
setTimeout(function () {
Expand Down Expand Up @@ -757,13 +771,19 @@ describe('PUT /api/dapps/withdrawal', function () {
node.expect(res.body).to.have.property('success').to.be.ok;
node.expect(res.body).to.have.property('transactionId').to.not.be.empty;

setTimeout(function () {
putWithdrawal(validParams, function (err, res) {
node.expect(res.body).to.have.property('success').to.be.not.ok;
node.expect(res.body).to.have.property('error').to.equal('Transaction is already processed: ' + validParams.transactionId);
putWithdrawal(validParams, function (err, res) {
node.expect(res.body).to.have.property('success').to.be.not.ok;
node.get('/api/transactions/queued', function (err, trsRes) {
node.expect(trsRes.body).to.have.property('success').to.be.ok;
node.expect(trsRes.body.transactions).to.be.an('array').and.to.have.length.of.at.least(1);
var trsQueued = trsRes.body.transactions.find(function (t) {
return t.asset.outTransfer.transactionId === validParams.transactionId;
});
node.expect(trsQueued).to.be.not.empty;
node.expect(res.body).to.have.property('error').to.equal('Transaction is already processed: ' + trsQueued.id);
done();
});
}, 2000);
});
});
});

Expand Down
4 changes: 2 additions & 2 deletions test/common/globalBefore.js
Expand Up @@ -27,13 +27,13 @@ function waitUntilBlockchainReady (cb, retries, timeout) {
retries = 10;
}
if (!timeout) {
timeout = 200;
timeout = 1000;
}
(function fetchBlockchainStatus () {
node.get('/api/loader/status', function (err, res) {
node.expect(err).to.not.exist;
retries -= 1;
if (!res.body.success && res.body.error === 'Blockchain is loading' && retries >= 0) {
if (!res.body.loaded && retries >= 0) {
return setTimeout(function () {
fetchBlockchainStatus();
}, timeout);
Expand Down

0 comments on commit 69e46f9

Please sign in to comment.