Skip to content

Commit 68dce12

Browse files
author
Bengt Lofgren
committed
clippy auto edits
1 parent 30f2e16 commit 68dce12

24 files changed

+251
-326
lines changed

solana/Cargo.lock

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

solana/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ cast_possible_wrap = "deny"
8383
cast_precision_loss = "deny"
8484
cast_sign_loss = "deny"
8585
eq_op = "deny"
86-
expect_used = "allow" # TODO: Change this back once we get there
86+
expect_used = "deny"
8787
float_cmp = "deny"
8888
integer_division = "deny"
8989
large_futures = "deny"

solana/clippy.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,7 @@ disallowed-methods = [
44
{ path = "std::option::Option::map_or", reason = "prefer `map_or_else` for lazy evaluation" },
55
{ path = "std::option::Option::ok_or", reason = "prefer `ok_or_else` for lazy evaluation" },
66
{ path = "std::option::Option::unwrap_or", reason = "prefer `unwrap_or_else` for lazy evaluation" },
7-
]
7+
]
8+
9+
[expect_used]
10+
ignore-tests = true

solana/programs/matching-engine/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ tracing = "0.1"
6161
tracing-subscriber = { version = "0.3", features = ["env-filter"] }
6262
tracing-log = "0.2.0"
6363
once_cell = "1.8"
64+
anyhow = "1.0.97"
6465
wormhole-svm-shim.workspace = true
6566
wormhole-svm-definitions.workspace = true
6667

solana/programs/matching-engine/tests/integration_tests.rs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -119,15 +119,10 @@ pub async fn test_post_message_shims() {
119119
None,
120120
)
121121
.await;
122-
let actors = testing_context.testing_actors;
122+
let actors = &testing_context.testing_actors;
123123
let emitter_signer = actors.owner.keypair();
124124
let payer_signer = actors.solvers[0].keypair();
125-
set_up_post_message_transaction_test(
126-
&testing_context.test_context,
127-
&payer_signer,
128-
&emitter_signer,
129-
)
130-
.await;
125+
set_up_post_message_transaction_test(&testing_context, &payer_signer, &emitter_signer).await;
131126
}
132127

