mirror of
https://github.com/Instadapp/chains.git
synced 2024-07-29 22:37:19 +00:00
parent
bf8ce68096
commit
02a3e91b01
|
@ -26,9 +26,12 @@ val optionalFields = listOf(
|
|||
"explorers",
|
||||
"title",
|
||||
"parent",
|
||||
"status"
|
||||
"status",
|
||||
"redFlags"
|
||||
)
|
||||
|
||||
val allowedRedFlags = listOf("reusedChainId")
|
||||
|
||||
val moshi: Moshi = Moshi.Builder().build()
|
||||
val chainAdapter: JsonAdapter<Chain> = moshi.adapter(Chain::class.java)
|
||||
|
||||
|
|
|
@ -272,6 +272,21 @@ fun checkChain(chainFile: File, connectRPC: Boolean) {
|
|||
throw StatusMustBeIncubatingActiveOrDeprecated()
|
||||
}
|
||||
}
|
||||
|
||||
jsonObject["redFlags"]?.let { redFlags ->
|
||||
if (redFlags !is List<*>) {
|
||||
throw RedFlagsMustBeArray()
|
||||
}
|
||||
redFlags.forEach {
|
||||
if (it !is String) {
|
||||
throw RedFlagMustBeString()
|
||||
}
|
||||
|
||||
if (!allowedRedFlags.contains(it))
|
||||
throw(InvalidRedFlags(it))
|
||||
}
|
||||
}
|
||||
|
||||
jsonObject["parent"]?.let {
|
||||
if (it !is JsonObject) {
|
||||
throw ParentMustBeObject()
|
||||
|
@ -286,6 +301,7 @@ fun checkChain(chainFile: File, connectRPC: Boolean) {
|
|||
throw ParentHasExtraFields(extraParentFields)
|
||||
}
|
||||
|
||||
|
||||
val bridges = it["bridges"]
|
||||
if (bridges != null && bridges !is List<*>) {
|
||||
throw ParentBridgeNoArray()
|
||||
|
|
|
@ -21,6 +21,9 @@ class ExplorerMustWithHttps: Exception("Explorer have url starting with https://
|
|||
class ExplorerCannotEndInSlash: Exception("Explorer cannot have a slash on the end")
|
||||
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")
|
||||
class RedFlagMustBeString: Exception("redFlag not an string")
|
||||
class InvalidRedFlags(flag: String): Exception("redFlags invalid $flag")
|
||||
class ParentMustBeObject: Exception("parent must be an object")
|
||||
class ParentMustHaveChainAndType: Exception("parent must have fields 'chain' and 'type'")
|
||||
class ParentHasExtraFields(fields: Set<String>): Exception("parent has extra field: $fields")
|
||||
|
|
|
@ -71,6 +71,21 @@ class TheChainChecker {
|
|||
checkChain(file, false)
|
||||
}
|
||||
|
||||
|
||||
@Test(expected = RedFlagsMustBeArray::class)
|
||||
fun shouldFailForInvalidRedFlagsNotArray() {
|
||||
val file = getFile("invalid/invalid_redFlags/eip155-2.json")
|
||||
|
||||
checkChain(file, false)
|
||||
}
|
||||
|
||||
@Test(expected = InvalidRedFlags::class)
|
||||
fun shouldFailForInvalidRedFlag() {
|
||||
val file = getFile("invalid/invalid_redFlags/eip155-3.json")
|
||||
|
||||
checkChain(file, false)
|
||||
}
|
||||
|
||||
@Test(expected = ParentHasExtraFields::class)
|
||||
fun shouldFailForParentWithExtraParentField() {
|
||||
val file = getFile("invalid/withparentextrafield/eip155-2.json")
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
{
|
||||
"name": "Ethereum Mainnet",
|
||||
"shortName": "eth",
|
||||
"chain": "ETH",
|
||||
"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
|
||||
},
|
||||
"redFlags": "yolo"
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
{
|
||||
"name": "Ethereum Mainnet",
|
||||
"shortName": "eth",
|
||||
"chain": "ETH",
|
||||
"chainId": 3,
|
||||
"networkId": 3,
|
||||
"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
|
||||
},
|
||||
"redFlags": ["yolo"]
|
||||
}
|
|
@ -20,6 +20,9 @@
|
|||
"chainId": 5,
|
||||
"networkId": 5,
|
||||
"ens": {
|
||||
"registry":"0x112234455c3a32fd11230c42e7bccd4a84e02010"
|
||||
}
|
||||
"registry": "0x112234455c3a32fd11230c42e7bccd4a84e02010"
|
||||
},
|
||||
"redFlags": [
|
||||
"reusedChainId"
|
||||
]
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user