Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug in TransactionPool.transactionInPool - Closes #707 #1360

Merged
merged 5 commits into from Jan 23, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 5 additions & 2 deletions logic/transactionPool.js
Expand Up @@ -90,16 +90,19 @@ TransactionPool.prototype.bind = function (accounts, transactions, loader) {

/**
* Determines whether a transaction is in the pool based on transaction id.
* Checks unconfirmed, bundled, queued and multisignature lists.
* @param {string} id - Transaction id.
* @return {boolean} True if transaction is found in any of the indexes.
* @return {boolean} true If transaction id exists in at least one of indexes.
*/
TransactionPool.prototype.transactionInPool = function (id) {
return [
self.unconfirmed.index[id],
self.bundled.index[id],
self.queued.index[id],
self.multisignature.index[id]
].filter(Boolean).length > 0;
].some(function (index) {
return typeof(index) === 'number';
});
};

/**
Expand Down
95 changes: 95 additions & 0 deletions test/unit/logic/transactionPool.js
Expand Up @@ -596,4 +596,99 @@ describe('transactionPool', function () {
});
});
});

describe('transactionInPool', function () {

afterEach(function () {
resetStates();
});

describe('when transaction is in pool', function () {

var tx = '123';

describe('unconfirmed list', function () {

describe('with index 0', function () {

it('should return true', function () {
transactionPool.unconfirmed.index[tx] = 0;
expect(transactionPool.transactionInPool(tx)).to.equal(true);
});
});

describe('with other index', function () {

it('should return true', function () {
transactionPool.unconfirmed.index[tx] = 1;
expect(transactionPool.transactionInPool(tx)).to.equal(true);
});
});
});

describe('bundled list', function () {

describe('with index 0', function () {

it('should return true', function () {
transactionPool.bundled.index[tx] = 0;
expect(transactionPool.transactionInPool(tx)).to.equal(true);
});
});

describe('with other index', function () {

it('should return true', function () {
transactionPool.bundled.index[tx] = 1;
expect(transactionPool.transactionInPool(tx)).to.equal(true);
});
});
});

describe('queued list', function () {

describe('with index 0', function () {

it('should return true', function () {
transactionPool.queued.index[tx] = 0;
expect(transactionPool.transactionInPool(tx)).to.equal(true);
});
});

describe('with other index', function () {

it('should return true', function () {
transactionPool.queued.index[tx] = 1;
expect(transactionPool.transactionInPool(tx)).to.equal(true);
});
});
});

describe('multisignature list', function () {

describe('with index 0', function () {

it('should return true', function () {
transactionPool.multisignature.index[tx] = 0;
expect(transactionPool.transactionInPool(tx)).to.equal(true);
});
});

describe('with other index', function () {

it('should return true', function () {
transactionPool.multisignature.index[tx] = 1;
expect(transactionPool.transactionInPool(tx)).to.equal(true);
});
});
});
});

describe('when transaction is not in pool', function () {

it('should return false', function () {
expect(transactionPool.transactionInPool('123')).to.equal(false);
});
});
});
});