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 ec670710..14018ab1 100644 --- a/processor/src/main/kotlin/org/ethereum/lists/chains/Main.kt +++ b/processor/src/main/kotlin/org/ethereum/lists/chains/Main.kt @@ -22,7 +22,7 @@ val chainsPath = File(dataPath, "chains") private val allFiles = chainsPath.listFiles() ?: error("${chainsPath.absolutePath} must contain the chain json files - but it does not") private val allChainFiles = allFiles.filter { !it.isDirectory } -private val allIconFilesList = iconsPath.listFiles() ?: error("${iconsPath.absolutePath} must contain the icon json files - but it does not") +private val allIconFilesList = iconsPath.listFiles() ?: error("${iconsPath.absolutePath} must contain the icon json files - but it does not") private val allIconFiles = allIconFilesList.filter { !it.isDirectory } fun main(args: Array) { @@ -69,7 +69,7 @@ private fun createOutputFiles() { .forEach { iconLocation -> val jsonData = Klaxon().parseJsonArray(iconLocation.reader()) - val iconName = iconLocation.toString().replace("../_data/icons/","").replace(".json","") + val iconName = iconLocation.toString().replace("../_data/icons/", "").replace(".json", "") val iconJson = JsonObject() iconJson["name"] = iconName @@ -202,7 +202,7 @@ fun checkChain(chainFile: File, connectRPC: Boolean, verbose: Boolean = false) { val chainAsLong = getNumber(jsonObject, "chainId") if (chainFile.nameWithoutExtension.startsWith("eip155-")) { - if (chainAsLong != chainFile.nameWithoutExtension.replace("eip155-", "").toLongOrNull()) { + if (chainAsLong.toString() != chainFile.nameWithoutExtension.replace("eip155-", "")) { throw (FileNameMustMatchChainId()) } } else { @@ -314,7 +314,7 @@ fun checkChain(chainFile: File, connectRPC: Boolean, verbose: Boolean = false) { } if (!allowedRedFlags.contains(it)) - throw(InvalidRedFlags(it)) + throw (InvalidRedFlags(it)) } } 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 100c1538..58302dab 100644 --- a/processor/src/test/kotlin/org/ethereum/lists/chains/TheChainChecker.kt +++ b/processor/src/test/kotlin/org/ethereum/lists/chains/TheChainChecker.kt @@ -128,6 +128,13 @@ class TheChainChecker { checkChain(file, false) } + @Test(expected = FileNameMustMatchChainId::class) + fun shouldFailForFilenameWithLeadingZero() { + val file = getFile("invalid/leadingzero/eip155-01.json") + + checkChain(file, false) + } + @Test(expected = FileNameMustMatchChainId::class) fun shouldFailForChainNotMatchingFilename() { val file = getFile("invalid/eip155-3.json") diff --git a/processor/src/test/resources/test_chains/invalid/leadingzero/eip155-01.json b/processor/src/test/resources/test_chains/invalid/leadingzero/eip155-01.json new file mode 100644 index 00000000..63a38df4 --- /dev/null +++ b/processor/src/test/resources/test_chains/invalid/leadingzero/eip155-01.json @@ -0,0 +1,23 @@ +{ + "name": "Ethereum Mainnet", + "shortName": "eth", + "chain": "ETH", + "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": [{ + "name": "etherscan", + "url": "https://etherscan.io", + "standard": "none" + }] +} \ No newline at end of file