From 61c44116979325a847de1c9848b3687155f0ce0d Mon Sep 17 00:00:00 2001 From: Alexandre Bini Date: Mon, 12 Dec 2022 18:52:24 -0300 Subject: [PATCH] Add support for symbols containing unicode chars (#176) * [#175] Add support for symbols containing unicode chars * [#175] Adding support for empty symbols and names * [#175] Add support for names containing unicode chars --- src/tokenlist.schema.json | 24 ++++++++++++++---- .../tokenlist.schema.test.ts.snap | 2 ++ test/schema/empty-name-symbol.tokenlist.json | 25 +++++++++++++++++++ ...e-symbol-special-characters.tokenlist.json | 14 +++++++++++ test/tokenlist.schema.test.ts | 5 ++++ 5 files changed, 65 insertions(+), 5 deletions(-) create mode 100644 test/schema/empty-name-symbol.tokenlist.json diff --git a/src/tokenlist.schema.json b/src/tokenlist.schema.json index ccb1ec65..2fdea263 100644 --- a/src/tokenlist.schema.json +++ b/src/tokenlist.schema.json @@ -231,19 +231,33 @@ "name": { "type": "string", "description": "The name of the token", - "minLength": 1, + "minLength": 0, "maxLength": 40, - "pattern": "^[ \\w.'+\\-%/À-ÖØ-öø-ÿ:&\\[\\]\\(\\)]+$", + "anyOf": [ + { + "const": "" + }, + { + "pattern": "^[ \\S+]+$" + } + ], "examples": [ "USD Coin" ] }, "symbol": { "type": "string", - "description": "The symbol for the token; must be alphanumeric", - "pattern": "^[a-zA-Z0-9+\\-%/$.]+$", - "minLength": 1, + "description": "The symbol for the token", + "minLength": 0, "maxLength": 20, + "anyOf": [ + { + "const": "" + }, + { + "pattern": "^\\S+$" + } + ], "examples": [ "USDC" ] diff --git a/test/__snapshots__/tokenlist.schema.test.ts.snap b/test/__snapshots__/tokenlist.schema.test.ts.snap index ecc36943..0d192939 100644 --- a/test/__snapshots__/tokenlist.schema.test.ts.snap +++ b/test/__snapshots__/tokenlist.schema.test.ts.snap @@ -579,6 +579,8 @@ exports[`schema token symbols may contain periods 1`] = `null`; exports[`schema works for big example schema 1`] = `null`; +exports[`schema works for empty names and symbols 1`] = `null`; + exports[`schema works for example schema 1`] = `null`; exports[`schema works for special characters schema 1`] = `null`; diff --git a/test/schema/empty-name-symbol.tokenlist.json b/test/schema/empty-name-symbol.tokenlist.json new file mode 100644 index 00000000..517ee01a --- /dev/null +++ b/test/schema/empty-name-symbol.tokenlist.json @@ -0,0 +1,25 @@ +{ + "name": "My Token List", + "timestamp": "2020-06-12T00:00:00+00:00", + "tokens": [ + { + "chainId": 137, + "address": "0xc31C535F4d9A789df0c16D461B4F811543b72FEb", + "decimals": 0, + "name": "", + "symbol": "" + }, + { + "chainId": 137, + "address": "0xF336f5624D34c3Be82eF3EFc4978bd2397B1524A", + "decimals": 0, + "name": "", + "symbol": "" + } + ], + "version": { + "major": 1, + "minor": 0, + "patch": 0 + } +} diff --git a/test/schema/example-name-symbol-special-characters.tokenlist.json b/test/schema/example-name-symbol-special-characters.tokenlist.json index 88667ada..1f62d332 100644 --- a/test/schema/example-name-symbol-special-characters.tokenlist.json +++ b/test/schema/example-name-symbol-special-characters.tokenlist.json @@ -43,6 +43,20 @@ "decimals": 18, "name": "[brackets]&(parenthesis)", "symbol": "symbol" + }, + { + "chainId": 1, + "address": "0x76ee13b775331eeae2bc5e3b67f4a44101b27a94", + "decimals": 18, + "name": "Amatsukami", + "symbol": "天津神" + }, + { + "chainId": 137, + "address": "0x841120E51aD43EfE489244728532854A352073aD", + "decimals": 6, + "name": "Timeless ERC4626-Wrapped", + "symbol": "∞-waUSDC-xPYT" } ], "version": { diff --git a/test/tokenlist.schema.test.ts b/test/tokenlist.schema.test.ts index 09b6d62e..84fe3b0d 100644 --- a/test/tokenlist.schema.test.ts +++ b/test/tokenlist.schema.test.ts @@ -5,6 +5,7 @@ import exampleNameSymbolSpecialCharacters from './schema/example-name-symbol-spe import bigExampleList from './schema/bigexample.tokenlist.json'; import exampleListMinimum from './schema/exampleminimum.tokenlist.json'; import emptyList from './schema/empty.tokenlist.json'; +import emptyNameSymbol from './schema/empty-name-symbol.tokenlist.json'; import bigWords from './schema/bigwords.tokenlist.json'; import invalidTokenAddress from './schema/invalidtokenaddress.tokenlist.json'; import invalidTimestamp from './schema/invalidtimestamp.tokenlist.json'; @@ -63,6 +64,10 @@ describe('schema', () => { checkSchema(emptyList, false); }); + it('works for empty names and symbols', () => { + checkSchema(emptyNameSymbol, true); + }); + it('fails with big names', () => { checkSchema(bigWords, false); });