diff --git a/elements/lisk-api-client/src/resources/delegates.ts b/elements/lisk-api-client/src/resources/delegates.ts index f894d276319..b9a951ac9d6 100644 --- a/elements/lisk-api-client/src/resources/delegates.ts +++ b/elements/lisk-api-client/src/resources/delegates.ts @@ -31,7 +31,7 @@ export class DelegatesResource extends APIResource { this.get = apiMethod({ defaultData: { - sort: 'username:asc', + sort: 'voteWeight:desc', }, method: GET, }).bind(this); @@ -39,7 +39,7 @@ export class DelegatesResource extends APIResource { this.getStandby = apiMethod({ defaultData: { offset: 101, - sort: 'username:asc', + sort: 'voteWeight:desc', }, method: GET, }).bind(this); diff --git a/framework/src/modules/http_api/schema/swagger.yml b/framework/src/modules/http_api/schema/swagger.yml index 84aadcec340..7f1a37dea33 100755 --- a/framework/src/modules/http_api/schema/swagger.yml +++ b/framework/src/modules/http_api/schema/swagger.yml @@ -583,7 +583,9 @@ paths: - missedBlocks:desc - producedBlocks:asc - producedBlocks:desc - default: username:asc + - voteWeight:asc + - voteWeight:desc + default: voteWeight:desc responses: 200: description: Search results matching criteria diff --git a/framework/test/mocha/functional/http/get/delegates.js b/framework/test/mocha/functional/http/get/delegates.js index e60bb2b5e9d..2fe9a1d6a41 100644 --- a/framework/test/mocha/functional/http/get/delegates.js +++ b/framework/test/mocha/functional/http/get/delegates.js @@ -515,6 +515,28 @@ describe('GET /delegates', () => { }); }); + it('using sort="voteWeight:asc" should sort results in ascending order', async () => { + return delegatesEndpoint + .makeRequest({ sort: 'voteWeight:asc' }, 200) + .then(res => { + expect(_.map(res.data, 'voteWeight').sort()).to.eql( + _.map(res.data, 'voteWeight'), + ); + }); + }); + + it('using sort="voteWeight:desc" should sort results in descending order', async () => { + return delegatesEndpoint + .makeRequest({ sort: 'voteWeight:desc' }, 200) + .then(res => { + expect( + _.map(res.data, 'voteWeight') + .sort() + .reverse(), + ).to.eql(_.map(res.data, 'voteWeight')); + }); + }); + it('using sort with any of sort fields should not place NULLs first', async () => { const delegatesSortFields = [ 'username',