Skip to content

Commit

Permalink
Add make_keypairs Util Function
Browse files Browse the repository at this point in the history
  • Loading branch information
0xIchigo committed May 3, 2024
1 parent 61243de commit 241f9d4
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/utils/make_keypairs.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
use solana_sdk::signature::Keypair;

/// Generates a specified number of keypairs
///
/// # Arguments
/// * `amount` - The number of keypairs to generate
///
/// # Returns
/// A vector of `Keypair`
pub fn make_keypairs(amount: usize) -> Vec<Keypair> {
(0..amount).map(|_| Keypair::new()).collect()
}
2 changes: 2 additions & 0 deletions src/utils/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
pub use self::deserialize_str_to_number::deserialize_str_to_number;
pub use self::is_valid_solana_address::is_valid_solana_address;
pub use self::make_keypairs::make_keypairs;

mod deserialize_str_to_number;
mod is_valid_solana_address;
mod make_keypairs;
1 change: 1 addition & 0 deletions tests/tests.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
mod utils {
mod test_deserialize_str_to_number;
mod test_is_valid_solana_address;
mod test_make_keypairs;
}

mod rpc {
Expand Down
24 changes: 24 additions & 0 deletions tests/utils/test_make_keypairs.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
use helius_sdk::utils::make_keypairs;
use solana_sdk::{signature::Keypair, signer::Signer};
use std::collections::HashSet;

#[test]
fn test_make_keypairs_generates_correct_amount() {
let amounts: Vec<usize> = vec![1, 5, 10];

for amount in amounts {
let keypairs: Vec<Keypair> = make_keypairs(amount);
assert_eq!(keypairs.len(), amount, "Should generate the correct number of keypairs");
}
}

#[test]
fn test_make_keypairs_are_unique() {
let keypairs: Vec<Keypair> = make_keypairs(10);
let mut seen: HashSet<_> = HashSet::new();

for keypair in keypairs {
let pk = keypair.pubkey().to_string();
assert!(seen.insert(pk), "Each keypair should be unique");
}
}

0 comments on commit 241f9d4

Please sign in to comment.