diff --git a/processor/src/main/kotlin/org/ethereum/lists/chains/Env.kt b/processor/src/main/kotlin/org/ethereum/lists/chains/Env.kt index b84b67cd..49f3c64a 100644 --- a/processor/src/main/kotlin/org/ethereum/lists/chains/Env.kt +++ b/processor/src/main/kotlin/org/ethereum/lists/chains/Env.kt @@ -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 = moshi.adapter(Chain::class.java) 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 82c83d9e..fee03aaa 100644 --- a/processor/src/main/kotlin/org/ethereum/lists/chains/Main.kt +++ b/processor/src/main/kotlin/org/ethereum/lists/chains/Main.kt @@ -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() 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 f8503500..839c8d2b 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 @@ -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): Exception("parent has extra field: $fields") diff --git a/processor/src/test/kotlin/org/ethereum/lists/chains/TheChainChecker.kt b/processor/src/test/kotlin/org/ethereum/lists/chains/TheChainChecker.kt index 6ab8ea30..e87b2f75 100644 --- a/processor/src/test/kotlin/org/ethereum/lists/chains/TheChainChecker.kt +++ b/processor/src/test/kotlin/org/ethereum/lists/chains/TheChainChecker.kt @@ -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") diff --git a/processor/src/test/resources/test_chains/invalid/invalid_redFlags/eip155-2.json b/processor/src/test/resources/test_chains/invalid/invalid_redFlags/eip155-2.json new file mode 100644 index 00000000..b2e327d6 --- /dev/null +++ b/processor/src/test/resources/test_chains/invalid/invalid_redFlags/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" +} diff --git a/processor/src/test/resources/test_chains/invalid/invalid_redFlags/eip155-3.json b/processor/src/test/resources/test_chains/invalid/invalid_redFlags/eip155-3.json new file mode 100644 index 00000000..b1c3ff86 --- /dev/null +++ b/processor/src/test/resources/test_chains/invalid/invalid_redFlags/eip155-3.json @@ -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"] +} 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 15387bf6..2ea2fbd5 100644 --- a/processor/src/test/resources/test_chains/valid/eip155-5.json +++ b/processor/src/test/resources/test_chains/valid/eip155-5.json @@ -20,6 +20,9 @@ "chainId": 5, "networkId": 5, "ens": { - "registry":"0x112234455c3a32fd11230c42e7bccd4a84e02010" - } + "registry": "0x112234455c3a32fd11230c42e7bccd4a84e02010" + }, + "redFlags": [ + "reusedChainId" + ] }