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

Incorrect validators rank #1908

Merged
merged 2 commits into from
Oct 31, 2023
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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