Skip to content

Commit

Permalink
actually these tests are meaningless now
Browse files Browse the repository at this point in the history
  • Loading branch information
2501babe committed Nov 9, 2024
1 parent 7a881b4 commit 48eaadd
Showing 1 changed file with 1 addition and 343 deletions.
344 changes: 1 addition & 343 deletions svm/tests/integration_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,13 @@ use {
EXECUTION_SLOT, WALLCLOCK_TIME,
},
solana_sdk::{
account::{AccountSharedData, ReadableAccount, WritableAccount, PROGRAM_OWNERS},
bpf_loader_upgradeable::{self, UpgradeableLoaderState},
account::{AccountSharedData, ReadableAccount, WritableAccount},
clock::Slot,
compute_budget::ComputeBudgetInstruction,
entrypoint::MAX_PERMITTED_DATA_INCREASE,
feature_set::{self, FeatureSet},
hash::Hash,
instruction::{AccountMeta, Instruction},
native_loader,
native_token::LAMPORTS_PER_SOL,
nonce::{self, state::DurableNonce},
pubkey::Pubkey,
Expand Down Expand Up @@ -2286,344 +2284,6 @@ fn simd83_account_reallocate(enable_fee_only_transactions: bool) -> Vec<SvmTestE
test_entries
}

fn simd83_bpf_loader_buffer(enable_fee_only_transactions: bool) -> Vec<SvmTestEntry> {
let mut test_entries = vec![];

let mut common_test_entry = SvmTestEntry::default();
common_test_entry
.enabled_features
.push(feature_set::enable_account_loader_cache::id());
if enable_fee_only_transactions {
common_test_entry
.enabled_features
.push(feature_set::enable_transaction_loading_failure_fees::id());
}

let program_name = "write-to-account";
let program_id = program_address(program_name);
common_test_entry.add_initial_program(program_name);

let fee_payer_keypair = Keypair::new();
let fee_payer = fee_payer_keypair.pubkey();

let mut fee_payer_data = AccountSharedData::default();
fee_payer_data.set_lamports(LAMPORTS_PER_SOL);
fee_payer_data.set_rent_epoch(u64::MAX);
common_test_entry.add_initial_account(fee_payer, &fee_payer_data);

let buffer_keypair = Keypair::new();
let buffer = buffer_keypair.pubkey();

let mut buffer_bytes = vec![0; MAX_PERMITTED_DATA_INCREASE];
bincode::serialize_into(
&mut buffer_bytes,
&UpgradeableLoaderState::Buffer {
authority_address: Some(fee_payer),
},
)
.unwrap();

// this is used to test non-buffer accounts for all loaders
let mut throwaway_account_owners = vec![None];
for program_owner in PROGRAM_OWNERS {
throwaway_account_owners.push(Some(*program_owner));
}

let initial_buffer_data = AccountSharedData::create(
LAMPORTS_PER_SOL,
buffer_bytes.clone(),
bpf_loader_upgradeable::id(),
false,
u64::MAX,
);
common_test_entry.add_initial_account(buffer, &initial_buffer_data);

// bpf_loader_upgradeable does not reassign closed accounts to system
// so reopening a closed buffer under a new owner can only be done in a subsequent transaction
let close_transaction = Transaction::new_signed_with_payer(
&[bpf_loader_upgradeable::close(
&buffer, &fee_payer, &fee_payer,
)],
Some(&fee_payer),
&[&fee_payer_keypair],
Hash::default(),
);

// make a transaction to reopen an account with a given size
let reopen = |new_size: usize| {
let reopen_transaction = Transaction::new_signed_with_payer(
&[system_instruction::create_account(
&fee_payer,
&buffer,
LAMPORTS_PER_SOL,
new_size as u64,
&system_program::id(),
)],
Some(&fee_payer),
&[&fee_payer_keypair, &buffer_keypair],
Hash::default(),
);

let reopened_buffer_data = AccountSharedData::create(
LAMPORTS_PER_SOL,
vec![0; new_size],
system_program::id(),
false,
u64::MAX,
);

(reopen_transaction, reopened_buffer_data)
};

let print_transaction = WriteProgramInstruction::Print.create_transaction(
program_id,
&fee_payer_keypair,
buffer,
None,
);

let common_test_entry = common_test_entry;

// batch 0:
// * check buffer size (must be account size)
{
let mut test_entry = common_test_entry.clone();

test_entry.push_transaction(print_transaction.clone());
test_entry.transaction_batch[0]
.asserts
.logs
.push(format!("Program log: account size {}", buffer_bytes.len(),));

test_entry.decrease_expected_lamports(&fee_payer, LAMPORTS_PER_SIGNATURE);

test_entries.push(test_entry);
}

// batch 1:
// * close buffer
// * check buffer size (must be zero)
{
let mut test_entry = common_test_entry.clone();

test_entry.push_transaction(close_transaction.clone());
test_entry.push_transaction(print_transaction.clone());
test_entry.transaction_batch[1]
.asserts
.logs
.push("Program log: account size 0".to_string());

test_entry
.increase_expected_lamports(&fee_payer, LAMPORTS_PER_SOL - LAMPORTS_PER_SIGNATURE * 2);
test_entry.drop_expected_account(buffer);

test_entries.push(test_entry);
}

// batch 2:
// * close buffer
// * reopen as system account of large size
// * check buffer size (must be new size)
{
let mut test_entry = common_test_entry.clone();

let (reopen_transaction, reopened_buffer_data) = reopen(MAX_PERMITTED_DATA_INCREASE);

test_entry.push_transaction(close_transaction.clone());
test_entry.push_transaction(reopen_transaction);
test_entry.push_transaction(print_transaction);
test_entry.transaction_batch[2].asserts.logs.push(format!(
"Program log: account size {}",
MAX_PERMITTED_DATA_INCREASE,
));

test_entry.decrease_expected_lamports(&fee_payer, LAMPORTS_PER_SIGNATURE * 4);
test_entry.update_expected_account_data(buffer, &reopened_buffer_data);

test_entries.push(test_entry);
}

// HANA TODO this is kind of nonsense with the new design
// it tests an escape hatch that is no longer there
// however it might retain some merit if its possible to reopen a programdata account
// i asked in discord if it was ever user-settable
// if no one knows i can just pull every program account from mainnet ig
// also remember to update the paragraph below if i change this test
//
// batch 3/4:
// * close buffer
// * reopen as (3: small, 4: large) system account
// * include account as invisible and use compute budget to check size
//
// batch 3 is a sanity check that compute budget failure depends only on the new account size
// it succeeds because we create a 1 byte account with a 10kb transaction data size limit
//
// in batch 4 we expect the third transaction to see a 10kb account
// this fails given a 10kb limit because there are some other accounts of negligible size
// this codepath will find it in the accounts cache, then find it in the program cache
// the program cache check normally substitutes a different transaction size
// this is so read-only non-instruction upgradeable program sizes include programdata
// in this case, however, we do *not* use the program cache size (which is always 0)
// because the program cache does not evict entries, even if the account was closed
//
// the test account must be read-only non-instruction, so we append it to account keys
// we use a system program transfer for our no-op to simplify size math because its only 14 bytes
for sanity_check in [true, false] {
let mut test_entry = common_test_entry.clone();

let new_account_size = if sanity_check {
1
} else {
MAX_PERMITTED_DATA_INCREASE
};

let (reopen_transaction, reopened_buffer_data) = reopen(new_account_size);

let mut noop_transaction = Transaction::new_with_payer(
&[
ComputeBudgetInstruction::set_loaded_accounts_data_size_limit(
MAX_PERMITTED_DATA_INCREASE as u32,
),
system_instruction::transfer(&fee_payer, &fee_payer, 0),
],
Some(&fee_payer),
);

noop_transaction.message.account_keys.push(buffer);
noop_transaction
.message
.header
.num_readonly_unsigned_accounts += 1;
noop_transaction.sign(&[&fee_payer_keypair], Hash::default());

let expected_status = if sanity_check {
test_entry.decrease_expected_lamports(&fee_payer, LAMPORTS_PER_SIGNATURE * 4);
ExecutionStatus::Succeeded
} else if enable_fee_only_transactions {
test_entry.decrease_expected_lamports(&fee_payer, LAMPORTS_PER_SIGNATURE * 4);
ExecutionStatus::ProcessedFailed
} else {
test_entry.decrease_expected_lamports(&fee_payer, LAMPORTS_PER_SIGNATURE * 3);
ExecutionStatus::Discarded
};

test_entry.push_transaction(close_transaction.clone());
test_entry.push_transaction(reopen_transaction);
test_entry.push_transaction_with_status(noop_transaction, expected_status);

test_entry.update_expected_account_data(buffer, &reopened_buffer_data);

test_entries.push(test_entry);
}

/* HANA TODO this test changes because of my feature gate
i believe i can just delete this, we always use real sizes for tombstoned cache entries now
i dont think there remains anything to actually test. maybe just test we get real sizes
oh i should actually test a closed program size goes to 36 tho
// batch 5: buffer from program cache has zero size
// batch 6: same as above but force it into account cache
// batches 7-14: both of above, with an account owned by each loader
for throwaway_account_owner in throwaway_account_owners {
for transaction_count in 1..=2 {
let mut test_entry = common_test_entry.clone();
let target = match throwaway_account_owner {
None => buffer,
Some(loader_id) => {
let target = Pubkey::new_unique();
let throwaway_account_data = AccountSharedData::create(
LAMPORTS_PER_SOL,
vec![0; MAX_PERMITTED_DATA_INCREASE],
loader_id,
false,
u64::MAX,
);
test_entry.add_initial_account(target, &throwaway_account_data);
target
}
};
// 10kb budget is a comfortable margin to ensure the calculated size of the target is zero
// if the real account size is used, the program sizes push us over this threshold
let mut noop_transaction = Transaction::new_with_payer(
&[
ComputeBudgetInstruction::set_loaded_accounts_data_size_limit(
MAX_PERMITTED_DATA_INCREASE as u32,
),
system_instruction::transfer(&fee_payer, &fee_payer, 0),
],
Some(&fee_payer),
);
noop_transaction.message.account_keys.push(target);
noop_transaction
.message
.header
.num_readonly_unsigned_accounts += 1;
noop_transaction.sign(&[&fee_payer_keypair], Hash::default());
for _ in 0..transaction_count {
test_entry.push_transaction(noop_transaction.clone());
}
test_entry
.decrease_expected_lamports(&fee_payer, LAMPORTS_PER_SIGNATURE * transaction_count);
test_entries.push(test_entry);
}
}
*/

// batch 15: non-builtin accounts owned by NativeLoader are never added to the cache
{
let mut test_entry = common_test_entry.clone();

let target = Pubkey::new_unique();

let throwaway_account_data = AccountSharedData::create(
LAMPORTS_PER_SOL,
vec![0; MAX_PERMITTED_DATA_INCREASE],
native_loader::id(),
false,
u64::MAX,
);

test_entry.add_initial_account(target, &throwaway_account_data);

let mut noop_transaction = Transaction::new_with_payer(
&[
ComputeBudgetInstruction::set_loaded_accounts_data_size_limit(
MAX_PERMITTED_DATA_INCREASE as u32 / 2,
),
system_instruction::transfer(&fee_payer, &fee_payer, 0),
],
Some(&fee_payer),
);

noop_transaction.message.account_keys.push(target);
noop_transaction
.message
.header
.num_readonly_unsigned_accounts += 1;
noop_transaction.sign(&[&fee_payer_keypair], Hash::default());

let expected_status = if enable_fee_only_transactions {
test_entry.decrease_expected_lamports(&fee_payer, LAMPORTS_PER_SIGNATURE);
ExecutionStatus::ProcessedFailed
} else {
ExecutionStatus::Discarded
};

test_entry.push_transaction_with_status(noop_transaction, expected_status);

test_entries.push(test_entry);
}

test_entries
}

#[test_case(program_medley())]
#[test_case(simple_transfer(false))]
#[test_case(simple_transfer(true))]
Expand All @@ -2642,8 +2302,6 @@ fn simd83_bpf_loader_buffer(enable_fee_only_transactions: bool) -> Vec<SvmTestEn
#[test_case(simd83_fee_payer_deallocate(true))]
#[test_case(simd83_account_reallocate(false))]
#[test_case(simd83_account_reallocate(true))]
#[test_case(simd83_bpf_loader_buffer(false))]
#[test_case(simd83_bpf_loader_buffer(true))]
fn svm_integration(test_entries: Vec<SvmTestEntry>) {
for test_entry in test_entries {
let env = SvmTestEnvironment::create(test_entry);
Expand Down

0 comments on commit 48eaadd

Please sign in to comment.