Skip to content

Commit

Permalink
use format keyword for timestamp and uri
Browse files Browse the repository at this point in the history
  • Loading branch information
moodysalem committed Jun 12, 2020
1 parent b978e17 commit 0f6d7e1
Show file tree
Hide file tree
Showing 13 changed files with 141 additions and 32 deletions.
16 changes: 8 additions & 8 deletions src/tokenlist.schema.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "https://uniswap.org/tokenlist.schema.json",
"title": "Uniswap Token Lists",
"title": "Uniswap Token List",
"description": "Schema for lists of tokens compatible with the Uniswap Interface",
"$ref": "#/definitions/TokenList",
"definitions": {
Expand Down Expand Up @@ -73,7 +73,7 @@
},
"address": {
"type": "string",
"description": "The address of the token on the given chain ID",
"description": "The address of the token on the specified chain ID",
"pattern": "^0x[a-fA-F0-9]{40}$"
},
"decimals": {
Expand All @@ -96,10 +96,10 @@
"minLength": 1,
"maxLength": 20
},
"logoUrl": {
"logoURI": {
"type": "string",
"description": "A URL to the token logo asset; if not set, interface will attempt to find a logo based on the address",
"pattern": "^(https|ipfs|ipns)://.+$"
"description": "A URI to the token logo asset; if not set, interface will attempt to find a logo based on the address",
"format": "uri"
},
"tags": {
"type": "array",
Expand All @@ -126,9 +126,9 @@
"pattern": "^[\\w\\s]+$"
},
"timestamp": {
"type": "integer",
"description": "The epoch seconds timestamp of the list version; must be after June 11, 2020",
"minimum": 1591833600
"type": "string",
"format": "date-time",
"description": "The update timestamp of the list version; i.e. when this version was created"
},
"version": {
"$ref": "#/definitions/Version"
Expand Down
2 changes: 1 addition & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export interface TokenInfo {
name?: string;
decimals?: number;
symbol?: string;
logoUrl?: string;
logoURI?: string;
tagIds?: string[];
}

Expand Down
28 changes: 28 additions & 0 deletions test/__snapshots__/tokenlist.schema.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,34 @@ Array [
]
`;

exports[`schema invalid logo URI 1`] = `
Array [
Object {
"dataPath": ".tokens[0].logoURI",
"keyword": "format",
"message": "should match format \\"uri\\"",
"params": Object {
"format": "uri",
},
"schemaPath": "#/properties/logoURI/format",
},
]
`;

exports[`schema invalid timestamp 1`] = `
Array [
Object {
"dataPath": ".timestamp",
"keyword": "format",
"message": "should match format \\"date-time\\"",
"params": Object {
"format": "date-time",
},
"schemaPath": "#/properties/timestamp/format",
},
]
`;

exports[`schema requires name, timestamp, version, tokens 1`] = `
Array [
Object {
Expand Down
4 changes: 2 additions & 2 deletions test/testschemas/bigwords.tokenlist.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@
"description": "blah blah"
}
},
"timestamp": 1591897594,
"timestamp": "2018-11-13T20:20:39+00:00",
"tokens": [
{
"name": "blah blah blah blah blah blah blah",
"address": "0x0000000000000000000000000000000000000000",
"chainId": 1,
"decimals": 18,
"logoUrl": "https://test",
"logoURI": "https://test",
"symbol": "abc",
"tags": [
"coin"
Expand Down
2 changes: 1 addition & 1 deletion test/testschemas/empty.tokenlist.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"description": "blah blah"
}
},
"timestamp": 1591897594,
"timestamp": "2018-11-13T20:20:39+00:00",
"tokens": [
],
"version": {
Expand Down
38 changes: 27 additions & 11 deletions test/testschemas/example.tokenlist.json
Original file line number Diff line number Diff line change
@@ -1,25 +1,41 @@
{
"name": "My Example List",
"name": "My Token List",
"keywords": [
"abc"
"audited",
"verified"
],
"tags": {
"coin": {
"stablecoin": {
"name": "Stablecoin",
"description": "blah blah"
"description": "Tokens that are fixed to an external asset"
},
"compound": {
"name": "Compound Finance",
"description": "Tokens that earn interest on compound.finance"
}
},
"timestamp": 1591897594,
"timestamp": "2020-06-12T00:00:00+00:00",
"tokens": [
{
"name": "blah",
"address": "0x0000000000000000000000000000000000000000",
"chainId": 1,
"decimals": 18,
"logoUrl": "https://test",
"symbol": "abc",
"address": "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
"symbol": "USDC",
"name": "USD Coin",
"decimals": 6,
"logoURI": "ipfs://QmXfzKRvjZz3u5JRgC4v5mGVbm9ahrUiB4DgzHBsnWbTMM",
"tags": [
"coin"
"stablecoin"
]
},
{
"chainId": 1,
"address": "0x39AA39c021dfbaE8faC545936693aC917d5E7563",
"symbol": "cUSDC",
"name": "Compound USD Coin",
"decimals": 8,
"logoURI": "ipfs://QmUSNbwUxUYNMvMksKypkgWs8unSm8dX2GjCPBVGZ7GGMr",
"tags": [
"compound"
]
}
],
Expand Down
24 changes: 24 additions & 0 deletions test/testschemas/invalidlogouri.tokenlist.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"name": "My Token List",
"keywords": [
],
"timestamp": "2020-06-12T00:00:00+00:00",
"tokens": [
{
"chainId": 1,
"address": "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
"symbol": "USDC",
"name": "USD Coin",
"decimals": 6,
"logoURI": "hello",
"tags": [
"stablecoin"
]
}
],
"version": {
"major": 0,
"minor": 0,
"patch": 1
}
}
31 changes: 31 additions & 0 deletions test/testschemas/invalidtimestamp.tokenlist.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"name": "My Example List",
"keywords": [
"abc"
],
"tags": {
"coin": {
"name": "Stablecoin",
"description": "blah blah"
}
},
"timestamp": "abc",
"tokens": [
{
"name": "blah",
"address": "0x0000000000000000000000000000000000000000",
"chainId": 1,
"decimals": 18,
"logoURI": "https://test",
"symbol": "abc",
"tags": [
"coin"
]
}
],
"version": {
"major": 0,
"minor": 0,
"patch": 1
}
}
4 changes: 2 additions & 2 deletions test/testschemas/invalidtokenaddress.tokenlist.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@
"description": "blah blah"
}
},
"timestamp": 1591897594,
"timestamp": "2018-11-13T20:20:39+00:00",
"tokens": [
{
"name": "blah blah ",
"address": "0x00000000000000000000000000000000000000_0",
"chainId": 1,
"decimals": 18,
"logoUrl": "https://test",
"logoURI": "https://test",
"symbol": "abc",
"tags": [
"coin"
Expand Down
4 changes: 2 additions & 2 deletions test/testschemas/invalidversion.1.tokenlist.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@
"description": "blah blah"
}
},
"timestamp": 1591897594,
"timestamp": "2018-11-13T20:20:39+00:00",
"tokens": [
{
"name": "blah blah ",
"address": "0x0000000000000000000000000000000000000000",
"chainId": 1,
"decimals": 18,
"logoUrl": "https://test",
"logoURI": "https://test",
"symbol": "abc",
"tags": [
"coin"
Expand Down
4 changes: 2 additions & 2 deletions test/testschemas/invalidversion.2.tokenlist.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@
"description": "blah blah"
}
},
"timestamp": 1591897594,
"timestamp": "2018-11-13T20:20:39+00:00",
"tokens": [
{
"name": "blah blah ",
"address": "0x0000000000000000000000000000000000000000",
"chainId": 1,
"decimals": 18,
"logoUrl": "https://test",
"logoURI": "https://test",
"symbol": "abc",
"tags": [
"coin"
Expand Down
4 changes: 2 additions & 2 deletions test/testschemas/invalidversion.3.tokenlist.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@
"description": "blah blah"
}
},
"timestamp": 1591897594,
"timestamp": "2018-11-13T20:20:39+00:00",
"tokens": [
{
"name": "blah blah ",
"address": "0x0000000000000000000000000000000000000000",
"chainId": 1,
"decimals": 18,
"logoUrl": "https://test",
"logoURI": "https://test",
"symbol": "abc",
"tags": [
"coin"
Expand Down
12 changes: 11 additions & 1 deletion test/tokenlist.schema.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ import exampleList from './testschemas/example.tokenlist.json';
import emptyList from './testschemas/empty.tokenlist.json';
import bigWords from './testschemas/bigwords.tokenlist.json';
import invalidTokenAddress from './testschemas/invalidtokenaddress.tokenlist.json';
import invalidTimestamp from './testschemas/invalidtimestamp.tokenlist.json';
import invalidLogoURI from './testschemas/invalidlogouri.tokenlist.json';
import invalidVersion1 from './testschemas/invalidversion.1.tokenlist.json';
import invalidVersion2 from './testschemas/invalidversion.2.tokenlist.json';
import invalidVersion3 from './testschemas/invalidversion.3.tokenlist.json';

const ajv = new Ajv({ allErrors: true });
const ajv = new Ajv({ allErrors: true, format: 'full' });
const validator = ajv.compile(schema);

describe('schema', () => {
Expand Down Expand Up @@ -41,6 +43,14 @@ describe('schema', () => {
checkSchema(invalidTokenAddress, false);
});

it('invalid timestamp', () => {
checkSchema(invalidTimestamp, false);
});

it('invalid logo URI', () => {
checkSchema(invalidLogoURI, false);
});

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

0 comments on commit 0f6d7e1

Please sign in to comment.