Skip to content

Commit

Permalink
Return UserError and convert that to RejectContext
Browse files Browse the repository at this point in the history
  • Loading branch information
mbjorkqvist committed Nov 8, 2024
1 parent b6379fc commit a6d6189
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions rs/state_machine_tests/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2120,7 +2120,7 @@ impl StateMachine {
fn build_sign_with_ecdsa_reply(
&self,
context: &SignWithThresholdContext,
) -> Result<SignWithECDSAReply, RejectContext> {
) -> Result<SignWithECDSAReply, UserError> {
assert!(context.is_ecdsa());

if let Some(SignatureSecretKey::EcdsaSecp256k1(k)) =
Expand All @@ -2136,8 +2136,8 @@ impl StateMachine {
.to_vec();
Ok(SignWithECDSAReply { signature })
} else {
Err(RejectContext::new(
RejectCode::CanisterError,
Err(UserError::new(
ErrorCode::CanisterRejectedMessage,
format!(
"Subnet {} does not hold threshold key {}.",
self.subnet_id,
Expand All @@ -2150,7 +2150,7 @@ impl StateMachine {
fn build_sign_with_schnorr_reply(
&self,
context: &SignWithThresholdContext,
) -> Result<SignWithSchnorrReply, RejectContext> {
) -> Result<SignWithSchnorrReply, UserError> {
assert!(context.is_schnorr());

let signature = match self.idkg_subnet_secret_keys.get(&context.key_id()) {
Expand All @@ -2174,8 +2174,8 @@ impl StateMachine {
dk.sign_message(&context.schnorr_args().message).to_vec()
}
_ => {
return Err(RejectContext::new(
RejectCode::CanisterError,
return Err(UserError::new(
ErrorCode::CanisterRejectedMessage,
format!(
"Subnet {} does not hold threshold key {}.",
self.subnet_id,
Expand Down Expand Up @@ -2203,10 +2203,10 @@ impl StateMachine {
MsgPayload::Data(response.encode()),
));
}
Err(reject_context) => {
Err(user_error) => {
payload.consensus_responses.push(ConsensusResponse::new(
*id,
MsgPayload::Reject(reject_context),
MsgPayload::Reject(RejectContext::from(user_error)),
));
}
}
Expand All @@ -2219,10 +2219,10 @@ impl StateMachine {
MsgPayload::Data(response.encode()),
));
}
Err(reject_context) => {
Err(user_error) => {
payload.consensus_responses.push(ConsensusResponse::new(
*id,
MsgPayload::Reject(reject_context),
MsgPayload::Reject(RejectContext::from(user_error)),
));
}
}
Expand Down

0 comments on commit a6d6189

Please sign in to comment.