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

Commit

Permalink
Added uint64 numeric string param parser
Browse files Browse the repository at this point in the history
  • Loading branch information
Vektrat authored Jun 29, 2020
1 parent 2a3ab25 commit 5eb7eac
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 4 deletions.
2 changes: 1 addition & 1 deletion rest/src/routes/blockRoutes.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ module.exports = {

const offsetParsers = {
id: 'objectId',
height: 'uint64'
height: 'uint64hex'
};
const options = routeUtils.parsePaginationArguments(params, services.config.pageSize, offsetParsers);

Expand Down
3 changes: 2 additions & 1 deletion rest/src/routes/routeUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ const namedParserMap = {

return result;
},
uint64: str => uint64.fromHex(str),
uint64: str => uint64.fromString(str),
uint64hex: str => uint64.fromHex(str),
address: str => {
if (constants.sizes.addressEncoded === str.length)
return address.stringToAddress(str);
Expand Down
4 changes: 2 additions & 2 deletions rest/test/routes/blockRoutes_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ describe('block routes', () => {
return mockServer.callRoute(route, req).then(() => {
// Assert:
expect(paginationParser.firstCall.args[0]).to.deep.equal(req.params);
expect(paginationParser.firstCall.args[2]).to.deep.equal({ id: 'objectId', height: 'uint64' });
expect(paginationParser.firstCall.args[2]).to.deep.equal({ id: 'objectId', height: 'uint64hex' });

expect(dbBlocksFake.calledOnce).to.equal(true);
expect(dbBlocksFake.firstCall.args[2]).to.deep.equal(pagingBag);
Expand All @@ -138,7 +138,7 @@ describe('block routes', () => {
const paginationParserSpy = sinon.spy(routeUtils, 'parsePaginationArguments');
const expectedAllowedSortFields = {
id: 'objectId',
height: 'uint64'
height: 'uint64hex'
};

// Act:
Expand Down
8 changes: 8 additions & 0 deletions rest/test/routes/routeUtils_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,14 @@ describe('route utils', () => {

describe('uint64', () => addParserTests({
parser: 'uint64',
valid: [
{ id: '4468410971573743', parsed: [0x00ABCDEF, 0x000FDFFF] }
],
invalid: ['-43534534', '0DC67FBE1CAD29E'].map(id => ({ id }))
}));

describe('uint64hex', () => addParserTests({
parser: 'uint64hex',
valid: [
{ id: '0DC67FBE1CAD29E3', parsed: [481110499, 231112638] }
],
Expand Down

0 comments on commit 5eb7eac

Please sign in to comment.