Skip to content

Commit 9f4b56e

Browse files
committed
test: add coverage for mutants
1 parent 98d05a4 commit 9f4b56e

File tree

3 files changed

+38
-4
lines changed

3 files changed

+38
-4
lines changed

stacks-signer/src/client/stacks_client.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ use blockstack_lib::net::api::get_tenures_fork_info::{
3333
use blockstack_lib::net::api::getaccount::AccountEntryResponse;
3434
use blockstack_lib::net::api::getpoxinfo::RPCPoxInfoData;
3535
use blockstack_lib::net::api::getsortition::{SortitionInfo, RPC_SORTITION_INFO_PATH};
36-
use blockstack_lib::net::api::getstackers::GetStackersResponse;
36+
use blockstack_lib::net::api::getstackers::{GetStackersErrors, GetStackersResponse};
3737
use blockstack_lib::net::api::postblock::StacksBlockAcceptedData;
3838
use blockstack_lib::net::api::postblock_proposal::NakamotoBlockProposal;
3939
use blockstack_lib::net::api::postblock_v3;
@@ -541,7 +541,7 @@ impl StacksClient {
541541
warn!("Failed to parse the GetStackers error response: {e}");
542542
backoff::Error::permanent(e.into())
543543
})?;
544-
if error_data.err_type == "not_available_try_again" {
544+
if &error_data.err_type == GetStackersErrors::NOT_AVAILABLE_ERR_TYPE {
545545
return Err(backoff::Error::transient(ClientError::NoSortitionOnChain));
546546
} else {
547547
warn!("Got error response ({status}): {}", error_data.err_msg);

stackslib/src/net/api/getstackers.rs

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,13 @@ pub enum GetStackersErrors {
5757
}
5858

5959
impl GetStackersErrors {
60+
pub const NOT_AVAILABLE_ERR_TYPE: &'static str = "not_available_try_again";
61+
pub const OTHER_ERR_TYPE: &'static str = "other";
62+
6063
pub fn error_type_string(&self) -> &'static str {
6164
match self {
62-
GetStackersErrors::NotAvailableYet(_) => "not_available_try_again",
63-
GetStackersErrors::Other(_) => "other",
65+
Self::NotAvailableYet(_) => Self::NOT_AVAILABLE_ERR_TYPE,
66+
Self::Other(_) => Self::OTHER_ERR_TYPE,
6467
}
6568
}
6669
}
@@ -252,3 +255,31 @@ impl StacksHttpResponse {
252255
Ok(response)
253256
}
254257
}
258+
259+
#[cfg(test)]
260+
mod test {
261+
use super::GetStackersErrors;
262+
263+
#[test]
264+
// Test the formatting and error type strings of GetStackersErrors
265+
fn get_stackers_errors() {
266+
let not_available_err = GetStackersErrors::NotAvailableYet(
267+
crate::chainstate::coordinator::Error::PoXNotProcessedYet,
268+
);
269+
let other_err = GetStackersErrors::Other("foo".into());
270+
271+
assert_eq!(
272+
not_available_err.error_type_string(),
273+
GetStackersErrors::NOT_AVAILABLE_ERR_TYPE
274+
);
275+
assert_eq!(
276+
other_err.error_type_string(),
277+
GetStackersErrors::OTHER_ERR_TYPE
278+
);
279+
280+
assert!(not_available_err
281+
.to_string()
282+
.starts_with("Could not read reward set"));
283+
assert_eq!(other_err.to_string(), "foo".to_string());
284+
}
285+
}

testnet/stacks-node/src/nakamoto_node/sign_coordinator.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -631,6 +631,9 @@ impl SignCoordinator {
631631
/// This function begins by sending a `BlockProposal` message
632632
/// to the signers, and then waits for the signers to respond
633633
/// with their signatures.
634+
// Mutants skip here: this function is covered via integration tests,
635+
// which the mutation testing does not see.
636+
#[cfg_attr(test, mutants::skip)]
634637
pub fn begin_sign_v0(
635638
&mut self,
636639
block: &NakamotoBlock,

0 commit comments

Comments
 (0)