Skip to content

Commit 3f7f6a8

Browse files
committed
chore(various): random wips which need cleanup
1 parent eec3843 commit 3f7f6a8

File tree

6 files changed

+157
-245
lines changed

6 files changed

+157
-245
lines changed

Cargo.lock

+48-130
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/interledger-btp/src/lib.rs

+93-100
Original file line numberDiff line numberDiff line change
@@ -188,105 +188,98 @@ mod client_server {
188188
}
189189

190190
// TODO should this be an integration test, since it binds to a port?
191-
#[test]
192-
fn client_server_test() {
193-
let mut runtime = Runtime::new().unwrap();
194-
runtime
195-
.block_on(lazy(|| {
196-
let bind_addr = get_open_port();
197-
198-
let server_store = TestStore {
199-
accounts: Arc::new(vec![TestAccount {
200-
id: Uuid::new_v4(),
201-
ilp_over_btp_incoming_token: Some("test_auth_token".to_string()),
202-
ilp_over_btp_outgoing_token: None,
203-
ilp_over_btp_url: None,
204-
}]),
205-
};
206-
let server_address = Address::from_str("example.server").unwrap();
207-
let btp_service = BtpOutgoingService::new(
208-
server_address.clone(),
209-
outgoing_service_fn(move |_| {
210-
Err(RejectBuilder {
211-
code: ErrorCode::F02_UNREACHABLE,
212-
message: b"No other outgoing handler",
213-
triggered_by: Some(&server_address),
214-
data: &[],
215-
}
216-
.build())
217-
}),
218-
);
219-
let filter = btp_service_as_filter(btp_service.clone(), server_store);
220-
btp_service.handle_incoming(incoming_service_fn(|_| {
221-
Ok(FulfillBuilder {
222-
fulfillment: &[0; 32],
223-
data: b"test data",
224-
}
225-
.build())
226-
}));
227-
228-
let account = TestAccount {
229-
id: Uuid::new_v4(),
230-
ilp_over_btp_url: Some(
231-
Url::parse(&format!("btp+ws://{}/accounts/alice/ilp/btp", bind_addr))
232-
.unwrap(),
233-
),
234-
ilp_over_btp_outgoing_token: Some("test_auth_token".to_string()),
235-
ilp_over_btp_incoming_token: None,
236-
};
237-
let accounts = vec![account.clone()];
238-
let addr = Address::from_str("example.address").unwrap();
239-
let addr_clone = addr.clone();
240-
let client = connect_client(
241-
addr.clone(),
242-
accounts,
243-
true,
244-
outgoing_service_fn(move |_| {
245-
Err(RejectBuilder {
246-
code: ErrorCode::F02_UNREACHABLE,
247-
message: &[],
248-
data: &[],
249-
triggered_by: Some(&addr_clone),
250-
}
251-
.build())
252-
}),
253-
)
254-
.and_then(move |btp_service| {
255-
let mut btp_service =
256-
btp_service.handle_incoming(incoming_service_fn(move |_| {
257-
Err(RejectBuilder {
258-
code: ErrorCode::F02_UNREACHABLE,
259-
message: &[],
260-
data: &[],
261-
triggered_by: Some(&addr),
262-
}
263-
.build())
264-
}));
265-
let btp_service_clone = btp_service.clone();
266-
btp_service
267-
.send_request(OutgoingRequest {
268-
from: account.clone(),
269-
to: account.clone(),
270-
original_amount: 100,
271-
prepare: PrepareBuilder {
272-
destination: Address::from_str("example.destination").unwrap(),
273-
amount: 100,
274-
execution_condition: &[0; 32],
275-
expires_at: SystemTime::now() + Duration::from_secs(30),
276-
data: b"test data",
277-
}
278-
.build(),
279-
})
280-
.map_err(|reject| println!("Packet was rejected: {:?}", reject))
281-
.and_then(move |_| {
282-
btp_service_clone.close();
283-
Ok(())
284-
})
285-
});
286-
let server = warp::serve(filter);
287-
tokio::spawn(server.bind(bind_addr));
288-
client
289-
}))
290-
.unwrap();
191+
#[tokio::test]
192+
async fn client_server_test() {
193+
let bind_addr = get_open_port();
194+
195+
let server_store = TestStore {
196+
accounts: Arc::new(vec![TestAccount {
197+
id: Uuid::new_v4(),
198+
ilp_over_btp_incoming_token: Some("test_auth_token".to_string()),
199+
ilp_over_btp_outgoing_token: None,
200+
ilp_over_btp_url: None,
201+
}]),
202+
};
203+
let server_address = Address::from_str("example.server").unwrap();
204+
let btp_service = BtpOutgoingService::new(
205+
server_address.clone(),
206+
outgoing_service_fn(move |_| {
207+
Err(RejectBuilder {
208+
code: ErrorCode::F02_UNREACHABLE,
209+
message: b"No other outgoing handler",
210+
triggered_by: Some(&server_address),
211+
data: &[],
212+
}
213+
.build())
214+
}),
215+
);
216+
btp_service.clone().handle_incoming(incoming_service_fn(|_| {
217+
Ok(FulfillBuilder {
218+
fulfillment: &[0; 32],
219+
data: b"test data",
220+
}
221+
.build())
222+
}));
223+
let filter = btp_service_as_filter(btp_service.clone(), server_store);
224+
let server = warp::serve(filter);
225+
// Spawn the server and listen for incoming connections
226+
tokio::spawn(server.bind(bind_addr));
227+
228+
// Try to connect
229+
let account = TestAccount {
230+
id: Uuid::new_v4(),
231+
ilp_over_btp_url: Some(
232+
Url::parse(&format!("btp+ws://{}/accounts/alice/ilp/btp", bind_addr))
233+
.unwrap(),
234+
),
235+
ilp_over_btp_outgoing_token: Some("test_auth_token".to_string()),
236+
ilp_over_btp_incoming_token: None,
237+
};
238+
let accounts = vec![account.clone()];
239+
let addr = Address::from_str("example.address").unwrap();
240+
let addr_clone = addr.clone();
241+
242+
let btp_service = connect_client(
243+
addr.clone(),
244+
accounts,
245+
true,
246+
outgoing_service_fn(move |_| {
247+
Err(RejectBuilder {
248+
code: ErrorCode::F02_UNREACHABLE,
249+
message: &[],
250+
data: &[],
251+
triggered_by: Some(&addr_clone),
252+
}
253+
.build())
254+
}),
255+
).await.unwrap();
256+
257+
let mut btp_service = btp_service.handle_incoming(incoming_service_fn(move |_| {
258+
Err(RejectBuilder {
259+
code: ErrorCode::F02_UNREACHABLE,
260+
message: &[],
261+
data: &[],
262+
triggered_by: Some(&addr),
263+
}
264+
.build())
265+
})).await;
266+
267+
let res = btp_service
268+
.send_request(OutgoingRequest {
269+
from: account.clone(),
270+
to: account.clone(),
271+
original_amount: 100,
272+
prepare: PrepareBuilder {
273+
destination: Address::from_str("example.destination").unwrap(),
274+
amount: 100,
275+
execution_condition: &[0; 32],
276+
expires_at: SystemTime::now() + Duration::from_secs(30),
277+
data: b"test data",
278+
}
279+
.build(),
280+
}).await;
281+
dbg!(&res);
282+
assert!(res.is_ok());
283+
btp_service.close();
291284
}
292285
}

