Feature: TransactionContext, InstructionContext and BorrowedAccount (#21706)

* Adds TransactionContext, InstructionContext and BorrowedAccount.

* Redirects the usage of accounts in InvokeContext through TransactionContext.
Also use the types declared in transaction_context.rs everywhere.

* Adjusts all affected tests.
This commit is contained in:
Alexander Meißner
2021-12-27 18:49:32 +01:00
committed by GitHub
parent bb97c8fdcd
commit a06646631c
14 changed files with 926 additions and 530 deletions

View File

@ -1308,6 +1308,7 @@ mod tests {
native_token,
pubkey::Pubkey,
system_program,
transaction_context::TransactionContext,
},
solana_vote_program::vote_state,
std::{cell::RefCell, iter::FromIterator},
@ -4998,7 +4999,8 @@ mod tests {
#[test]
fn test_merge() {
let invoke_context = InvokeContext::new_mock(&[], &[]);
let transaction_context = TransactionContext::new(Vec::new(), 1);
let invoke_context = InvokeContext::new_mock(&transaction_context, &[]);
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();
@ -5108,7 +5110,8 @@ mod tests {
#[test]
fn test_merge_self_fails() {
let invoke_context = InvokeContext::new_mock(&[], &[]);
let transaction_context = TransactionContext::new(Vec::new(), 1);
let invoke_context = InvokeContext::new_mock(&transaction_context, &[]);
let stake_address = Pubkey::new_unique();
let authority_pubkey = Pubkey::new_unique();
let signers = HashSet::from_iter(vec![authority_pubkey]);
@ -5153,7 +5156,8 @@ mod tests {
#[test]
fn test_merge_incorrect_authorized_staker() {
let invoke_context = InvokeContext::new_mock(&[], &[]);
let transaction_context = TransactionContext::new(Vec::new(), 1);
let invoke_context = InvokeContext::new_mock(&transaction_context, &[]);
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();
@ -5222,7 +5226,8 @@ mod tests {
#[test]
fn test_merge_invalid_account_data() {
let invoke_context = InvokeContext::new_mock(&[], &[]);
let transaction_context = TransactionContext::new(Vec::new(), 1);
let invoke_context = InvokeContext::new_mock(&transaction_context, &[]);
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();
@ -5272,7 +5277,8 @@ mod tests {
#[test]
fn test_merge_fake_stake_source() {
let invoke_context = InvokeContext::new_mock(&[], &[]);
let transaction_context = TransactionContext::new(Vec::new(), 1);
let invoke_context = InvokeContext::new_mock(&transaction_context, &[]);
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();
@ -5314,7 +5320,8 @@ mod tests {
#[test]
fn test_merge_active_stake() {
let invoke_context = InvokeContext::new_mock(&[], &[]);
let transaction_context = TransactionContext::new(Vec::new(), 1);
let invoke_context = InvokeContext::new_mock(&transaction_context, &[]);
let base_lamports = 4242424242;
let stake_address = Pubkey::new_unique();
let source_address = Pubkey::new_unique();
@ -5936,7 +5943,8 @@ mod tests {
#[test]
fn test_things_can_merge() {
let invoke_context = InvokeContext::new_mock(&[], &[]);
let transaction_context = TransactionContext::new(Vec::new(), 1);
let invoke_context = InvokeContext::new_mock(&transaction_context, &[]);
let good_stake = Stake {
credits_observed: 4242,
delegation: Delegation {
@ -6034,7 +6042,8 @@ mod tests {
#[test]
fn test_metas_can_merge_pre_v4() {
let invoke_context = InvokeContext::new_mock(&[], &[]);
let transaction_context = TransactionContext::new(Vec::new(), 1);
let invoke_context = InvokeContext::new_mock(&transaction_context, &[]);
// Identical Metas can merge
assert!(MergeKind::metas_can_merge(
&invoke_context,
@ -6120,7 +6129,8 @@ mod tests {
#[test]
fn test_metas_can_merge_v4() {
let invoke_context = InvokeContext::new_mock(&[], &[]);
let transaction_context = TransactionContext::new(Vec::new(), 1);
let invoke_context = InvokeContext::new_mock(&transaction_context, &[]);
// Identical Metas can merge
assert!(MergeKind::metas_can_merge(
&invoke_context,
@ -6266,7 +6276,8 @@ mod tests {
#[test]
fn test_merge_kind_get_if_mergeable() {
let invoke_context = InvokeContext::new_mock(&[], &[]);
let transaction_context = TransactionContext::new(Vec::new(), 1);
let invoke_context = InvokeContext::new_mock(&transaction_context, &[]);
let authority_pubkey = Pubkey::new_unique();
let initial_lamports = 4242424242;
let rent = Rent::default();
@ -6498,7 +6509,8 @@ mod tests {
#[test]
fn test_merge_kind_merge() {
let invoke_context = InvokeContext::new_mock(&[], &[]);
let transaction_context = TransactionContext::new(Vec::new(), 1);
let invoke_context = InvokeContext::new_mock(&transaction_context, &[]);
let lamports = 424242;
let meta = Meta {
rent_exempt_reserve: 42,
@ -6576,7 +6588,8 @@ mod tests {
#[test]
fn test_active_stake_merge() {
let invoke_context = InvokeContext::new_mock(&[], &[]);
let transaction_context = TransactionContext::new(Vec::new(), 1);
let invoke_context = InvokeContext::new_mock(&transaction_context, &[]);
let delegation_a = 4_242_424_242u64;
let delegation_b = 6_200_000_000u64;
let credits_a = 124_521_000u64;