Unifies ThisInvokeContext and dyn trait InvokeContext. (#21563)

This commit is contained in:
Alexander Meißner
2021-12-02 18:47:16 +01:00
committed by GitHub
parent 8dfa83c579
commit bfdb775ffc
21 changed files with 366 additions and 431 deletions

View File

@ -25,7 +25,7 @@ pub use solana_sdk::stake::instruction::*;
pub fn process_instruction(
first_instruction_account: usize,
data: &[u8],
invoke_context: &mut dyn InvokeContext,
invoke_context: &mut InvokeContext,
) -> Result<(), InstructionError> {
let keyed_accounts = invoke_context.get_keyed_accounts()?;
@ -327,7 +327,7 @@ mod tests {
use crate::stake_state::{Meta, StakeState};
use bincode::serialize;
use solana_program_runtime::invoke_context::{
mock_process_instruction, prepare_mock_invoke_context, ThisInvokeContext,
mock_process_instruction, prepare_mock_invoke_context, InvokeContext,
};
use solana_sdk::{
account::{self, AccountSharedData},
@ -416,7 +416,7 @@ mod tests {
let mut data = Vec::with_capacity(sysvar::clock::Clock::size_of());
bincode::serialize_into(&mut data, &sysvar::clock::Clock::default()).unwrap();
let sysvars = [(sysvar::clock::id(), data)];
let mut invoke_context = ThisInvokeContext::new_mock_with_sysvars_and_features(
let mut invoke_context = InvokeContext::new_mock_with_sysvars_and_features(
&preparation.accounts,
&[],
&sysvars,
@ -1066,7 +1066,7 @@ mod tests {
let mut data = Vec::with_capacity(sysvar::clock::Clock::size_of());
bincode::serialize_into(&mut data, &sysvar::clock::Clock::default()).unwrap();
let sysvars = [(sysvar::clock::id(), data)];
let mut invoke_context = ThisInvokeContext::new_mock_with_sysvars_and_features(
let mut invoke_context = InvokeContext::new_mock_with_sysvars_and_features(
&preparation.accounts,
&[],
&sysvars,

View File

@ -395,7 +395,7 @@ pub trait StakeAccount {
) -> Result<(), InstructionError>;
fn merge(
&self,
invoke_context: &dyn InvokeContext,
invoke_context: &InvokeContext,
source_stake: &KeyedAccount,
clock: &Clock,
stake_history: &StakeHistory,
@ -701,7 +701,7 @@ impl<'a> StakeAccount for KeyedAccount<'a> {
fn merge(
&self,
invoke_context: &dyn InvokeContext,
invoke_context: &InvokeContext,
source_account: &KeyedAccount,
clock: &Clock,
stake_history: &StakeHistory,
@ -865,7 +865,7 @@ impl MergeKind {
}
fn get_if_mergeable(
invoke_context: &dyn InvokeContext,
invoke_context: &InvokeContext,
stake_keyed_account: &KeyedAccount,
clock: &Clock,
stake_history: &StakeHistory,
@ -897,7 +897,7 @@ impl MergeKind {
}
fn metas_can_merge(
invoke_context: &dyn InvokeContext,
invoke_context: &InvokeContext,
stake: &Meta,
source: &Meta,
clock: Option<&Clock>,
@ -926,7 +926,7 @@ impl MergeKind {
}
fn active_delegations_can_merge(
invoke_context: &dyn InvokeContext,
invoke_context: &InvokeContext,
stake: &Delegation,
source: &Delegation,
) -> Result<(), InstructionError> {
@ -946,7 +946,7 @@ impl MergeKind {
// Remove this when the `stake_merge_with_unmatched_credits_observed` feature is removed
fn active_stakes_can_merge(
invoke_context: &dyn InvokeContext,
invoke_context: &InvokeContext,
stake: &Stake,
source: &Stake,
) -> Result<(), InstructionError> {
@ -969,7 +969,7 @@ impl MergeKind {
fn merge(
self,
invoke_context: &dyn InvokeContext,
invoke_context: &InvokeContext,
source: Self,
clock: Option<&Clock>,
) -> Result<Option<StakeState>, InstructionError> {
@ -1033,7 +1033,7 @@ impl MergeKind {
}
fn merge_delegation_stake_and_credits_observed(
invoke_context: &dyn InvokeContext,
invoke_context: &InvokeContext,
stake: &mut Stake,
absorbed_lamports: u64,
absorbed_credits_observed: u64,
@ -1372,7 +1372,7 @@ fn do_create_account(
mod tests {
use super::*;
use proptest::prelude::*;
use solana_program_runtime::invoke_context::ThisInvokeContext;
use solana_program_runtime::invoke_context::InvokeContext;
use solana_sdk::{
account::{AccountSharedData, WritableAccount},
clock::UnixTimestamp,
@ -5068,7 +5068,7 @@ mod tests {
#[test]
fn test_merge() {
let invoke_context = ThisInvokeContext::new_mock(&[], &[]);
let invoke_context = InvokeContext::new_mock(&[], &[]);
let stake_pubkey = solana_sdk::pubkey::new_rand();
let source_stake_pubkey = solana_sdk::pubkey::new_rand();
let authorized_pubkey = solana_sdk::pubkey::new_rand();
@ -5178,7 +5178,7 @@ mod tests {
#[test]
fn test_merge_self_fails() {
let invoke_context = ThisInvokeContext::new_mock(&[], &[]);
let invoke_context = InvokeContext::new_mock(&[], &[]);
let stake_address = Pubkey::new_unique();
let authority_pubkey = Pubkey::new_unique();
let signers = HashSet::from_iter(vec![authority_pubkey]);
@ -5223,7 +5223,7 @@ mod tests {
#[test]
fn test_merge_incorrect_authorized_staker() {
let invoke_context = ThisInvokeContext::new_mock(&[], &[]);
let invoke_context = InvokeContext::new_mock(&[], &[]);
let stake_pubkey = solana_sdk::pubkey::new_rand();
let source_stake_pubkey = solana_sdk::pubkey::new_rand();
let authorized_pubkey = solana_sdk::pubkey::new_rand();
@ -5292,7 +5292,7 @@ mod tests {
#[test]
fn test_merge_invalid_account_data() {
let invoke_context = ThisInvokeContext::new_mock(&[], &[]);
let invoke_context = InvokeContext::new_mock(&[], &[]);
let stake_pubkey = solana_sdk::pubkey::new_rand();
let source_stake_pubkey = solana_sdk::pubkey::new_rand();
let authorized_pubkey = solana_sdk::pubkey::new_rand();
@ -5342,7 +5342,7 @@ mod tests {
#[test]
fn test_merge_fake_stake_source() {
let invoke_context = ThisInvokeContext::new_mock(&[], &[]);
let invoke_context = InvokeContext::new_mock(&[], &[]);
let stake_pubkey = solana_sdk::pubkey::new_rand();
let source_stake_pubkey = solana_sdk::pubkey::new_rand();
let authorized_pubkey = solana_sdk::pubkey::new_rand();
@ -5384,7 +5384,7 @@ mod tests {
#[test]
fn test_merge_active_stake() {
let invoke_context = ThisInvokeContext::new_mock(&[], &[]);
let invoke_context = InvokeContext::new_mock(&[], &[]);
let base_lamports = 4242424242;
let stake_address = Pubkey::new_unique();
let source_address = Pubkey::new_unique();
@ -5453,7 +5453,7 @@ mod tests {
);
fn try_merge(
invoke_context: &dyn InvokeContext,
invoke_context: &InvokeContext,
stake_account: &KeyedAccount,
source_account: &KeyedAccount,
clock: &Clock,
@ -6006,7 +6006,7 @@ mod tests {
#[test]
fn test_things_can_merge() {
let invoke_context = ThisInvokeContext::new_mock(&[], &[]);
let invoke_context = InvokeContext::new_mock(&[], &[]);
let good_stake = Stake {
credits_observed: 4242,
delegation: Delegation {
@ -6104,7 +6104,7 @@ mod tests {
#[test]
fn test_metas_can_merge_pre_v4() {
let invoke_context = ThisInvokeContext::new_mock(&[], &[]);
let invoke_context = InvokeContext::new_mock(&[], &[]);
// Identical Metas can merge
assert!(MergeKind::metas_can_merge(
&invoke_context,
@ -6190,7 +6190,7 @@ mod tests {
#[test]
fn test_metas_can_merge_v4() {
let invoke_context = ThisInvokeContext::new_mock(&[], &[]);
let invoke_context = InvokeContext::new_mock(&[], &[]);
// Identical Metas can merge
assert!(MergeKind::metas_can_merge(
&invoke_context,
@ -6336,7 +6336,7 @@ mod tests {
#[test]
fn test_merge_kind_get_if_mergeable() {
let invoke_context = ThisInvokeContext::new_mock(&[], &[]);
let invoke_context = InvokeContext::new_mock(&[], &[]);
let authority_pubkey = Pubkey::new_unique();
let initial_lamports = 4242424242;
let rent = Rent::default();
@ -6568,7 +6568,7 @@ mod tests {
#[test]
fn test_merge_kind_merge() {
let invoke_context = ThisInvokeContext::new_mock(&[], &[]);
let invoke_context = InvokeContext::new_mock(&[], &[]);
let lamports = 424242;
let meta = Meta {
rent_exempt_reserve: 42,
@ -6646,7 +6646,7 @@ mod tests {
#[test]
fn test_active_stake_merge() {
let invoke_context = ThisInvokeContext::new_mock(&[], &[]);
let invoke_context = InvokeContext::new_mock(&[], &[]);
let delegation_a = 4_242_424_242u64;
let delegation_b = 6_200_000_000u64;
let credits_a = 124_521_000u64;