Skip to content

Commit

Permalink
small fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
sevenzing committed Oct 25, 2024
1 parent 349e5ba commit 95b1f66
Show file tree
Hide file tree
Showing 3 changed files with 181 additions and 81 deletions.
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "alloy-ccip-read"
version = "0.1.2"
version = "0.2.0"
authors = ["Lev Lymarenko its@llev.me"]
license = "MIT"
edition = "2018"
Expand Down Expand Up @@ -48,3 +48,4 @@ alloy = { version = "0.1", features = ["full"] }
anyhow = "1.0.75"
pretty_assertions = "1.4.1"
rstest = "0.23.0"
async-std = { version = "1", features = ["attributes", "tokio1"] }
29 changes: 23 additions & 6 deletions src/protocols/d3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,23 @@ use crate::{
};
use alloy::{primitives::Address, providers::Provider};

/// Resolves a D3 name.
///
/// # Arguments
///
/// * `reader`: The CCIP reader.
/// * `resolver_address`: The resolver's address.
/// * `name`: The name to resolve.
/// * `network`: The network to resolve the name on. Empty string means current network where resolver deployed.
pub async fn resolve_d3_name<P: Provider, D: DomainIdProvider>(
reader: &CCIPReader<P, D>,
resolver_address: Address,
name: &str,
network: &str,
name: impl Into<String>,
network: impl Into<String>,
) -> Result<ResolveResult, CCIPReaderError> {
let call = contracts::D3Connect::resolveCall {
name: name.to_string(),
network: network.to_string(),
name: name.into(),
network: network.into(),
};
let mut ccip_read_used = false;
let (result, requests) =
Expand All @@ -30,14 +38,23 @@ pub async fn resolve_d3_name<P: Provider, D: DomainIdProvider>(
})
}

/// Reverse resolves a D3 name.
///
/// # Arguments
///
/// * `reader`: The CCIP reader.
/// * `address`: The address to reverse resolve.
/// * `resolver_address`: The resolver's address.
/// * `network`: The network to reverse resolve the name on. Empty string means current network where resolver deployed.
pub async fn reverse_resolve_d3_name<P: Provider, D: DomainIdProvider>(
reader: &CCIPReader<P, D>,
address: Address,
resolver_address: Address,
network: impl Into<String>,
) -> Result<ReverseResolveResult, CCIPReaderError> {
let call = contracts::D3Connect::reverseResolveCall {
addr: address,
network: "".to_string(),
network: network.into(),
};
let mut ccip_read_used = false;
let (result, requests) =
Expand Down Expand Up @@ -98,7 +115,7 @@ mod tests {
.unwrap()
);

let result = reverse_resolve_d3_name(reader, address, resolver_address)
let result = reverse_resolve_d3_name(reader, address, resolver_address, network)
.await
.unwrap();
assert_eq!(result.name.value, "d3connect.shib");
Expand Down
230 changes: 156 additions & 74 deletions src/protocols/ens.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,82 +271,164 @@ mod tests {
);
}

