Skip to content

Commit

Permalink
Merge pull request #8 from movemntdev/0xmovses/unit-tests
Browse files Browse the repository at this point in the history
add initial unit tests
  • Loading branch information
0xmovses authored Feb 8, 2024
2 parents 87825cd + c983fe2 commit 1ec6131
Show file tree
Hide file tree
Showing 29 changed files with 522 additions and 213 deletions.
1 change: 1 addition & 0 deletions rust/chains/hyperlane-ethereum/src/mailbox.rs
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,7 @@ mod test {
domain: &HyperlaneDomain::Known(KnownHyperlaneDomain::ArbitrumGoerli),
// Address doesn't matter because we're using a MockProvider
address: H256::default(),
modules: None,
},
);

Expand Down
12 changes: 10 additions & 2 deletions rust/chains/hyperlane-ethereum/src/provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use async_trait::async_trait;
use derive_new::new;
use ethers::prelude::Middleware;
use ethers_core::abi::Address;
use hyperlane_core::{ethers_core_types, U256};
use hyperlane_core::{ethers_core_types, LookupKind, U256};
use tokio::time::sleep;
use tracing::instrument;

Expand Down Expand Up @@ -51,7 +51,15 @@ where
M: Middleware + 'static,
{
#[instrument(err, skip(self))]
async fn get_block_by_hash(&self, hash: &H256) -> ChainResult<BlockInfo> {
async fn get_block_by_hash(&self, hash: LookupKind) -> ChainResult<BlockInfo> {
let hash = match hash {
LookupKind::Eth(h) => h,
_ => {
return Err(
ChainCommunicationError::from_contract_error_str("Invalid hash type").into(),
)
}
};
let block = get_with_retry_on_none(hash, |h| {
let eth_h256: ethers_core_types::H256 = h.into();
self.provider.get_block(eth_h256)
Expand Down
4 changes: 2 additions & 2 deletions rust/chains/hyperlane-fuel/src/provider.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use async_trait::async_trait;

use hyperlane_core::{
BlockInfo, ChainResult, HyperlaneChain, HyperlaneDomain, HyperlaneProvider, TxnInfo, H256, U256,
BlockInfo, ChainResult, HyperlaneChain, HyperlaneDomain, HyperlaneProvider, LookupKind, TxnInfo, H256, U256
};

/// A wrapper around a fuel provider to get generic blockchain information.
Expand All @@ -20,7 +20,7 @@ impl HyperlaneChain for FuelProvider {

#[async_trait]
impl HyperlaneProvider for FuelProvider {
async fn get_block_by_hash(&self, hash: &H256) -> ChainResult<BlockInfo> {
async fn get_block_by_hash(&self, hash: LookupKind) -> ChainResult<BlockInfo> {
todo!()
}

Expand Down
4 changes: 2 additions & 2 deletions rust/chains/hyperlane-sealevel/src/provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::{str::FromStr, sync::Arc};
use async_trait::async_trait;

use hyperlane_core::{
BlockInfo, ChainResult, HyperlaneChain, HyperlaneDomain, HyperlaneProvider, TxnInfo, H256, U256,
BlockInfo, ChainResult, HyperlaneChain, HyperlaneDomain, HyperlaneProvider, LookupKind, TxnInfo, H256, U256
};
use solana_sdk::{commitment_config::CommitmentConfig, pubkey::Pubkey};

Expand Down Expand Up @@ -60,7 +60,7 @@ impl HyperlaneChain for SealevelProvider {

#[async_trait]
impl HyperlaneProvider for SealevelProvider {
async fn get_block_by_hash(&self, _hash: &H256) -> ChainResult<BlockInfo> {
async fn get_block_by_hash(&self, _hash: LookupKind) -> ChainResult<BlockInfo> {
todo!() // FIXME
}

Expand Down
20 changes: 8 additions & 12 deletions rust/chains/hyperlane-sui/src/client.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
use sui_sdk::{SuiClientBuilder, SuiClient};
use std::str::FromStr;
use url::Url;

/// Sui RPC client
pub struct SuiRpcClient(SuiClient);
impl SuiRpcClient {
/// Create a new aptos rpc client from node url
pub async fn new(rpc_endpoint: String) -> Result<Self, anyhow::Error> {
let client = SuiClientBuilder::default()
.build(Url::from_str(&rpc_endpoint).unwrap())
.await?;
pub async fn new() -> Result<Self, anyhow::Error> {
// TODO: feature flag for testnet/mainnet
let client = SuiClientBuilder::default().build_testnet().await?;
Ok(Self(client))
}
}
Expand All @@ -29,12 +26,11 @@ impl std::fmt::Debug for SuiRpcClient {
}

mod tests {
use super::*;
use std::str::FromStr;
use url::Url;
use crate::SuiRpcClient;

#[tokio::test]
async fn test_new() {
let rpc_endpoint = "https://fullnode.testnet.sui.io:443";

async fn test_creates_new_client() {
let client = SuiRpcClient::new().await.unwrap();
}
}

Loading

0 comments on commit 1ec6131

Please sign in to comment.