From fde00b7d1a46c087c99823a72fe67dbae090a273 Mon Sep 17 00:00:00 2001 From: ligi Date: Sun, 9 Jan 2022 16:10:52 +0100 Subject: [PATCH] Prevent shortName '*' closes #734 --- .../kotlin/org/ethereum/lists/chains/Main.kt | 5 +++++ .../ethereum/lists/chains/model/Exceptions.kt | 3 ++- .../ethereum/lists/chains/TheChainChecker.kt | 7 +++++++ .../shortNameMustNotBeStar/eip155-1.json | 20 +++++++++++++++++++ 4 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 processor/src/test/resources/test_chains/invalid/shortNameMustNotBeStar/eip155-1.json diff --git a/processor/src/main/kotlin/org/ethereum/lists/chains/Main.kt b/processor/src/main/kotlin/org/ethereum/lists/chains/Main.kt index 904d62f6..ee2f58d8 100644 --- a/processor/src/main/kotlin/org/ethereum/lists/chains/Main.kt +++ b/processor/src/main/kotlin/org/ethereum/lists/chains/Main.kt @@ -284,6 +284,11 @@ private fun parseWithMoshi(fileToParse: File) { if (parsedShortNames.contains(parsedChain.shortName)) { throw ShortNameMustBeUnique(parsedChain.shortName) } + + if (parsedChain.shortName == "*") { + throw ShortNameMustNotBeStar() + } + parsedShortNames.add(parsedChain.shortName) } diff --git a/processor/src/main/kotlin/org/ethereum/lists/chains/model/Exceptions.kt b/processor/src/main/kotlin/org/ethereum/lists/chains/model/Exceptions.kt index 2b88a7d4..9be8edbb 100644 --- a/processor/src/main/kotlin/org/ethereum/lists/chains/model/Exceptions.kt +++ b/processor/src/main/kotlin/org/ethereum/lists/chains/model/Exceptions.kt @@ -11,7 +11,8 @@ class ENSMustHaveOnlyRegistry: Exception("ens can only have a registry currently class ENSRegistryAddressMustBeValid: Exception("ens registry must have valid address") class NameMustBeUnique(dup: String): Exception(" name must be unique - but found `$dup` more than once") class ShortNameMustBeUnique(dup: String): Exception("short name must be unique - but found `$dup` more than once") -class UnsupportedNamespace(): Exception("So far only the EIP155 namespace is supported") +class ShortNameMustNotBeStar: Exception("short name must not be '*'") +class UnsupportedNamespace: Exception("So far only the EIP155 namespace is supported") class ExplorersMustBeArray: Exception("explorers must be an array") class ExplorerMustHaveName: Exception("Explorer must have name") class ExplorerInvalidUrl: Exception("Explorer have url starting with https://") diff --git a/processor/src/test/kotlin/org/ethereum/lists/chains/TheChainChecker.kt b/processor/src/test/kotlin/org/ethereum/lists/chains/TheChainChecker.kt index 19a0a681..a4c23394 100644 --- a/processor/src/test/kotlin/org/ethereum/lists/chains/TheChainChecker.kt +++ b/processor/src/test/kotlin/org/ethereum/lists/chains/TheChainChecker.kt @@ -177,6 +177,13 @@ class TheChainChecker { checkChain(file, false) } + @Test(expected = ShortNameMustNotBeStar::class) + fun shouldFailForStarShortName() { + val file = getFile("invalid/shortNameMustNotBeStar/eip155-1.json") + + checkChain(file, false) + } + @Test(expected = NameMustBeUnique::class) fun shouldFailOnNonUniqueName() { checkChain(getFile("valid/eip155-1.json"), false) diff --git a/processor/src/test/resources/test_chains/invalid/shortNameMustNotBeStar/eip155-1.json b/processor/src/test/resources/test_chains/invalid/shortNameMustNotBeStar/eip155-1.json new file mode 100644 index 00000000..bb4c8f1e --- /dev/null +++ b/processor/src/test/resources/test_chains/invalid/shortNameMustNotBeStar/eip155-1.json @@ -0,0 +1,20 @@ +{ + "name": "Ethereum Mainnet", + "shortName": "*", + "chain": "ETH", + "network": "mainnet", + "chainId": 1, + "networkId": 1, + "rpc": [ + "https://mainnet.infura.io/v3/${INFURA_API_KEY}", + "https://api.mycryptoapi.com/eth" + ], + "faucets": [], + "infoURL": "https://ethereum.org", + "nativeCurrency": { + "name": "Ether", + "symbol": "ETH", + "decimals": 18 + }, + "explorers": [] +} \ No newline at end of file