#[tokio::test]
async fn test_eip_2544_ens_wildcards() {
use rstest::rstest;

#[rstest]
#[case(
"1.offchainexample.eth",
true,
true,
"0xC1735677a60884ABbCF72295E88d47764BeDa282",
"0x41563129cDbbD0c5D3e1c86cf9563926b243834d"
)]
#[case(
"levvv.xyz",
true,
true,
"0xF142B308cF687d4358410a4cB885513b30A42025",
"0xc0de20a37e2dac848f81a93bd85fe4acdde7c0de"
)]
#[case(
"vitalik.eth",
false,
false,
"0x231b0Ee14048e9dCcD1d247744d114a4EB5E8E63",
"0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045"
)]
#[case(
"itslev.cb.id",
true,
true,
"0x1934FC75aD10d7eEd51dc7A92773cAc96A06BE56",
"0xD578780f1dA7404d9CC0eEbC9D684c140CC4b638"
)]
#[case(
"moo331.nft-owner.eth",
true,
false,
"0x56942dd93A6778F4331994A1e5b2f59613DE1387",
"0x51050ec063d393217B436747617aD1C2285Aeeee"
)]
#[case(
"offchaindemo.eth",
true,
true,
"0x35b920d4329c5797727af8b15358b43509e5e237",
"0x179A862703a4adfb29896552DF9e307980D19285"
)]
async fn test_ens_wildcards(
#[case] ens_name: &str,
#[case] expected_wildcarded: bool,
#[case] expected_ccip_read_used: bool,
#[case] expected_resolver: &str,
#[case] expected_addr: &str,
) {
let reader = CCIPReader::mainnet();

// hope they will never change their domains 🙏
for (ens_name, wildcarded, ccip_read_used, expected_resolver, expected_addr) in [
(
"1.offchainexample.eth",
true,
true,
"0xC1735677a60884ABbCF72295E88d47764BeDa282",
"0x41563129cDbbD0c5D3e1c86cf9563926b243834d",
),
(
"levvv.xyz",
true,
true,
"0xF142B308cF687d4358410a4cB885513b30A42025",
"0xc0de20a37e2dac848f81a93bd85fe4acdde7c0de",
),
(
"vitalik.eth",
false,
false,
"0x231b0Ee14048e9dCcD1d247744d114a4EB5E8E63",
"0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045",
),
(
"itslev.cb.id",
true,
true,
"0x1934FC75aD10d7eEd51dc7A92773cAc96A06BE56",
"0xD578780f1dA7404d9CC0eEbC9D684c140CC4b638",
),
(
"moo331.nft-owner.eth",
true,
false,
"0x56942dd93A6778F4331994A1e5b2f59613DE1387",
"0x51050ec063d393217B436747617aD1C2285Aeeee",
),
(
"offchaindemo.eth",
true,
true,
"0xDB34Da70Cfd694190742E94B7f17769Bc3d84D27",
"0x179A862703a4adfb29896552DF9e307980D19285",
),
] {
let resolver_address = get_resolver_wildcarded(&reader, None, ens_name)
.await
.unwrap();
assert_eq!(
resolver_address,
Address::from_str(expected_resolver).unwrap(),
"{ens_name}: expected resolver_address to be {expected_resolver}, but got {}",
resolver_address
);
let resolver_address = get_resolver_wildcarded(&reader, None, ens_name)
.await
.unwrap();
assert_eq!(
resolver_address,
Address::from_str(expected_resolver).unwrap(),
"{ens_name}: expected resolver_address to be {expected_resolver}, but got {}",
resolver_address
);

let result = resolve_name(&reader, None, ens_name).await.unwrap();
assert_eq!(
result.addr.value,
Address::from_str(expected_addr).unwrap(),
"{ens_name}: expected resolved_address to be {expected_addr}, but got {}",
result.addr.value
);
assert_eq!(
result.ccip_read_used, ccip_read_used,
"{ens_name}: expected ccip_read_used to be {ccip_read_used}, but got {}",
result.ccip_read_used
);
assert_eq!(
result.wildcard_used, wildcarded,
"{ens_name}: wildcard_used is {}, expected to be {wildcarded}",
result.wildcard_used
);
}
let result = resolve_name(&reader, None, ens_name).await.unwrap();
assert_eq!(
result.addr.value,
Address::from_str(expected_addr).unwrap(),
"{ens_name}: expected resolved_address to be {expected_addr}, but got {}",
result.addr.value
);
assert_eq!(
result.ccip_read_used, expected_ccip_read_used,
"{ens_name}: expected ccip_read_used to be {expected_ccip_read_used}, but got {}",
result.ccip_read_used
);
assert_eq!(
result.wildcard_used, expected_wildcarded,
"{ens_name}: wildcard_used is {}, expected to be {expected_wildcarded}",
result.wildcard_used
);
}
// #[tokio::test]
// async fn test_eip_2544_ens_wildcards() {
// let reader = CCIPReader::mainnet();

// // hope they will never change their domains 🙏
// for (ens_name, wildcarded, ccip_read_used, expected_resolver, expected_addr) in [
// (
// "1.offchainexample.eth",
// true,
// true,
// "0xC1735677a60884ABbCF72295E88d47764BeDa282",
// "0x41563129cDbbD0c5D3e1c86cf9563926b243834d",
// ),
// (
// "levvv.xyz",
// true,
// true,
// "0xF142B308cF687d4358410a4cB885513b30A42025",
// "0xc0de20a37e2dac848f81a93bd85fe4acdde7c0de",
// ),
// (
// "vitalik.eth",
// false,
// false,
// "0x231b0Ee14048e9dCcD1d247744d114a4EB5E8E63",
// "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045",
// ),
// (
// "itslev.cb.id",
// true,
// true,
// "0x1934FC75aD10d7eEd51dc7A92773cAc96A06BE56",
// "0xD578780f1dA7404d9CC0eEbC9D684c140CC4b638",
// ),
// (
// "moo331.nft-owner.eth",
// true,
// false,
// "0x56942dd93A6778F4331994A1e5b2f59613DE1387",
// "0x51050ec063d393217B436747617aD1C2285Aeeee",
// ),
// (
// "offchaindemo.eth",
// true,
// true,
// "0xDB34Da70Cfd694190742E94B7f17769Bc3d84D27",
// "0x179A862703a4adfb29896552DF9e307980D19285",
// ),
// ] {
// let resolver_address = get_resolver_wildcarded(&reader, None, ens_name)
// .await
// .unwrap();
// assert_eq!(
// resolver_address,
// Address::from_str(expected_resolver).unwrap(),
// "{ens_name}: expected resolver_address to be {expected_resolver}, but got {}",
// resolver_address
// );

// let result = resolve_name(&reader, None, ens_name).await.unwrap();
// assert_eq!(
// result.addr.value,
// Address::from_str(expected_addr).unwrap(),
// "{ens_name}: expected resolved_address to be {expected_addr}, but got {}",
// result.addr.value
// );
// assert_eq!(
// result.ccip_read_used, ccip_read_used,
// "{ens_name}: expected ccip_read_used to be {ccip_read_used}, but got {}",
// result.ccip_read_used
// );
// assert_eq!(
// result.wildcard_used, wildcarded,
// "{ens_name}: wildcard_used is {}, expected to be {wildcarded}",
// result.wildcard_used
// );
// }
// }
}

0 comments on commit 95b1f66

Please sign in to comment.