This repository has been archived by the owner on Jun 11, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 457
Fix transactionInPool bug - Closes #707 #821
Merged
Merged
Changes from 7 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
78271a7
Fix #707
diego-G a7175f2
Simplify logic of txPool test
diego-G 463b72e
Revert rename to transactionPool.js
diego-G 4dcf00e
Clean jobsQueue before and after tests
MaciejBaj 40c2dbf
Revert rename to transactionPool.js & clean jobsQueue
diego-G 000023c
Merge remote-tracking branch 'origin/707-fix_transactionInPool' into …
MaciejBaj e598ce2
Replace emptying jobs queue with stubbing restore
MaciejBaj 9f1ac7f
Improve condition in transactionInPool, change description
4miners File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
'use strict'; | ||
|
||
var async = require('async'); | ||
var expect = require('chai').expect; | ||
var sinon = require('sinon'); | ||
|
||
var node = require('../../node'); | ||
|
||
var jobsQueue = require('../../../helpers/jobsQueue'); | ||
var TransactionPool = require('../../../logic/transactionPool'); | ||
var TransactionLogic = require('../../../logic/transaction'); | ||
var TransferLogic = require('../../../logic/transfer'); | ||
var modulesLoader = require('../../common/initModule').modulesLoader; | ||
var transactionTypes = require('../../../helpers/transactionTypes'); | ||
|
||
describe('txPool', function () { | ||
|
||
var txPool; | ||
var jobsQueueRegisterStub; | ||
|
||
before(function (done) { | ||
// Init transaction logic | ||
modulesLoader.initLogic(TransactionLogic, modulesLoader.scope, function (err, __trsLogic) { | ||
expect(err).to.not.exist; | ||
txPool = new TransactionPool( | ||
modulesLoader.scope.config.broadcasts.broadcastInterval, | ||
modulesLoader.scope.config.broadcasts.releaseLimit, | ||
__trsLogic, | ||
modulesLoader.scope.bus, | ||
modulesLoader.scope.logger | ||
); | ||
|
||
modulesLoader.initModules([ | ||
{accounts: require('../../../modules/accounts')}, | ||
], [ | ||
{'transaction': require('../../../logic/transaction')}, | ||
{'account': require('../../../logic/account')} | ||
], {}, function (err, __modules) { | ||
expect(err).to.not.exist; | ||
|
||
txPool.bind( | ||
__modules.accounts, | ||
null, | ||
__modules.loader | ||
); | ||
__trsLogic.attachAssetType(transactionTypes.SEND, new TransferLogic(modulesLoader.scope.logger, modulesLoader.scope.schema)); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
|
||
beforeEach(function () { | ||
jobsQueueRegisterStub = sinon.stub(jobsQueue, 'register'); | ||
}); | ||
|
||
afterEach(function () { | ||
jobsQueueRegisterStub.restore(); | ||
}); | ||
|
||
describe('receiveTransactions', function () { | ||
|
||
it('should return empty array when using empty array', function (done) { | ||
txPool.receiveTransactions([], false, function (err, data) { | ||
expect(err).to.not.exist; | ||
expect(data).to.be.an('array').that.is.empty; | ||
done(); | ||
}); | ||
}); | ||
|
||
it('should return error when using empty object', function (done) { | ||
txPool.receiveTransactions([{}], false, function (err, data) { | ||
expect(err).to.be.equal('Invalid public key'); | ||
done(); | ||
}); | ||
}); | ||
|
||
it('should return error when using invalid tx', function (done) { | ||
txPool.receiveTransactions([{ id: '123' }], false, function (err, data) { | ||
expect(err).to.exist; | ||
done(); | ||
}); | ||
}); | ||
|
||
it('should process tx if valid and insert tx into queue', function (done) { | ||
var account = node.randomAccount(); | ||
const tx = node.lisk.transaction.createTransaction(account.address, 100000000000, node.gAccount.password); | ||
|
||
txPool.receiveTransactions([tx], false, function (err, data) { | ||
expect(err).to.not.exist; | ||
expect(txPool.transactionInPool(tx.id)).to.be.true; | ||
done(); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('transactionInPool', function () { | ||
|
||
it('should return false for an unknown id', function () { | ||
expect(txPool.transactionInPool('11111')).to.be.false; | ||
}); | ||
}); | ||
}); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://github.com/LiskHQ/lisk/pull/708/files#diff-895da543e4bd2fc106ead06568c6b75aR104