Cleanup use (#16327)

This commit is contained in:
Jack May 2021-04-02 08:54:09 -07:00 committed by GitHub
parent 9784bbb802
commit dee655df35
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 46 additions and 79 deletions

1
Cargo.lock generated
View File

@ -4985,7 +4985,6 @@ dependencies = [
"solana-banks-server",
"solana-bpf-loader-program",
"solana-logger 1.7.0",
"solana-program 1.7.0",
"solana-runtime",
"solana-sdk",
"solana-stake-program",

View File

@ -18,7 +18,6 @@ solana-banks-client = { path = "../banks-client", version = "=1.7.0" }
solana-banks-server = { path = "../banks-server", version = "=1.7.0" }
solana-bpf-loader-program = { path = "../programs/bpf_loader", version = "=1.7.0" }
solana-logger = { path = "../logger", version = "=1.7.0" }
solana-program = { path = "../sdk/program", version = "=1.7.0" }
solana-runtime = { path = "../runtime", version = "=1.7.0" }
solana-sdk = { path = "../sdk", version = "=1.7.0" }
solana-vote-program = { path = "../programs/vote", version = "=1.7.0" }

View File

@ -7,20 +7,6 @@ use {
log::*,
solana_banks_client::start_client,
solana_banks_server::banks_server::start_local_server,
solana_program::{
account_info::AccountInfo,
entrypoint::ProgramResult,
fee_calculator::{FeeCalculator, FeeRateGovernor},
hash::Hash,
instruction::Instruction,
instruction::InstructionError,
message::Message,
native_token::sol_to_lamports,
program_error::ProgramError,
program_stubs,
pubkey::Pubkey,
rent::Rent,
},
solana_runtime::{
bank::{Bank, Builtin, ExecuteTimings},
bank_forks::BankForks,
@ -29,13 +15,24 @@ use {
},
solana_sdk::{
account::{Account, AccountSharedData, ReadableAccount},
account_info::AccountInfo,
clock::Slot,
entrypoint::ProgramResult,
feature_set::demote_sysvar_write_locks,
fee_calculator::{FeeCalculator, FeeRateGovernor},
genesis_config::{ClusterType, GenesisConfig},
hash::Hash,
instruction::Instruction,
instruction::InstructionError,
keyed_account::KeyedAccount,
message::Message,
native_token::sol_to_lamports,
process_instruction::{
stable_log, BpfComputeBudget, InvokeContext, ProcessInstructionWithContext,
},
program_error::ProgramError,
pubkey::Pubkey,
rent::Rent,
signature::{Keypair, Signer},
},
solana_vote_program::vote_state::{VoteState, VoteStateVersions},
@ -94,7 +91,7 @@ fn get_invoke_context<'a>() -> &'a mut dyn InvokeContext {
}
pub fn builtin_process_instruction(
process_instruction: solana_program::entrypoint::ProcessInstruction,
process_instruction: solana_sdk::entrypoint::ProcessInstruction,
program_id: &Pubkey,
keyed_accounts: &[KeyedAccount],
input: &[u8],
@ -185,7 +182,7 @@ macro_rules! processor {
}
struct SyscallStubs {}
impl program_stubs::SyscallStubs for SyscallStubs {
impl solana_sdk::program_stubs::SyscallStubs for SyscallStubs {
fn sol_log(&self, message: &str) {
let invoke_context = get_invoke_context();
let logger = invoke_context.get_logger();
@ -529,7 +526,7 @@ impl ProgramTest {
program_id: Pubkey,
process_instruction: Option<ProcessInstructionWithContext>,
) {
let loader = solana_program::bpf_loader::id();
let loader = solana_sdk::bpf_loader::id();
let program_file = find_file(&format!("{}.so", program_name));
if process_instruction.is_none() && program_file.is_none() {
@ -604,7 +601,7 @@ impl ProgramTest {
static ONCE: Once = Once::new();
ONCE.call_once(|| {
program_stubs::set_syscall_stubs(Box::new(SyscallStubs {}));
solana_sdk::program_stubs::set_syscall_stubs(Box::new(SyscallStubs {}));
});
}

View File

@ -42,7 +42,7 @@ pub fn spl_programs(rent: &Rent) -> Vec<(Pubkey, AccountSharedData)> {
AccountSharedData::from(Account {
lamports: rent.minimum_balance(elf.len()).min(1),
data: elf.to_vec(),
owner: solana_program::bpf_loader::id(),
owner: solana_sdk::bpf_loader::id(),
executable: true,
rent_epoch: 0,
}),

View File

@ -1,14 +1,15 @@
use {
solana_program::{
solana_program_test::{processor, ProgramTest},
solana_sdk::{
account_info::{next_account_info, AccountInfo},
entrypoint::ProgramResult,
instruction::{AccountMeta, Instruction},
msg,
program::invoke,
pubkey::Pubkey,
signature::Signer,
transaction::Transaction,
},
solana_program_test::{processor, ProgramTest},
solana_sdk::{signature::Signer, transaction::Transaction},
};
// Process instruction to invoke into another program
@ -44,20 +45,19 @@ fn invoked_process_instruction(
#[tokio::test]
async fn cpi() {
let invoker_program_id = Pubkey::new_unique();
// Initialize and start the test network
let mut program_test = ProgramTest::new(
"program-test-fuzz-invoker",
"invoker",
invoker_program_id,
processor!(invoker_process_instruction),
);
let invoked_program_id = Pubkey::new_unique();
program_test.add_program(
"program-test-fuzz-invoked",
"invoked",
invoked_program_id,
processor!(invoked_process_instruction),
);
let mut test_state = program_test.start_with_context().await;
let mut context = program_test.start_with_context().await;
let instructions = vec![Instruction::new_with_bincode(
invoker_program_id,
&[0],
@ -66,12 +66,12 @@ async fn cpi() {
let transaction = Transaction::new_signed_with_payer(
&instructions,
Some(&test_state.payer.pubkey()),
&[&test_state.payer],
test_state.last_blockhash,
Some(&context.payer.pubkey()),
&[&context.payer],
context.last_blockhash,
);
test_state
context
.banks_client
.process_transaction(transaction)
.await

View File

@ -1,11 +1,11 @@
use {
solana_banks_client::BanksClient,
solana_program::{
account_info::AccountInfo, entrypoint::ProgramResult, hash::Hash, instruction::Instruction,
msg, pubkey::Pubkey, rent::Rent, system_instruction,
},
solana_program_test::{processor, ProgramTest},
solana_sdk::{signature::Keypair, signature::Signer, transaction::Transaction},
solana_sdk::{
account_info::AccountInfo, entrypoint::ProgramResult, hash::Hash, instruction::Instruction,
msg, pubkey::Pubkey, rent::Rent, signature::Keypair, signature::Signer, system_instruction,
transaction::Transaction,
},
};
#[allow(clippy::unnecessary_wraps)]
@ -57,16 +57,16 @@ fn simulate_fuzz_with_context() {
processor!(process_instruction),
);
let mut test_state = rt.block_on(async { program_test.start_with_context().await });
let mut context = rt.block_on(async { program_test.start_with_context().await });
// the honggfuzz `fuzz!` macro does not allow for async closures,
// so we have to use the runtime directly to run async functions
rt.block_on(async {
run_fuzz_instructions(
&[1, 2, 3, 4, 5],
&mut test_state.banks_client,
&test_state.payer,
test_state.last_blockhash,
&mut context.banks_client,
&context.payer,
context.last_blockhash,
&program_id,
)
.await

View File

@ -1,6 +1,7 @@
#![allow(clippy::integer_arithmetic)]
use {
solana_program::{
solana_program_test::{processor, ProgramTest, ProgramTestError},
solana_sdk::{
account_info::{next_account_info, AccountInfo},
clock::Clock,
entrypoint::ProgramResult,
@ -8,12 +9,9 @@ use {
program_error::ProgramError,
pubkey::Pubkey,
rent::Rent,
signature::{Keypair, Signer},
system_instruction, system_program,
sysvar::{clock, Sysvar},
},
solana_program_test::{processor, ProgramTest, ProgramTestError},
solana_sdk::{
signature::{Keypair, Signer},
transaction::{Transaction, TransactionError},
},
solana_stake_program::{

View File

@ -878,11 +878,7 @@ impl Executor for BpfExecutor {
mod tests {
use super::*;
use rand::Rng;
use solana_runtime::{
bank::Bank,
bank_client::BankClient,
message_processor::{Executors, ThisInvokeContext},
};
use solana_runtime::{bank::Bank, bank_client::BankClient};
use solana_sdk::{
account::{
create_account_shared_data_for_test as create_account_for_test, AccountSharedData,
@ -895,7 +891,7 @@ mod tests {
instruction::Instruction,
instruction::{AccountMeta, InstructionError},
message::Message,
process_instruction::{BpfComputeBudget, MockInvokeContext},
process_instruction::{MockComputeMeter, MockInvokeContext},
pubkey::Pubkey,
rent::Rent,
signature::{Keypair, Signer},
@ -1128,33 +1124,11 @@ mod tests {
// Case: limited budget
let program_id = Pubkey::default();
let mut invoke_context = ThisInvokeContext::new(
&program_id,
Rent::default(),
vec![],
&[],
&[],
&[],
None,
BpfComputeBudget {
max_units: 1,
log_units: 100,
log_64_units: 100,
create_program_address_units: 1500,
invoke_units: 1000,
max_invoke_depth: 2,
sha256_base_cost: 85,
sha256_byte_cost: 1,
max_call_depth: 20,
stack_frame_size: 4096,
log_pubkey_units: 100,
max_cpi_instruction_size: usize::MAX,
cpi_bytes_per_unit: 250,
},
Rc::new(RefCell::new(Executors::default())),
None,
Arc::new(FeatureSet::default()),
);
let mut invoke_context = MockInvokeContext {
key: program_id,
compute_meter: MockComputeMeter::default(),
..MockInvokeContext::default()
};
assert_eq!(
Err(InstructionError::ProgramFailedToComplete),
process_instruction(&program_key, &keyed_accounts, &[], &mut invoke_context)