From 79c696a26f28bce487d2637abb53260f73726b5f Mon Sep 17 00:00:00 2001 From: nagdahimanshu Date: Tue, 31 Oct 2023 14:53:35 +0100 Subject: [PATCH 1/2] :bug: Fix validators rank calculation --- .../blockchain-indexer/shared/dataService/pos/validators.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/blockchain-indexer/shared/dataService/pos/validators.js b/services/blockchain-indexer/shared/dataService/pos/validators.js index 4e763b6556..1d821c5c40 100644 --- a/services/blockchain-indexer/shared/dataService/pos/validators.js +++ b/services/blockchain-indexer/shared/dataService/pos/validators.js @@ -60,7 +60,7 @@ let validatorList = []; const validatorComparator = (a, b) => { const diff = BigInt(b.validatorWeight) - BigInt(a.validatorWeight); if (diff !== BigInt('0')) return Number(diff); - return Buffer.from(a.hexAddress, 'hex').compare(Buffer.from(b.hexAddress, 'hex')); + return Buffer.from(b.hexAddress, 'hex').compare(Buffer.from(a.hexAddress, 'hex')); }; const computeValidatorRank = async () => { From 79386df926c351093826398c7e7f47b5166124dd Mon Sep 17 00:00:00 2001 From: nagdahimanshu Date: Tue, 31 Oct 2023 14:53:58 +0100 Subject: [PATCH 2/2] Update unit tests --- .../tests/unit/shared/dataservice/pos/validators.test.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/services/blockchain-indexer/tests/unit/shared/dataservice/pos/validators.test.js b/services/blockchain-indexer/tests/unit/shared/dataservice/pos/validators.test.js index fba1aea41a..a0e5a224d0 100644 --- a/services/blockchain-indexer/tests/unit/shared/dataservice/pos/validators.test.js +++ b/services/blockchain-indexer/tests/unit/shared/dataservice/pos/validators.test.js @@ -65,22 +65,22 @@ describe('Test validatorComparator method', () => { expect(result).toBeGreaterThan(0); }); - it('should return -1 when validator weight is same but first address is smaller', async () => { + it('should return 1 when validator weight is same but first address is smaller', async () => { const { validatorComparator } = require(posValidatorsPath); const result = validatorComparator( { validatorWeight: BigInt(1e20), hexAddress: '002e84247fd3876baca6698d98f0ace199af96ed' }, { validatorWeight: BigInt(1e20), hexAddress: '0282ed03925a5c31271fa3b70bb94ce12fd83ea9' }, ); - expect(result).toBe(-1); + expect(result).toBe(1); }); - it('should return 1 when validator weight is same but first address is greater', async () => { + it('should return -1 when validator weight is same but first address is greater', async () => { const { validatorComparator } = require(posValidatorsPath); const result = validatorComparator( { validatorWeight: BigInt(1e20), hexAddress: '0282ed03925a5c31271fa3b70bb94ce12fd83ea9' }, { validatorWeight: BigInt(1e20), hexAddress: '002e84247fd3876baca6698d98f0ace199af96ed' }, ); - expect(result).toBe(1); + expect(result).toBe(-1); }); it('should return 0 when both validator weight and address are equal', async () => {