From 341ae07c036e454b6df9d093e49ed05ef0b8e06d Mon Sep 17 00:00:00 2001 From: ligi Date: Sun, 10 Oct 2021 17:39:21 +0200 Subject: [PATCH] Allow 'none' as value for explorer standard --- .../kotlin/org/ethereum/lists/chains/Main.kt | 4 +-- .../ethereum/lists/chains/model/Exceptions.kt | 2 +- .../ethereum/lists/chains/TheChainChecker.kt | 10 ++++++- .../valid/withexplorer/eip155-2.json | 26 +++++++++++++++++++ 4 files changed, 38 insertions(+), 4 deletions(-) create mode 100644 src/test/resources/test_chains/valid/withexplorer/eip155-2.json diff --git a/src/main/kotlin/org/ethereum/lists/chains/Main.kt b/src/main/kotlin/org/ethereum/lists/chains/Main.kt index 8fb02d59..73d8a0c5 100644 --- a/src/main/kotlin/org/ethereum/lists/chains/Main.kt +++ b/src/main/kotlin/org/ethereum/lists/chains/Main.kt @@ -191,8 +191,8 @@ fun checkChain(chainFile: File, connectRPC: Boolean) { throw(ExplorerInvalidUrl()) } - if (explorer["standard"] != "EIP3091") { - throw(ExplorerStandardMustBeEIP3091()) + if (explorer["standard"] != "EIP3091" && explorer["standard"] != "none") { + throw(ExplorerStandardMustBeEIP3091OrNone()) } } } diff --git a/src/main/kotlin/org/ethereum/lists/chains/model/Exceptions.kt b/src/main/kotlin/org/ethereum/lists/chains/model/Exceptions.kt index e4af9a9b..2b88a7d4 100644 --- a/src/main/kotlin/org/ethereum/lists/chains/model/Exceptions.kt +++ b/src/main/kotlin/org/ethereum/lists/chains/model/Exceptions.kt @@ -15,7 +15,7 @@ class UnsupportedNamespace(): Exception("So far only the EIP155 namespace is sup class ExplorersMustBeArray: Exception("explorers must be an array") class ExplorerMustHaveName: Exception("Explorer must have name") class ExplorerInvalidUrl: Exception("Explorer have url starting with https://") -class ExplorerStandardMustBeEIP3091: Exception("explorer standard must be EIP3091 - currently the only one supported") +class ExplorerStandardMustBeEIP3091OrNone: Exception("explorer standard must be 'none' or 'EIP3091'") class ParentHasInvalidType(type: String?): Exception("Parent has invalid type $type - only L2 or shard allowed") class ParentMustBeObject: Exception("parent must be an object") class ParentMustHaveChainAndType: Exception("parent must have fields 'chain' and 'type'") diff --git a/src/test/kotlin/org/ethereum/lists/chains/TheChainChecker.kt b/src/test/kotlin/org/ethereum/lists/chains/TheChainChecker.kt index ef74c284..bd3c3ad4 100644 --- a/src/test/kotlin/org/ethereum/lists/chains/TheChainChecker.kt +++ b/src/test/kotlin/org/ethereum/lists/chains/TheChainChecker.kt @@ -28,6 +28,14 @@ class TheChainChecker { checkChain(file, false) } + @Test + fun shouldPassForValidChainWithExplorersNoStandard() { + val file = getFile("valid/withexplorer/eip155-2.json") + + checkChain(file, false) + } + + @Test fun shouldPassForValidChainWithParent() { val file = getFile("valid/withparent/eip155-2.json") @@ -186,7 +194,7 @@ class TheChainChecker { checkChain(getFile("invalid/explorersnotarray/eip155-1.json"), false) } - @Test(expected = ExplorerStandardMustBeEIP3091::class) + @Test(expected = ExplorerStandardMustBeEIP3091OrNone::class) fun shouldFailOnWrongExplorerStandard() { checkChain(getFile("invalid/wrongexplorerstandard/eip155-1.json"), false) } diff --git a/src/test/resources/test_chains/valid/withexplorer/eip155-2.json b/src/test/resources/test_chains/valid/withexplorer/eip155-2.json new file mode 100644 index 00000000..fadae45a --- /dev/null +++ b/src/test/resources/test_chains/valid/withexplorer/eip155-2.json @@ -0,0 +1,26 @@ +{ + "name": "Ethereum Mainnet", + "shortName": "eth", + "chain": "ETH", + "network": "mainnet", + "chainId": 2, + "networkId": 2, + "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": [ + { + "name": "some", + "url": "https://etherscan.io", + "standard": "none" + } + ] +}