Skip to content

Commit

Permalink
fix sandbox for liana-gui tests
Browse files Browse the repository at this point in the history
  • Loading branch information
edouardparis committed Jan 31, 2025
1 parent 8fe5d4a commit b9467b3
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 17 deletions.
12 changes: 7 additions & 5 deletions liana-gui/src/installer/step/descriptor/editor/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -651,7 +651,8 @@ impl DescriptorEditModal for EditThresholdModal {
#[cfg(test)]
mod tests {
use super::*;
use iced_runtime::command::Action;
use iced::futures::StreamExt;
use iced_runtime::{task::into_stream, Action};
use std::path::PathBuf;
use std::sync::{Arc, Mutex};

Expand All @@ -674,10 +675,11 @@ mod tests {
pub async fn update(&self, message: Message) {
let mut hws = HardwareWallets::new(PathBuf::from_str("/").unwrap(), Network::Bitcoin);
let cmd = self.step.lock().unwrap().update(&mut hws, message);
for action in cmd.actions() {
if let Action::Future(f) = action {
let msg = f.await;
let _cmd = self.step.lock().unwrap().update(&mut hws, msg);
if let Some(mut stream) = into_stream(cmd) {
while let Some(action) = stream.next().await {
if let Action::Output(msg) = action {
let _cmd = self.step.lock().unwrap().update(&mut hws, msg);
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion liana-gui/src/loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ impl Loader {
if self.internal_bitcoind.is_some() {
let log_path = internal_bitcoind_debug_log_path(&self.datadir_path, self.network);
iced::Subscription::run_with_id("bitcoind_log", get_bitcoind_log(log_path))
.map(|msg| Message::BitcoindLog(msg))
.map(Message::BitcoindLog)
} else {
Subscription::none()
}
Expand Down
24 changes: 13 additions & 11 deletions liana-gui/src/utils/sandbox.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use iced::futures::StreamExt;
use std::sync::Arc;

use iced_runtime::command::Action;
use iced_runtime::{task::into_stream, Action};

use crate::{
app::{cache::Cache, message::Message, state::State, wallet::Wallet},
Expand All @@ -11,7 +12,7 @@ pub struct Sandbox<S: State> {
state: S,
}

impl<S: State + Send + 'static> Sandbox<S> {
impl<S: State + 'static> Sandbox<S> {
pub fn new(state: S) -> Self {
Self { state }
}
Expand All @@ -27,13 +28,13 @@ impl<S: State + Send + 'static> Sandbox<S> {
message: Message,
) -> Self {
let cmd = self.state.update(daemon.clone(), cache, message);
for action in cmd.actions() {
if let Action::Future(f) = action {
let msg = f.await;
let _cmd = self.state.update(daemon.clone(), cache, msg);
if let Some(mut stream) = into_stream(cmd) {
while let Some(action) = stream.next().await {
if let Action::Output(msg) = action {
let _cmd = self.state.update(daemon.clone(), cache, msg);
}
}
}

self
}

Expand All @@ -44,10 +45,11 @@ impl<S: State + Send + 'static> Sandbox<S> {
wallet: Arc<Wallet>,
) -> Self {
let cmd = self.state.reload(daemon.clone(), wallet);
for action in cmd.actions() {
if let Action::Future(f) = action {
let msg = f.await;
self = self.update(daemon.clone(), cache, msg).await;
if let Some(mut stream) = into_stream(cmd) {
while let Some(action) = stream.next().await {
if let Action::Output(msg) = action {
let _cmd = self.state.update(daemon.clone(), cache, msg);
}
}
}

Expand Down

0 comments on commit b9467b3

Please sign in to comment.