Skip to content

Commit

Permalink
Clean Up Solana Address Tests and Add Invalid Test Case
Browse files Browse the repository at this point in the history
  • Loading branch information
0xIchigo committed Apr 18, 2024
1 parent e759f0b commit 3b3d096
Showing 1 changed file with 31 additions and 17 deletions.
48 changes: 31 additions & 17 deletions tests/utils/test_is_valid_solana_address.rs
Original file line number Diff line number Diff line change
@@ -1,23 +1,37 @@
use helius_sdk::utils::is_valid_solana_address;

#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_valid_addresses() {
let valid_addresses: [&str; 3] = [
"DezXAZ8z7PnrnRJjz3wXBoRgixCa6xjnB7YaB1pPB263",
"9AhKqLR67hwapvG8SA2JFXaCshXc9nALJjpKaHZrsbkw",
"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA",
];

#[test]
fn test_valid_addresses() {
let valid_addresses = [
"DezXAZ8z7PnrnRJjz3wXBoRgixCa6xjnB7YaB1pPB263",
"9AhKqLR67hwapvG8SA2JFXaCshXc9nALJjpKaHZrsbkw",
"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA",
];
for addr in valid_addresses.iter() {
assert!(
is_valid_solana_address(addr),
"Address {} is a valid Solana address",
addr
);
}
}

#[test]
fn test_invalid_addresses() {
let invalid_addresses: [&str; 5] = [
"DefinitelyNotASolanaAddress",
"12345",
"",
"TooShort",
"12345678901234567890123456789012345678901234",
];

for addr in valid_addresses.iter() {
assert!(
is_valid_solana_address(addr),
"Address {} is a valid Solana address",
addr
);
}
for addr in invalid_addresses.iter() {
assert!(
!is_valid_solana_address(addr),
"Address {} is not a valid Solana address",
addr
);
}
}

0 comments on commit 3b3d096

Please sign in to comment.