feat: Add check if an address is a contract in Cosmos (#4369)
### Description Currently, integration into Cosmos make an assumption that the address where a message should be delivered is a contract. This change allows Relayer to actually check if the recipient is a contract. ### Backward compatibility Yes ### Testing * Tested using E2E tests for Cosmos. * Tested using auxiliary unit test (it is marked as ignored since it connects to real gRPC of Neutron). --------- Co-authored-by: Danil Nemirovsky <4614623+ameten@users.noreply.github.com>pull/4379/head
parent
25c235a8e2
commit
86b1c7646c
@ -0,0 +1,77 @@ |
||||
use std::str::FromStr; |
||||
|
||||
use url::Url; |
||||
|
||||
use hyperlane_core::config::OperationBatchConfig; |
||||
use hyperlane_core::{ContractLocator, HyperlaneDomain, KnownHyperlaneDomain}; |
||||
|
||||
use crate::address::CosmosAddress; |
||||
use crate::grpc::{WasmGrpcProvider, WasmProvider}; |
||||
use crate::{ConnectionConf, CosmosAmount, RawCosmosAmount}; |
||||
|
||||
#[ignore] |
||||
#[tokio::test] |
||||
async fn test_wasm_contract_info_success() { |
||||
// given
|
||||
let provider = provider("neutron1sjzzd4gwkggy6hrrs8kxxatexzcuz3jecsxm3wqgregkulzj8r7qlnuef4"); |
||||
|
||||
// when
|
||||
let result = provider.wasm_contract_info().await; |
||||
|
||||
// then
|
||||
assert!(result.is_ok()); |
||||
|
||||
let contract_info = result.unwrap(); |
||||
|
||||
assert_eq!( |
||||
contract_info.creator, |
||||
"neutron1dwnrgwsf5c9vqjxsax04pdm0mx007yrre4yyvm", |
||||
); |
||||
assert_eq!( |
||||
contract_info.admin, |
||||
"neutron1fqf5mprg3f5hytvzp3t7spmsum6rjrw80mq8zgkc0h6rxga0dtzqws3uu7", |
||||
); |
||||
} |
||||
|
||||
#[ignore] |
||||
#[tokio::test] |
||||
async fn test_wasm_contract_info_no_contract() { |
||||
// given
|
||||
let provider = provider("neutron1dwnrgwsf5c9vqjxsax04pdm0mx007yrre4yyvm"); |
||||
|
||||
// when
|
||||
let result = provider.wasm_contract_info().await; |
||||
|
||||
// then
|
||||
assert!(result.is_err()); |
||||
} |
||||
|
||||
fn provider(address: &str) -> WasmGrpcProvider { |
||||
let domain = HyperlaneDomain::Known(KnownHyperlaneDomain::Neutron); |
||||
let address = CosmosAddress::from_str(address).unwrap(); |
||||
let locator = Some(ContractLocator::new(&domain, address.digest())); |
||||
|
||||
WasmGrpcProvider::new( |
||||
domain.clone(), |
||||
ConnectionConf::new( |
||||
vec![Url::parse("http://grpc-kralum.neutron-1.neutron.org:80").unwrap()], |
||||
"https://rpc-kralum.neutron-1.neutron.org".to_owned(), |
||||
"neutron-1".to_owned(), |
||||
"neutron".to_owned(), |
||||
"untrn".to_owned(), |
||||
RawCosmosAmount::new("untrn".to_owned(), "0".to_owned()), |
||||
32, |
||||
OperationBatchConfig { |
||||
batch_contract_address: None, |
||||
max_batch_size: 1, |
||||
}, |
||||
), |
||||
CosmosAmount { |
||||
denom: "untrn".to_owned(), |
||||
amount: Default::default(), |
||||
}, |
||||
locator, |
||||
None, |
||||
) |
||||
.unwrap() |
||||
} |
Loading…
Reference in new issue