The home for Hyperlane core contracts, sdk packages, and other infrastructure
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
hyperlane-monorepo/rust/hyperlane-core/src/chain.rs

401 lines
10 KiB

#![allow(missing_docs)]
use std::fmt::{Debug, Display, Formatter};
use std::hash::{Hash, Hasher};
use num_derive::FromPrimitive;
use num_traits::FromPrimitive;
use strum::{EnumIter, EnumString, IntoStaticStr};
use crate::utils::many_to_one;
use crate::{ChainResult, HyperlaneProtocolError, H160, H256};
#[derive(Debug, Clone)]
pub struct Address(pub bytes::Bytes);
#[derive(Debug, Clone)]
pub struct Balance(pub num::BigInt);
#[derive(Debug, Clone)]
Better Agent Configuration Parsing (#2070) ### Description This is a significant change to how we parse user configs. The main goal of this PR is to give a clear path and env key to any errors that are encountered when parsing configuration. In order to accomplish this, I have crated a new trait `FromRawConf` which defines a set of steps to validate and convert individual fields. Also for every major config struct, there is now a `Raw*` variant of it which is used by the `config` library to reduce errors that occur during deserialization itself. `Raw*` types should always use the most basic form of a value, such as `String`, `StrOrInt`, `bool`, and ideally optional in all cases. Missing values should be handled during the raw conversion and not by `config`. I also needed to make changes to a number of types stored in the parsed config types to force validation forward to the parsing step instead of doing it when we read the config value. This also required me to create a filter to prevent trying to validate certain configs that we would not ever need to load. These changes can also be built on later to support something other than `config` if we choose to, or add support for merging configs from multiple sources since everything is optional. ### Drive-by changes - Default to `http` for connection type - Default to no gas payment enforcement if not specified instead of failing - `ChainSetup` -> `ChainConf` - `GasPaymentEnforcementConfig` -> `GasPaymentEnforcementConf` - Made ethereum connection configuration more forgiving - Moved hyperlane base settings from `mod.rs` to `base.rs` - Moved config chain tests in hyperlane core to `tests` dir to fix a cyclical import problem - Extension traits to help with config in hyperlane core - Moved `StrOrInt` to new hyperlane core `config` module - Support for parsing `U256` from `StrOrInt` - Removed `HexString` type which is now redundant - Updated base settings to use hyperlane domain - Use `heyKey` as signer type if `type` is not specified and `key` is - Moved hyperlane ethereum chain config to a new module ### Related issues - Fixes #2033 - Fixes #2012 ### Backward compatibility _Are these changes backward compatible?_ Yes - This should take in configs in the same shape but be more forgiving in a few places _Are there any infrastructure implications, e.g. changes that would prohibit deploying older commits using this infra tooling?_ None ### Testing _What kind of testing have these changes undergone?_ Manual Unit Test
2 years ago
pub struct ContractLocator<'a> {
pub domain: &'a HyperlaneDomain,
pub address: H256,
}
Better Agent Configuration Parsing (#2070) ### Description This is a significant change to how we parse user configs. The main goal of this PR is to give a clear path and env key to any errors that are encountered when parsing configuration. In order to accomplish this, I have crated a new trait `FromRawConf` which defines a set of steps to validate and convert individual fields. Also for every major config struct, there is now a `Raw*` variant of it which is used by the `config` library to reduce errors that occur during deserialization itself. `Raw*` types should always use the most basic form of a value, such as `String`, `StrOrInt`, `bool`, and ideally optional in all cases. Missing values should be handled during the raw conversion and not by `config`. I also needed to make changes to a number of types stored in the parsed config types to force validation forward to the parsing step instead of doing it when we read the config value. This also required me to create a filter to prevent trying to validate certain configs that we would not ever need to load. These changes can also be built on later to support something other than `config` if we choose to, or add support for merging configs from multiple sources since everything is optional. ### Drive-by changes - Default to `http` for connection type - Default to no gas payment enforcement if not specified instead of failing - `ChainSetup` -> `ChainConf` - `GasPaymentEnforcementConfig` -> `GasPaymentEnforcementConf` - Made ethereum connection configuration more forgiving - Moved hyperlane base settings from `mod.rs` to `base.rs` - Moved config chain tests in hyperlane core to `tests` dir to fix a cyclical import problem - Extension traits to help with config in hyperlane core - Moved `StrOrInt` to new hyperlane core `config` module - Support for parsing `U256` from `StrOrInt` - Removed `HexString` type which is now redundant - Updated base settings to use hyperlane domain - Use `heyKey` as signer type if `type` is not specified and `key` is - Moved hyperlane ethereum chain config to a new module ### Related issues - Fixes #2033 - Fixes #2012 ### Backward compatibility _Are these changes backward compatible?_ Yes - This should take in configs in the same shape but be more forgiving in a few places _Are there any infrastructure implications, e.g. changes that would prohibit deploying older commits using this infra tooling?_ None ### Testing _What kind of testing have these changes undergone?_ Manual Unit Test
2 years ago
impl<'a> Display for ContractLocator<'a> {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(
f,
"{}[@{}]+contract:0x{:x}",
self.domain.name(),
self.domain.id(),
self.address
)
}
}
#[async_trait::async_trait]
pub trait Chain {
/// Query the balance on a chain
async fn query_balance(&self, addr: Address) -> ChainResult<Balance>;
}
impl From<Address> for H160 {
fn from(addr: Address) -> Self {
H160::from_slice(addr.0.as_ref())
}
}
impl From<H160> for Address {
fn from(addr: H160) -> Self {
Address(addr.as_bytes().to_owned().into())
}
}
impl From<&'_ Address> for H160 {
fn from(addr: &Address) -> Self {
H160::from_slice(addr.0.as_ref())
}
}
/// All domains supported by Hyperlane.
#[derive(
FromPrimitive,
EnumString,
IntoStaticStr,
strum::Display,
EnumIter,
PartialEq,
Eq,
Debug,
Clone,
Copy,
Hash,
)]
#[strum(serialize_all = "lowercase", ascii_case_insensitive)]
pub enum KnownHyperlaneDomain {
Ethereum = 1,
Goerli = 5,
Sepolia = 11155111,
Polygon = 137,
Mumbai = 80001,
Avalanche = 43114,
Fuji = 43113,
Arbitrum = 42161,
ArbitrumGoerli = 421613,
Optimism = 10,
OptimismGoerli = 420,
#[strum(serialize = "bsc")]
BinanceSmartChain = 56,
#[strum(serialize = "bsctestnet")]
BinanceSmartChainTestnet = 97,
Celo = 42220,
Alfajores = 44787,
Moonbeam = 1284,
MoonbaseAlpha = 1287,
Gnosis = 100,
Zksync2Testnet = 280,
// -- Local test chains --
/// Test1 local chain
Test1 = 13371,
/// Test2 local chain
Test2 = 13372,
/// Test3 local chain
Test3 = 13373,
/// Fuel1 local chain
FuelTest1 = 13374,
}
#[derive(Clone)]
pub enum HyperlaneDomain {
Known(KnownHyperlaneDomain),
Unknown {
domain_id: u32,
chain_name: String,
domain_type: HyperlaneDomainType,
domain_protocol: HyperlaneDomainProtocol,
},
}
impl HyperlaneDomain {
pub fn is_arbitrum_nitro(&self) -> bool {
matches!(
self,
HyperlaneDomain::Known(
KnownHyperlaneDomain::Arbitrum | KnownHyperlaneDomain::ArbitrumGoerli,
)
)
}
}
/// Types of Hyperlane domains.
#[derive(
FromPrimitive, EnumString, IntoStaticStr, strum::Display, Copy, Clone, Eq, PartialEq, Debug,
)]
#[strum(serialize_all = "lowercase", ascii_case_insensitive)]
pub enum HyperlaneDomainType {
/// A mainnet.
Mainnet,
/// A testnet.
Testnet,
/// A local chain for testing (i.e. Hardhat node).
LocalTestChain,
/// User provided chain of an unknown domain type.
Unknown,
}
/// A selector for which base library should handle this domain.
#[derive(
FromPrimitive, EnumString, IntoStaticStr, strum::Display, Copy, Clone, Eq, PartialEq, Debug,
)]
#[strum(serialize_all = "lowercase", ascii_case_insensitive)]
pub enum HyperlaneDomainProtocol {
/// An EVM-based chain type which uses hyperlane-ethereum.
Ethereum,
/// A Fuel-based chain type which uses hyperlane-fuel.
Fuel,
}
impl HyperlaneDomainProtocol {
pub fn fmt_address(&self, addr: H256) -> String {
use HyperlaneDomainProtocol::*;
match self {
Ethereum => format!("{:?}", H160::from(addr)),
Fuel => format!("{:?}", addr),
}
}
}
impl KnownHyperlaneDomain {
pub fn as_str(self) -> &'static str {
self.into()
}
pub const fn domain_type(self) -> HyperlaneDomainType {
use self::{HyperlaneDomainType::*, KnownHyperlaneDomain::*};
many_to_one!(match self {
Mainnet: [
Ethereum, Avalanche, Arbitrum, Polygon, Optimism, BinanceSmartChain, Celo,
Moonbeam,
Gnosis
],
Testnet: [
Goerli, Mumbai, Fuji, ArbitrumGoerli, OptimismGoerli, BinanceSmartChainTestnet,
Alfajores, MoonbaseAlpha, Zksync2Testnet, Sepolia
],
LocalTestChain: [Test1, Test2, Test3, FuelTest1],
})
}
pub const fn domain_protocol(self) -> HyperlaneDomainProtocol {
use KnownHyperlaneDomain::*;
many_to_one!(match self {
HyperlaneDomainProtocol::Ethereum: [
Ethereum, Goerli, Sepolia, Polygon, Mumbai, Avalanche, Fuji, Arbitrum, ArbitrumGoerli,
Optimism, OptimismGoerli, BinanceSmartChain, BinanceSmartChainTestnet, Celo, Gnosis,
Alfajores, Moonbeam, MoonbaseAlpha, Zksync2Testnet, Test1, Test2, Test3
],
HyperlaneDomainProtocol::Fuel: [FuelTest1],
})
}
}
impl PartialEq<Self> for HyperlaneDomain {
fn eq(&self, other: &Self) -> bool {
self.id() == other.id()
}
}
impl Eq for HyperlaneDomain {}
impl Hash for HyperlaneDomain {
fn hash<H: Hasher>(&self, state: &mut H) {
self.id().hash(state)
}
}
impl AsRef<str> for HyperlaneDomain {
fn as_ref(&self) -> &str {
self.name()
}
}
impl From<&HyperlaneDomain> for u32 {
fn from(domain: &HyperlaneDomain) -> Self {
domain.id()
}
}
impl TryFrom<u32> for KnownHyperlaneDomain {
type Error = HyperlaneProtocolError;
fn try_from(domain_id: u32) -> Result<Self, Self::Error> {
FromPrimitive::from_u32(domain_id).ok_or(HyperlaneProtocolError::UnknownDomainId(domain_id))
}
}
impl From<&HyperlaneDomain> for HyperlaneDomainType {
fn from(d: &HyperlaneDomain) -> Self {
d.domain_type()
}
}
impl From<&HyperlaneDomain> for HyperlaneDomainProtocol {
fn from(d: &HyperlaneDomain) -> Self {
d.domain_protocol()
}
}
impl Display for HyperlaneDomain {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self.name())
}
}
impl Debug for HyperlaneDomain {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(f, "HyperlaneDomain({} ({}))", self.name(), self.id())
}
}
Better Agent Configuration Parsing (#2070) ### Description This is a significant change to how we parse user configs. The main goal of this PR is to give a clear path and env key to any errors that are encountered when parsing configuration. In order to accomplish this, I have crated a new trait `FromRawConf` which defines a set of steps to validate and convert individual fields. Also for every major config struct, there is now a `Raw*` variant of it which is used by the `config` library to reduce errors that occur during deserialization itself. `Raw*` types should always use the most basic form of a value, such as `String`, `StrOrInt`, `bool`, and ideally optional in all cases. Missing values should be handled during the raw conversion and not by `config`. I also needed to make changes to a number of types stored in the parsed config types to force validation forward to the parsing step instead of doing it when we read the config value. This also required me to create a filter to prevent trying to validate certain configs that we would not ever need to load. These changes can also be built on later to support something other than `config` if we choose to, or add support for merging configs from multiple sources since everything is optional. ### Drive-by changes - Default to `http` for connection type - Default to no gas payment enforcement if not specified instead of failing - `ChainSetup` -> `ChainConf` - `GasPaymentEnforcementConfig` -> `GasPaymentEnforcementConf` - Made ethereum connection configuration more forgiving - Moved hyperlane base settings from `mod.rs` to `base.rs` - Moved config chain tests in hyperlane core to `tests` dir to fix a cyclical import problem - Extension traits to help with config in hyperlane core - Moved `StrOrInt` to new hyperlane core `config` module - Support for parsing `U256` from `StrOrInt` - Removed `HexString` type which is now redundant - Updated base settings to use hyperlane domain - Use `heyKey` as signer type if `type` is not specified and `key` is - Moved hyperlane ethereum chain config to a new module ### Related issues - Fixes #2033 - Fixes #2012 ### Backward compatibility _Are these changes backward compatible?_ Yes - This should take in configs in the same shape but be more forgiving in a few places _Are there any infrastructure implications, e.g. changes that would prohibit deploying older commits using this infra tooling?_ None ### Testing _What kind of testing have these changes undergone?_ Manual Unit Test
2 years ago
#[derive(thiserror::Error, Debug)]
pub enum HyperlaneDomainConfigError {
#[error("Domain name (`{0}`) does not match the name of a known domain id; the name is probably misspelled.")]
UnknownDomainName(String),
#[error("The domain name (`{0}`) implies a different domain than the domain id provided; the domain id ({1}) is probably wrong.")]
DomainNameMismatch(String, u32),
}
impl HyperlaneDomain {
pub fn from_config(
domain_id: u32,
name: &str,
protocol: HyperlaneDomainProtocol,
Better Agent Configuration Parsing (#2070) ### Description This is a significant change to how we parse user configs. The main goal of this PR is to give a clear path and env key to any errors that are encountered when parsing configuration. In order to accomplish this, I have crated a new trait `FromRawConf` which defines a set of steps to validate and convert individual fields. Also for every major config struct, there is now a `Raw*` variant of it which is used by the `config` library to reduce errors that occur during deserialization itself. `Raw*` types should always use the most basic form of a value, such as `String`, `StrOrInt`, `bool`, and ideally optional in all cases. Missing values should be handled during the raw conversion and not by `config`. I also needed to make changes to a number of types stored in the parsed config types to force validation forward to the parsing step instead of doing it when we read the config value. This also required me to create a filter to prevent trying to validate certain configs that we would not ever need to load. These changes can also be built on later to support something other than `config` if we choose to, or add support for merging configs from multiple sources since everything is optional. ### Drive-by changes - Default to `http` for connection type - Default to no gas payment enforcement if not specified instead of failing - `ChainSetup` -> `ChainConf` - `GasPaymentEnforcementConfig` -> `GasPaymentEnforcementConf` - Made ethereum connection configuration more forgiving - Moved hyperlane base settings from `mod.rs` to `base.rs` - Moved config chain tests in hyperlane core to `tests` dir to fix a cyclical import problem - Extension traits to help with config in hyperlane core - Moved `StrOrInt` to new hyperlane core `config` module - Support for parsing `U256` from `StrOrInt` - Removed `HexString` type which is now redundant - Updated base settings to use hyperlane domain - Use `heyKey` as signer type if `type` is not specified and `key` is - Moved hyperlane ethereum chain config to a new module ### Related issues - Fixes #2033 - Fixes #2012 ### Backward compatibility _Are these changes backward compatible?_ Yes - This should take in configs in the same shape but be more forgiving in a few places _Are there any infrastructure implications, e.g. changes that would prohibit deploying older commits using this infra tooling?_ None ### Testing _What kind of testing have these changes undergone?_ Manual Unit Test
2 years ago
) -> Result<Self, HyperlaneDomainConfigError> {
let name = name.to_ascii_lowercase();
if let Ok(domain) = KnownHyperlaneDomain::try_from(domain_id) {
if name == domain.as_str() {
Ok(HyperlaneDomain::Known(domain))
} else {
Better Agent Configuration Parsing (#2070) ### Description This is a significant change to how we parse user configs. The main goal of this PR is to give a clear path and env key to any errors that are encountered when parsing configuration. In order to accomplish this, I have crated a new trait `FromRawConf` which defines a set of steps to validate and convert individual fields. Also for every major config struct, there is now a `Raw*` variant of it which is used by the `config` library to reduce errors that occur during deserialization itself. `Raw*` types should always use the most basic form of a value, such as `String`, `StrOrInt`, `bool`, and ideally optional in all cases. Missing values should be handled during the raw conversion and not by `config`. I also needed to make changes to a number of types stored in the parsed config types to force validation forward to the parsing step instead of doing it when we read the config value. This also required me to create a filter to prevent trying to validate certain configs that we would not ever need to load. These changes can also be built on later to support something other than `config` if we choose to, or add support for merging configs from multiple sources since everything is optional. ### Drive-by changes - Default to `http` for connection type - Default to no gas payment enforcement if not specified instead of failing - `ChainSetup` -> `ChainConf` - `GasPaymentEnforcementConfig` -> `GasPaymentEnforcementConf` - Made ethereum connection configuration more forgiving - Moved hyperlane base settings from `mod.rs` to `base.rs` - Moved config chain tests in hyperlane core to `tests` dir to fix a cyclical import problem - Extension traits to help with config in hyperlane core - Moved `StrOrInt` to new hyperlane core `config` module - Support for parsing `U256` from `StrOrInt` - Removed `HexString` type which is now redundant - Updated base settings to use hyperlane domain - Use `heyKey` as signer type if `type` is not specified and `key` is - Moved hyperlane ethereum chain config to a new module ### Related issues - Fixes #2033 - Fixes #2012 ### Backward compatibility _Are these changes backward compatible?_ Yes - This should take in configs in the same shape but be more forgiving in a few places _Are there any infrastructure implications, e.g. changes that would prohibit deploying older commits using this infra tooling?_ None ### Testing _What kind of testing have these changes undergone?_ Manual Unit Test
2 years ago
Err(HyperlaneDomainConfigError::UnknownDomainName(name))
}
} else if name.as_str().parse::<KnownHyperlaneDomain>().is_ok() {
Better Agent Configuration Parsing (#2070) ### Description This is a significant change to how we parse user configs. The main goal of this PR is to give a clear path and env key to any errors that are encountered when parsing configuration. In order to accomplish this, I have crated a new trait `FromRawConf` which defines a set of steps to validate and convert individual fields. Also for every major config struct, there is now a `Raw*` variant of it which is used by the `config` library to reduce errors that occur during deserialization itself. `Raw*` types should always use the most basic form of a value, such as `String`, `StrOrInt`, `bool`, and ideally optional in all cases. Missing values should be handled during the raw conversion and not by `config`. I also needed to make changes to a number of types stored in the parsed config types to force validation forward to the parsing step instead of doing it when we read the config value. This also required me to create a filter to prevent trying to validate certain configs that we would not ever need to load. These changes can also be built on later to support something other than `config` if we choose to, or add support for merging configs from multiple sources since everything is optional. ### Drive-by changes - Default to `http` for connection type - Default to no gas payment enforcement if not specified instead of failing - `ChainSetup` -> `ChainConf` - `GasPaymentEnforcementConfig` -> `GasPaymentEnforcementConf` - Made ethereum connection configuration more forgiving - Moved hyperlane base settings from `mod.rs` to `base.rs` - Moved config chain tests in hyperlane core to `tests` dir to fix a cyclical import problem - Extension traits to help with config in hyperlane core - Moved `StrOrInt` to new hyperlane core `config` module - Support for parsing `U256` from `StrOrInt` - Removed `HexString` type which is now redundant - Updated base settings to use hyperlane domain - Use `heyKey` as signer type if `type` is not specified and `key` is - Moved hyperlane ethereum chain config to a new module ### Related issues - Fixes #2033 - Fixes #2012 ### Backward compatibility _Are these changes backward compatible?_ Yes - This should take in configs in the same shape but be more forgiving in a few places _Are there any infrastructure implications, e.g. changes that would prohibit deploying older commits using this infra tooling?_ None ### Testing _What kind of testing have these changes undergone?_ Manual Unit Test
2 years ago
Err(HyperlaneDomainConfigError::DomainNameMismatch(
name, domain_id,
))
} else {
Ok(HyperlaneDomain::Unknown {
domain_id,
chain_name: name,
// we might want to support accepting these from the config later
domain_type: HyperlaneDomainType::Unknown,
domain_protocol: protocol,
})
}
}
/// The chain name
pub fn name(&self) -> &str {
match self {
HyperlaneDomain::Known(domain) => domain.as_str(),
HyperlaneDomain::Unknown { chain_name, .. } => chain_name.as_str(),
}
}
/// The domain id
pub const fn id(&self) -> u32 {
match self {
HyperlaneDomain::Known(domain) => *domain as u32,
HyperlaneDomain::Unknown { domain_id, .. } => *domain_id,
}
}
/// Type of domain this is
pub const fn domain_type(&self) -> HyperlaneDomainType {
match self {
HyperlaneDomain::Known(domain) => domain.domain_type(),
HyperlaneDomain::Unknown { domain_type, .. } => *domain_type,
}
}
/// Backend implementation for this domain
pub const fn domain_protocol(&self) -> HyperlaneDomainProtocol {
match self {
HyperlaneDomain::Known(domain) => domain.domain_protocol(),
HyperlaneDomain::Unknown {
domain_protocol, ..
} => *domain_protocol,
}
}
}
#[cfg(test)]
mod tests {
use crate::KnownHyperlaneDomain;
Better Agent Configuration Parsing (#2070) ### Description This is a significant change to how we parse user configs. The main goal of this PR is to give a clear path and env key to any errors that are encountered when parsing configuration. In order to accomplish this, I have crated a new trait `FromRawConf` which defines a set of steps to validate and convert individual fields. Also for every major config struct, there is now a `Raw*` variant of it which is used by the `config` library to reduce errors that occur during deserialization itself. `Raw*` types should always use the most basic form of a value, such as `String`, `StrOrInt`, `bool`, and ideally optional in all cases. Missing values should be handled during the raw conversion and not by `config`. I also needed to make changes to a number of types stored in the parsed config types to force validation forward to the parsing step instead of doing it when we read the config value. This also required me to create a filter to prevent trying to validate certain configs that we would not ever need to load. These changes can also be built on later to support something other than `config` if we choose to, or add support for merging configs from multiple sources since everything is optional. ### Drive-by changes - Default to `http` for connection type - Default to no gas payment enforcement if not specified instead of failing - `ChainSetup` -> `ChainConf` - `GasPaymentEnforcementConfig` -> `GasPaymentEnforcementConf` - Made ethereum connection configuration more forgiving - Moved hyperlane base settings from `mod.rs` to `base.rs` - Moved config chain tests in hyperlane core to `tests` dir to fix a cyclical import problem - Extension traits to help with config in hyperlane core - Moved `StrOrInt` to new hyperlane core `config` module - Support for parsing `U256` from `StrOrInt` - Removed `HexString` type which is now redundant - Updated base settings to use hyperlane domain - Use `heyKey` as signer type if `type` is not specified and `key` is - Moved hyperlane ethereum chain config to a new module ### Related issues - Fixes #2033 - Fixes #2012 ### Backward compatibility _Are these changes backward compatible?_ Yes - This should take in configs in the same shape but be more forgiving in a few places _Are there any infrastructure implications, e.g. changes that would prohibit deploying older commits using this infra tooling?_ None ### Testing _What kind of testing have these changes undergone?_ Manual Unit Test
2 years ago
use std::str::FromStr;
#[test]
fn domain_strings() {
assert_eq!(
KnownHyperlaneDomain::from_str("ethereum").unwrap(),
KnownHyperlaneDomain::Ethereum,
);
assert_eq!(
KnownHyperlaneDomain::Ethereum.to_string(),
"ethereum".to_string(),
);
}
#[test]
fn domain_ids() {
assert_eq!(
KnownHyperlaneDomain::try_from(1).unwrap(),
KnownHyperlaneDomain::Ethereum,
);
assert_eq!(KnownHyperlaneDomain::Ethereum as u32, 1);
}
#[test]
fn test_name_from_domain_id() {
assert_eq!(
KnownHyperlaneDomain::try_from(1).unwrap().to_string(),
"ethereum"
);
assert_eq!(
KnownHyperlaneDomain::try_from(1).unwrap().as_str(),
"ethereum"
);
assert!(KnownHyperlaneDomain::try_from(0xf00u32).is_err());
}
#[test]
fn test_domain_id_from_name() {
assert_eq!(
"ethereum".parse::<KnownHyperlaneDomain>().map(|v| v as u32),
Ok(1)
);
assert_eq!(
"EthEreum".parse::<KnownHyperlaneDomain>().map(|v| v as u32),
Ok(1)
);
assert_eq!(
"Bsc".parse::<KnownHyperlaneDomain>().map(|v| v as u32),
Ok(56)
);
assert!("foo".parse::<KnownHyperlaneDomain>().is_err());
}
}