Cleanup unsupported sysvars (#16390)
* Cleanup unsupported sysvars * fix ser description
This commit is contained in:
@ -7,11 +7,12 @@ use solana_program::{
|
||||
entrypoint,
|
||||
entrypoint::ProgramResult,
|
||||
msg,
|
||||
program_error::ProgramError,
|
||||
pubkey::Pubkey,
|
||||
rent,
|
||||
sysvar::{
|
||||
self, clock::Clock, fees::Fees, rent::Rent, slot_hashes::SlotHashes,
|
||||
stake_history::StakeHistory, Sysvar,
|
||||
self, clock::Clock, fees::Fees, instructions, rent::Rent, slot_hashes::SlotHashes,
|
||||
slot_history::SlotHistory, stake_history::StakeHistory, Sysvar,
|
||||
},
|
||||
};
|
||||
|
||||
@ -25,37 +26,54 @@ fn process_instruction(
|
||||
// Clock
|
||||
msg!("Clock identifier:");
|
||||
sysvar::clock::id().log();
|
||||
let clock = Clock::from_account_info(&accounts[2]).expect("clock");
|
||||
let clock = Clock::from_account_info(&accounts[2]).unwrap();
|
||||
assert_eq!(clock.slot, DEFAULT_SLOTS_PER_EPOCH + 1);
|
||||
|
||||
// Fees
|
||||
msg!("Fees identifier:");
|
||||
sysvar::fees::id().log();
|
||||
let fees = Fees::from_account_info(&accounts[3]).expect("fees");
|
||||
let fees = Fees::from_account_info(&accounts[3]).unwrap();
|
||||
let fee_calculator = fees.fee_calculator;
|
||||
assert_eq!(fee_calculator.lamports_per_signature, 0);
|
||||
|
||||
// Instructions
|
||||
msg!("Instructions identifier:");
|
||||
sysvar::instructions::id().log();
|
||||
let index = instructions::load_current_index(&accounts[4].try_borrow_data()?);
|
||||
assert_eq!(0, index);
|
||||
msg!(
|
||||
"instruction {:?}",
|
||||
instructions::load_instruction_at(index as usize, &accounts[4].try_borrow_data()?)
|
||||
);
|
||||
|
||||
let due = Rent::from_account_info(&accounts[5]).unwrap().due(
|
||||
rent::DEFAULT_LAMPORTS_PER_BYTE_YEAR * rent::DEFAULT_EXEMPTION_THRESHOLD as u64,
|
||||
1,
|
||||
1.0,
|
||||
);
|
||||
assert_eq!(due, (0, true));
|
||||
|
||||
// Slot Hashes
|
||||
msg!("SlotHashes identifier:");
|
||||
sysvar::slot_hashes::id().log();
|
||||
let slot_hashes = SlotHashes::from_account_info(&accounts[4]).expect("slot_hashes");
|
||||
assert!(slot_hashes.len() >= 1);
|
||||
assert_eq!(
|
||||
Err(ProgramError::UnsupportedSysvar),
|
||||
SlotHashes::from_account_info(&accounts[6])
|
||||
);
|
||||
|
||||
// Slot History
|
||||
msg!("SlotHistory identifier:");
|
||||
sysvar::slot_history::id().log();
|
||||
assert_eq!(
|
||||
Err(ProgramError::UnsupportedSysvar),
|
||||
SlotHistory::from_account_info(&accounts[7])
|
||||
);
|
||||
|
||||
// Stake History
|
||||
msg!("StakeHistory identifier:");
|
||||
sysvar::stake_history::id().log();
|
||||
let stake_history = StakeHistory::from_account_info(&accounts[5]).expect("stake_history");
|
||||
let stake_history = StakeHistory::from_account_info(&accounts[8]).unwrap();
|
||||
assert!(stake_history.len() >= 1);
|
||||
|
||||
let rent = Rent::from_account_info(&accounts[6]).unwrap();
|
||||
assert_eq!(
|
||||
rent.due(
|
||||
rent::DEFAULT_LAMPORTS_PER_BYTE_YEAR * rent::DEFAULT_EXEMPTION_THRESHOLD as u64,
|
||||
1,
|
||||
1.0
|
||||
),
|
||||
(0, true)
|
||||
);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
@ -35,7 +35,7 @@ use solana_sdk::{
|
||||
pubkey::Pubkey,
|
||||
signature::{keypair_from_seed, Keypair, Signer},
|
||||
system_instruction,
|
||||
sysvar::{clock, fees, rent, slot_hashes, stake_history},
|
||||
sysvar::{clock, fees, rent, slot_hashes, slot_history, stake_history, instructions},
|
||||
transaction::{Transaction, TransactionError},
|
||||
};
|
||||
use solana_transaction_status::{
|
||||
@ -465,11 +465,14 @@ fn test_program_bpf_sanity() {
|
||||
let account_metas = vec![
|
||||
AccountMeta::new(mint_keypair.pubkey(), true),
|
||||
AccountMeta::new(Keypair::new().pubkey(), false),
|
||||
AccountMeta::new(clock::id(), false),
|
||||
AccountMeta::new(fees::id(), false),
|
||||
AccountMeta::new(slot_hashes::id(), false),
|
||||
AccountMeta::new(stake_history::id(), false),
|
||||
AccountMeta::new(rent::id(), false),
|
||||
AccountMeta::new_readonly(clock::id(), false),
|
||||
AccountMeta::new_readonly(fees::id(), false),
|
||||
AccountMeta::new_readonly(instructions::id(), false),
|
||||
AccountMeta::new_readonly(rent::id(), false),
|
||||
AccountMeta::new_readonly(slot_hashes::id(), false),
|
||||
AccountMeta::new_readonly(slot_history::id(), false),
|
||||
AccountMeta::new_readonly(stake_history::id(), false),
|
||||
|
||||
];
|
||||
let instruction = Instruction::new_with_bytes(program_id, &[1], account_metas);
|
||||
let result = bank_client.send_and_confirm_instruction(&mint_keypair, instruction);
|
||||
|
Reference in New Issue
Block a user