Simplify account.rent_epoch handling for sysvar rent (#16049)

* Add some code for special local testing

* Add comment to store_account_and_update_capitalization

* Simplify account.rent_epoch handling for sysvar rent

* Introduce *_for_test functions

* Add deprecation messages to existing api
This commit is contained in:
Ryo Onodera
2021-03-25 15:23:20 +09:00
committed by GitHub
parent 7f0ac6a67c
commit 6d5c6c17c5
16 changed files with 206 additions and 104 deletions

View File

@ -884,7 +884,9 @@ mod tests {
message_processor::{Executors, ThisInvokeContext},
};
use solana_sdk::{
account::{create_account_shared_data as create_account, AccountSharedData},
account::{
create_account_shared_data_for_test as create_account_for_test, AccountSharedData,
},
account_utils::StateMut,
client::SyncClient,
clock::Clock,
@ -2215,15 +2217,12 @@ mod tests {
file.read_to_end(&mut elf_new).unwrap();
assert_ne!(elf_orig.len(), elf_new.len());
let rent = Rent::default();
let rent_account = RefCell::new(create_account(&Rent::default(), 1));
let rent_account = RefCell::new(create_account_for_test(&Rent::default()));
let slot = 42;
let clock_account = RefCell::new(create_account(
&Clock {
slot,
..Clock::default()
},
1,
));
let clock_account = RefCell::new(create_account_for_test(&Clock {
slot,
..Clock::default()
}));
let min_program_balance =
1.max(rent.minimum_balance(UpgradeableLoaderState::program_len().unwrap()));
let min_programdata_balance = 1.max(rent.minimum_balance(

View File

@ -663,15 +663,17 @@ mod tests {
.iter()
.map(|meta| {
RefCell::new(if sysvar::clock::check_id(&meta.pubkey) {
account::create_account_shared_data(&sysvar::clock::Clock::default(), 1)
account::create_account_shared_data_for_test(&sysvar::clock::Clock::default())
} else if sysvar::rewards::check_id(&meta.pubkey) {
account::create_account_shared_data(&sysvar::rewards::Rewards::new(0.0), 1)
account::create_account_shared_data_for_test(&sysvar::rewards::Rewards::new(
0.0,
))
} else if sysvar::stake_history::check_id(&meta.pubkey) {
account::create_account_shared_data(&StakeHistory::default(), 1)
account::create_account_shared_data_for_test(&StakeHistory::default())
} else if config::check_id(&meta.pubkey) {
config::create_account(0, &config::Config::default())
} else if sysvar::rent::check_id(&meta.pubkey) {
account::create_account_shared_data(&Rent::default(), 1)
account::create_account_shared_data_for_test(&Rent::default())
} else if meta.pubkey == invalid_stake_state_pubkey() {
AccountSharedData::from(Account {
owner: id(),
@ -973,7 +975,9 @@ mod tests {
KeyedAccount::new(
&sysvar::rent::id(),
false,
&RefCell::new(account::create_account_shared_data(&Rent::default(), 0))
&RefCell::new(account::create_account_shared_data_for_test(
&Rent::default()
))
)
],
&serialize(&StakeInstruction::Initialize(
@ -1028,17 +1032,15 @@ mod tests {
KeyedAccount::new(
&sysvar::clock::id(),
false,
&RefCell::new(account::create_account_shared_data(
&RefCell::new(account::create_account_shared_data_for_test(
&sysvar::clock::Clock::default(),
1
))
),
KeyedAccount::new(
&sysvar::stake_history::id(),
false,
&RefCell::new(account::create_account_shared_data(
&RefCell::new(account::create_account_shared_data_for_test(
&sysvar::stake_history::StakeHistory::default(),
1
))
),
KeyedAccount::new(
@ -1063,17 +1065,15 @@ mod tests {
KeyedAccount::new(
&sysvar::rewards::id(),
false,
&RefCell::new(account::create_account_shared_data(
&RefCell::new(account::create_account_shared_data_for_test(
&sysvar::rewards::Rewards::new(0.0),
1
))
),
KeyedAccount::new(
&sysvar::stake_history::id(),
false,
&RefCell::new(account::create_account_shared_data(
&RefCell::new(account::create_account_shared_data_for_test(
&StakeHistory::default(),
1,
))
),
],
@ -1107,9 +1107,8 @@ mod tests {
KeyedAccount::new(
&sysvar::rewards::id(),
false,
&RefCell::new(account::create_account_shared_data(
&RefCell::new(account::create_account_shared_data_for_test(
&sysvar::rewards::Rewards::new(0.0),
1
))
),
],

View File

@ -370,11 +370,11 @@ mod tests {
.iter()
.map(|meta| {
RefCell::new(if sysvar::clock::check_id(&meta.pubkey) {
account::create_account_shared_data(&Clock::default(), 1)
account::create_account_shared_data_for_test(&Clock::default())
} else if sysvar::slot_hashes::check_id(&meta.pubkey) {
account::create_account_shared_data(&SlotHashes::default(), 1)
account::create_account_shared_data_for_test(&SlotHashes::default())
} else if sysvar::rent::check_id(&meta.pubkey) {
account::create_account_shared_data(&Rent::free(), 1)
account::create_account_shared_data_for_test(&Rent::free())
} else if meta.pubkey == invalid_vote_state_pubkey() {
AccountSharedData::from(Account {
owner: invalid_vote_state_pubkey(),