Skip to content

Commit

Permalink
Merge #394: fix installer: wrong detection of hot signer usage.
Browse files Browse the repository at this point in the history
789ba50 fix installer: wrong detection of hot signer usage. (edouard)

Pull request description:

  We did not check that the keys in the primary path were using the hot signer. In the case of a hot signing key only used for the primary path,
  the hot signer was not advertised to the context
  passing to each installer step and was not stored after install.

ACKs for top commit:
  darosior:
    tested ACK 789ba50

Tree-SHA512: bd7107b5380616e0c18563556e585e243c89decd85a95247049272cc53317891527b6c4641ee017fb425310010e3f38172f7b62aa8e424309d76a812bc0df7c4
  • Loading branch information
darosior committed Mar 30, 2023
2 parents 26ff92d + 789ba50 commit b1ca067
Showing 1 changed file with 100 additions and 0 deletions.
100 changes: 100 additions & 0 deletions gui/src/installer/step/descriptor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,9 @@ impl Step for DefineDescriptor {
master_fingerprint,
name: spending_key.name.clone(),
});
if master_fingerprint == self.signer.fingerprint() {
signer_is_used = true;
}
}
let xpub = DescriptorMultiXKey {
origin: xpub.origin.clone(),
Expand Down Expand Up @@ -1282,3 +1285,100 @@ impl From<BackupDescriptor> for Box<dyn Step> {
Box::new(s)
}
}

#[cfg(test)]
mod tests {
use super::*;
use iced_native::command::Action;
use std::sync::{Arc, Mutex};

pub struct Sandbox<S: Step> {
step: Arc<Mutex<S>>,
}

impl<S: Step + 'static> Sandbox<S> {
pub fn new(step: S) -> Self {
Self {
step: Arc::new(Mutex::new(step)),
}
}

pub fn check<F: FnOnce(&mut S)>(&self, check: F) {
let mut step = self.step.lock().unwrap();
check(&mut step)
}

pub async fn update(&self, message: Message) {
let cmd = self.step.lock().unwrap().update(message);
for action in cmd.actions() {
if let Action::Future(f) = action {
let msg = f.await;
let _cmd = self.step.lock().unwrap().update(msg);
}
}
}
}

#[tokio::test]
async fn test_define_descriptor_use_hotkey() {
let mut ctx = Context::new(Network::Signet, PathBuf::from_str("/").unwrap());
let sandbox: Sandbox<DefineDescriptor> = Sandbox::new(DefineDescriptor::new());

// Edit primary key
sandbox
.update(Message::DefineDescriptor(message::DefineDescriptor::Key(
false,
0,
message::DefineKey::Edit,
)))
.await;
sandbox.check(|step| assert!(step.modal.is_some()));
sandbox.update(Message::UseHotSigner).await;
sandbox
.update(Message::DefineDescriptor(
message::DefineDescriptor::NameEdited("hot signer key".to_string()),
))
.await;
sandbox
.update(Message::DefineDescriptor(
message::DefineDescriptor::ConfirmXpub,
))
.await;
sandbox.check(|step| assert!(step.modal.is_none()));

// Edit sequence
sandbox
.update(Message::DefineDescriptor(
message::DefineDescriptor::SequenceEdited("1000".to_string()),
))
.await;

// Edit recovery key
sandbox
.update(Message::DefineDescriptor(message::DefineDescriptor::Key(
true,
0,
message::DefineKey::Edit,
)))
.await;
sandbox.check(|step| assert!(step.modal.is_some()));
sandbox.update(Message::DefineDescriptor(
message::DefineDescriptor::XPubEdited("[f5acc2fd/48'/1'/0'/2']tpubDFAqEGNyad35aBCKUAXbQGDjdVhNueno5ZZVEn3sQbW5ci457gLR7HyTmHBg93oourBssgUxuWz1jX5uhc1qaqFo9VsybY1J5FuedLfm4dK".to_string()),
)).await;
sandbox
.update(Message::DefineDescriptor(
message::DefineDescriptor::NameEdited("external recovery key".to_string()),
))
.await;
sandbox
.update(Message::DefineDescriptor(
message::DefineDescriptor::ConfirmXpub,
))
.await;
sandbox.check(|step| {
assert!(step.modal.is_none());
assert!((step).apply(&mut ctx));
assert!(ctx.signer.is_some());
});
}
}

0 comments on commit b1ca067

Please sign in to comment.