Skip to content

Commit

Permalink
chore: don't use empty uri
Browse files Browse the repository at this point in the history
  • Loading branch information
shumkov committed Oct 22, 2024
1 parent 8269c1f commit a9a96a0
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 3 deletions.
15 changes: 15 additions & 0 deletions packages/rs-dapi-client/src/address_list.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//! Subsystem to manage DAPI nodes.
use chrono::Utc;
use dapi_grpc::tonic::codegen::http;
use dapi_grpc::tonic::transport::Uri;
use rand::{rngs::SmallRng, seq::IteratorRandom, SeedableRng};
use std::collections::HashSet;
Expand All @@ -20,6 +21,16 @@ pub struct Address {
uri: Uri,
}

impl FromStr for Address {
type Err = AddressListError;

fn from_str(s: &str) -> Result<Self, Self::Err> {
Uri::from_str(s)
.map(Address::from)
.map_err(AddressListError::from)
}
}

impl PartialEq<Self> for Address {
fn eq(&self, other: &Self) -> bool {
self.uri == other.uri
Expand Down Expand Up @@ -81,6 +92,9 @@ impl Address {
pub enum AddressListError {
#[error("address {0} not found in the list")]
AddressNotFound(#[cfg_attr(feature = "mocks", serde(with = "http_serde::uri"))] Uri),
#[error("unable parse address: {0}")]
#[cfg_attr(feature = "mocks", serde(skip))]
InvalidAddressUri(#[from] http::uri::InvalidUri),
}

/// A structure to manage DAPI addresses to select from
Expand Down Expand Up @@ -200,6 +214,7 @@ impl AddressList {
}
}

// TODO: Must be changed to FromStr
impl From<&str> for AddressList {
fn from(value: &str) -> Self {
let uri_list: Vec<Uri> = value
Expand Down
4 changes: 3 additions & 1 deletion packages/rs-dapi-client/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,9 @@ impl<R: Mockable> Mockable for ExecutionResponse<R> {
R::mock_deserialize(data).map(|inner| ExecutionResponse {
inner,
retries: 0,
address: Address::from(Uri::default()),
address: "http://127.0.0.1:9000"
.parse()
.expect("failed to parse address"),
})
}
}
Expand Down
4 changes: 3 additions & 1 deletion packages/rs-dapi-client/tests/mock_dapi_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ async fn test_mock_get_identity_dapi_client() {
let execution_response = ExecutionResponse {
inner,
retries: 0,
address: Address::from(Uri::default()),
address: "http://127.0.0.1:9000"
.parse()
.expect("failed to parse address"),
};

dapi.expect(&request, &Ok(execution_response.clone()))
Expand Down
2 changes: 1 addition & 1 deletion packages/rs-sdk/src/mock/sdk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ impl MockDashPlatformSdk {
&Ok(ExecutionResponse {
inner: Default::default(),
retries: 0,
address: Uri::default().into(),
address: "http://127.0.0.1".parse().expect("failed to parse address"),
}),
)?;

Expand Down

0 comments on commit a9a96a0

Please sign in to comment.