Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tests #112

Merged
merged 20 commits into from
Feb 3, 2024
Merged

Tests #112

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 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
3 changes: 3 additions & 0 deletions .github/actions/setup-rust/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ runs:
rustup default nightly
rustup component add rustfmt clippy
shell: bash
- name: Install Cargo Expand
run: cargo install cargo-expand
shell: bash
- name: Get rustc version
id: rust-version
run: echo "::set-output name=RUSTC_HASH::$(rustc -V | cut -d " " -f 3 | tail -c +2)"
Expand Down
3 changes: 2 additions & 1 deletion crates/client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ anyhow = { version = "1.0.45", features = ["std"], default-features = false }

[dev-dependencies]
pretty_assertions = "1.1.0"
macrotest = "1.0.9"

[dependencies]
trdelnik-test = { workspace = true }
Expand Down Expand Up @@ -60,4 +61,4 @@ shellexpand = { workspace = true }
trdelnik-derive-displayix = { path = "./derive/display_ix" }
trdelnik-derive-fuzz-deserialize = { path = "./derive/fuzz_deserialize" }
trdelnik-derive-fuzz-test-executor = { path = "./derive/fuzz_test_executor" }
pathdiff="0.2.1"
pathdiff = "0.2.1"
46 changes: 20 additions & 26 deletions crates/client/src/fuzzer/fuzzer_generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,31 +173,25 @@ pub fn generate_source_code(idl: &Idl) -> String {
)
.into_iter();

let fuzz_accounts = idl_program
.instruction_account_pairs
.iter()
.fold(
HashMap::new(),
|mut fuzz_accounts, (_idl_instruction, idl_account_group)| {
idl_account_group.accounts.iter().fold(
&mut fuzz_accounts,
|fuzz_accounts, (name, _ty)| {
let name = format_ident!("{name}");
fuzz_accounts.entry(name).or_insert_with(|| "".to_string());
fuzz_accounts
},
);

fuzz_accounts
},
)
.into_iter()
.map(|fuzz_accounts| {
// TODO find out the type of the account and remember it as Keypair, PdaStore, TokenStore, MintStore, ProgramStore etc.
fuzz_accounts.0
})
.collect::<Vec<_>>()
.into_iter();
let fuzz_accounts = idl_program.instruction_account_pairs.iter().fold(
HashMap::new(),
|mut fuzz_accounts, (_idl_instruction, idl_account_group)| {
idl_account_group.accounts.iter().fold(
&mut fuzz_accounts,
|fuzz_accounts, (name, _ty)| {
let name = format_ident!("{name}");
fuzz_accounts.entry(name).or_insert_with(|| "".to_string());
fuzz_accounts
},
);

fuzz_accounts
},
);
// this ensures that the order of accounts is deterministic
// so we can use expected generated template within tests
let mut sorted_fuzz_accounts: Vec<_> = fuzz_accounts.keys().collect();
sorted_fuzz_accounts.sort();

let fuzzer_module: syn::ItemMod = parse_quote! {
pub mod #fuzz_instructions_module_name {
Expand All @@ -218,7 +212,7 @@ pub fn generate_source_code(idl: &Idl) -> String {
/// Keypair, PdaStore, TokenStore, MintStore, ProgramStore
#[derive(Default)]
pub struct FuzzAccounts {
#(#fuzz_accounts: AccountsStorage<todo!()>),*
#(#sorted_fuzz_accounts: AccountsStorage<todo!()>),*
}

impl FuzzAccounts {
Expand Down
5 changes: 5 additions & 0 deletions crates/client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,8 @@ pub use error_reporter::*;

pub mod cleaner;
pub use cleaner::*;

// This is a workaround for tests: https://github.com/Ackee-Blockchain/trdelnik/pull/112#issuecomment-1924920952
pub use trdelnik_derive_displayix::DisplayIx;
pub use trdelnik_derive_fuzz_deserialize::FuzzDeserialize;
pub use trdelnik_derive_fuzz_test_executor::FuzzTestExecutor;
Loading
Loading