Skip to content

Commit a9a96a0

Browse files
committed
chore: don't use empty uri
1 parent 8269c1f commit a9a96a0

File tree

4 files changed

+22
-3
lines changed

4 files changed

+22
-3
lines changed

packages/rs-dapi-client/src/address_list.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
//! Subsystem to manage DAPI nodes.
22
33
use chrono::Utc;
4+
use dapi_grpc::tonic::codegen::http;
45
use dapi_grpc::tonic::transport::Uri;
56
use rand::{rngs::SmallRng, seq::IteratorRandom, SeedableRng};
67
use std::collections::HashSet;
@@ -20,6 +21,16 @@ pub struct Address {
2021
uri: Uri,
2122
}
2223

24+
impl FromStr for Address {
25+
type Err = AddressListError;
26+
27+
fn from_str(s: &str) -> Result<Self, Self::Err> {
28+
Uri::from_str(s)
29+
.map(Address::from)
30+
.map_err(AddressListError::from)
31+
}
32+
}
33+
2334
impl PartialEq<Self> for Address {
2435
fn eq(&self, other: &Self) -> bool {
2536
self.uri == other.uri
@@ -81,6 +92,9 @@ impl Address {
8192
pub enum AddressListError {
8293
#[error("address {0} not found in the list")]
8394
AddressNotFound(#[cfg_attr(feature = "mocks", serde(with = "http_serde::uri"))] Uri),
95+
#[error("unable parse address: {0}")]
96+
#[cfg_attr(feature = "mocks", serde(skip))]
97+
InvalidAddressUri(#[from] http::uri::InvalidUri),
8498
}
8599

86100
/// A structure to manage DAPI addresses to select from
@@ -200,6 +214,7 @@ impl AddressList {
200214
}
201215
}
202216

217+
// TODO: Must be changed to FromStr
203218
impl From<&str> for AddressList {
204219
fn from(value: &str) -> Self {
205220
let uri_list: Vec<Uri> = value

packages/rs-dapi-client/src/mock.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,9 @@ impl<R: Mockable> Mockable for ExecutionResponse<R> {
270270
R::mock_deserialize(data).map(|inner| ExecutionResponse {
271271
inner,
272272
retries: 0,
273-
address: Address::from(Uri::default()),
273+
address: "http://127.0.0.1:9000"
274+
.parse()
275+
.expect("failed to parse address"),
274276
})
275277
}
276278
}

packages/rs-dapi-client/tests/mock_dapi_client.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ async fn test_mock_get_identity_dapi_client() {
2626
let execution_response = ExecutionResponse {
2727
inner,
2828
retries: 0,
29-
address: Address::from(Uri::default()),
29+
address: "http://127.0.0.1:9000"
30+
.parse()
31+
.expect("failed to parse address"),
3032
};
3133

3234
dapi.expect(&request, &Ok(execution_response.clone()))

packages/rs-sdk/src/mock/sdk.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ impl MockDashPlatformSdk {
368368
&Ok(ExecutionResponse {
369369
inner: Default::default(),
370370
retries: 0,
371-
address: Uri::default().into(),
371+
address: "http://127.0.0.1".parse().expect("failed to parse address"),
372372
}),
373373
)?;
374374

0 commit comments

Comments
 (0)