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
Refactor and cleanup
  • Loading branch information
joncinque committed Nov 25, 2020
commit 9e9f1dddf4440cc9cc5cd940f516fa0128ad5008
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 6 additions & 3 deletions token-swap/program/fuzz/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
[package]
name = "spl-token-swap-fuzz"
version = "0.0.0"
authors = ["Automatically generated"]
publish = false
version = "0.0.1"
description = "Solana Program Library Token Swap Fuzzer"
authors = ["Solana Maintainers <maintainers@solana.foundation>"]
repository = "https://github.com/solana-labs/solana-program-library"
license = "Apache-2.0"
edition = "2018"
publish = false

[dependencies]
honggfuzz = { version = "0.5" }
Expand Down
21 changes: 12 additions & 9 deletions token-swap/program/fuzz/src/instructions.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use spl_token_swap_fuzz::{get_token_balance, AccountData, TokenSwapAccountInfo};
use spl_token_swap_fuzz::{
native_account_data::NativeAccountData, native_token::get_token_balance,
native_token_swap::NativeTokenSwap,
};

Copy link
Contributor

Choose a reason for hiding this comment

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

nit: try remove whitespace between successive use statements

use spl_token_swap::{
curve::{
Expand Down Expand Up @@ -85,16 +88,16 @@ fn run_fuzz_instructions(fuzz_instructions: Vec<FuzzInstruction>) {
host_fee_denominator,
}),
};
let mut token_swap = TokenSwapAccountInfo::new(
let mut token_swap = NativeTokenSwap::new(
swap_curve,
INITIAL_SWAP_TOKEN_A_AMOUNT,
INITIAL_SWAP_TOKEN_B_AMOUNT,
);

// keep track of all accounts, including swap accounts
let mut token_a_accounts: HashMap<AccountId, AccountData> = HashMap::new();
let mut token_b_accounts: HashMap<AccountId, AccountData> = HashMap::new();
let mut pool_accounts: HashMap<AccountId, AccountData> = HashMap::new();
let mut token_a_accounts: HashMap<AccountId, NativeAccountData> = HashMap::new();
let mut token_b_accounts: HashMap<AccountId, NativeAccountData> = HashMap::new();
let mut pool_accounts: HashMap<AccountId, NativeAccountData> = HashMap::new();

// to ensure that we never create or remove base tokens
let before_total_token_a =
Expand Down Expand Up @@ -173,10 +176,10 @@ fn run_fuzz_instructions(fuzz_instructions: Vec<FuzzInstruction>) {

fn run_fuzz_instruction(
fuzz_instruction: FuzzInstruction,
token_swap: &mut TokenSwapAccountInfo,
token_a_accounts: &mut HashMap<AccountId, AccountData>,
token_b_accounts: &mut HashMap<AccountId, AccountData>,
pool_accounts: &mut HashMap<AccountId, AccountData>,
token_swap: &mut NativeTokenSwap,
token_a_accounts: &mut HashMap<AccountId, NativeAccountData>,
token_b_accounts: &mut HashMap<AccountId, NativeAccountData>,
pool_accounts: &mut HashMap<AccountId, NativeAccountData>,
) {
let result = match fuzz_instruction {
FuzzInstruction::Swap {
Expand Down
Loading