Test to cover this case (#1833)

* Test to cover this case

* Fail in case of leading zero(es)
This commit is contained in:
ligi 2022-11-05 20:33:05 +01:00 committed by GitHub
parent 43886b87eb
commit 3418667a05
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 34 additions and 4 deletions

View File

@ -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<String>) {
@ -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))
}
}

View File

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

View File

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