Skip to content

Commit

Permalink
fix: add missing methods to generate-stacking-signature
Browse files Browse the repository at this point in the history
  • Loading branch information
hstove committed May 16, 2024
1 parent 83d338d commit 0904dec
Showing 1 changed file with 47 additions and 6 deletions.
53 changes: 47 additions & 6 deletions stacks-signer/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ pub struct RunSignerArgs {
pub config: PathBuf,
}

#[derive(Clone, Debug)]
#[derive(Clone, Debug, PartialEq)]
/// Wrapper around `Pox4SignatureTopic` to implement `ValueEnum`
pub struct StackingSignatureMethod(Pox4SignatureTopic);

Expand All @@ -150,22 +150,27 @@ impl ValueEnum for StackingSignatureMethod {
Self(Pox4SignatureTopic::StackStx),
Self(Pox4SignatureTopic::StackExtend),
Self(Pox4SignatureTopic::AggregationCommit),
Self(Pox4SignatureTopic::AggregationIncrease),
Self(Pox4SignatureTopic::StackIncrease),
]
}

fn from_str(input: &str, _ignore_case: bool) -> Result<Self, String> {
let topic = match input {
"stack-stx" => Pox4SignatureTopic::StackStx,
"stack-extend" => Pox4SignatureTopic::StackExtend,
"aggregation-commit" => Pox4SignatureTopic::AggregationCommit,
"agg-commit" => Pox4SignatureTopic::AggregationCommit,
_ => return Err(format!("Invalid topic: {}", input)),
"aggregation-increase" => Pox4SignatureTopic::AggregationIncrease,
method => match Pox4SignatureTopic::lookup_by_name(method) {
Some(topic) => topic,
None => {
return Err(format!("Invalid topic: {}", input));
}
},
};
Ok(topic.into())
}
}

#[derive(Parser, Debug, Clone)]
#[derive(Parser, Debug, Clone, PartialEq)]
/// Arguments for the generate-stacking-signature command
pub struct GenerateStackingSignatureArgs {
/// BTC address used to receive rewards
Expand Down Expand Up @@ -404,4 +409,40 @@ mod tests {
_ => panic!("Invalid parsed address"),
}
}

#[test]
fn test_parse_stacking_method() {
assert_eq!(
StackingSignatureMethod::from_str("agg-increase", true).unwrap(),
Pox4SignatureTopic::AggregationIncrease.into()
);
assert_eq!(
StackingSignatureMethod::from_str("agg-commit", true).unwrap(),
Pox4SignatureTopic::AggregationCommit.into()
);
assert_eq!(
StackingSignatureMethod::from_str("stack-increase", true).unwrap(),
Pox4SignatureTopic::StackIncrease.into()
);
assert_eq!(
StackingSignatureMethod::from_str("stack-extend", true).unwrap(),
Pox4SignatureTopic::StackExtend.into()
);
assert_eq!(
StackingSignatureMethod::from_str("stack-stx", true).unwrap(),
Pox4SignatureTopic::StackStx.into()
);

// These don't exactly match the enum, but are accepted if passed as
// CLI args

assert_eq!(
StackingSignatureMethod::from_str("aggregation-increase", true).unwrap(),
Pox4SignatureTopic::AggregationIncrease.into()
);
assert_eq!(
StackingSignatureMethod::from_str("aggregation-commit", true).unwrap(),
Pox4SignatureTopic::AggregationCommit.into()
);
}
}

0 comments on commit 0904dec

Please sign in to comment.