Skip to content

Commit

Permalink
decimals uint8 bounds
Browse files Browse the repository at this point in the history
  • Loading branch information
moodysalem committed Jun 12, 2020
1 parent 114b600 commit f4038c8
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/tokenlist.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
"type": "integer",
"description": "The number of decimals for the token balance; if not set, defaults to on-chain data",
"minimum": 0,
"maximum": 78
"maximum": 255
},
"name": {
"type": "string",
Expand Down
32 changes: 32 additions & 0 deletions test/__snapshots__/tokenlist.schema.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,38 @@ Array [
]
`;

exports[`schema invalid decimals 1`] = `
Array [
Object {
"dataPath": ".tokens[0].decimals",
"keyword": "maximum",
"message": "should be <= 255",
"params": Object {
"comparison": "<=",
"exclusive": false,
"limit": 255,
},
"schemaPath": "#/properties/decimals/maximum",
},
]
`;

exports[`schema invalid decimals 2`] = `
Array [
Object {
"dataPath": ".tokens[0].decimals",
"keyword": "minimum",
"message": "should be >= 0",
"params": Object {
"comparison": ">=",
"exclusive": false,
"limit": 0,
},
"schemaPath": "#/properties/decimals/minimum",
},
]
`;

exports[`schema invalid logo URI 1`] = `
Array [
Object {
Expand Down
31 changes: 31 additions & 0 deletions test/schema/invaliddecimals.1.tokenlist.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"name": "My Example List",
"keywords": [
"abc"
],
"tags": {
"1": {
"name": "tag 1",
"description": "blah blah"
}
},
"timestamp": "2018-11-13T20:20:39+00:00",
"tokens": [
{
"name": "name",
"address": "0x0000000000000000000000000000000000000000",
"chainId": 1,
"decimals": 256,
"logoURI": "https://test",
"symbol": "abc",
"tags": [
"coin"
]
}
],
"version": {
"major": 0,
"minor": 0,
"patch": 1
}
}
31 changes: 31 additions & 0 deletions test/schema/invaliddecimals.2.tokenlist.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"name": "My Example List",
"keywords": [
"abc"
],
"tags": {
"1": {
"name": "tag 1",
"description": "blah blah"
}
},
"timestamp": "2018-11-13T20:20:39+00:00",
"tokens": [
{
"name": "name",
"address": "0x0000000000000000000000000000000000000000",
"chainId": 1,
"decimals": -1,
"logoURI": "https://test",
"symbol": "abc",
"tags": [
"coin"
]
}
],
"version": {
"major": 0,
"minor": 0,
"patch": 1
}
}
7 changes: 7 additions & 0 deletions test/tokenlist.schema.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import invalidLogoURI from './schema/invalidlogouri.tokenlist.json';
import invalidVersion1 from './schema/invalidversion.1.tokenlist.json';
import invalidVersion2 from './schema/invalidversion.2.tokenlist.json';
import invalidVersion3 from './schema/invalidversion.3.tokenlist.json';
import invalidDecimals1 from './schema/invaliddecimals.1.tokenlist.json';
import invalidDecimals2 from './schema/invaliddecimals.2.tokenlist.json';

const ajv = new Ajv({ allErrors: true, format: 'full' });
const validator = ajv.compile(schema);
Expand Down Expand Up @@ -53,6 +55,11 @@ describe('schema', () => {
checkSchema(invalidLogoURI, false);
});

it('invalid decimals', () => {
checkSchema(invalidDecimals1, false);
checkSchema(invalidDecimals2, false);
});

it('checks version', () => {
checkSchema(invalidVersion1, false);
checkSchema(invalidVersion2, false);
Expand Down

0 comments on commit f4038c8

Please sign in to comment.