mirror of
				https://github.com/Instadapp/chains.git
				synced 2024-07-29 22:37:19 +00:00 
			
		
		
		
	Initial explorers support - closes #59
This commit is contained in:
		
							parent
							
								
									3f062564b0
								
							
						
					
					
						commit
						884838f5e3
					
				|  | @ -22,5 +22,10 @@ | |||
|   "slip44": 60, | ||||
|   "ens": { | ||||
|     "registry":"0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e" | ||||
|   } | ||||
|   }, | ||||
|   "explorers": [{ | ||||
|     "name": "etherscan", | ||||
|     "url": "https://etherscan.io", | ||||
|     "standard": "EIP3091" | ||||
|   }] | ||||
| } | ||||
|  |  | |||
|  | @ -20,7 +20,8 @@ val mandatory_fields = listOf( | |||
| val optionalFields = listOf( | ||||
|         "slip44", | ||||
|         "ens", | ||||
|         "icon" | ||||
|         "icon", | ||||
|         "explorers" | ||||
| ) | ||||
| 
 | ||||
| val moshi: Moshi = Moshi.Builder().add(KotlinJsonAdapterFactory()).build() | ||||
|  |  | |||
|  | @ -103,11 +103,35 @@ fun checkChain(chainFile: File, connectRPC: Boolean) { | |||
|     } | ||||
| 
 | ||||
|     jsonObject["icon"]?.let { | ||||
|         if (!File(iconsPath,"$it.json").exists()) { | ||||
|         if (!File(iconsPath, "$it.json").exists()) { | ||||
|             error("The Icon $it does not exist - was used in ${chainFile.name}") | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     jsonObject["explorers"]?.let { | ||||
|         if (it !is JsonArray<*>) { | ||||
|             throw (ExplorersMustBeArray()) | ||||
|         } | ||||
| 
 | ||||
|         it.forEach { explorer -> | ||||
|             if (explorer !is JsonObject) { | ||||
|                 error("explorer must be object") | ||||
|             } | ||||
| 
 | ||||
|             if (explorer["name"] == null) { | ||||
|                 throw(ExplorerMustHaveName()) | ||||
|             } | ||||
| 
 | ||||
|             val url = explorer["url"] | ||||
|             if (url == null || url !is String || !url.startsWith("https://")) { | ||||
|                 throw(ExplorerInvalidUrl()) | ||||
|             } | ||||
| 
 | ||||
|             if (explorer["standard"] != "EIP3091") { | ||||
|                 throw(ExplorerStandardMustBeEIP3091()) | ||||
|             } | ||||
|         } | ||||
|     } | ||||
|     jsonObject["ens"]?.let { | ||||
|         if (it !is JsonObject) { | ||||
|             throw ENSMustBeObject() | ||||
|  |  | |||
|  | @ -11,4 +11,8 @@ class ENSMustHaveOnlyRegistry: Exception("ens can only have a registry currently | |||
| class ENSRegistryAddressMustBeValid: Exception("ens registry must have valid address") | ||||
| class NameMustBeUnique(dup: String): Exception(" name must be unique - but found `$dup` more than once") | ||||
| class ShortNameMustBeUnique(dup: String): Exception("short name must be unique - but found `$dup` more than once") | ||||
| class UnsupportedNamespace(): Exception("So far only the EIP155 namespace is supported") | ||||
| class UnsupportedNamespace(): Exception("So far only the EIP155 namespace is supported") | ||||
| 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") | ||||
|  |  | |||
|  | @ -1,5 +1,6 @@ | |||
| package org.ethereum.lists.chains | ||||
| 
 | ||||
| import com.squareup.moshi.JsonEncodingException | ||||
| import org.ethereum.lists.chains.* | ||||
| import org.ethereum.lists.chains.model.* | ||||
| import org.junit.Before | ||||
| import org.junit.Test | ||||
|  | @ -20,6 +21,13 @@ class TheChainChecker { | |||
|         checkChain(file, false) | ||||
|     } | ||||
| 
 | ||||
|     @Test | ||||
|     fun shouldPassForValidChainWithExplorers() { | ||||
|         val file = getFile("valid/withexplorer/eip155-1.json") | ||||
| 
 | ||||
|         checkChain(file, false) | ||||
|     } | ||||
| 
 | ||||
|     @Test(expected = FileNameMustMatchChainId::class) | ||||
|     fun shouldFailForInvalidFilename() { | ||||
|         val file = getFile("invalid/eip155-invalid_filename.json") | ||||
|  | @ -103,6 +111,31 @@ class TheChainChecker { | |||
|         checkChain(getFile("invalid/sameshortname/eip155-1.json"), false) | ||||
|     } | ||||
| 
 | ||||
|     @Test(expected = ExplorersMustBeArray::class) | ||||
|     fun shouldFailWhenExplorerIsNotArray() { | ||||
|         checkChain(getFile("invalid/explorersnotarray/eip155-1.json"), false) | ||||
|     } | ||||
| 
 | ||||
|     @Test(expected = ExplorerStandardMustBeEIP3091::class) | ||||
|     fun shouldFailOnWrongExplorerStandard() { | ||||
|         checkChain(getFile("invalid/wrongexplorerstandard/eip155-1.json"), false) | ||||
|     } | ||||
| 
 | ||||
|     @Test(expected = ExplorerMustHaveName::class) | ||||
|     fun shouldFailOnNoExplorerName() { | ||||
|         checkChain(getFile("invalid/explorernoname/eip155-1.json"), false) | ||||
|     } | ||||
| 
 | ||||
|     @Test(expected = ExplorerInvalidUrl::class) | ||||
|     fun shouldFailOnInvalidUrl() { | ||||
|         checkChain(getFile("invalid/explorerinvalidurl/eip155-1.json"), false) | ||||
|     } | ||||
| 
 | ||||
|     @Test(expected = ExplorerInvalidUrl::class) | ||||
|     fun shouldFailOnMissingURL() { | ||||
|         checkChain(getFile("invalid/explorermissingurl/eip155-1.json"), false) | ||||
|     } | ||||
| 
 | ||||
|     @Test | ||||
|     fun canParse2chains() { | ||||
|         checkChain(getFile("valid/eip155-1.json"), false) | ||||
|  | @ -0,0 +1,24 @@ | |||
| { | ||||
|   "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 | ||||
|   }, | ||||
|   "explorers": [{ | ||||
|     "name": "yolo", | ||||
|     "url": "failme", | ||||
|     "standard": "EIP3091" | ||||
|   }] | ||||
| } | ||||
|  | @ -0,0 +1,23 @@ | |||
| { | ||||
|   "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 | ||||
|   }, | ||||
|   "explorers": [{ | ||||
|     "name": "yolo", | ||||
|     "standard": "EIP3091" | ||||
|   }] | ||||
| } | ||||
|  | @ -0,0 +1,23 @@ | |||
| { | ||||
|   "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 | ||||
|   }, | ||||
|   "explorers": [{ | ||||
|     "url": "https://etherscan.io", | ||||
|     "standard": "EIP3091" | ||||
|   }] | ||||
| } | ||||
|  | @ -0,0 +1,20 @@ | |||
| { | ||||
|   "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 | ||||
|   }, | ||||
|   "explorers": "should_fail" | ||||
| } | ||||
|  | @ -0,0 +1,24 @@ | |||
| { | ||||
|   "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 | ||||
|   }, | ||||
|   "explorers": [{ | ||||
|     "name": "etherscan", | ||||
|     "url": "https://etherscan.io", | ||||
|     "standard": "failme" | ||||
|   }] | ||||
| } | ||||
|  | @ -0,0 +1,26 @@ | |||
| { | ||||
|   "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 | ||||
|   }, | ||||
|   "explorers": [ | ||||
|     { | ||||
|       "name": "etherscan", | ||||
|       "url": "https://etherscan.io", | ||||
|       "standard": "EIP3091" | ||||
|     } | ||||
|   ] | ||||
| } | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user
	 ligi
						ligi