Skip to content
This repository has been archived by the owner on Jun 11, 2024. It is now read-only.

Commit

Permalink
Merge pull request #1908 from LiskHQ/1876-incorrect-validators-rank
Browse files Browse the repository at this point in the history
Incorrect validators rank
  • Loading branch information
sameersubudhi authored Oct 31, 2023
2 parents 3cfebbc + 79386df commit 8a5104d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down

0 comments on commit 8a5104d

Please sign in to comment.