mirror of
https://github.com/Instadapp/chains.git
synced 2024-07-29 22:37:19 +00:00
Fail CI on extra comma
This commit is contained in:
parent
0532b7cc3b
commit
87d90de9f4
|
@ -2,6 +2,9 @@ package org.ethereum.lists.chains
|
||||||
|
|
||||||
import com.beust.klaxon.JsonObject
|
import com.beust.klaxon.JsonObject
|
||||||
import com.beust.klaxon.Klaxon
|
import com.beust.klaxon.Klaxon
|
||||||
|
import com.squareup.moshi.Moshi
|
||||||
|
import com.squareup.moshi.kotlin.reflect.KotlinJsonAdapterFactory
|
||||||
|
import org.ethereum.lists.chains.model.Chain
|
||||||
import org.kethereum.erc55.isValid
|
import org.kethereum.erc55.isValid
|
||||||
import org.kethereum.model.Address
|
import org.kethereum.model.Address
|
||||||
import org.kethereum.rpc.HttpEthereumRPC
|
import org.kethereum.rpc.HttpEthereumRPC
|
||||||
|
@ -36,6 +39,9 @@ class ENSRegistryAddressMustBeValid: Exception("ens registry must have valid add
|
||||||
|
|
||||||
fun checkChain(it: File, connectRPC: Boolean) {
|
fun checkChain(it: File, connectRPC: Boolean) {
|
||||||
println("processing $it")
|
println("processing $it")
|
||||||
|
|
||||||
|
parseWithMoshi(it)
|
||||||
|
|
||||||
val jsonObject = Klaxon().parseJsonObject(it.reader())
|
val jsonObject = Klaxon().parseJsonObject(it.reader())
|
||||||
val chainAsLong = getNumber(jsonObject, "chainId")
|
val chainAsLong = getNumber(jsonObject, "chainId")
|
||||||
|
|
||||||
|
@ -93,6 +99,15 @@ fun checkChain(it: File, connectRPC: Boolean) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
moshi fails for extra commas
|
||||||
|
https://github.com/ethereum-lists/chains/issues/126
|
||||||
|
*/
|
||||||
|
private fun parseWithMoshi(fileToParse: File) {
|
||||||
|
val moshi = Moshi.Builder().add(KotlinJsonAdapterFactory()).build()
|
||||||
|
moshi.adapter(Chain::class.java).fromJson(fileToParse.readText())
|
||||||
|
}
|
||||||
|
|
||||||
private fun getNumber(jsonObject: JsonObject, field: String): Long {
|
private fun getNumber(jsonObject: JsonObject, field: String): Long {
|
||||||
return when (val chainId = jsonObject[field]) {
|
return when (val chainId = jsonObject[field]) {
|
||||||
is Int -> chainId.toLong()
|
is Int -> chainId.toLong()
|
||||||
|
|
13
src/main/kotlin/org/ethereum/lists/chains/model/Chain.kt
Normal file
13
src/main/kotlin/org/ethereum/lists/chains/model/Chain.kt
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
package org.ethereum.lists.chains.model
|
||||||
|
|
||||||
|
data class Chain(
|
||||||
|
val name: String,
|
||||||
|
val shortName: String,
|
||||||
|
val chain: String,
|
||||||
|
val network: String,
|
||||||
|
val chainId: Long,
|
||||||
|
val networkId: Long,
|
||||||
|
val rpc: List<String>,
|
||||||
|
val faucets: List<String>,
|
||||||
|
val infoURL: String,
|
||||||
|
)
|
|
@ -1,3 +1,4 @@
|
||||||
|
import com.squareup.moshi.JsonEncodingException
|
||||||
import org.ethereum.lists.chains.*
|
import org.ethereum.lists.chains.*
|
||||||
import org.junit.Test
|
import org.junit.Test
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
@ -69,12 +70,19 @@ class TheChainChecker {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = ExtensionMustBeJSON::class)
|
@Test(expected = ExtensionMustBeJSON::class)
|
||||||
fun shouldFailFoNonJSON() {
|
fun shouldFailForNonJSON() {
|
||||||
val file = getFile("invalid/1.nojson")
|
val file = getFile("invalid/1.nojson")
|
||||||
|
|
||||||
checkChain(file, false)
|
checkChain(file, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test(expected = JsonEncodingException::class)
|
||||||
|
fun shouldFailForExtraComma() {
|
||||||
|
val file = getFile("invalid/extracomma.json")
|
||||||
|
|
||||||
|
checkChain(file, false)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private fun getFile(s: String) = File(javaClass.classLoader.getResource("test_chains/$s").file)
|
private fun getFile(s: String) = File(javaClass.classLoader.getResource("test_chains/$s").file)
|
||||||
|
|
||||||
|
|
|
@ -9,5 +9,6 @@
|
||||||
"https://mainnet.infura.io/v3/${INFURA_API_KEY}",
|
"https://mainnet.infura.io/v3/${INFURA_API_KEY}",
|
||||||
"https://api.mycryptoapi.com/eth"
|
"https://api.mycryptoapi.com/eth"
|
||||||
],
|
],
|
||||||
"faucets": []
|
"faucets": [],
|
||||||
|
"infoURL": "https://ethereum.org"
|
||||||
}
|
}
|
||||||
|
|
14
src/test/resources/test_chains/invalid/extracomma.json
Normal file
14
src/test/resources/test_chains/invalid/extracomma.json
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
{
|
||||||
|
"name": "Ethereum Mainnet",
|
||||||
|
"shortName": "eth",
|
||||||
|
"chain": "ETH",
|
||||||
|
"network": "mainnet",
|
||||||
|
"chainId": 1,
|
||||||
|
"networkId": 1,
|
||||||
|
"rpc": [
|
||||||
|
"https://mainnet.infura.io/v3/${INFURA_API_KEY}",
|
||||||
|
"https://api.mycryptoapi.com/eth"
|
||||||
|
],
|
||||||
|
"faucets": [],
|
||||||
|
"infoURL": "https://ethereum.org",
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user