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 8d16e129..c82bd729 100644 --- a/processor/src/main/kotlin/org/ethereum/lists/chains/Main.kt +++ b/processor/src/main/kotlin/org/ethereum/lists/chains/Main.kt @@ -320,9 +320,11 @@ fun checkChain(chainFile: File, connectRPC: Boolean, verbose: Boolean = false) { } if (url.endsWith("/")) { - throw (ExplorerCannotEndInSlash()) + throw ExplorerCannotEndInSlash() } + url.checkString("Explorer URL") + if (explorer["standard"] != "EIP3091" && explorer["standard"] != "none") { throw (ExplorerStandardMustBeEIP3091OrNone()) } @@ -360,9 +362,7 @@ fun checkChain(chainFile: File, connectRPC: Boolean, verbose: Boolean = false) { throw FaucetMustBeString() } - if (it.isBlank()) { - throw FaucetMustBeString() - } + it.checkString("Faucet URL") } } @@ -376,6 +376,7 @@ fun checkChain(chainFile: File, connectRPC: Boolean, verbose: Boolean = false) { throw RedFlagMustBeString() } + it.checkString("Red flag") if (!allowedRedFlags.contains(it)) throw (InvalidRedFlags(it)) } @@ -427,11 +428,10 @@ fun checkChain(chainFile: File, connectRPC: Boolean, verbose: Boolean = false) { (jsonObject["rpc"] as List<*>).forEach { if (it !is String) { throw (RPCMustBeListOfStrings()) - } else if (it.isBlank()) { - throw (RPCCannotBeEmpty()) } else if (rpcPrefixes.none { prefix -> it.startsWith(prefix) }) { throw (InvalidRPCPrefix(it)) } else { + it.checkString("RPC URL") if (connectRPC) { var chainId: BigInteger? = null try { @@ -457,6 +457,16 @@ fun checkChain(chainFile: File, connectRPC: Boolean, verbose: Boolean = false) { } } +private fun String.checkString(which: String) { + if (isBlank()) { + throw StringCannotBeBlank(which) + } + + if (trim() != this) { + throw StringCannotHaveExtraSpaces(which) + } +} + fun String.normalizeName() = replace(" ", "").uppercase() /* 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 997cef19..5d263f1c 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 @@ -22,6 +22,9 @@ class ExplorersMustBeArray: Exception("explorers must be an array") class ExplorerMustHaveName: Exception("Explorer must have name") class ExplorerMustWithHttpsOrHttp: Exception("Explorer have url starting with https:// or http://") class ExplorerCannotEndInSlash: Exception("Explorer cannot have a slash on the end") +class StringCannotBeBlank(which: String): Exception("$which cannot be blank") + +class StringCannotHaveExtraSpaces(which: String): Exception("$which cannot have leading or tailing spaces") 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 RedFlagsMustBeArray: Exception("redFlags not an array") diff --git a/processor/src/test/resources/test_chains/invalid/sameshortname/eip155-5.json b/processor/src/test/resources/test_chains/invalid/sameshortname/eip155-5.json index 82d9966e..5b24c243 100644 --- a/processor/src/test/resources/test_chains/invalid/sameshortname/eip155-5.json +++ b/processor/src/test/resources/test_chains/invalid/sameshortname/eip155-5.json @@ -3,7 +3,7 @@ "chain": "ETH", "rpc": [ "https://rpc.goerli.mudit.blog/", - "https://rpc.slock.it/goerli ", + "https://rpc.slock.it/goerli", "https://goerli.prylabs.net" ], "faucets": [ diff --git a/processor/src/test/resources/test_chains/valid/eip155-5.json b/processor/src/test/resources/test_chains/valid/eip155-5.json index 3a5b5851..4f8e394b 100644 --- a/processor/src/test/resources/test_chains/valid/eip155-5.json +++ b/processor/src/test/resources/test_chains/valid/eip155-5.json @@ -3,7 +3,7 @@ "chain": "ETH", "rpc": [ "https://rpc.goerli.mudit.blog/", - "https://rpc.slock.it/goerli ", + "https://rpc.slock.it/goerli", "https://goerli.prylabs.net" ], "faucets": [