crates/interledger-btp/src/server.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ struct WsWrap<W> {
222222
// .skip_while(|message| {
223223
// // Skip non-binary messages like Pings and Pongs
224224
// // Note that the BTP protocol spec technically specifies that
225-
// // the auth message MUST be the first packet sent over the
225+
// // the auth message MUST be the first packet sent over the
226226
// // WebSocket connection. However, the JavaScript implementation
227227
// // of BTP sends a Ping packet first, so we should ignore it.
228228
// // (Be liberal in what you accept but strict in what you send)

crates/interledger-ccp/src/server.rs

-1
Original file line numberDiff line numberDiff line change
@@ -681,7 +681,6 @@ where
681681

682682
update_routes.await
683683
} else {
684-
dbg!("not chagned");
685684
// The routing table hasn't changed
686685
Ok(())
687686
}

crates/interledger-service-util/src/exchange_rates_service.rs

+15-12
Original file line numberDiff line numberDiff line change
@@ -251,18 +251,21 @@ where
251251
}
252252

253253
// TODO: This compiles on nightly but fails on 1.39?
254-
pub fn spawn_interval(self, interval: Duration) {
255-
debug!("Starting interval to poll exchange rate provider: {:?} for rates", self.provider);
256-
let interval = async move {
257-
let mut interval = tokio::time::interval(interval);
258-
while let _ = interval.tick().await {
259-
// Ignore errors so that they don't cause the Interval to stop
260-
let _ = self.update_rates().await;
261-
}
262-
Ok::<(), ()>(())
263-
};
264-
tokio::spawn(interval);
265-
}
254+
// pub fn spawn_interval(self, interval: Duration) {
255+
// debug!(
256+
// "Starting interval to poll exchange rate provider: {:?} for rates",
257+
// self.provider
258+
// );
259+
// let interval = async move {
260+
// let mut interval = tokio::time::interval(interval);
261+
// while let _ = interval.tick().await {
262+
// // Ignore errors so that they don't cause the Interval to stop
263+
// let _ = self.update_rates().await;
264+
// }
265+
// Ok::<(), ()>(())
266+
// };
267+
// tokio::spawn(interval);
268+
// }
266269

267270
async fn fetch_rates(&self) -> Result<HashMap<String, f64>, ()> {
268271
match self.provider {

crates/interledger-store/src/redis/mod.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1835,7 +1835,6 @@ async fn update_routes(
18351835
mut connection: RedisReconnect,
18361836
routing_table: Arc<RwLock<Arc<HashMap<String, Uuid>>>>,
18371837
) -> Result<(), ()> {
1838-
println!("updating routes");
18391838
let mut pipe = redis_crate::pipe();
18401839
pipe.hgetall(ROUTES_KEY)
18411840
.hgetall(STATIC_ROUTES_KEY)

0 commit comments

Comments
 (0)