133128
#[tokio::test]
@@ -222,13 +217,14 @@ pub async fn test_approve_usdc() {
222217
// TODO: Create an issue based on this bug. So this function will transfer the ownership of whatever the guardian signatures signer is set to to the verify shim program. This means that the argument to this function MUST be ephemeral and cannot be used until the close signatures instruction has been executed.
223218
let (_guardian_set_pubkey, _guardian_signatures_pubkey, _guardian_set_bump) =
224219
shimful::verify_shim::create_guardian_signatures(
225-
&testing_context.test_context,
220+
&testing_context,
226221
&actors.owner.keypair(),
227222
&vaa_data,
228223
&CORE_BRIDGE_PROGRAM_ID,
229224
None,
230225
)
231-
.await;
226+
.await
227+
.expect("Failed to create guardian signatures");
232228

233229
println!("Solver USDC balance: {:?}", usdc_balance);
234230
let solver_token_account_address = solver.token_account_address().unwrap();

solana/programs/matching-engine/tests/shimful/fast_market_order_shim.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -141,9 +141,7 @@ pub async fn close_fast_market_order_fallback(
141141
expected_error: Option<&ExpectedError>,
142142
) {
143143
let program_id = &testing_context.get_matching_engine_program_id();
144-
let test_ctx = &testing_context.test_context;
145-
let recent_blockhash = test_ctx
146-
.borrow_mut()
144+
let recent_blockhash = testing_context
147145
.get_new_latest_blockhash()
148146
.await
149147
.expect("Failed to get new blockhash");
@@ -211,7 +209,7 @@ pub fn create_fast_market_order_state_from_vaa_data(
211209
min_amount_out: order.min_amount_out,
212210
deadline: order.deadline,
213211
target_chain: order.target_chain,
214-
redeemer_message_length: order.redeemer_message.len() as u16,
212+
redeemer_message_length: u16::try_from(order.redeemer_message.len()).unwrap(),
215213
redeemer: order.redeemer,
216214
sender: order.sender,
217215
refund_address: order.refund_address,

solana/programs/matching-engine/tests/shimful/post_message.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::utils::constants::*;
1+
use crate::utils::{constants::*, setup::TestingContext};
22
use solana_program_test::ProgramTestContext;
33
use solana_sdk::{
44
compute_budget::ComputeBudgetInstruction,
@@ -36,7 +36,7 @@ impl BumpCosts {
3636
}
3737

3838
fn bump_cu_cost(bump: u8) -> u64 {
39-
1_500 * (255 - u64::from(bump))
39+
1_500 * (255_u64.saturating_sub(u64::from(bump)))
4040
}
4141
}
4242

@@ -50,12 +50,11 @@ impl BumpCosts {
5050
/// * `payer_signer` - The payer signer keypair
5151
/// * `emitter_signer` - The emitter signer keypair
5252
pub async fn set_up_post_message_transaction_test(
53-
test_ctx: &Rc<RefCell<ProgramTestContext>>,
53+
testing_context: &TestingContext,
5454
payer_signer: &Rc<Keypair>,
5555
emitter_signer: &Rc<Keypair>,
5656
) {
57-
let recent_blockhash = test_ctx
58-
.borrow_mut()
57+
let recent_blockhash = testing_context
5958
.get_new_latest_blockhash()
6059
.await
6160
.expect("Could not get last blockhash");
@@ -66,12 +65,14 @@ pub async fn set_up_post_message_transaction_test(
6665
recent_blockhash,
6766
);
6867
let details = {
69-
let out = test_ctx
70-
.borrow_mut()
68+
let test_ctx = &testing_context.test_context;
69+
let mut ctx = test_ctx.borrow_mut();
70+
let out = ctx
7171
.banks_client
7272
.simulate_transaction(transaction)
7373
.await
7474
.unwrap();
75+
drop(ctx);
7576
assert!(out.result.clone().unwrap().is_ok(), "{:?}", out.result);
7677
out.simulation_details.unwrap()
7778
};

solana/programs/matching-engine/tests/shimful/shims_make_offer.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ use std::rc::Rc;
3636
///
3737
/// * The expected error is reached
3838
/// * If successful, the solver's USDC balance should decrease by the offer price
39+
#[allow(clippy::too_many_arguments)]
3940
pub async fn place_initial_offer_fallback(
4041
testing_context: &TestingContext,
4142
payer_signer: &Rc<Keypair>,
@@ -143,7 +144,8 @@ pub async fn place_initial_offer_fallback(
143144
offer_price,
144145
},
145146
};
146-
let new_auction_state = utils::auction::AuctionState::Active(new_active_auction_state);
147+
let new_auction_state =
148+
utils::auction::AuctionState::Active(Box::new(new_active_auction_state));
147149
Some(InitialOfferPlacedState {
148150
auction_state: new_auction_state,
149151
})

solana/programs/matching-engine/tests/shimful/verify_shim.rs

Lines changed: 18 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
1-
use crate::utils;
21
use crate::utils::constants::*;
2+
use crate::utils::{self, setup::TestingContext};
33
use anchor_lang::prelude::*;
4-
use solana_program_test::ProgramTestContext;
4+
use anyhow::Result as AnyhowResult;
5+
56
use solana_sdk::{
67
compute_budget::ComputeBudgetInstruction,
78
hash::Hash,
89
message::{v0::Message, VersionedMessage},
910
signature::{Keypair, Signer},
1011
transaction::VersionedTransaction,
1112
};
12-
use std::cell::RefCell;
13+
1314
use std::rc::Rc;
1415
use std::str::FromStr;
1516
use wormhole_svm_definitions::GUARDIAN_SIGNATURE_LENGTH;
@@ -31,36 +32,34 @@ use wormhole_svm_shim::verify_vaa;
3132
///
3233
/// * `(guardian_set_pubkey, guardian_signatures_pubkey, guardian_set_bump)` - The guardian set pubkey, the guardian signatures pubkey and the guardian set bump
3334
pub async fn create_guardian_signatures(
34-
test_ctx: &Rc<RefCell<ProgramTestContext>>,
35+
testing_context: &TestingContext,
3536
payer_signer: &Rc<Keypair>,
3637
vaa_data: &utils::vaa::PostedVaaData,
3738
wormhole_program_id: &Pubkey,
3839
guardian_signature_signer: Option<&Rc<Keypair>>,
39-
) -> (Pubkey, Pubkey, u8) {
40+
) -> AnyhowResult<(Pubkey, Pubkey, u8)> {
4041
let new_keypair = Rc::new(Keypair::new());
41-
let guardian_signature_signer = guardian_signature_signer.unwrap_or(&new_keypair);
42+
let guardian_signature_signer = guardian_signature_signer.unwrap_or_else(|| &new_keypair);
4243
let (guardian_set_pubkey, guardian_set_bump) =
4344
wormhole_svm_definitions::find_guardian_set_address(
4445
0_u32.to_be_bytes(),
45-
&wormhole_program_id,
46+
wormhole_program_id,
4647
);
47-
let guardian_secret_key = secp256k1::SecretKey::from_str(GUARDIAN_SECRET_KEY)
48-
.expect("Failed to parse guardian secret key");
48+
let guardian_secret_key = secp256k1::SecretKey::from_str(GUARDIAN_SECRET_KEY)?;
4949
let guardian_set_signatures = vaa_data.sign_with_guardian_key(&guardian_secret_key, 0);
5050
let guardian_signatures_pubkey = add_guardian_signatures_account(
51-
test_ctx,
51+
testing_context,
5252
payer_signer,
5353
guardian_signature_signer,
5454
vec![guardian_set_signatures],
5555
0,
5656
)
57-
.await
58-
.expect("Failed to post guardian signatures");
59-
(
57+
.await?;
58+
Ok((
6059
guardian_set_pubkey,
6160
guardian_signatures_pubkey,
6261
guardian_set_bump,
63-
)
62+
))
6463
}
6564

6665
/// Add a guardian signatures account
@@ -79,31 +78,22 @@ pub async fn create_guardian_signatures(
7978
///
8079
/// * `guardian_signatures_pubkey` - The guardian signatures pubkey
8180
async fn add_guardian_signatures_account(
82-
test_ctx: &Rc<RefCell<ProgramTestContext>>,
81+
testing_context: &TestingContext,
8382
payer_signer: &Rc<Keypair>,
8483
signatures_signer: &Rc<Keypair>,
8584
guardian_signatures: Vec<[u8; GUARDIAN_SIGNATURE_LENGTH]>,
8685
guardian_set_index: u32,
87-
) -> Result<Pubkey> {
88-
let new_blockhash = test_ctx
89-
.borrow_mut()
90-
.get_new_latest_blockhash()
91-
.await
92-
.expect("Failed to get new blockhash");
86+
) -> AnyhowResult<Pubkey> {
87+
let new_blockhash = testing_context.get_new_latest_blockhash().await?;
9388
let transaction = post_signatures_transaction(
9489
payer_signer,
9590
signatures_signer,
9691
guardian_set_index,
97-
guardian_signatures.len() as u8,
92+
u8::try_from(guardian_signatures.len())?,
9893
&guardian_signatures,
9994
new_blockhash,
10095
);
101-
test_ctx
102-
.borrow_mut()
103-
.banks_client
104-
.process_transaction(transaction)
105-
.await
106-
.expect("Failed to add guardian signatures account");
96+
testing_context.process_transaction(transaction).await?;
10797

10898
Ok(signatures_signer.pubkey())
10999
}

solana/programs/matching-engine/tests/shimless/initialize.rs

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@ pub struct InitializeFixture {
3232

3333
impl InitializeFixture {
3434
pub fn get_custodian_address(&self) -> Pubkey {
35-
self.addresses.custodian_address.clone()
35+
self.addresses.custodian_address
3636
}
3737

3838
pub fn get_auction_config_address(&self) -> Pubkey {
39-
self.addresses.auction_config_address.clone()
39+
self.addresses.auction_config_address
4040
}
4141
}
4242

@@ -121,17 +121,17 @@ impl Default for AuctionParametersConfig {
121121
}
122122
}
123123

124-
impl Into<AuctionParameters> for AuctionParametersConfig {
125-
fn into(self) -> AuctionParameters {
124+
impl From<AuctionParametersConfig> for AuctionParameters {
125+
fn from(val: AuctionParametersConfig) -> Self {
126126
AuctionParameters {
127-
user_penalty_reward_bps: self.user_penalty_reward_bps,
128-
initial_penalty_bps: self.initial_penalty_bps,
129-
duration: self.duration,
130-
grace_period: self.grace_period,
131-
penalty_period: self.penalty_period,
132-
min_offer_delta_bps: self.min_offer_delta_bps,
133-
security_deposit_base: self.security_deposit_base,
134-
security_deposit_bps: self.security_deposit_bps,
127+
user_penalty_reward_bps: val.user_penalty_reward_bps,
128+
initial_penalty_bps: val.initial_penalty_bps,
129+
duration: val.duration,
130+
grace_period: val.grace_period,
131+
penalty_period: val.penalty_period,
132+
min_offer_delta_bps: val.min_offer_delta_bps,
133+
security_deposit_base: val.security_deposit_base,
134+
security_deposit_bps: val.security_deposit_bps,
135135
}
136136
}
137137
}
@@ -199,11 +199,10 @@ pub async fn initialize_program(
199199
// Create and sign transaction
200200
let mut transaction =
201201
Transaction::new_with_payer(&[instruction], Some(&test_context.borrow().payer.pubkey()));
202-
let new_blockhash = test_context
203-
.borrow_mut()
202+
let new_blockhash = testing_context
204203
.get_new_latest_blockhash()
205204
.await
206-
.expect("Failed to get new blockhash");
205+
.expect("Could not get new blockhash");
207206
transaction.sign(
208207
&[
209208
&test_context.borrow().payer,
@@ -213,19 +212,15 @@ pub async fn initialize_program(
213212
);
214213

215214
// Process transaction
216-
let versioned_transaction = VersionedTransaction::try_from(transaction)
217-
.expect("Failed to convert transaction to versioned transaction");
218-
215+
let versioned_transaction = VersionedTransaction::from(transaction);
219216
testing_context
220217
.execute_and_verify_transaction(versioned_transaction, expected_error)
221218
.await;
222219

223220
if expected_error.is_none() {
224221
// Verify the results
225-
let custodian_account = test_context
226-
.borrow_mut()
227-
.banks_client
228-
.get_account(custodian.clone())
222+
let custodian_account = testing_context
223+
.get_account(custodian)
229224
.await
230225
.expect("Failed to get custodian account")
231226
.expect("Custodian account not found");

0 commit comments

Comments
 (0)