Skip to content

Commit

Permalink
📌 unify exports from trident
Browse files Browse the repository at this point in the history
  • Loading branch information
lukacan committed Jun 27, 2024
1 parent 1cc34a4 commit 23f7008
Show file tree
Hide file tree
Showing 56 changed files with 745 additions and 183 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
incremented upon a breaking change and the patch version will be incremented for features.

## [dev] - Unreleased
- fix/in case of fuzzing failure throw error instead of only printing message([#167](https://github.com/Ackee-Blockchain/trident/pull/167))
- feat/unify dependencies provided by the Trident ([#172](https://github.com/Ackee-Blockchain/trident/pull/172))
- fix/in case of fuzzing failure throw error instead of only printing message ([#167](https://github.com/Ackee-Blockchain/trident/pull/167))
- del/remove Trident explorer ([#171](https://github.com/Ackee-Blockchain/trident/pull/171))
- fix/snapshot's zeroed account as optional ([#170](https://github.com/Ackee-Blockchain/trident/pull/170))
- feat/fuzzer-stats-logging, an optional statistics output for fuzzing session ([#144](https://github.com/Ackee-Blockchain/trident/pull/144))
Expand Down
2 changes: 1 addition & 1 deletion crates/cli/src/command/build.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use anyhow::{bail, Error};
use fehler::throws;
use trident_client::*;
use trident_client::___private::TestGenerator;

use crate::_discover;

Expand Down
2 changes: 1 addition & 1 deletion crates/cli/src/command/clean.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use anyhow::Error;
use fehler::throws;
use trident_client::Cleaner;
use trident_client::___private::Cleaner;

#[throws]
pub async fn clean() {
Expand Down
2 changes: 1 addition & 1 deletion crates/cli/src/command/fuzz.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use anyhow::{bail, Error};

use clap::Subcommand;
use fehler::throws;
use trident_client::{Commander, TestGenerator};
use trident_client::___private::{Commander, TestGenerator};

use crate::_discover;

Expand Down
2 changes: 1 addition & 1 deletion crates/cli/src/command/init.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use anyhow::{bail, Error};
use clap::ValueEnum;
use fehler::throws;
use trident_client::TestGenerator;
use trident_client::___private::TestGenerator;

use crate::_discover;

Expand Down
2 changes: 1 addition & 1 deletion crates/cli/src/command/keypair.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use anyhow::Error;
use clap::Subcommand;
use fehler::throws;
use solana_sdk::signer::Signer;
use trident_client::{keypair as other_keypair, program_keypair, system_keypair};
use trident_client::___private::{keypair as other_keypair, program_keypair, system_keypair};

#[derive(Subcommand)]
pub enum KeyPairCommand {
Expand Down
2 changes: 1 addition & 1 deletion crates/cli/src/command/localnet.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use anyhow::Error;
use fehler::throws;
use tokio::signal;
use trident_client::*;
use trident_client::___private::Commander;

#[throws]
pub async fn localnet() {
Expand Down
2 changes: 1 addition & 1 deletion crates/cli/src/command/test.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use anyhow::{bail, Error};
use fehler::throws;
use trident_client::*;
use trident_client::___private::Commander;

use crate::_discover;

Expand Down
4 changes: 3 additions & 1 deletion crates/client/src/client.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use crate::{config::Config, Reader, TempClone};
use crate::___private::Reader;
use crate::___private::TempClone;
use crate::config::Config;
use anchor_client::{
anchor_lang::{
prelude::System, solana_program::program_pack::Pack, AccountDeserialize, Id,
Expand Down
8 changes: 3 additions & 5 deletions crates/client/src/commander.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
use crate::___private::Client;
use crate::config::Config;
use crate::idl::{self};
use crate::test_generator::ProgramData;
use crate::{
idl::{self},
Client,
};
use fehler::{throw, throws};
use log::debug;
use solana_sdk::signer::keypair::Keypair;
Expand All @@ -19,7 +17,7 @@ use tokio::{
};

use crate::constants::*;
use crate::fuzzing_stats::FuzzingStatistics;
use crate::fuzzer::fuzzing_stats::FuzzingStatistics;
use tokio::io::AsyncBufReadExt;

#[derive(Error, Debug)]
Expand Down
3 changes: 2 additions & 1 deletion crates/client/src/fuzzer/accounts_storage.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#![allow(dead_code)]
use std::collections::HashMap;

use solana_sdk::{pubkey::Pubkey, signature::Keypair};

use crate::{data_builder::FuzzClient, AccountId};
use crate::fuzzer::{data_builder::FuzzClient, AccountId};

pub struct PdaStore {
pub pubkey: Pubkey,
Expand Down
4 changes: 3 additions & 1 deletion crates/client/src/fuzzer/data_builder.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(dead_code)]

use anchor_client::anchor_lang::solana_program::account_info::{Account as Acc, AccountInfo};
use anchor_client::anchor_lang::solana_program::hash::Hash;
use anchor_lang::prelude::Rent;
Expand All @@ -13,7 +15,7 @@ use std::collections::HashMap;
use std::error::Error;
use std::fmt::Display;

use crate::error::*;
use crate::fuzzer::error::*;

pub struct FuzzData<T, U> {
pub pre_ixs: Vec<T>,
Expand Down
2 changes: 2 additions & 0 deletions crates/client/src/fuzzer/error.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(dead_code)]

use solana_banks_client::BanksClientError;
use solana_sdk::pubkey::Pubkey;
use std::fmt::{Debug, Display};
Expand Down
2 changes: 2 additions & 0 deletions crates/client/src/fuzzer/fuzzing_stats.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(dead_code)]

use prettytable::{row, Table};
use std::collections::HashMap;

Expand Down
11 changes: 6 additions & 5 deletions crates/client/src/fuzzer/program_test_client_blocking.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use crate::fuzzing::ProgramTest;
use crate::fuzzing::{ProgramTestContext, SYSTEM_PROGRAM_ID};
use crate::solana_sdk::account::Account;
use solana_program_runtime::invoke_context::BuiltinFunctionWithContext;
use solana_program_test::ProgramTest;
use solana_program_test::ProgramTestContext;
use solana_sdk::account::Account;
use solana_sdk::account_info::AccountInfo;
use solana_sdk::entrypoint::ProgramResult;
use solana_sdk::system_program::ID as SYSTEM_PROGRAM_ID;
use solana_sdk::{
account::AccountSharedData, hash::Hash, instruction::AccountMeta, program_option::COption,
program_pack::Pack, pubkey::Pubkey, rent::Rent, signature::Keypair, signature::Signer,
Expand All @@ -12,8 +13,8 @@ use solana_sdk::{
use spl_token::state::Mint;
use tokio::runtime::Builder;

use crate::data_builder::FuzzClient;
use crate::error::*;
use crate::fuzzer::data_builder::FuzzClient;
use crate::fuzzer::error::*;

pub type ProgramEntry = for<'info> fn(
program_id: &Pubkey,
Expand Down
4 changes: 2 additions & 2 deletions crates/client/src/fuzzer/snapshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ use anchor_client::anchor_lang::solana_program::account_info::Account as Acc;
use anchor_client::anchor_lang::solana_program::account_info::AccountInfo;
use solana_sdk::{account::Account, instruction::AccountMeta};

use crate::data_builder::{FuzzClient, FuzzDeserialize};
use crate::error::*;
use crate::fuzzer::data_builder::{FuzzClient, FuzzDeserialize};
use crate::fuzzer::error::*;
pub struct Snapshot<'info, T> {
before: Vec<Option<Account>>,
before_acc_inf: Vec<Option<AccountInfo<'info>>>,
Expand Down
4 changes: 2 additions & 2 deletions crates/client/src/fuzzer/snapshot_generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ pub fn generate_snapshots_code(programs_data: &[ProgramData]) -> Result<String,
let program_name_ident = format_ident!("{}", program_data.program_idl.name.snake_case);

let use_statements = quote! {
use trident_client::anchor_lang::{prelude::*, self};
use trident_client::fuzzing::FuzzingError;
use anchor_lang::prelude::*;
use trident_client::fuzzing::{anchor_lang, FuzzingError};
use #program_name_ident::ID as PROGRAM_ID;
}
.into_token_stream();
Expand Down
172 changes: 95 additions & 77 deletions crates/client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,105 +3,123 @@
//!
//! Trident could be useful for writing Rust dApps, too.

pub use anchor_client::{
self,
anchor_lang::{self, prelude::System, Id, InstructionData, ToAccountMetas},
solana_sdk::{
self,
instruction::Instruction,
pubkey::Pubkey,
signature::Signature,
signer::{keypair::Keypair, Signer},
},
ClientError,
};
pub use anyhow::{self, Error};

/// Aimed for the fuzz tests
#[cfg(feature = "fuzzing")]
pub mod fuzzing {
pub use self::anchor_lang::solana_program::instruction::AccountMeta;
pub use super::{
anchor_lang, anchor_lang::system_program::ID as SYSTEM_PROGRAM_ID,
anchor_lang::InstructionData, anchor_lang::ToAccountInfo, anchor_lang::ToAccountMetas,
fuzz_trident, show_account, solana_sdk::account::Account,
solana_sdk::entrypoint::ProcessInstruction, solana_sdk::transaction::Transaction,
Instruction, Keypair, Pubkey, Signer, TempClone,
};
pub use anchor_client::anchor_lang::solana_program::account_info::AccountInfo;
pub use anchor_client::anchor_lang::solana_program::hash::Hash;
/// anchor_lang
pub use anchor_lang;
pub use anchor_lang::solana_program::hash::Hash;
pub use anchor_lang::InstructionData;
pub use anchor_lang::Key;
pub use anchor_lang::ToAccountInfo;
pub use anchor_lang::ToAccountMetas;

/// solana_sdk
pub use solana_sdk;
pub use solana_sdk::account_info::AccountInfo;
pub use solana_sdk::entrypoint::ProcessInstruction;
pub use solana_sdk::instruction::AccountMeta;
pub use solana_sdk::instruction::Instruction;
pub use solana_sdk::pubkey::Pubkey;
pub use solana_sdk::signer::keypair::Keypair;
pub use solana_sdk::signer::Signer;
pub use solana_sdk::transaction::Transaction;

/// arbitrary and honggfuzz
pub use arbitrary;
pub use arbitrary::Arbitrary;
pub use honggfuzz::fuzz;
pub use solana_program_test::{
processor, tokio::runtime::Runtime, BanksClient, BanksClientError, ProgramTest,
ProgramTestContext,
};

pub use super::error::*;
/// trident derive
pub use trident_derive_displayix::DisplayIx;
pub use trident_derive_fuzz_deserialize::FuzzDeserialize;
pub use trident_derive_fuzz_test_executor::FuzzTestExecutor;

/// trident macros
pub use super::fuzzer::*;
pub use crate::convert_entry;
pub use crate::fuzz_trident;
pub use crate::show_account;

pub use super::fuzzer::program_test_client_blocking::ProgramEntry;
pub use solana_program_test::processor;

/// trident methods
pub use super::fuzzer::accounts_storage::*;
pub use super::fuzzer::data_builder::build_ix_fuzz_data;
pub use super::fuzzer::data_builder::*;
pub use super::fuzzing_stats::FuzzingStatistics;

pub use super::fuzzer::program_test_client_blocking::ProgramEntry;
pub use super::fuzzer::error::*;
pub use super::fuzzer::fuzzing_stats::FuzzingStatistics;
pub use super::fuzzer::program_test_client_blocking::ProgramTestClientBlocking;
pub use super::fuzzer::snapshot::Snapshot;
pub use super::fuzzer::*;
pub use super::temp_clone::*;

pub use std::cell::RefCell;
pub use std::collections::HashMap;
pub use trident_derive_displayix::DisplayIx;
pub use trident_derive_fuzz_deserialize::FuzzDeserialize;
pub use trident_derive_fuzz_test_executor::FuzzTestExecutor;
}

pub use futures::{self, FutureExt};
pub use rstest::*;
pub use serial_test;
pub use solana_transaction_status::EncodedConfirmedTransactionWithStatusMeta;
pub use tokio;

pub use trident_test::trident_test;
/// Aimed for the integration tests
pub mod test {
pub use super::client::*;
pub use super::error_reporter::report_error;
pub use super::keys::*;
pub use super::tester::Tester;
pub use anyhow::{self, Error, Result};
pub use futures::{self, FutureExt};
pub use rstest::*;
pub use serial_test;
pub use solana_transaction_status::EncodedConfirmedTransactionWithStatusMeta;
pub use tokio;
pub use trident_test::trident_test;
}

mod config;
/// Aimed for general usage
pub mod prelude {
pub use super::temp_clone::*;
pub use anchor_client::ClientError;
pub use anchor_lang;
pub use anchor_lang::InstructionData;
pub use anchor_lang::ToAccountMetas;
pub use solana_sdk;
pub use solana_sdk::instruction::Instruction;
pub use solana_sdk::pubkey::Pubkey;
pub use solana_sdk::signer::keypair::Keypair;
pub use solana_sdk::signer::Signer;
}

mod cleaner;
mod client;
pub use client::Client;
pub use client::PrintableTransaction;

mod reader;
pub use reader::Reader;

mod commander;
pub use commander::{Commander, LocalnetHandle};

mod tester;
pub use tester::Tester;

mod temp_clone;
pub use temp_clone::TempClone;

mod keys;
pub use keys::*;

mod config;
mod error_reporter;
mod fuzzer;
pub use fuzzer::*;
pub mod idl;
pub mod program_client_generator;

pub mod test_generator;
pub use test_generator::TestGenerator;

pub mod error_reporter;
pub use error_reporter::*;

pub mod cleaner;
pub use cleaner::*;
mod idl;
mod keys;
mod program_client_generator;
mod reader;
mod temp_clone;
mod test_generator;
mod tester;

// This is a workaround for tests: https://github.com/Ackee-Blockchain/trident/pull/112#issuecomment-1924920952
pub use trident_derive_displayix::DisplayIx;
pub use trident_derive_fuzz_deserialize::FuzzDeserialize;
pub use trident_derive_fuzz_test_executor::FuzzTestExecutor;
pub mod ___private {
pub use super::cleaner::*;
pub use super::client::*;
pub use super::commander::Commander;
pub use super::commander::Error;
pub use super::commander::LocalnetHandle;
pub use super::error_reporter::*;
pub use super::fuzzer::fuzzer_generator;
pub use super::fuzzer::snapshot_generator;
pub use super::idl::*;
pub use super::keys::*;
pub use super::program_client_generator::*;
pub use super::reader::*;
pub use super::temp_clone::TempClone;
pub use super::test_generator::ProgramData;
pub use super::test_generator::TestGenerator;
pub use super::tester::*;
// pub use trident_fuzz_test::fuzz_trident;
}

mod constants {
// program_client
Expand Down
3 changes: 1 addition & 2 deletions crates/client/src/temp_clone.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use crate::Keypair;

use solana_sdk::signer::keypair::Keypair;
// @TODO remove once `Clone` is implemented for `Keypair`
// https://docs.rs/solana-sdk/latest/solana_sdk/signer/keypair/struct.Keypair.html

Expand Down
3 changes: 2 additions & 1 deletion crates/client/src/templates/trident-tests/test.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use fehler::throws;
use trident_client::{anyhow::Result, *};
use trident_client::prelude::*;
use trident_client::test::*;

// @todo: create and deploy your fixture
#[throws]
Expand Down
Loading

0 comments on commit 23f7008

Please sign in to comment.