Skip to content

Commit

Permalink
Merge pull request #5723 from jbencin/chore/clippy-format-strings
Browse files Browse the repository at this point in the history
chore: Apply Clippy format string lints
  • Loading branch information
jbencin authored Jan 22, 2025
2 parents e0d3f3c + 02841df commit a077937
Show file tree
Hide file tree
Showing 26 changed files with 97 additions and 174 deletions.
7 changes: 1 addition & 6 deletions stacks-common/src/types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -700,12 +700,7 @@ impl Address for StacksAddress {
}

fn from_string(s: &str) -> Option<StacksAddress> {
let (version, bytes) = match c32_address_decode(s) {
Ok((v, b)) => (v, b),
Err(_) => {
return None;
}
};
let (version, bytes) = c32_address_decode(s).ok()?;

if bytes.len() != 20 {
return None;
Expand Down
2 changes: 1 addition & 1 deletion stackslib/src/burnchains/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1620,7 +1620,7 @@ impl BurnchainDB {
conn,
"SELECT affirmation_map FROM overrides WHERE reward_cycle = ?1",
params![u64_to_sql(reward_cycle)?],
|| format!("BUG: more than one override affirmation map for the same reward cycle"),
|| "BUG: more than one override affirmation map for the same reward cycle".to_string(),
)?;
if let Some(am) = &am_opt {
assert_eq!((am.len() + 1) as u64, reward_cycle);
Expand Down
2 changes: 1 addition & 1 deletion stackslib/src/chainstate/burn/db/sortdb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -940,7 +940,7 @@ impl db_keys {
}

pub fn pox_reward_set_payouts_key() -> String {
format!("sortition_db::reward_set::payouts")
"sortition_db::reward_set::payouts".to_string()
}

pub fn pox_reward_set_payouts_value(addrs: Vec<PoxAddress>, payout_per_addr: u128) -> String {
Expand Down
4 changes: 1 addition & 3 deletions stackslib/src/chainstate/stacks/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -383,9 +383,7 @@ impl StacksMessageCodec for OrderIndependentMultisigSpendingCondition {

// must all be compressed if we're using P2WSH
if have_uncompressed && hash_mode == OrderIndependentMultisigHashMode::P2WSH {
let msg = format!(
"Failed to deserialize order independent multisig spending condition: expected compressed keys only"
);
let msg = "Failed to deserialize order independent multisig spending condition: expected compressed keys only".to_string();
test_debug!("{msg}");
return Err(codec_error::DeserializeError(msg));
}
Expand Down
5 changes: 1 addition & 4 deletions stackslib/src/chainstate/stacks/boot/docs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,10 +160,7 @@ pub fn make_json_boot_contracts_reference() -> String {
&contract_supporting_docs,
ClarityVersion::Clarity1,
);
format!(
"{}",
serde_json::to_string(&api_out).expect("Failed to serialize documentation")
)
serde_json::to_string(&api_out).expect("Failed to serialize documentation")
}

#[cfg(test)]
Expand Down
45 changes: 13 additions & 32 deletions stackslib/src/chainstate/stacks/boot/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -280,9 +280,7 @@ impl RewardSet {
/// If there are no reward set signers, a ChainstateError is returned.
pub fn total_signing_weight(&self) -> Result<u32, String> {
let Some(ref reward_set_signers) = self.signers else {
return Err(format!(
"Unable to calculate total weight - No signers in reward set"
));
return Err("Unable to calculate total weight - No signers in reward set".to_string());
};
Ok(reward_set_signers
.iter()
Expand Down Expand Up @@ -630,17 +628,12 @@ impl StacksChainState {
sortdb: &SortitionDB,
stacks_block_id: &StacksBlockId,
) -> Result<u128, Error> {
self.eval_boot_code_read_only(
sortdb,
stacks_block_id,
"pox",
&format!("(get-stacking-minimum)"),
)
.map(|value| {
value
.expect_u128()
.expect("FATAL: unexpected PoX structure")
})
self.eval_boot_code_read_only(sortdb, stacks_block_id, "pox", "(get-stacking-minimum)")
.map(|value| {
value
.expect_u128()
.expect("FATAL: unexpected PoX structure")
})
}

pub fn get_total_ustx_stacked(
Expand Down Expand Up @@ -1743,11 +1736,7 @@ pub mod test {
}

pub fn get_balance(peer: &mut TestPeer, addr: &PrincipalData) -> u128 {
let value = eval_at_tip(
peer,
"pox",
&format!("(stx-get-balance '{})", addr.to_string()),
);
let value = eval_at_tip(peer, "pox", &format!("(stx-get-balance '{addr})"));
if let Value::UInt(balance) = value {
return balance;
} else {
Expand All @@ -1759,11 +1748,7 @@ pub mod test {
peer: &mut TestPeer,
addr: &PrincipalData,
) -> Option<(PoxAddress, u128, u128, Vec<u128>)> {
let value_opt = eval_at_tip(
peer,
"pox-4",
&format!("(get-stacker-info '{})", addr.to_string()),
);
let value_opt = eval_at_tip(peer, "pox-4", &format!("(get-stacker-info '{addr})"));
let data = if let Some(d) = value_opt.expect_optional().unwrap() {
d
} else {
Expand Down Expand Up @@ -1812,11 +1797,7 @@ pub mod test {
peer: &mut TestPeer,
addr: &PrincipalData,
) -> Option<(u128, PoxAddress, u128, u128)> {
let value_opt = eval_at_tip(
peer,
"pox",
&format!("(get-stacker-info '{})", addr.to_string()),
);
let value_opt = eval_at_tip(peer, "pox", &format!("(get-stacker-info '{addr})"));
let data = if let Some(d) = value_opt.expect_optional().unwrap() {
d
} else {
Expand Down Expand Up @@ -4267,7 +4248,7 @@ pub mod test {
(var-set test-result
(match result ok_value -1 err_value err_value))
(var-set test-run true))
", boot_code_test_addr().to_string()));
", boot_code_test_addr()));

block_txs.push(bob_test_tx);

Expand All @@ -4281,7 +4262,7 @@ pub mod test {
(var-set test-result
(match result ok_value -1 err_value err_value))
(var-set test-run true))
", boot_code_test_addr().to_string()));
", boot_code_test_addr()));

block_txs.push(alice_test_tx);

Expand All @@ -4295,7 +4276,7 @@ pub mod test {
(var-set test-result
(match result ok_value -1 err_value err_value))
(var-set test-run true))
", boot_code_test_addr().to_string()));
", boot_code_test_addr()));

block_txs.push(charlie_test_tx);
}
Expand Down
24 changes: 10 additions & 14 deletions stackslib/src/chainstate/stacks/boot/pox_2_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -281,26 +281,22 @@ pub fn check_pox_print_event(
match inner_tuple.data_map.get(inner_key) {
Some(v) => {
if v != &inner_val {
wrong.push((
format!("{}", &inner_key),
format!("{}", v),
format!("{}", &inner_val),
));
wrong.push((inner_key.to_string(), v.to_string(), inner_val.to_string()));
}
}
None => {
missing.push(format!("{}", &inner_key));
missing.push(inner_key.to_string());
}
}
// assert_eq!(inner_tuple.data_map.get(inner_key), Some(&inner_val));
}
if !missing.is_empty() || !wrong.is_empty() {
eprintln!("missing:\n{:#?}", &missing);
eprintln!("wrong:\n{:#?}", &wrong);
eprintln!("missing:\n{missing:#?}");
eprintln!("wrong:\n{wrong:#?}");
assert!(false);
}
} else {
error!("unexpected event type: {:?}", event);
error!("unexpected event type: {event:?}");
panic!("Unexpected transaction event type.")
}
}
Expand Down Expand Up @@ -1466,15 +1462,15 @@ fn delegate_stack_increase() {

assert_eq!(first_v2_cycle, EXPECTED_FIRST_V2_CYCLE);

eprintln!("First v2 cycle = {}", first_v2_cycle);
eprintln!("First v2 cycle = {first_v2_cycle}");

let epochs = StacksEpoch::all(0, 0, EMPTY_SORTITIONS as u64 + 10);

let observer = TestEventObserver::new();

let (mut peer, mut keys) = instantiate_pox_peer_with_epoch(
&burnchain,
&format!("pox_2_delegate_stack_increase"),
"pox_2_delegate_stack_increase",
Some(epochs.clone()),
Some(&observer),
);
Expand Down Expand Up @@ -1830,7 +1826,7 @@ fn stack_increase() {

let (mut peer, mut keys) = instantiate_pox_peer_with_epoch(
&burnchain,
&format!("test_simple_pox_2_increase"),
"test_simple_pox_2_increase",
Some(epochs.clone()),
Some(&observer),
);
Expand Down Expand Up @@ -4509,7 +4505,7 @@ fn stack_aggregation_increase() {

let (mut peer, mut keys) = instantiate_pox_peer_with_epoch(
&burnchain,
&format!("pox_2_stack_aggregation_increase"),
"pox_2_stack_aggregation_increase",
Some(epochs.clone()),
Some(&observer),
);
Expand Down Expand Up @@ -4959,7 +4955,7 @@ fn stack_in_both_pox1_and_pox2() {

let (mut peer, mut keys) = instantiate_pox_peer_with_epoch(
&burnchain,
&format!("stack_in_both_pox1_and_pox2"),
"stack_in_both_pox1_and_pox2",
Some(epochs.clone()),
Some(&observer),
);
Expand Down
2 changes: 1 addition & 1 deletion stackslib/src/chainstate/stacks/db/blocks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ impl StacksChainState {

let _ = StacksChainState::mkdirs(&block_path)?;

block_path.push(format!("{}", to_hex(block_hash_bytes)));
block_path.push(to_hex(block_hash_bytes).to_string());
let blocks_path_str = block_path
.to_str()
.ok_or_else(|| Error::DBError(db_error::ParseError))?
Expand Down
12 changes: 6 additions & 6 deletions stackslib/src/chainstate/stacks/db/transactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ impl StacksTransactionReceipt {
span.start_line, span.start_column, check_error.diagnostic.message
)
} else {
format!("{}", check_error.diagnostic.message)
check_error.diagnostic.message.to_string()
}
}
clarity_error::Parse(ref parse_error) => {
Expand All @@ -222,7 +222,7 @@ impl StacksTransactionReceipt {
span.start_line, span.start_column, parse_error.diagnostic.message
)
} else {
format!("{}", parse_error.diagnostic.message)
parse_error.diagnostic.message.to_string()
}
}
_ => error.to_string(),
Expand Down Expand Up @@ -980,14 +980,14 @@ impl StacksChainState {
// post-conditions are not allowed for this variant, since they're non-sensical.
// Their presence in this variant makes the transaction invalid.
if !tx.post_conditions.is_empty() {
let msg = format!("Invalid Stacks transaction: TokenTransfer transactions do not support post-conditions");
let msg = "Invalid Stacks transaction: TokenTransfer transactions do not support post-conditions".to_string();
info!("{}", &msg; "txid" => %tx.txid());

return Err(Error::InvalidStacksTransaction(msg, false));
}

if *addr == origin_account.principal {
let msg = format!("Invalid TokenTransfer: address tried to send to itself");
let msg = "Invalid TokenTransfer: address tried to send to itself".to_string();
info!("{}", &msg; "txid" => %tx.txid());
return Err(Error::InvalidStacksTransaction(msg, false));
}
Expand Down Expand Up @@ -1392,7 +1392,7 @@ impl StacksChainState {
// post-conditions are not allowed for this variant, since they're non-sensical.
// Their presence in this variant makes the transaction invalid.
if !tx.post_conditions.is_empty() {
let msg = format!("Invalid Stacks transaction: PoisonMicroblock transactions do not support post-conditions");
let msg = "Invalid Stacks transaction: PoisonMicroblock transactions do not support post-conditions".to_string();
info!("{}", &msg);

return Err(Error::InvalidStacksTransaction(msg, false));
Expand Down Expand Up @@ -1424,7 +1424,7 @@ impl StacksChainState {
// post-conditions are not allowed for this variant, since they're non-sensical.
// Their presence in this variant makes the transaction invalid.
if !tx.post_conditions.is_empty() {
let msg = format!("Invalid Stacks transaction: TenureChange transactions do not support post-conditions");
let msg = "Invalid Stacks transaction: TenureChange transactions do not support post-conditions".to_string();
info!("{msg}");

return Err(Error::InvalidStacksTransaction(msg, false));
Expand Down
3 changes: 1 addition & 2 deletions stackslib/src/chainstate/stacks/miner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2585,8 +2585,7 @@ impl StacksBlockBuilder {
event_observer: Option<&dyn MemPoolEventDispatcher>,
burnchain: &Burnchain,
) -> Result<(StacksBlock, ExecutionCost, u64), Error> {
if let TransactionPayload::Coinbase(..) = coinbase_tx.payload {
} else {
if !matches!(coinbase_tx.payload, TransactionPayload::Coinbase(..)) {
return Err(Error::MemPoolError(
"Not a coinbase transaction".to_string(),
));
Expand Down
6 changes: 3 additions & 3 deletions stackslib/src/clarity_cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -515,21 +515,21 @@ impl CLIHeadersDB {
"CREATE TABLE IF NOT EXISTS cli_chain_tips(id INTEGER PRIMARY KEY AUTOINCREMENT, block_hash TEXT UNIQUE NOT NULL);",
NO_PARAMS
),
&format!("FATAL: failed to create 'cli_chain_tips' table"),
"FATAL: failed to create 'cli_chain_tips' table",
);

friendly_expect(
tx.execute(
"CREATE TABLE IF NOT EXISTS cli_config(testnet BOOLEAN NOT NULL);",
NO_PARAMS,
),
&format!("FATAL: failed to create 'cli_config' table"),
"FATAL: failed to create 'cli_config' table",
);

if !mainnet {
friendly_expect(
tx.execute("INSERT INTO cli_config (testnet) VALUES (?1)", &[&true]),
&format!("FATAL: failed to set testnet flag"),
"FATAL: failed to set testnet flag",
);
}

Expand Down
6 changes: 2 additions & 4 deletions stackslib/src/clarity_vm/database/marf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -294,10 +294,8 @@ impl ReadOnlyMarfStore<'_> {
}

pub fn trie_exists_for_block(&mut self, bhh: &StacksBlockId) -> Result<bool, DatabaseError> {
self.marf.with_conn(|conn| match conn.has_block(bhh) {
Ok(res) => Ok(res),
Err(e) => Err(DatabaseError::IndexError(e)),
})
self.marf
.with_conn(|conn| conn.has_block(bhh).map_err(DatabaseError::IndexError))
}
}

Expand Down
10 changes: 4 additions & 6 deletions stackslib/src/clarity_vm/tests/contracts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1322,13 +1322,12 @@ fn test_block_heights_across_versions_traits_3_from_2() {
(contract-call? get-trait get-int)
)
"#;
let contract_e3c3 = format!(
r#"
let contract_e3c3 = r#"
(define-public (get-int)
(ok (+ stacks-block-height tenure-height))
)
"#
);
.to_string();

sim.execute_next_block(|_env| {});

Expand Down Expand Up @@ -1465,14 +1464,13 @@ fn test_block_heights_across_versions_traits_2_from_3() {
(ok (+ stacks-block-height (var-get tenure-height)))
)
"#;
let contract_e3c3 = format!(
r#"
let contract_e3c3 = r#"
(define-trait getter ((get-int () (response uint uint))))
(define-public (get-it (get-trait <getter>))
(contract-call? get-trait get-int)
)
"#
);
.to_string();

sim.execute_next_block(|_env| {});

Expand Down
8 changes: 4 additions & 4 deletions stackslib/src/clarity_vm/tests/forking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ fn test_at_block_mutations(#[case] version: ClarityVersion, #[case] epoch: Stack

{
let mut env = owned_env.get_exec_environment(None, None, &placeholder_context);
let command = format!("(var-get datum)");
let value = env.eval_read_only(&c, &command).unwrap();
let command = "(var-get datum)";
let value = env.eval_read_only(&c, command).unwrap();
assert_eq!(value, Value::Int(expected_value));
}

Expand Down Expand Up @@ -168,8 +168,8 @@ fn test_at_block_good(#[case] version: ClarityVersion, #[case] epoch: StacksEpoc

{
let mut env = owned_env.get_exec_environment(None, None, &placeholder_context);
let command = format!("(var-get datum)");
let value = env.eval_read_only(&c, &command).unwrap();
let command = "(var-get datum)";
let value = env.eval_read_only(&c, command).unwrap();
assert_eq!(value, Value::Int(expected_value));
}

Expand Down
Loading

0 comments on commit a077937

Please sign in to comment.