Skip to content

Commit

Permalink
Merge pull request #112 from Ackee-Blockchain/tests
Browse files Browse the repository at this point in the history
Tests
  • Loading branch information
Ikrk authored Feb 3, 2024
2 parents c0d76e2 + 16e18bc commit 9776295
Show file tree
Hide file tree
Showing 27 changed files with 4,812 additions and 33 deletions.
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

0 comments on commit 9776295

Please sign in to comment.