Skip to content

Commit a2a7924

Browse files
committed
chore: apply clippy to tests
1 parent 17c1363 commit a2a7924

22 files changed

+105
-102
lines changed

program/rust/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Allow non upper case globals from C
33
#![allow(non_upper_case_globals)]
44
#![allow(incomplete_features)]
5+
#![allow(clippy::bool_assert_comparison)]
56
#![feature(adt_const_params)]
67

78
mod c_oracle_header;

program/rust/src/tests/pyth_simulator.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ impl PythSimulator {
136136
.await
137137
.unwrap();
138138

139-
return result;
139+
result
140140
}
141141

142142

@@ -232,7 +232,7 @@ impl PythSimulator {
232232

233233
self.process_ix(
234234
instruction,
235-
&vec![&mapping_keypair, &product_keypair],
235+
&vec![mapping_keypair, &product_keypair],
236236
&copy_keypair(&self.genesis_keypair),
237237
)
238238
.await
@@ -258,7 +258,7 @@ impl PythSimulator {
258258

259259
self.process_ix(
260260
instruction,
261-
&vec![&mapping_keypair, &product_keypair],
261+
&vec![mapping_keypair, product_keypair],
262262
&copy_keypair(&self.genesis_keypair),
263263
)
264264
.await
@@ -290,7 +290,7 @@ impl PythSimulator {
290290

291291
self.process_ix(
292292
instruction,
293-
&vec![&product_keypair, &price_keypair],
293+
&vec![product_keypair, &price_keypair],
294294
&copy_keypair(&self.genesis_keypair),
295295
)
296296
.await
@@ -316,7 +316,7 @@ impl PythSimulator {
316316

317317
self.process_ix(
318318
instruction,
319-
&vec![&product_keypair, &price_keypair],
319+
&vec![product_keypair, price_keypair],
320320
&copy_keypair(&self.genesis_keypair),
321321
)
322322
.await
@@ -341,7 +341,7 @@ impl PythSimulator {
341341

342342
self.process_ix(
343343
instruction,
344-
&vec![&price_keypair],
344+
&vec![price_keypair],
345345
&copy_keypair(&self.genesis_keypair),
346346
)
347347
.await
@@ -387,7 +387,7 @@ impl PythSimulator {
387387
pub async fn get_account_data_as<T: Pod>(&mut self, key: Pubkey) -> Option<T> {
388388
self.get_account(key)
389389
.await
390-
.map(|x| load::<T>(&x.data).unwrap().clone())
390+
.map(|x| *load::<T>(&x.data).unwrap())
391391
}
392392

393393
pub fn is_owned_by_oracle(&self, account: &Account) -> bool {
@@ -405,10 +405,10 @@ impl PythSimulator {
405405
pub fn get_permissions_pubkey(&self) -> Pubkey {
406406
let (permissions_pubkey, __bump) =
407407
Pubkey::find_program_address(&[PERMISSIONS_SEED.as_bytes()], &self.program_id);
408-
return permissions_pubkey;
408+
permissions_pubkey
409409
}
410410
}
411411

412412
pub fn copy_keypair(keypair: &Keypair) -> Keypair {
413-
return Keypair::from_bytes(&keypair.to_bytes()).unwrap();
413+
Keypair::from_bytes(&keypair.to_bytes()).unwrap()
414414
}

program/rust/src/tests/test_add_mapping.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,14 @@ fn test_add_mapping() {
3535
let program_id = Pubkey::new_unique();
3636

3737
let mut funding_setup = AccountSetup::new_funding();
38-
let funding_account = funding_setup.to_account_info();
38+
let funding_account = funding_setup.as_account_info();
3939

4040
let mut curr_mapping_setup = AccountSetup::new::<MappingAccount>(&program_id);
41-
let cur_mapping = curr_mapping_setup.to_account_info();
41+
let cur_mapping = curr_mapping_setup.as_account_info();
4242
initialize_pyth_account_checked::<MappingAccount>(&cur_mapping, PC_VERSION).unwrap();
4343

4444
let mut next_mapping_setup = AccountSetup::new::<MappingAccount>(&program_id);
45-
let next_mapping = next_mapping_setup.to_account_info();
45+
let next_mapping = next_mapping_setup.as_account_info();
4646

4747
{
4848
let mut cur_mapping_data =

program/rust/src/tests/test_add_price.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,20 +42,20 @@ fn test_add_price() {
4242
let program_id = Pubkey::new_unique();
4343

4444
let mut funding_setup = AccountSetup::new_funding();
45-
let funding_account = funding_setup.to_account_info();
45+
let funding_account = funding_setup.as_account_info();
4646

4747
let mut mapping_setup = AccountSetup::new::<MappingAccount>(&program_id);
48-
let mapping_account = mapping_setup.to_account_info();
48+
let mapping_account = mapping_setup.as_account_info();
4949
initialize_pyth_account_checked::<MappingAccount>(&mapping_account, PC_VERSION).unwrap();
5050

5151
let mut product_setup = AccountSetup::new::<ProductAccount>(&program_id);
52-
let product_account = product_setup.to_account_info();
52+
let product_account = product_setup.as_account_info();
5353

5454
let mut price_setup = AccountSetup::new::<PriceAccount>(&program_id);
55-
let mut price_account = price_setup.to_account_info();
55+
let mut price_account = price_setup.as_account_info();
5656

5757
let mut price_setup_2 = AccountSetup::new::<PriceAccount>(&program_id);
58-
let price_account_2 = price_setup_2.to_account_info();
58+
let price_account_2 = price_setup_2.as_account_info();
5959

6060
assert!(process_instruction(
6161
&program_id,

program/rust/src/tests/test_add_product.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,17 +44,17 @@ fn test_add_product() {
4444
let program_id = Pubkey::new_unique();
4545

4646
let mut funding_setup = AccountSetup::new_funding();
47-
let funding_account = funding_setup.to_account_info();
47+
let funding_account = funding_setup.as_account_info();
4848

4949
let mut mapping_setup = AccountSetup::new::<MappingAccount>(&program_id);
50-
let mapping_account = mapping_setup.to_account_info();
50+
let mapping_account = mapping_setup.as_account_info();
5151
initialize_pyth_account_checked::<MappingAccount>(&mapping_account, PC_VERSION).unwrap();
5252

5353
let mut product_setup = AccountSetup::new::<ProductAccount>(&program_id);
54-
let product_account = product_setup.to_account_info();
54+
let product_account = product_setup.as_account_info();
5555

5656
let mut product_setup_2 = AccountSetup::new::<ProductAccount>(&program_id);
57-
let product_account_2 = product_setup_2.to_account_info();
57+
let product_account_2 = product_setup_2.as_account_info();
5858

5959
assert!(process_instruction(
6060
&program_id,

program/rust/src/tests/test_add_publisher.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,10 @@ fn test_add_publisher() {
4141
let mut instruction_data = bytes_of::<AddPublisherArgs>(&cmd);
4242

4343
let mut funding_setup = AccountSetup::new_funding();
44-
let funding_account = funding_setup.to_account_info();
44+
let funding_account = funding_setup.as_account_info();
4545

4646
let mut price_setup = AccountSetup::new::<PriceAccount>(&program_id);
47-
let price_account = price_setup.to_account_info();
47+
let price_account = price_setup.as_account_info();
4848
initialize_pyth_account_checked::<PriceAccount>(&price_account, PC_VERSION).unwrap();
4949

5050

program/rust/src/tests/test_del_product.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,12 @@ fn mapping_product_list_equals(mapping_data: &MappingAccount, expected: Vec<Pubk
8282
return false;
8383
}
8484

85+
#[allow(clippy::needless_range_loop)]
8586
for i in 0..expected.len() {
8687
if mapping_data.products_list[i] != expected[i] {
8788
return false;
8889
}
8990
}
9091

91-
return true;
92+
true
9293
}

program/rust/src/tests/test_del_publisher.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,10 @@ fn test_del_publisher() {
5252
hdr.publisher = publisher;
5353

5454
let mut funding_setup = AccountSetup::new_funding();
55-
let funding_account = funding_setup.to_account_info();
55+
let funding_account = funding_setup.as_account_info();
5656

5757
let mut price_setup = AccountSetup::new::<PriceAccount>(&program_id);
58-
let price_account = price_setup.to_account_info();
58+
let price_account = price_setup.as_account_info();
5959
initialize_pyth_account_checked::<PriceAccount>(&price_account, PC_VERSION).unwrap();
6060
{
6161
let mut price_data = load_checked::<PriceAccount>(&price_account, PC_VERSION).unwrap();

program/rust/src/tests/test_init_mapping.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,13 @@ fn test_init_mapping() {
3737
let program_id_2 = Pubkey::new_unique();
3838

3939
let mut funding_setup = AccountSetup::new_funding();
40-
let mut funding_account = funding_setup.to_account_info();
40+
let mut funding_account = funding_setup.as_account_info();
4141

4242
let mut attacker_setup = AccountSetup::new_funding();
43-
let attacker_account = attacker_setup.to_account_info();
43+
let attacker_account = attacker_setup.as_account_info();
4444

4545
let mut mapping_setup = AccountSetup::new::<MappingAccount>(&program_id);
46-
let mut mapping_account = mapping_setup.to_account_info();
46+
let mut mapping_account = mapping_setup.as_account_info();
4747

4848
assert!(process_instruction(
4949
&program_id,
@@ -162,7 +162,7 @@ fn test_init_mapping() {
162162
mapping_account.is_signer = false;
163163

164164
let mut permissions_setup = AccountSetup::new_permission(&program_id);
165-
let permissions_account = permissions_setup.to_account_info();
165+
let permissions_account = permissions_setup.as_account_info();
166166

167167
// Permissions account is unitialized
168168
assert_eq!(
@@ -201,7 +201,7 @@ fn test_init_mapping() {
201201

202202
// Attacker tries to impersonate permissions account
203203
let mut impersonating_permission_setup = AccountSetup::new::<PermissionAccount>(&program_id);
204-
let impersonating_permission_account = impersonating_permission_setup.to_account_info();
204+
let impersonating_permission_account = impersonating_permission_setup.as_account_info();
205205

206206
{
207207
let mut impersonating_permission_account_data =

program/rust/src/tests/test_init_price.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,10 @@ fn test_init_price() {
4343
let next_price = Pubkey::new_unique();
4444

4545
let mut funding_setup = AccountSetup::new_funding();
46-
let funding_account = funding_setup.to_account_info();
46+
let funding_account = funding_setup.as_account_info();
4747

4848
let mut price_setup = AccountSetup::new::<PriceAccount>(&program_id);
49-
let mut price_account = price_setup.to_account_info();
49+
let mut price_account = price_setup.as_account_info();
5050

5151
// Price account must be initialized
5252
assert_eq!(

0 commit comments

Comments
 (0)