From 41b5bc9a52e9a0ec9b07c3c27bff76f1f8f33dd5 Mon Sep 17 00:00:00 2001 From: Roger Hernandez Date: Wed, 29 Jul 2020 12:10:36 +0200 Subject: [PATCH] Fixed Longs that were being implicitly converted to ints in the namespaces/names endpoint --- rest/src/db/CatapultDb.js | 2 +- rest/test/db/CatapultDb_spec.js | 23 ++++++++++++++++++++--- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/rest/src/db/CatapultDb.js b/rest/src/db/CatapultDb.js index f984252b5..a70b0593e 100644 --- a/rest/src/db/CatapultDb.js +++ b/rest/src/db/CatapultDb.js @@ -476,7 +476,7 @@ class CatapultDb { }; const collection = this.database.collection('transactions'); - return collection.aggregate([conditions, grouping]) + return collection.aggregate([conditions, grouping], { promoteLongs: false }) .sort({ _id: -1 }) .toArray() .then(this.sanitizer.deleteIds); diff --git a/rest/test/db/CatapultDb_spec.js b/rest/test/db/CatapultDb_spec.js index 9d2d45846..259218c2f 100644 --- a/rest/test/db/CatapultDb_spec.js +++ b/rest/test/db/CatapultDb_spec.js @@ -984,9 +984,9 @@ describe('catapult db', () => { ); const createExpected = (parentId, markerId) => ({ - markerId, + markerId: Long.fromNumber(markerId), markerName: `marker-${markerId}`, - parentMarkerId: parentId + parentMarkerId: Long.fromNumber(parentId) }); it('returns empty array for unknown ids', () => @@ -1016,9 +1016,26 @@ describe('catapult db', () => { return assertTransactions(expected, [[20003, 0], [123, 456], [20008, 0]]); }); + + it('does not promote MongoDb.Long to regular `number` for small enough numbers and ends up returning Long always', () => { + const dbEntity = { + transactions: [{ + _id: test.db.createObjectId(55), + meta: {}, + transaction: { id: Long.fromNumber(23), type: 0x12345, parentId: Long.fromNumber(10) } + }] + }; + return runDbTest( + dbEntity, + db => db.findNamesByIds([23], 0x12345, { id: 'id', name: 'name', parentId: 'parentId' }), + tuples => { + expect(tuples[0].parentId instanceof Long).to.be.equal(true); + } + ); + }); }); - describe('queryPagedDocuments 2', () => { + describe('queryPagedDocuments', () => { describe('calls queryPagedDocumentsWithConditions with', () => { const sortConditions = { $sort: { _id: 1 } }; const options = { pageSize: 10, pageNumber: 1 };