mirror of
https://github.com/Instadapp/chains.git
synced 2024-07-29 22:37:19 +00:00
Support parent field - closes #318
This commit is contained in:
parent
3f5ca6dbf0
commit
c8477c7410
|
@ -21,7 +21,8 @@ val optionalFields = listOf(
|
|||
"slip44",
|
||||
"ens",
|
||||
"icon",
|
||||
"explorers"
|
||||
"explorers",
|
||||
"parent"
|
||||
)
|
||||
|
||||
val moshi: Moshi = Moshi.Builder().add(KotlinJsonAdapterFactory()).build()
|
||||
|
|
|
@ -8,6 +8,7 @@ import org.ethereum.lists.chains.model.*
|
|||
import org.kethereum.erc55.isValid
|
||||
import org.kethereum.model.Address
|
||||
import org.kethereum.rpc.HttpEthereumRPC
|
||||
import java.lang.IllegalArgumentException
|
||||
|
||||
val parsedShortNames = mutableSetOf<String>()
|
||||
val parsedNames = mutableSetOf<String>()
|
||||
|
@ -207,6 +208,25 @@ fun checkChain(chainFile: File, connectRPC: Boolean) {
|
|||
}
|
||||
}
|
||||
|
||||
jsonObject["parent"]?.let {
|
||||
if (it !is JsonObject) {
|
||||
throw ParentMustBeObject()
|
||||
}
|
||||
|
||||
if (it.keys != mutableSetOf("chain", "type")) {
|
||||
throw ParentMustHaveChainAndType()
|
||||
}
|
||||
|
||||
if (!setOf("L2", "shard").contains(it["type"])) {
|
||||
throw ParentHasInvalidType(it["type"] as? String)
|
||||
}
|
||||
|
||||
if (!File(chainFile.parentFile, it["chain"] as String + ".json").exists()) {
|
||||
throw ParentChainDoesNotExist(it["chain"] as String)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (connectRPC) {
|
||||
if (jsonObject["rpc"] is List<*>) {
|
||||
(jsonObject["rpc"] as List<*>).forEach {
|
||||
|
|
|
@ -16,3 +16,7 @@ class ExplorersMustBeArray: Exception("explorers must be an array")
|
|||
class ExplorerMustHaveName: Exception("Explorer must have name")
|
||||
class ExplorerInvalidUrl: Exception("Explorer have url starting with https://")
|
||||
class ExplorerStandardMustBeEIP3091: Exception("explorer standard must be EIP3091 - currently the only one supported")
|
||||
class ParentHasInvalidType(type: String?): Exception("Parent has invalid type $type - only L2 or shard allowed")
|
||||
class ParentMustBeObject: Exception("parent must be an object")
|
||||
class ParentMustHaveChainAndType: Exception("parent must have fields 'chain' and 'type'")
|
||||
class ParentChainDoesNotExist(chain: String): Exception("Referenced parent chain ($chain) does not exist")
|
|
@ -28,6 +28,35 @@ class TheChainChecker {
|
|||
checkChain(file, false)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun shouldPassForValidChainWithParent() {
|
||||
val file = getFile("valid/withparent/eip155-2.json")
|
||||
|
||||
checkChain(file, false)
|
||||
}
|
||||
|
||||
@Test(expected = ParentMustBeObject::class)
|
||||
fun shouldFailForParentNoObject() {
|
||||
val file = getFile("invalid/withparentnobject/eip155-2.json")
|
||||
|
||||
checkChain(file, false)
|
||||
}
|
||||
|
||||
@Test(expected = ParentHasInvalidType::class)
|
||||
fun shouldFailForParentWithInvalidType() {
|
||||
val file = getFile("invalid/withparentinvalidtype/eip155-2.json")
|
||||
|
||||
checkChain(file, false)
|
||||
}
|
||||
|
||||
|
||||
@Test(expected = ParentChainDoesNotExist::class)
|
||||
fun shouldFailIfParentChainDoesNotExist() {
|
||||
val file = getFile("invalid/withparentchaindoesnotexist/eip155-2.json")
|
||||
|
||||
checkChain(file, false)
|
||||
}
|
||||
|
||||
@Test(expected = FileNameMustMatchChainId::class)
|
||||
fun shouldFailForInvalidFilename() {
|
||||
val file = getFile("invalid/eip155-invalid_filename.json")
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
{
|
||||
"name": "Ethereum Mainnet",
|
||||
"shortName": "eth",
|
||||
"chain": "ETH",
|
||||
"network": "mainnet",
|
||||
"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
|
||||
},
|
||||
"parent": {
|
||||
"chain": "eip155-1",
|
||||
"type": "L2"
|
||||
}
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
{
|
||||
"name": "Ethereum Mainnet",
|
||||
"shortName": "eth",
|
||||
"chain": "ETH",
|
||||
"network": "mainnet",
|
||||
"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
|
||||
},
|
||||
"parent": {
|
||||
"chain": "eip155-1",
|
||||
"type": "yolo"
|
||||
}
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
{
|
||||
"name": "Ethereum Mainnet",
|
||||
"shortName": "eth",
|
||||
"chain": "ETH",
|
||||
"network": "mainnet",
|
||||
"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
|
||||
},
|
||||
"parent": "yolo"
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
{
|
||||
"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",
|
||||
"nativeCurrency": {
|
||||
"name": "Ether",
|
||||
"symbol": "ETH",
|
||||
"decimals": 18
|
||||
}
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
{
|
||||
"name": "Ethereum Mainnet",
|
||||
"shortName": "eth",
|
||||
"chain": "ETH",
|
||||
"network": "mainnet",
|
||||
"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
|
||||
},
|
||||
"parent": {
|
||||
"chain": "eip155-1",
|
||||
"type": "L2"
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user