Improve deprecation of chains

closes #1003
This commit is contained in:
ligi 2022-03-30 15:36:25 +02:00
parent 5a7564fe61
commit da94738893
No known key found for this signature in database
GPG Key ID: 8E81894010ABF23D
8 changed files with 48 additions and 15 deletions

View File

@ -1,5 +1,5 @@
{ {
"name": "Moonrock", "name": "Moonrock old",
"chain": "MOON", "chain": "MOON",
"rpc": [], "rpc": [],
"faucets": [], "faucets": [],
@ -9,7 +9,8 @@
"decimals": 18 "decimals": 18
}, },
"infoURL": "", "infoURL": "",
"shortName": "mrock", "shortName": "mrock-old",
"chainId": 1286, "chainId": 1286,
"networkId": 1286 "networkId": 1286,
} "deprecated": true
}

View File

@ -1,5 +1,5 @@
{ {
"name": "SoterOne Mainnet", "name": "SoterOne Mainnet old",
"chain": "SOTER", "chain": "SOTER",
"rpc": [ "rpc": [
"https://rpc.soter.one" "https://rpc.soter.one"
@ -12,7 +12,8 @@
"decimals": 18 "decimals": 18
}, },
"infoURL": "https://www.soterone.com", "infoURL": "https://www.soterone.com",
"shortName": "SO1", "shortName": "SO1-old",
"chainId": 218, "chainId": 218,
"networkId": 218 "networkId": 218,
"deprecated": true
} }

View File

@ -22,7 +22,8 @@ val optionalFields = listOf(
"explorers", "explorers",
"title", "title",
"network", "network",
"parent" "parent",
"deprecated"
) )
val moshi: Moshi = Moshi.Builder().build() val moshi: Moshi = Moshi.Builder().build()

View File

@ -93,10 +93,8 @@ private fun doChecks(doRPCConnect: Boolean) {
checkIcon(it) checkIcon(it)
} }
allFiles.filter { it.isDirectory }.forEach { allFiles.filter { it.isDirectory }.forEach { _ ->
if (it.name != "deprecated") { error("should not contain a directory")
error("the only directory allowed is 'deprecated'")
}
} }
} }
@ -214,7 +212,11 @@ fun checkChain(chainFile: File, connectRPC: Boolean) {
throw ENSRegistryAddressMustBeValid() throw ENSRegistryAddressMustBeValid()
} }
} }
jsonObject["deprecated"]?.let {
if (it !is Boolean) {
throw DeprecatedMustBeBoolean()
}
}
jsonObject["parent"]?.let { jsonObject["parent"]?.let {
if (it !is JsonObject) { if (it !is JsonObject) {
throw ParentMustBeObject() throw ParentMustBeObject()

View File

@ -25,4 +25,5 @@ class ParentHasExtraFields(fields: Set<String>): Exception("parent has extra fie
class ParentBridgeNoArray: Exception("parent bridge must be array") class ParentBridgeNoArray: Exception("parent bridge must be array")
class BridgeNoObject: Exception("parent bridges must be array consisting of json objects") class BridgeNoObject: Exception("parent bridges must be array consisting of json objects")
class BridgeOnlyURL: Exception("parent bridge only contain an URL") class BridgeOnlyURL: Exception("parent bridge only contain an URL")
class ParentChainDoesNotExist(chain: String): Exception("Referenced parent chain ($chain) does not exist") class ParentChainDoesNotExist(chain: String): Exception("Referenced parent chain ($chain) does not exist")
class DeprecatedMustBeBoolean: Exception("deprecated must be boolean")

View File

@ -221,6 +221,11 @@ class TheChainChecker {
checkChain(getFile("invalid/explorermissingurl/eip155-1.json"), false) checkChain(getFile("invalid/explorermissingurl/eip155-1.json"), false)
} }
@Test(expected = DeprecatedMustBeBoolean::class)
fun shouldFailOnInvalidDeprecation() {
checkChain(getFile("invalid/invalid_deprecation/eip155-1.json"), false)
}
@Test @Test
fun canParse2chains() { fun canParse2chains() {
checkChain(getFile("valid/eip155-1.json"), false) checkChain(getFile("valid/eip155-1.json"), false)

View File

@ -0,0 +1,21 @@
{
"name": "Ethereum Mainnet",
"shortName": "eth",
"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": [],
"deprecated": "yolo"
}

View File

@ -15,5 +15,6 @@
"name": "Ether", "name": "Ether",
"symbol": "ETH", "symbol": "ETH",
"decimals": 18 "decimals": 18
} },
"deprecated": true
} }