diff --git a/src/tokenlist.schema.json b/src/tokenlist.schema.json index 02811a23..987e0f13 100644 --- a/src/tokenlist.schema.json +++ b/src/tokenlist.schema.json @@ -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", diff --git a/test/__snapshots__/tokenlist.schema.test.ts.snap b/test/__snapshots__/tokenlist.schema.test.ts.snap index 971cdc9d..799ef588 100644 --- a/test/__snapshots__/tokenlist.schema.test.ts.snap +++ b/test/__snapshots__/tokenlist.schema.test.ts.snap @@ -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 { diff --git a/test/schema/invaliddecimals.1.tokenlist.json b/test/schema/invaliddecimals.1.tokenlist.json new file mode 100644 index 00000000..99e6575c --- /dev/null +++ b/test/schema/invaliddecimals.1.tokenlist.json @@ -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 + } +} \ No newline at end of file diff --git a/test/schema/invaliddecimals.2.tokenlist.json b/test/schema/invaliddecimals.2.tokenlist.json new file mode 100644 index 00000000..99631b62 --- /dev/null +++ b/test/schema/invaliddecimals.2.tokenlist.json @@ -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 + } +} \ No newline at end of file diff --git a/test/tokenlist.schema.test.ts b/test/tokenlist.schema.test.ts index 0f88ae69..3e16c3cd 100644 --- a/test/tokenlist.schema.test.ts +++ b/test/tokenlist.schema.test.ts @@ -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); @@ -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);