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

@ -202,7 +202,7 @@ fun checkChain(chainFile: File, connectRPC: Boolean, verbose: Boolean = false) {
val chainAsLong = getNumber(jsonObject, "chainId") val chainAsLong = getNumber(jsonObject, "chainId")
if (chainFile.nameWithoutExtension.startsWith("eip155-")) { if (chainFile.nameWithoutExtension.startsWith("eip155-")) {
if (chainAsLong != chainFile.nameWithoutExtension.replace("eip155-", "").toLongOrNull()) { if (chainAsLong.toString() != chainFile.nameWithoutExtension.replace("eip155-", "")) {
throw (FileNameMustMatchChainId()) throw (FileNameMustMatchChainId())
} }
} else { } else {

View File

@ -128,6 +128,13 @@ class TheChainChecker {
checkChain(file, false) checkChain(file, false)
} }
@Test(expected = FileNameMustMatchChainId::class)
fun shouldFailForFilenameWithLeadingZero() {
val file = getFile("invalid/leadingzero/eip155-01.json")
checkChain(file, false)
}
@Test(expected = FileNameMustMatchChainId::class) @Test(expected = FileNameMustMatchChainId::class)
fun shouldFailForChainNotMatchingFilename() { fun shouldFailForChainNotMatchingFilename() {
val file = getFile("invalid/eip155-3.json") 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"
}]
}