tests: Keypair::new().pubkey() -> pubkey::new_rand (#27705)

This commit is contained in:
Jeff Washington (jwash) 2022-09-10 13:56:45 -07:00 committed by GitHub
parent 1d9d5bef04
commit abd01553d5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 107 additions and 129 deletions

View File

@ -691,11 +691,11 @@ fn test_bank_forks_incremental_snapshot(
let bank = { let bank = {
let bank = Bank::new_from_parent(&bank_forks[slot - 1], &Pubkey::default(), slot); let bank = Bank::new_from_parent(&bank_forks[slot - 1], &Pubkey::default(), slot);
let key = Keypair::new().pubkey(); let key = solana_sdk::pubkey::new_rand();
let tx = system_transaction::transfer(mint_keypair, &key, 1, bank.last_blockhash()); let tx = system_transaction::transfer(mint_keypair, &key, 1, bank.last_blockhash());
assert_eq!(bank.process_transaction(&tx), Ok(())); assert_eq!(bank.process_transaction(&tx), Ok(()));
let key = Keypair::new().pubkey(); let key = solana_sdk::pubkey::new_rand();
let tx = system_transaction::transfer(mint_keypair, &key, 0, bank.last_blockhash()); let tx = system_transaction::transfer(mint_keypair, &key, 0, bank.last_blockhash());
assert_eq!(bank.process_transaction(&tx), Ok(())); assert_eq!(bank.process_transaction(&tx), Ok(()));
@ -981,11 +981,11 @@ fn test_snapshots_with_background_services(
slot, slot,
); );
let key = Keypair::new().pubkey(); let key = solana_sdk::pubkey::new_rand();
let tx = system_transaction::transfer(mint_keypair, &key, 1, bank.last_blockhash()); let tx = system_transaction::transfer(mint_keypair, &key, 1, bank.last_blockhash());
assert_eq!(bank.process_transaction(&tx), Ok(())); assert_eq!(bank.process_transaction(&tx), Ok(()));
let key = Keypair::new().pubkey(); let key = solana_sdk::pubkey::new_rand();
let tx = system_transaction::transfer(mint_keypair, &key, 0, bank.last_blockhash()); let tx = system_transaction::transfer(mint_keypair, &key, 0, bank.last_blockhash());
assert_eq!(bank.process_transaction(&tx), Ok(())); assert_eq!(bank.process_transaction(&tx), Ok(()));

View File

@ -2005,7 +2005,6 @@ pub mod tests {
solana_sdk::{ solana_sdk::{
account::{AccountSharedData, WritableAccount}, account::{AccountSharedData, WritableAccount},
pubkey::PUBKEY_BYTES, pubkey::PUBKEY_BYTES,
signature::{Keypair, Signer},
}, },
std::ops::RangeInclusive, std::ops::RangeInclusive,
}; };
@ -2278,10 +2277,10 @@ pub mod tests {
#[test] #[test]
fn test_get_empty() { fn test_get_empty() {
let key = Keypair::new(); let key = solana_sdk::pubkey::new_rand();
let index = AccountsIndex::<bool>::default_for_tests(); let index = AccountsIndex::<bool>::default_for_tests();
let ancestors = Ancestors::default(); let ancestors = Ancestors::default();
let key = &key.pubkey(); let key = &key;
assert!(index.get_for_tests(key, Some(&ancestors), None).is_none()); assert!(index.get_for_tests(key, Some(&ancestors), None).is_none());
assert!(index.get_for_tests(key, None, None).is_none()); assert!(index.get_for_tests(key, None, None).is_none());
@ -2345,13 +2344,13 @@ pub mod tests {
#[test] #[test]
fn test_insert_no_ancestors() { fn test_insert_no_ancestors() {
let key = Keypair::new(); let key = solana_sdk::pubkey::new_rand();
let index = AccountsIndex::<bool>::default_for_tests(); let index = AccountsIndex::<bool>::default_for_tests();
let mut gc = Vec::new(); let mut gc = Vec::new();
index.upsert( index.upsert(
0, 0,
0, 0,
&key.pubkey(), &key,
&AccountSharedData::default(), &AccountSharedData::default(),
&AccountSecondaryIndexes::default(), &AccountSecondaryIndexes::default(),
true, true,
@ -2361,10 +2360,8 @@ pub mod tests {
assert!(gc.is_empty()); assert!(gc.is_empty());
let ancestors = Ancestors::default(); let ancestors = Ancestors::default();
assert!(index assert!(index.get_for_tests(&key, Some(&ancestors), None).is_none());
.get_for_tests(&key.pubkey(), Some(&ancestors), None) assert!(index.get_for_tests(&key, None, None).is_none());
.is_none());
assert!(index.get_for_tests(&key.pubkey(), None, None).is_none());
let mut num = 0; let mut num = 0;
index.unchecked_scan_accounts( index.unchecked_scan_accounts(
@ -2392,8 +2389,8 @@ pub mod tests {
} }
#[test] #[test]
fn test_insert_new_with_lock_no_ancestors() { fn test_insert_new_with_lock_no_ancestors() {
let key = Keypair::new(); let key = solana_sdk::pubkey::new_rand();
let pubkey = &key.pubkey(); let pubkey = &key;
let slot = 0; let slot = 0;
let index = AccountsIndex::<bool>::default_for_tests(); let index = AccountsIndex::<bool>::default_for_tests();
@ -2534,8 +2531,8 @@ pub mod tests {
#[test] #[test]
fn test_batch_insert() { fn test_batch_insert() {
let slot0 = 0; let slot0 = 0;
let key0 = Keypair::new().pubkey(); let key0 = solana_sdk::pubkey::new_rand();
let key1 = Keypair::new().pubkey(); let key1 = solana_sdk::pubkey::new_rand();
let index = AccountsIndex::<bool>::default_for_tests(); let index = AccountsIndex::<bool>::default_for_tests();
let account_infos = [true, false]; let account_infos = [true, false];
@ -2567,7 +2564,7 @@ pub mod tests {
let slot0 = 0; let slot0 = 0;
let slot1 = 1; let slot1 = 1;
let key = Keypair::new().pubkey(); let key = solana_sdk::pubkey::new_rand();
let mut config = ACCOUNTS_INDEX_CONFIG_FOR_TESTING; let mut config = ACCOUNTS_INDEX_CONFIG_FOR_TESTING;
config.index_limit_mb = if use_disk { config.index_limit_mb = if use_disk {
@ -2689,7 +2686,7 @@ pub mod tests {
#[test] #[test]
fn test_insert_with_lock_no_ancestors() { fn test_insert_with_lock_no_ancestors() {
let key = Keypair::new(); let key = solana_sdk::pubkey::new_rand();
let index = AccountsIndex::<bool>::default_for_tests(); let index = AccountsIndex::<bool>::default_for_tests();
let slot = 0; let slot = 0;
let account_info = true; let account_info = true;
@ -2700,9 +2697,9 @@ pub mod tests {
assert_eq!((slot, account_info), new_entry.clone().into()); assert_eq!((slot, account_info), new_entry.clone().into());
assert_eq!(0, account_maps_stats_len(&index)); assert_eq!(0, account_maps_stats_len(&index));
let r_account_maps = index.get_bin(&key.pubkey()); let r_account_maps = index.get_bin(&key);
r_account_maps.upsert( r_account_maps.upsert(
&key.pubkey(), &key,
new_entry, new_entry,
None, None,
&mut SlotList::default(), &mut SlotList::default(),
@ -2711,10 +2708,8 @@ pub mod tests {
assert_eq!(1, account_maps_stats_len(&index)); assert_eq!(1, account_maps_stats_len(&index));
let mut ancestors = Ancestors::default(); let mut ancestors = Ancestors::default();
assert!(index assert!(index.get_for_tests(&key, Some(&ancestors), None).is_none());
.get_for_tests(&key.pubkey(), Some(&ancestors), None) assert!(index.get_for_tests(&key, None, None).is_none());
.is_none());
assert!(index.get_for_tests(&key.pubkey(), None, None).is_none());
let mut num = 0; let mut num = 0;
index.unchecked_scan_accounts( index.unchecked_scan_accounts(
@ -2725,9 +2720,7 @@ pub mod tests {
); );
assert_eq!(num, 0); assert_eq!(num, 0);
ancestors.insert(slot, 0); ancestors.insert(slot, 0);
assert!(index assert!(index.get_for_tests(&key, Some(&ancestors), None).is_some());
.get_for_tests(&key.pubkey(), Some(&ancestors), None)
.is_some());
index.unchecked_scan_accounts( index.unchecked_scan_accounts(
"", "",
&ancestors, &ancestors,
@ -2739,13 +2732,13 @@ pub mod tests {
#[test] #[test]
fn test_insert_wrong_ancestors() { fn test_insert_wrong_ancestors() {
let key = Keypair::new(); let key = solana_sdk::pubkey::new_rand();
let index = AccountsIndex::<bool>::default_for_tests(); let index = AccountsIndex::<bool>::default_for_tests();
let mut gc = Vec::new(); let mut gc = Vec::new();
index.upsert( index.upsert(
0, 0,
0, 0,
&key.pubkey(), &key,
&AccountSharedData::default(), &AccountSharedData::default(),
&AccountSecondaryIndexes::default(), &AccountSecondaryIndexes::default(),
true, true,
@ -2755,9 +2748,7 @@ pub mod tests {
assert!(gc.is_empty()); assert!(gc.is_empty());
let ancestors = vec![(1, 1)].into_iter().collect(); let ancestors = vec![(1, 1)].into_iter().collect();
assert!(index assert!(index.get_for_tests(&key, Some(&ancestors), None).is_none());
.get_for_tests(&key.pubkey(), Some(&ancestors), None)
.is_none());
let mut num = 0; let mut num = 0;
index.unchecked_scan_accounts( index.unchecked_scan_accounts(
@ -2772,7 +2763,7 @@ pub mod tests {
fn test_insert_ignore_reclaims() { fn test_insert_ignore_reclaims() {
{ {
// non-cached // non-cached
let key = Keypair::new(); let key = solana_sdk::pubkey::new_rand();
let index = AccountsIndex::<u64>::default_for_tests(); let index = AccountsIndex::<u64>::default_for_tests();
let mut reclaims = Vec::new(); let mut reclaims = Vec::new();
let slot = 0; let slot = 0;
@ -2781,7 +2772,7 @@ pub mod tests {
index.upsert( index.upsert(
slot, slot,
slot, slot,
&key.pubkey(), &key,
&AccountSharedData::default(), &AccountSharedData::default(),
&AccountSecondaryIndexes::default(), &AccountSecondaryIndexes::default(),
value, value,
@ -2792,7 +2783,7 @@ pub mod tests {
index.upsert( index.upsert(
slot, slot,
slot, slot,
&key.pubkey(), &key,
&AccountSharedData::default(), &AccountSharedData::default(),
&AccountSecondaryIndexes::default(), &AccountSecondaryIndexes::default(),
value, value,
@ -2805,7 +2796,7 @@ pub mod tests {
index.upsert( index.upsert(
slot, slot,
slot, slot,
&key.pubkey(), &key,
&AccountSharedData::default(), &AccountSharedData::default(),
&AccountSecondaryIndexes::default(), &AccountSecondaryIndexes::default(),
value, value,
@ -2818,7 +2809,7 @@ pub mod tests {
} }
{ {
// cached // cached
let key = Keypair::new(); let key = solana_sdk::pubkey::new_rand();
let index = AccountsIndex::<AccountInfoTest>::default_for_tests(); let index = AccountsIndex::<AccountInfoTest>::default_for_tests();
let mut reclaims = Vec::new(); let mut reclaims = Vec::new();
let slot = 0; let slot = 0;
@ -2827,7 +2818,7 @@ pub mod tests {
index.upsert( index.upsert(
slot, slot,
slot, slot,
&key.pubkey(), &key,
&AccountSharedData::default(), &AccountSharedData::default(),
&AccountSecondaryIndexes::default(), &AccountSecondaryIndexes::default(),
value, value,
@ -2838,7 +2829,7 @@ pub mod tests {
index.upsert( index.upsert(
slot, slot,
slot, slot,
&key.pubkey(), &key,
&AccountSharedData::default(), &AccountSharedData::default(),
&AccountSecondaryIndexes::default(), &AccountSecondaryIndexes::default(),
value, value,
@ -2851,7 +2842,7 @@ pub mod tests {
index.upsert( index.upsert(
slot, slot,
slot, slot,
&key.pubkey(), &key,
&AccountSharedData::default(), &AccountSharedData::default(),
&AccountSecondaryIndexes::default(), &AccountSecondaryIndexes::default(),
value, value,
@ -2866,13 +2857,13 @@ pub mod tests {
#[test] #[test]
fn test_insert_with_ancestors() { fn test_insert_with_ancestors() {
let key = Keypair::new(); let key = solana_sdk::pubkey::new_rand();
let index = AccountsIndex::<bool>::default_for_tests(); let index = AccountsIndex::<bool>::default_for_tests();
let mut gc = Vec::new(); let mut gc = Vec::new();
index.upsert( index.upsert(
0, 0,
0, 0,
&key.pubkey(), &key,
&AccountSharedData::default(), &AccountSharedData::default(),
&AccountSecondaryIndexes::default(), &AccountSecondaryIndexes::default(),
true, true,
@ -2882,9 +2873,7 @@ pub mod tests {
assert!(gc.is_empty()); assert!(gc.is_empty());
let ancestors = vec![(0, 0)].into_iter().collect(); let ancestors = vec![(0, 0)].into_iter().collect();
let (list, idx) = index let (list, idx) = index.get_for_tests(&key, Some(&ancestors), None).unwrap();
.get_for_tests(&key.pubkey(), Some(&ancestors), None)
.unwrap();
assert_eq!(list.slot_list()[idx], (0, true)); assert_eq!(list.slot_list()[idx], (0, true));
let mut num = 0; let mut num = 0;
@ -2893,7 +2882,7 @@ pub mod tests {
"", "",
&ancestors, &ancestors,
|pubkey, _index| { |pubkey, _index| {
if pubkey == &key.pubkey() { if pubkey == &key {
found_key = true found_key = true
}; };
num += 1 num += 1
@ -3093,13 +3082,13 @@ pub mod tests {
#[test] #[test]
fn test_insert_with_root() { fn test_insert_with_root() {
let key = Keypair::new(); let key = solana_sdk::pubkey::new_rand();
let index = AccountsIndex::<bool>::default_for_tests(); let index = AccountsIndex::<bool>::default_for_tests();
let mut gc = Vec::new(); let mut gc = Vec::new();
index.upsert( index.upsert(
0, 0,
0, 0,
&key.pubkey(), &key,
&AccountSharedData::default(), &AccountSharedData::default(),
&AccountSecondaryIndexes::default(), &AccountSecondaryIndexes::default(),
true, true,
@ -3109,7 +3098,7 @@ pub mod tests {
assert!(gc.is_empty()); assert!(gc.is_empty());
index.add_root(0, false); index.add_root(0, false);
let (list, idx) = index.get_for_tests(&key.pubkey(), None, None).unwrap(); let (list, idx) = index.get_for_tests(&key, None, None).unwrap();
assert_eq!(list.slot_list()[idx], (0, true)); assert_eq!(list.slot_list()[idx], (0, true));
} }
@ -3207,14 +3196,14 @@ pub mod tests {
#[test] #[test]
fn test_update_last_wins() { fn test_update_last_wins() {
let key = Keypair::new(); let key = solana_sdk::pubkey::new_rand();
let index = AccountsIndex::<bool>::default_for_tests(); let index = AccountsIndex::<bool>::default_for_tests();
let ancestors = vec![(0, 0)].into_iter().collect(); let ancestors = vec![(0, 0)].into_iter().collect();
let mut gc = Vec::new(); let mut gc = Vec::new();
index.upsert( index.upsert(
0, 0,
0, 0,
&key.pubkey(), &key,
&AccountSharedData::default(), &AccountSharedData::default(),
&AccountSecondaryIndexes::default(), &AccountSecondaryIndexes::default(),
true, true,
@ -3222,9 +3211,7 @@ pub mod tests {
UPSERT_PREVIOUS_SLOT_ENTRY_WAS_CACHED_FALSE, UPSERT_PREVIOUS_SLOT_ENTRY_WAS_CACHED_FALSE,
); );
assert!(gc.is_empty()); assert!(gc.is_empty());
let (list, idx) = index let (list, idx) = index.get_for_tests(&key, Some(&ancestors), None).unwrap();
.get_for_tests(&key.pubkey(), Some(&ancestors), None)
.unwrap();
assert_eq!(list.slot_list()[idx], (0, true)); assert_eq!(list.slot_list()[idx], (0, true));
drop(list); drop(list);
@ -3232,7 +3219,7 @@ pub mod tests {
index.upsert( index.upsert(
0, 0,
0, 0,
&key.pubkey(), &key,
&AccountSharedData::default(), &AccountSharedData::default(),
&AccountSecondaryIndexes::default(), &AccountSecondaryIndexes::default(),
false, false,
@ -3240,23 +3227,21 @@ pub mod tests {
UPSERT_PREVIOUS_SLOT_ENTRY_WAS_CACHED_FALSE, UPSERT_PREVIOUS_SLOT_ENTRY_WAS_CACHED_FALSE,
); );
assert_eq!(gc, vec![(0, true)]); assert_eq!(gc, vec![(0, true)]);
let (list, idx) = index let (list, idx) = index.get_for_tests(&key, Some(&ancestors), None).unwrap();
.get_for_tests(&key.pubkey(), Some(&ancestors), None)
.unwrap();
assert_eq!(list.slot_list()[idx], (0, false)); assert_eq!(list.slot_list()[idx], (0, false));
} }
#[test] #[test]
fn test_update_new_slot() { fn test_update_new_slot() {
solana_logger::setup(); solana_logger::setup();
let key = Keypair::new(); let key = solana_sdk::pubkey::new_rand();
let index = AccountsIndex::<bool>::default_for_tests(); let index = AccountsIndex::<bool>::default_for_tests();
let ancestors = vec![(0, 0)].into_iter().collect(); let ancestors = vec![(0, 0)].into_iter().collect();
let mut gc = Vec::new(); let mut gc = Vec::new();
index.upsert( index.upsert(
0, 0,
0, 0,
&key.pubkey(), &key,
&AccountSharedData::default(), &AccountSharedData::default(),
&AccountSecondaryIndexes::default(), &AccountSecondaryIndexes::default(),
true, true,
@ -3267,7 +3252,7 @@ pub mod tests {
index.upsert( index.upsert(
1, 1,
1, 1,
&key.pubkey(), &key,
&AccountSharedData::default(), &AccountSharedData::default(),
&AccountSecondaryIndexes::default(), &AccountSecondaryIndexes::default(),
false, false,
@ -3275,26 +3260,22 @@ pub mod tests {
UPSERT_PREVIOUS_SLOT_ENTRY_WAS_CACHED_FALSE, UPSERT_PREVIOUS_SLOT_ENTRY_WAS_CACHED_FALSE,
); );
assert!(gc.is_empty()); assert!(gc.is_empty());
let (list, idx) = index let (list, idx) = index.get_for_tests(&key, Some(&ancestors), None).unwrap();
.get_for_tests(&key.pubkey(), Some(&ancestors), None)
.unwrap();
assert_eq!(list.slot_list()[idx], (0, true)); assert_eq!(list.slot_list()[idx], (0, true));
let ancestors = vec![(1, 0)].into_iter().collect(); let ancestors = vec![(1, 0)].into_iter().collect();
let (list, idx) = index let (list, idx) = index.get_for_tests(&key, Some(&ancestors), None).unwrap();
.get_for_tests(&key.pubkey(), Some(&ancestors), None)
.unwrap();
assert_eq!(list.slot_list()[idx], (1, false)); assert_eq!(list.slot_list()[idx], (1, false));
} }
#[test] #[test]
fn test_update_gc_purged_slot() { fn test_update_gc_purged_slot() {
let key = Keypair::new(); let key = solana_sdk::pubkey::new_rand();
let index = AccountsIndex::<bool>::default_for_tests(); let index = AccountsIndex::<bool>::default_for_tests();
let mut gc = Vec::new(); let mut gc = Vec::new();
index.upsert( index.upsert(
0, 0,
0, 0,
&key.pubkey(), &key,
&AccountSharedData::default(), &AccountSharedData::default(),
&AccountSecondaryIndexes::default(), &AccountSecondaryIndexes::default(),
true, true,
@ -3305,7 +3286,7 @@ pub mod tests {
index.upsert( index.upsert(
1, 1,
1, 1,
&key.pubkey(), &key,
&AccountSharedData::default(), &AccountSharedData::default(),
&AccountSecondaryIndexes::default(), &AccountSecondaryIndexes::default(),
false, false,
@ -3315,7 +3296,7 @@ pub mod tests {
index.upsert( index.upsert(
2, 2,
2, 2,
&key.pubkey(), &key,
&AccountSharedData::default(), &AccountSharedData::default(),
&AccountSecondaryIndexes::default(), &AccountSecondaryIndexes::default(),
true, true,
@ -3325,7 +3306,7 @@ pub mod tests {
index.upsert( index.upsert(
3, 3,
3, 3,
&key.pubkey(), &key,
&AccountSharedData::default(), &AccountSharedData::default(),
&AccountSecondaryIndexes::default(), &AccountSecondaryIndexes::default(),
true, true,
@ -3338,7 +3319,7 @@ pub mod tests {
index.upsert( index.upsert(
4, 4,
4, 4,
&key.pubkey(), &key,
&AccountSharedData::default(), &AccountSharedData::default(),
&AccountSecondaryIndexes::default(), &AccountSecondaryIndexes::default(),
true, true,
@ -3349,7 +3330,7 @@ pub mod tests {
// Updating index should not purge older roots, only purges // Updating index should not purge older roots, only purges
// previous updates within the same slot // previous updates within the same slot
assert_eq!(gc, vec![]); assert_eq!(gc, vec![]);
let (list, idx) = index.get_for_tests(&key.pubkey(), None, None).unwrap(); let (list, idx) = index.get_for_tests(&key, None, None).unwrap();
assert_eq!(list.slot_list()[idx], (3, true)); assert_eq!(list.slot_list()[idx], (3, true));
let mut num = 0; let mut num = 0;
@ -3358,7 +3339,7 @@ pub mod tests {
"", "",
&Ancestors::default(), &Ancestors::default(),
|pubkey, _index| { |pubkey, _index| {
if pubkey == &key.pubkey() { if pubkey == &key {
found_key = true; found_key = true;
assert_eq!(_index, (&true, 3)); assert_eq!(_index, (&true, 3));
}; };
@ -3376,14 +3357,14 @@ pub mod tests {
#[test] #[test]
fn test_purge() { fn test_purge() {
let key = Keypair::new(); let key = solana_sdk::pubkey::new_rand();
let index = AccountsIndex::<u64>::default_for_tests(); let index = AccountsIndex::<u64>::default_for_tests();
let mut gc = Vec::new(); let mut gc = Vec::new();
assert_eq!(0, account_maps_stats_len(&index)); assert_eq!(0, account_maps_stats_len(&index));
index.upsert( index.upsert(
1, 1,
1, 1,
&key.pubkey(), &key,
&AccountSharedData::default(), &AccountSharedData::default(),
&AccountSecondaryIndexes::default(), &AccountSecondaryIndexes::default(),
12, 12,
@ -3395,7 +3376,7 @@ pub mod tests {
index.upsert( index.upsert(
1, 1,
1, 1,
&key.pubkey(), &key,
&AccountSharedData::default(), &AccountSharedData::default(),
&AccountSecondaryIndexes::default(), &AccountSecondaryIndexes::default(),
10, 10,
@ -3404,18 +3385,18 @@ pub mod tests {
); );
assert_eq!(1, account_maps_stats_len(&index)); assert_eq!(1, account_maps_stats_len(&index));
let purges = index.purge_roots(&key.pubkey()); let purges = index.purge_roots(&key);
assert_eq!(purges, (vec![], false)); assert_eq!(purges, (vec![], false));
index.add_root(1, false); index.add_root(1, false);
let purges = index.purge_roots(&key.pubkey()); let purges = index.purge_roots(&key);
assert_eq!(purges, (vec![(1, 10)], true)); assert_eq!(purges, (vec![(1, 10)], true));
assert_eq!(1, account_maps_stats_len(&index)); assert_eq!(1, account_maps_stats_len(&index));
index.upsert( index.upsert(
1, 1,
1, 1,
&key.pubkey(), &key,
&AccountSharedData::default(), &AccountSharedData::default(),
&AccountSecondaryIndexes::default(), &AccountSecondaryIndexes::default(),
9, 9,

View File

@ -10752,15 +10752,15 @@ pub(crate) mod tests {
let bank = create_simple_test_bank(100); let bank = create_simple_test_bank(100);
// Test new account // Test new account
let key = Keypair::new(); let key = solana_sdk::pubkey::new_rand();
let new_balance = bank.deposit(&key.pubkey(), 10).unwrap(); let new_balance = bank.deposit(&key, 10).unwrap();
assert_eq!(new_balance, 10); assert_eq!(new_balance, 10);
assert_eq!(bank.get_balance(&key.pubkey()), 10); assert_eq!(bank.get_balance(&key), 10);
// Existing account // Existing account
let new_balance = bank.deposit(&key.pubkey(), 3).unwrap(); let new_balance = bank.deposit(&key, 3).unwrap();
assert_eq!(new_balance, 13); assert_eq!(new_balance, 13);
assert_eq!(bank.get_balance(&key.pubkey()), 13); assert_eq!(bank.get_balance(&key), 13);
} }
#[test] #[test]
@ -10768,24 +10768,24 @@ pub(crate) mod tests {
let bank = create_simple_test_bank(100); let bank = create_simple_test_bank(100);
// Test no account // Test no account
let key = Keypair::new(); let key = solana_sdk::pubkey::new_rand();
assert_eq!( assert_eq!(
bank.withdraw(&key.pubkey(), 10), bank.withdraw(&key, 10),
Err(TransactionError::AccountNotFound) Err(TransactionError::AccountNotFound)
); );
bank.deposit(&key.pubkey(), 3).unwrap(); bank.deposit(&key, 3).unwrap();
assert_eq!(bank.get_balance(&key.pubkey()), 3); assert_eq!(bank.get_balance(&key), 3);
// Low balance // Low balance
assert_eq!( assert_eq!(
bank.withdraw(&key.pubkey(), 10), bank.withdraw(&key, 10),
Err(TransactionError::InsufficientFundsForFee) Err(TransactionError::InsufficientFundsForFee)
); );
// Enough balance // Enough balance
assert_eq!(bank.withdraw(&key.pubkey(), 2), Ok(())); assert_eq!(bank.withdraw(&key, 2), Ok(()));
assert_eq!(bank.get_balance(&key.pubkey()), 1); assert_eq!(bank.get_balance(&key), 1);
} }
#[test] #[test]
@ -10848,17 +10848,17 @@ pub(crate) mod tests {
let capitalization = bank.capitalization(); let capitalization = bank.capitalization();
let key = Keypair::new(); let key = solana_sdk::pubkey::new_rand();
let tx = system_transaction::transfer( let tx = system_transaction::transfer(
&mint_keypair, &mint_keypair,
&key.pubkey(), &key,
arbitrary_transfer_amount, arbitrary_transfer_amount,
bank.last_blockhash(), bank.last_blockhash(),
); );
let initial_balance = bank.get_balance(&leader); let initial_balance = bank.get_balance(&leader);
assert_eq!(bank.process_transaction(&tx), Ok(())); assert_eq!(bank.process_transaction(&tx), Ok(()));
assert_eq!(bank.get_balance(&key.pubkey()), arbitrary_transfer_amount); assert_eq!(bank.get_balance(&key), arbitrary_transfer_amount);
assert_eq!( assert_eq!(
bank.get_balance(&mint_keypair.pubkey()), bank.get_balance(&mint_keypair.pubkey()),
mint - arbitrary_transfer_amount - expected_fee_paid mint - arbitrary_transfer_amount - expected_fee_paid
@ -10894,14 +10894,13 @@ pub(crate) mod tests {
// Verify that an InstructionError collects fees, too // Verify that an InstructionError collects fees, too
let mut bank = Bank::new_from_parent(&Arc::new(bank), &leader, 1); let mut bank = Bank::new_from_parent(&Arc::new(bank), &leader, 1);
let mut tx = let mut tx = system_transaction::transfer(&mint_keypair, &key, 1, bank.last_blockhash());
system_transaction::transfer(&mint_keypair, &key.pubkey(), 1, bank.last_blockhash());
// Create a bogus instruction to system_program to cause an instruction error // Create a bogus instruction to system_program to cause an instruction error
tx.message.instructions[0].data[0] = 40; tx.message.instructions[0].data[0] = 40;
bank.process_transaction(&tx) bank.process_transaction(&tx)
.expect_err("instruction error"); .expect_err("instruction error");
assert_eq!(bank.get_balance(&key.pubkey()), arbitrary_transfer_amount); // no change assert_eq!(bank.get_balance(&key), arbitrary_transfer_amount); // no change
assert_eq!( assert_eq!(
bank.get_balance(&mint_keypair.pubkey()), bank.get_balance(&mint_keypair.pubkey()),
mint - arbitrary_transfer_amount - 2 * expected_fee_paid mint - arbitrary_transfer_amount - 2 * expected_fee_paid
@ -10933,7 +10932,7 @@ pub(crate) mod tests {
fn test_bank_tx_compute_unit_fee() { fn test_bank_tx_compute_unit_fee() {
solana_logger::setup(); solana_logger::setup();
let key = Keypair::new(); let key = solana_sdk::pubkey::new_rand();
let arbitrary_transfer_amount = 42; let arbitrary_transfer_amount = 42;
let mint = arbitrary_transfer_amount * 10_000_000; let mint = arbitrary_transfer_amount * 10_000_000;
let leader = solana_sdk::pubkey::new_rand(); let leader = solana_sdk::pubkey::new_rand();
@ -10964,14 +10963,14 @@ pub(crate) mod tests {
let tx = system_transaction::transfer( let tx = system_transaction::transfer(
&mint_keypair, &mint_keypair,
&key.pubkey(), &key,
arbitrary_transfer_amount, arbitrary_transfer_amount,
bank.last_blockhash(), bank.last_blockhash(),
); );
let initial_balance = bank.get_balance(&leader); let initial_balance = bank.get_balance(&leader);
assert_eq!(bank.process_transaction(&tx), Ok(())); assert_eq!(bank.process_transaction(&tx), Ok(()));
assert_eq!(bank.get_balance(&key.pubkey()), arbitrary_transfer_amount); assert_eq!(bank.get_balance(&key), arbitrary_transfer_amount);
assert_eq!( assert_eq!(
bank.get_balance(&mint_keypair.pubkey()), bank.get_balance(&mint_keypair.pubkey()),
mint - arbitrary_transfer_amount - expected_fee_paid mint - arbitrary_transfer_amount - expected_fee_paid
@ -11007,14 +11006,13 @@ pub(crate) mod tests {
// Verify that an InstructionError collects fees, too // Verify that an InstructionError collects fees, too
let mut bank = Bank::new_from_parent(&Arc::new(bank), &leader, 1); let mut bank = Bank::new_from_parent(&Arc::new(bank), &leader, 1);
let mut tx = let mut tx = system_transaction::transfer(&mint_keypair, &key, 1, bank.last_blockhash());
system_transaction::transfer(&mint_keypair, &key.pubkey(), 1, bank.last_blockhash());
// Create a bogus instruction to system_program to cause an instruction error // Create a bogus instruction to system_program to cause an instruction error
tx.message.instructions[0].data[0] = 40; tx.message.instructions[0].data[0] = 40;
bank.process_transaction(&tx) bank.process_transaction(&tx)
.expect_err("instruction error"); .expect_err("instruction error");
assert_eq!(bank.get_balance(&key.pubkey()), arbitrary_transfer_amount); // no change assert_eq!(bank.get_balance(&key), arbitrary_transfer_amount); // no change
assert_eq!( assert_eq!(
bank.get_balance(&mint_keypair.pubkey()), bank.get_balance(&mint_keypair.pubkey()),
mint - arbitrary_transfer_amount - 2 * expected_fee_paid mint - arbitrary_transfer_amount - 2 * expected_fee_paid
@ -11072,22 +11070,22 @@ pub(crate) mod tests {
let bank = Bank::new_from_parent(&Arc::new(bank), &leader, 2); let bank = Bank::new_from_parent(&Arc::new(bank), &leader, 2);
// Send a transfer using cheap_blockhash // Send a transfer using cheap_blockhash
let key = Keypair::new(); let key = solana_sdk::pubkey::new_rand();
let initial_mint_balance = bank.get_balance(&mint_keypair.pubkey()); let initial_mint_balance = bank.get_balance(&mint_keypair.pubkey());
let tx = system_transaction::transfer(&mint_keypair, &key.pubkey(), 1, cheap_blockhash); let tx = system_transaction::transfer(&mint_keypair, &key, 1, cheap_blockhash);
assert_eq!(bank.process_transaction(&tx), Ok(())); assert_eq!(bank.process_transaction(&tx), Ok(()));
assert_eq!(bank.get_balance(&key.pubkey()), 1); assert_eq!(bank.get_balance(&key), 1);
assert_eq!( assert_eq!(
bank.get_balance(&mint_keypair.pubkey()), bank.get_balance(&mint_keypair.pubkey()),
initial_mint_balance - 1 - cheap_lamports_per_signature initial_mint_balance - 1 - cheap_lamports_per_signature
); );
// Send a transfer using expensive_blockhash // Send a transfer using expensive_blockhash
let key = Keypair::new(); let key = solana_sdk::pubkey::new_rand();
let initial_mint_balance = bank.get_balance(&mint_keypair.pubkey()); let initial_mint_balance = bank.get_balance(&mint_keypair.pubkey());
let tx = system_transaction::transfer(&mint_keypair, &key.pubkey(), 1, expensive_blockhash); let tx = system_transaction::transfer(&mint_keypair, &key, 1, expensive_blockhash);
assert_eq!(bank.process_transaction(&tx), Ok(())); assert_eq!(bank.process_transaction(&tx), Ok(()));
assert_eq!(bank.get_balance(&key.pubkey()), 1); assert_eq!(bank.get_balance(&key), 1);
assert_eq!( assert_eq!(
bank.get_balance(&mint_keypair.pubkey()), bank.get_balance(&mint_keypair.pubkey()),
initial_mint_balance - 1 - expensive_lamports_per_signature initial_mint_balance - 1 - expensive_lamports_per_signature
@ -11124,11 +11122,11 @@ pub(crate) mod tests {
let bank = Bank::new_from_parent(&Arc::new(bank), &leader, 2); let bank = Bank::new_from_parent(&Arc::new(bank), &leader, 2);
// Send a transfer using cheap_blockhash // Send a transfer using cheap_blockhash
let key = Keypair::new(); let key = solana_sdk::pubkey::new_rand();
let initial_mint_balance = bank.get_balance(&mint_keypair.pubkey()); let initial_mint_balance = bank.get_balance(&mint_keypair.pubkey());
let tx = system_transaction::transfer(&mint_keypair, &key.pubkey(), 1, cheap_blockhash); let tx = system_transaction::transfer(&mint_keypair, &key, 1, cheap_blockhash);
assert_eq!(bank.process_transaction(&tx), Ok(())); assert_eq!(bank.process_transaction(&tx), Ok(()));
assert_eq!(bank.get_balance(&key.pubkey()), 1); assert_eq!(bank.get_balance(&key), 1);
let cheap_fee = Bank::calculate_fee( let cheap_fee = Bank::calculate_fee(
&SanitizedMessage::try_from(Message::new(&[], Some(&Pubkey::new_unique()))).unwrap(), &SanitizedMessage::try_from(Message::new(&[], Some(&Pubkey::new_unique()))).unwrap(),
cheap_lamports_per_signature, cheap_lamports_per_signature,
@ -11142,11 +11140,11 @@ pub(crate) mod tests {
); );
// Send a transfer using expensive_blockhash // Send a transfer using expensive_blockhash
let key = Keypair::new(); let key = solana_sdk::pubkey::new_rand();
let initial_mint_balance = bank.get_balance(&mint_keypair.pubkey()); let initial_mint_balance = bank.get_balance(&mint_keypair.pubkey());
let tx = system_transaction::transfer(&mint_keypair, &key.pubkey(), 1, expensive_blockhash); let tx = system_transaction::transfer(&mint_keypair, &key, 1, expensive_blockhash);
assert_eq!(bank.process_transaction(&tx), Ok(())); assert_eq!(bank.process_transaction(&tx), Ok(()));
assert_eq!(bank.get_balance(&key.pubkey()), 1); assert_eq!(bank.get_balance(&key), 1);
let expensive_fee = Bank::calculate_fee( let expensive_fee = Bank::calculate_fee(
&SanitizedMessage::try_from(Message::new(&[], Some(&Pubkey::new_unique()))).unwrap(), &SanitizedMessage::try_from(Message::new(&[], Some(&Pubkey::new_unique()))).unwrap(),
expensive_lamports_per_signature, expensive_lamports_per_signature,
@ -11171,16 +11169,16 @@ pub(crate) mod tests {
genesis_config.fee_rate_governor = FeeRateGovernor::new(5000, 0); genesis_config.fee_rate_governor = FeeRateGovernor::new(5000, 0);
let bank = Bank::new_for_tests(&genesis_config); let bank = Bank::new_for_tests(&genesis_config);
let key = Keypair::new(); let key = solana_sdk::pubkey::new_rand();
let tx1 = SanitizedTransaction::from_transaction_for_tests(system_transaction::transfer( let tx1 = SanitizedTransaction::from_transaction_for_tests(system_transaction::transfer(
&mint_keypair, &mint_keypair,
&key.pubkey(), &key,
2, 2,
genesis_config.hash(), genesis_config.hash(),
)); ));
let tx2 = SanitizedTransaction::from_transaction_for_tests(system_transaction::transfer( let tx2 = SanitizedTransaction::from_transaction_for_tests(system_transaction::transfer(
&mint_keypair, &mint_keypair,
&key.pubkey(), &key,
5, 5,
genesis_config.hash(), genesis_config.hash(),
)); ));
@ -11222,16 +11220,16 @@ pub(crate) mod tests {
genesis_config.fee_rate_governor = FeeRateGovernor::new(2, 0); genesis_config.fee_rate_governor = FeeRateGovernor::new(2, 0);
let bank = Bank::new_for_tests(&genesis_config); let bank = Bank::new_for_tests(&genesis_config);
let key = Keypair::new(); let key = solana_sdk::pubkey::new_rand();
let tx1 = SanitizedTransaction::from_transaction_for_tests(system_transaction::transfer( let tx1 = SanitizedTransaction::from_transaction_for_tests(system_transaction::transfer(
&mint_keypair, &mint_keypair,
&key.pubkey(), &key,
2, 2,
genesis_config.hash(), genesis_config.hash(),
)); ));
let tx2 = SanitizedTransaction::from_transaction_for_tests(system_transaction::transfer( let tx2 = SanitizedTransaction::from_transaction_for_tests(system_transaction::transfer(
&mint_keypair, &mint_keypair,
&key.pubkey(), &key,
5, 5,
genesis_config.hash(), genesis_config.hash(),
)); ));
@ -12232,10 +12230,10 @@ pub(crate) mod tests {
let (genesis_config, mint_keypair) = create_genesis_config(500); let (genesis_config, mint_keypair) = create_genesis_config(500);
let mut bank = Bank::new_for_tests(&genesis_config); let mut bank = Bank::new_for_tests(&genesis_config);
bank.fee_rate_governor.lamports_per_signature = 2; bank.fee_rate_governor.lamports_per_signature = 2;
let key = Keypair::new(); let key = solana_sdk::pubkey::new_rand();
let mut transfer_instruction = let mut transfer_instruction =
system_instruction::transfer(&mint_keypair.pubkey(), &key.pubkey(), 0); system_instruction::transfer(&mint_keypair.pubkey(), &key, 0);
transfer_instruction.accounts[0].is_signer = false; transfer_instruction.accounts[0].is_signer = false;
let message = Message::new(&[transfer_instruction], None); let message = Message::new(&[transfer_instruction], None);
let tx = Transaction::new(&[&Keypair::new(); 0], message, bank.last_blockhash()); let tx = Transaction::new(&[&Keypair::new(); 0], message, bank.last_blockhash());
@ -12244,7 +12242,7 @@ pub(crate) mod tests {
bank.process_transaction(&tx), bank.process_transaction(&tx),
Err(TransactionError::SanitizeFailure) Err(TransactionError::SanitizeFailure)
); );
assert_eq!(bank.get_balance(&key.pubkey()), 0); assert_eq!(bank.get_balance(&key), 0);
} }
#[test] #[test]

View File

@ -78,7 +78,6 @@ fn test_shrink_and_clean() {
#[test] #[test]
fn test_bad_bank_hash() { fn test_bad_bank_hash() {
solana_logger::setup(); solana_logger::setup();
use solana_sdk::signature::{Keypair, Signer};
let db = AccountsDb::new_for_tests(Vec::new(), &ClusterType::Development); let db = AccountsDb::new_for_tests(Vec::new(), &ClusterType::Development);
let some_slot: Slot = 0; let some_slot: Slot = 0;
@ -88,7 +87,7 @@ fn test_bad_bank_hash() {
let mut accounts_keys: Vec<_> = (0..max_accounts) let mut accounts_keys: Vec<_> = (0..max_accounts)
.into_par_iter() .into_par_iter()
.map(|_| { .map(|_| {
let key = Keypair::new().pubkey(); let key = solana_sdk::pubkey::new_rand();
let lamports = thread_rng().gen_range(0, 100); let lamports = thread_rng().gen_range(0, 100);
let some_data_len = thread_rng().gen_range(0, 1000); let some_data_len = thread_rng().gen_range(0, 1000);
let account = AccountSharedData::new(lamports, some_data_len, &key); let account = AccountSharedData::new(lamports, some_data_len, &key);