Skip to content

Commit e0b6a17

Browse files
committed
fix clippy, add prelude
1 parent 027982f commit e0b6a17

24 files changed

+303
-311
lines changed

.github/workflows/ci.yml

Lines changed: 6 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,8 @@ jobs:
2121
with:
2222
components: rustfmt, clippy
2323

24-
- name: Cache dependencies
25-
uses: actions/cache@v3
26-
with:
27-
path: |
28-
~/.cargo/registry
29-
~/.cargo/git
30-
target
31-
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
32-
restore-keys: |
33-
${{ runner.os }}-cargo-
24+
- name: Rust Cache
25+
uses: Swatinem/rust-cache@v2
3426

3527
- name: Build
3628
run: cargo build --verbose
@@ -55,16 +47,8 @@ jobs:
5547
with:
5648
components: rustfmt
5749

58-
- name: Cache dependencies
59-
uses: actions/cache@v3
60-
with:
61-
path: |
62-
~/.cargo/registry
63-
~/.cargo/git
64-
target
65-
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
66-
restore-keys: |
67-
${{ runner.os }}-cargo-
50+
- name: Rust Cache
51+
uses: Swatinem/rust-cache@v2
6852

6953
- name: Check
7054
run: cargo check --verbose
@@ -94,16 +78,8 @@ jobs:
9478
with:
9579
components: clippy
9680

97-
- name: Cache dependencies
98-
uses: actions/cache@v3
99-
with:
100-
path: |
101-
~/.cargo/registry
102-
~/.cargo/git
103-
target
104-
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
105-
restore-keys: |
106-
${{ runner.os }}-cargo-
81+
- name: Rust Cache
82+
uses: Swatinem/rust-cache@v2
10783

10884
- name: Run clippy
10985
run: cargo clippy --all-targets --all-features -- -D warnings

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,17 @@
22
TestSVM
33
</h1>
44

