Skip to content
This repository has been archived by the owner on Jan 10, 2025. It is now read-only.

token-swap: Add fuzzer for swap / withdraw / deposit #875

Merged
merged 24 commits into from
Nov 30, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix unrelated new clippy errors
  • Loading branch information
joncinque committed Nov 25, 2020
commit 458043223c329c068b4b4da34b0240b10f341565
9 changes: 4 additions & 5 deletions shared-memory/program/tests/shared-memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ use solana_bpf_loader_program::{
serialization::{deserialize_parameters, serialize_parameters},
};
use solana_program::{
bpf_loader, entrypoint::SUCCESS, instruction::InstructionError, program_error::ProgramError,
pubkey::Pubkey,
bpf_loader, entrypoint::SUCCESS, program_error::ProgramError, pubkey::Pubkey,
};
use solana_rbpf::vm::EbpfVm;
use solana_sdk::{
Expand All @@ -26,7 +25,7 @@ fn run_program(
program_id: &Pubkey,
parameter_accounts: &[KeyedAccount],
instruction_data: &[u8],
) -> Result<u64, InstructionError> {
) -> u64 {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This came from a new clippy error

let program_account = Account {
data: load_program("../../target/deploy/spl_shared_memory.so"),
..Account::default()
Expand Down Expand Up @@ -58,7 +57,7 @@ fn run_program(
.unwrap()
);
deserialize_parameters(&loader_id, parameter_accounts, &parameter_bytes).unwrap();
Ok(vm.get_total_instruction_count())
vm.get_total_instruction_count()
}

#[test]
Expand All @@ -74,7 +73,7 @@ fn assert_instruction_count() {
let content = vec![42; NUM_TO_SHARE];
let mut instruction_data = OFFSET.to_le_bytes().to_vec();
instruction_data.extend_from_slice(&content);
let share_count = run_program(&program_id, &parameter_accounts[..], &instruction_data).unwrap();
let share_count = run_program(&program_id, &parameter_accounts[..], &instruction_data);
const BASELINE_COUNT: u64 = 1474; // 113 if NUM_TO_SHARE is 8
println!(
"BPF instructions executed {:?} (expected {:?})",
Expand Down
17 changes: 7 additions & 10 deletions token/perf-monitor/tests/assert_instruction_count.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use solana_sdk::{
account::{create_account, Account as SolanaAccount},
bpf_loader,
entrypoint::SUCCESS,
instruction::InstructionError,
keyed_account::KeyedAccount,
process_instruction::MockInvokeContext,
program_option::COption,
Expand All @@ -33,7 +32,7 @@ fn run_program(
program_id: &Pubkey,
parameter_accounts: &[KeyedAccount],
instruction_data: &[u8],
) -> Result<u64, InstructionError> {
) -> u64 {
let program_account = SolanaAccount {
data: load_program("../../target/deploy/spl_token.so"),
..SolanaAccount::default()
Expand Down Expand Up @@ -65,7 +64,7 @@ fn run_program(
vm.execute_program(parameter_bytes.as_mut_slice(), &[], &[heap_region])
);
deserialize_parameters(&loader_id, parameter_accounts, &parameter_bytes).unwrap();
Ok(vm.get_total_instruction_count())
vm.get_total_instruction_count()
}

#[test]
Expand Down Expand Up @@ -95,7 +94,7 @@ fn assert_instruction_count() {
KeyedAccount::new(&rent_key, false, &rent_account),
];
let initialize_mint_count =
run_program(&program_id, &parameter_accounts[..], &instruction_data).unwrap();
run_program(&program_id, &parameter_accounts[..], &instruction_data);

// Create source account
let instruction_data = TokenInstruction::InitializeAccount.pack();
Expand All @@ -105,8 +104,7 @@ fn assert_instruction_count() {
KeyedAccount::new(&owner_key, false, &owner_account),
KeyedAccount::new(&rent_key, false, &rent_account),
];
let mintto_count =
run_program(&program_id, &parameter_accounts[..], &instruction_data).unwrap();
let mintto_count = run_program(&program_id, &parameter_accounts[..], &instruction_data);

// Create destination account
let instruction_data = TokenInstruction::InitializeAccount.pack();
Expand All @@ -116,7 +114,7 @@ fn assert_instruction_count() {
KeyedAccount::new(&owner_key, false, &owner_account),
KeyedAccount::new(&rent_key, false, &rent_account),
];
let _ = run_program(&program_id, &parameter_accounts[..], &instruction_data).unwrap();
let _ = run_program(&program_id, &parameter_accounts[..], &instruction_data);

// MintTo source account
let instruction_data = TokenInstruction::MintTo { amount: 100 }.pack();
Expand All @@ -126,7 +124,7 @@ fn assert_instruction_count() {
KeyedAccount::new(&owner_key, true, &owner_account),
];
let initialize_account_count =
run_program(&program_id, &parameter_accounts[..], &instruction_data).unwrap();
run_program(&program_id, &parameter_accounts[..], &instruction_data);

// Transfer from source to destination
let instruction = TokenInstruction::Transfer { amount: 100 };
Expand All @@ -136,8 +134,7 @@ fn assert_instruction_count() {
KeyedAccount::new(&destination_key, false, &destination_account),
KeyedAccount::new(&owner_key, true, &owner_account),
];
let transfer_count =
run_program(&program_id, &parameter_accounts[..], &instruction_data).unwrap();
let transfer_count = run_program(&program_id, &parameter_accounts[..], &instruction_data);

const BASELINE_NEW_MINT_COUNT: u64 = 4000; // last known 3802
const BASELINE_INITIALIZE_ACCOUNT_COUNT: u64 = 6500; // last known 6445
Expand Down