Prevent shortName '*'

closes #734
This commit is contained in:
ligi 2022-01-09 16:10:52 +01:00
parent c2c676aaf9
commit fde00b7d1a
No known key found for this signature in database
GPG Key ID: 8E81894010ABF23D
4 changed files with 34 additions and 1 deletions

View File

@ -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)
}

View File

@ -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://")

View File

@ -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)

View File

@ -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": []
}