5-
TestSVM is a blazing fast testing framework for Solana programs, written in Rust. Built on top of [LiteSVM](https://github.com/LiteSVM/litesvm), tests written using TestSVM are an order of magnitude faster than traditional `solana-test-validator` + JavaScript tests.
5+
### TestSVM is a blazing fast testing framework for Solana programs, written in Rust.
66

7-
Features include:
7+
TestSVM provides:
88

99
- Account labeling and logging, so you can easily track what `Pubkey` maps to what account.
1010
- Assertions for transaction results: assert that a transaction fails with a specific error, or that it succeeds.
1111
- Nicely formatted transaction logs with account labeling, so you know what accounts have issues in a transaction.
1212
- Type-safe utilities for validating state and loading it from the SVM.
1313

14+
Built on top of [LiteSVM](https://github.com/LiteSVM/litesvm), tests written using TestSVM are an order of magnitude faster than traditional `solana-test-validator` + JavaScript tests.
15+
1416
**Note: this is a work in progress and is subject to change.**
1517

1618
## Examples

crates/address-book/src/address_book.rs

Lines changed: 21 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -565,7 +565,7 @@ impl AddressBook {
565565
AddressRole::Custom(role) => format!(
566566
"{} {}",
567567
label.bright_white().bold(),
568-
format!("[{}]", role).dimmed()
568+
format!("[{role}]").dimmed()
569569
),
570570
},
571571
None => format!("{}", pubkey.to_string().bright_red()),
@@ -682,13 +682,10 @@ impl AddressBook {
682682
);
683683
for (pubkey, label, _reg) in programs {
684684
println!(
685-
" {} {}",
685+
" {} {:<30} {}",
686686
"•".to_string().bright_blue(),
687-
format!(
688-
"{:<30} {}",
689-
label.bright_blue().bold(),
690-
pubkey.to_string().dimmed()
691-
)
687+
label.bright_blue().bold(),
688+
pubkey.to_string().dimmed()
692689
);
693690
}
694691
}
@@ -701,13 +698,10 @@ impl AddressBook {
701698
);
702699
for (pubkey, label, _reg) in wallets {
703700
println!(
704-
" {} {}",
701+
" {} {:<30} {}",
705702
"•".to_string().bright_cyan(),
706-
format!(
707-
"{:<30} {}",
708-
label.bright_cyan().bold(),
709-
pubkey.to_string().dimmed()
710-
)
703+
label.bright_cyan().bold(),
704+
pubkey.to_string().dimmed()
711705
);
712706
}
713707
}
@@ -720,13 +714,10 @@ impl AddressBook {
720714
);
721715
for (pubkey, label, _reg) in mints {
722716
println!(
723-
" {} {}",
717+
" {} {:<30} {}",
724718
"•".to_string().bright_green(),
725-
format!(
726-
"{:<30} {}",
727-
label.bright_green().bold(),
728-
pubkey.to_string().dimmed()
729-
)
719+
label.bright_green().bold(),
720+
pubkey.to_string().dimmed()
730721
);
731722
}
732723
}
@@ -740,14 +731,11 @@ impl AddressBook {
740731
for (pubkey, label, reg) in pdas {
741732
if let AddressRole::Pda { seeds, .. } = &reg.role {
742733
println!(
743-
" {} {}",
734+
" {} {:<30} {} [{}]",
744735
"•".to_string().bright_magenta(),
745-
format!(
746-
"{:<30} {} {}",
747-
label.to_string().bright_magenta().bold(),
748-
pubkey.to_string().dimmed(),
749-
format!("[{}]", seeds.join(",")).dimmed()
750-
)
736+
label.to_string().bright_magenta().bold(),
737+
pubkey.to_string().dimmed(),
738+
seeds.join(",").dimmed()
751739
);
752740
}
753741
}
@@ -761,13 +749,10 @@ impl AddressBook {
761749
);
762750
for (pubkey, label, _reg) in atas {
763751
println!(
764-
" {} {}",
752+
" {} {:<30} {}",
765753
"•".to_string().bright_yellow(),
766-
format!(
767-
"{:<30} {}",
768-
label.bright_yellow().bold(),
769-
pubkey.to_string().dimmed()
770-
)
754+
label.bright_yellow().bold(),
755+
pubkey.to_string().dimmed()
771756
);
772757
}
773758
}
@@ -781,14 +766,11 @@ impl AddressBook {
781766
for (pubkey, label, reg) in custom {
782767
if let AddressRole::Custom(role) = &reg.role {
783768
println!(
784-
" {} {}",
769+
" {} {:<30} {} [{}]",
785770
"•".to_string().bright_white(),
786-
format!(
787-
"{:<30} {} {}",
788-
label.bright_white().bold(),
789-
pubkey.to_string().dimmed(),
790-
format!("[{}]", role).dimmed()
791-
)
771+
label.bright_white().bold(),
772+
pubkey.to_string().dimmed(),
773+
role.dimmed()
792774
);
793775
}
794776
}

crates/address-book/src/pda_seeds.rs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
//! # PDA Seeds Management
2+
//!
3+
//! Utilities for working with Program Derived Addresses (PDAs) and their seeds.
4+
//!
5+
//! This module provides types and functions for creating, managing, and debugging
6+
//! PDAs in Solana programs. It includes a flexible seed system that can handle
7+
//! various data types and provides human-readable representations for debugging.
8+
//!
9+
//! ## Features
10+
//!
11+
//! - **Flexible Seed Types**: Support for strings, pubkeys, and raw bytes as seeds
12+
//! - **PDA Derivation**: Helper functions for finding PDAs with bumps
13+
//! - **Debug Support**: Human-readable seed representations for logging
14+
//! - **Verification**: Methods to verify PDA derivation correctness
15+
116
use anchor_lang::prelude::*;
217

318
/// Result of PDA derivation containing all relevant information
@@ -239,7 +254,7 @@ mod tests {
239254
let program_id = Pubkey::new_unique();
240255
let seeds: Vec<&dyn SeedPart> = vec![];
241256

242-
let (pda, bump) = find_pda_with_bump(&seeds, &program_id);
257+
let (pda, _bump) = find_pda_with_bump(&seeds, &program_id);
243258

244259
// Empty seeds should still produce a valid PDA
245260
assert!(!pda.is_on_curve());
@@ -341,7 +356,7 @@ mod tests {
341356

342357
// Check all fields are populated correctly
343358
assert!(!derived_pda.key.is_on_curve());
344-
assert!(derived_pda.bump <= 255);
359+
// bump is a u8 so it's always <= 255
345360
assert_eq!(derived_pda.seed_strings.len(), 3);
346361
assert_eq!(derived_pda.seeds.len(), 3);
347362

crates/anchor-utils/src/lib.rs

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -64,32 +64,6 @@ use solana_program::instruction::Instruction;
6464
/// },
6565
/// );
6666
/// ```
67-
///
68-
/// # Working with Real Programs
69-
///
70-
/// Here's an example using the Quarry mining program:
71-
///
72-
/// ```rust,ignore
73-
/// use anchor_lang::prelude::*;
74-
/// use anchor_utils::anchor_instruction;
75-
///
76-
/// // Load the Quarry program IDL
77-
/// declare_program!(quarry_mine);
78-
///
79-
/// // Create a stake instruction
80-
/// let stake_ix = anchor_instruction(
81-
/// quarry_mine::ID,
82-
/// quarry_mine::accounts::UserStake {
83-
/// authority: user_authority,
84-
/// miner: miner_account,
85-
/// quarry: quarry_account,
86-
/// token_program: token::ID,
87-
/// },
88-
/// quarry_mine::instruction::UserStake {
89-
/// amount: 1_000_000,
90-
/// },
91-
/// );
92-
/// ```
9367
pub fn anchor_instruction(
9468
program_id: Pubkey,
9569
accounts: impl ToAccountMetas,

0 commit comments

Comments
 (0)