Support redFlags - context #1499 (#1511)

This commit is contained in:
ligi 2022-08-28 15:12:35 +02:00 committed by GitHub
parent bf8ce68096
commit 02a3e91b01
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 81 additions and 3 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -20,6 +20,9 @@
"chainId": 5,
"networkId": 5,
"ens": {
"registry":"0x112234455c3a32fd11230c42e7bccd4a84e02010"
}
"registry": "0x112234455c3a32fd11230c42e7bccd4a84e02010"
},
"redFlags": [
"reusedChainId"
]
}