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

Additional anchor types #115

Merged
merged 14 commits into from
Feb 14, 2024
Merged
2 changes: 1 addition & 1 deletion .github/actions/setup-rust/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ runs:
rustup component add rustfmt clippy
shell: bash
- name: Install Cargo Expand
run: cargo install cargo-expand
run: cargo install --locked cargo-expand
shell: bash
- name: Get rustc version
id: rust-version
Expand Down
190 changes: 174 additions & 16 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions crates/client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ macrotest = "1.0.9"

[dependencies]
trdelnik-test = { workspace = true }
anchor-lang = { version = "0.29.0", features = ["idl-build"] }
solana-sdk = { workspace = true }
solana-cli-output = { workspace = true }
solana-transaction-status = { workspace = true }
Expand Down
1 change: 1 addition & 0 deletions crates/client/src/fuzzer/data_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ pub enum FuzzingError {
CannotGetInstructionData,
CannotDeserializeAccount,
NotEnoughAccounts, // TODO add also custom error
AccountNotFound,
}

#[macro_export]
Expand Down
18 changes: 18 additions & 0 deletions crates/client/src/fuzzer/snapshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,25 @@ where
Ok(accounts)
}

fn set_missing_accounts_to_default(accounts: &mut [Option<Account>]) {
for acc in accounts.iter_mut() {
if acc.is_none() {
*acc = Some(solana_sdk::account::Account::default());
}
}
}

pub fn get_snapshot(&'info mut self) -> Result<(T::Ix, T::Ix), FuzzingError> {
// When user passes an account that is not initialized, the runtime will provide
// a default empty account to the program. If the uninitialized account is of type
// AccountInfo, Signer or UncheckedAccount, Anchor will not return an error. However
// when we try to fetch "on-chain" accounts and an account is not initilized, this
// account simply does not exist and the get_account() method returns None. To prevent
// errors during deserialization due to missing accounts, we replace the missing accounts
// with default values similar as the runtime does.
Self::set_missing_accounts_to_default(&mut self.before);
Self::set_missing_accounts_to_default(&mut self.after);

let pre_ix = self.ix.deserialize_option(self.metas, &mut self.before)?;
let post_ix = self.ix.deserialize_option(self.metas, &mut self.after)?;
Ok((pre_ix, post_ix))
Expand Down
Loading
Loading