Skip to content

Commit

Permalink
💚 Fixing pipeline checks
Browse files Browse the repository at this point in the history
  • Loading branch information
lukacan committed Dec 22, 2023
1 parent a1343d6 commit 61ddbf2
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 74 deletions.
23 changes: 8 additions & 15 deletions crates/client/src/client.rs
Original file line number Diff line number Diff line change
@@ -1,23 +1,19 @@
use crate::{constants::*, Config, Reader, TempClone};

use anchor_client;
use anchor_client::ClientError as Error;
// TODO maybe can deleted
use borsh;
// use borsh;
use fehler::{throw, throws};
use solana_sdk::program_pack::Pack;
use solana_sdk::signer::Signer;
// TODO maybe can deleted
use futures::{self, StreamExt};
use log;
// TODO maybe can deleted
use serde;
// use serde;
// TODO maybe can deleted
use solana_account_decoder;
// use solana_account_decoder;
// TODO maybe can deleted
use solana_cli_output;
use solana_transaction_status;
use spl_associated_token_account;
// use solana_cli_output;

// @TODO: Make compatible with the latest Anchor deps.
// https://github.com/project-serum/anchor/pull/1307#issuecomment-1022592683
Expand Down Expand Up @@ -187,7 +183,7 @@ impl Client {
.program(solana_sdk::system_program::ID)?
.async_rpc();
rpc_client
.get_account_with_commitment(&account, rpc_client.commitment())
.get_account_with_commitment(account, rpc_client.commitment())
.await
.unwrap()
.value
Expand Down Expand Up @@ -326,10 +322,7 @@ impl Client {
.unwrap()
.async_rpc();

let signature = rpc_client
.request_airdrop(&address, lamports)
.await
.unwrap();
let signature = rpc_client.request_airdrop(address, lamports).await.unwrap();

let (airdrop_result, error) = loop {
match rpc_client.get_signature_status(&signature).await.unwrap() {
Expand Down Expand Up @@ -708,14 +701,14 @@ impl Client {
spl_associated_token_account::instruction::create_associated_token_account(
&self.payer().pubkey(),
&owner.pubkey(),
&mint,
mint,
&spl_token::ID,
),
],
&[],
)
.await?;
spl_associated_token_account::get_associated_token_address(&owner.pubkey(), &mint)
spl_associated_token_account::get_associated_token_address(&owner.pubkey(), mint)
}

/// Executes a transaction creating and filling the given account with the given data.
Expand Down
6 changes: 3 additions & 3 deletions crates/client/src/commander.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ use crate::Client;
use crate::Config;
use crate::{Idl, IdlError};
use fehler::{throw, throws};
use log;
// use log;
use thiserror::Error;
// TODO maybe unused
use tokio;
// use tokio;

// -----
use crate::constants::*;
use indicatif;
// use indicatif;
#[derive(Error, Debug)]
pub enum Error {
#[error("{0:?}")]
Expand Down
8 changes: 7 additions & 1 deletion crates/client/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ pub struct Config {
pub fuzz: Fuzz,
}

#[derive(Default, Debug, Deserialize, Clone)]
#[derive(Debug, Deserialize, Clone)]
struct _Config {
#[serde(default)]
pub test: Option<_Test>,
Expand All @@ -261,6 +261,12 @@ impl From<_Config> for Config {
}
}

impl Default for Config {
fn default() -> Self {
Config::new()
}
}

impl Config {
pub fn new() -> Self {
let root = Config::discover_root().expect("failed to find the root folder");
Expand Down
5 changes: 3 additions & 2 deletions crates/client/src/idl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,9 @@ impl Idl {

let static_program_id =
static_program_id.ok_or(IdlError::MissingOrInvalidProgramItems("missing static ID"))?;
let mod_private =
mod_private.ok_or(IdlError::MissingOrInvalidProgramItems("missing mod private"))?;
let mod_private = mod_private.ok_or(IdlError::MissingOrInvalidProgramItems(
"missing mod private",
))?;
let mod_instruction = mod_instruction.ok_or(IdlError::MissingOrInvalidProgramItems(
"missing mod instruction",
))?;
Expand Down
2 changes: 1 addition & 1 deletion crates/client/src/program_client_generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ pub fn generate_source_code(idl: &Idl, use_modules: &[syn::ItemUse]) -> String {
let last_type =
&tp.path.segments.last().unwrap().ident.to_string();
if last_type == "Pubkey" {
let reference = format!("&solana_sdk::pubkey::Pubkey");
let reference = "&solana_sdk::pubkey::Pubkey".to_string();
let t: syn::Type = parse_str(&reference).unwrap();
t
} else {
Expand Down
99 changes: 48 additions & 51 deletions crates/client/src/workspace_builder.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::commander::{Commander, Error as CommanderError};
use cargo_metadata::Package;
use fehler::{throw, throws};
use pathdiff;
// use pathdiff;
use std::{
env,
fs::OpenOptions,
Expand All @@ -12,10 +12,7 @@ use std::{fs::File, io::prelude::*};
use syn::ItemUse;
use thiserror::Error;
use tokio::fs;
use toml::{
value::{Map, Table},
Value,
};
use toml::{value::Table, Value};

use crate::constants::*;
use crate::generate_source_code;
Expand Down Expand Up @@ -533,52 +530,52 @@ impl WorkspaceBuilder {
};
}

#[throws]
async fn add_feature_to_dep(&self, dependency: &str, feature: &str, cargo_dir: &Path) {
let cargo_toml_path = cargo_dir.join(CARGO);
let rel_path = &cargo_toml_path
.strip_prefix(&self.root)
.unwrap()
.to_str()
.unwrap();
let mut content: Value = fs::read_to_string(&cargo_toml_path).await?.parse()?;
let deps = content
.get_mut("dependencies")
.and_then(Value::as_table_mut)
.ok_or(Error::CannotParseCargoToml)?;

let values = deps
.get_mut(dependency)
.and_then(|f| {
if f.is_table() {
f.as_table_mut()
} else if f.is_str() {
// if the value is only a string with version such as dependency = 0.0, create a new table with that version
let version = f.as_str().unwrap();
let mut map = Map::new();
let _ = map.insert("version".to_string(), Value::String(version.to_string()));
let t = Value::Table(map);
*f = t.to_owned();
f.as_table_mut()
} else {
None
}
})
.ok_or(Error::CannotParseCargoToml)?;

let fuzzing = Value::String(feature.to_string());
let value = Value::Array(vec![]);
let features = values.entry("features").or_insert(value);
if let Some(features) = features.as_array_mut() {
if !features.iter().any(|f| *f == fuzzing) {
features.push(fuzzing);
fs::write(&cargo_toml_path, content.to_string()).await?;
println!("\x1b[92mSuccesfully\x1b[0m updated: \x1b[93m{rel_path}\x1b[0m {feature} feature added.");
} else {
println!("\x1b[93m--> Skipping <--\x1b[0m \x1b[93m{rel_path}\x1b[0m, already contains {feature} feature.")
}
}
}
// #[throws]
// async fn add_feature_to_dep(&self, dependency: &str, feature: &str, cargo_dir: &Path) {
// let cargo_toml_path = cargo_dir.join(CARGO);
// let rel_path = &cargo_toml_path
// .strip_prefix(&self.root)
// .unwrap()
// .to_str()
// .unwrap();
// let mut content: Value = fs::read_to_string(&cargo_toml_path).await?.parse()?;
// let deps = content
// .get_mut("dependencies")
// .and_then(Value::as_table_mut)
// .ok_or(Error::CannotParseCargoToml)?;

// let values = deps
// .get_mut(dependency)
// .and_then(|f| {
// if f.is_table() {
// f.as_table_mut()
// } else if f.is_str() {
// // if the value is only a string with version such as dependency = 0.0, create a new table with that version
// let version = f.as_str().unwrap();
// let mut map = Map::new();
// let _ = map.insert("version".to_string(), Value::String(version.to_string()));
// let t = Value::Table(map);
// *f = t.to_owned();
// f.as_table_mut()
// } else {
// None
// }
// })
// .ok_or(Error::CannotParseCargoToml)?;

// let fuzzing = Value::String(feature.to_string());
// let value = Value::Array(vec![]);
// let features = values.entry("features").or_insert(value);
// if let Some(features) = features.as_array_mut() {
// if !features.iter().any(|f| *f == fuzzing) {
// features.push(fuzzing);
// fs::write(&cargo_toml_path, content.to_string()).await?;
// println!("\x1b[92mSuccesfully\x1b[0m updated: \x1b[93m{rel_path}\x1b[0m {feature} feature added.");
// } else {
// println!("\x1b[93m--> Skipping <--\x1b[0m \x1b[93m{rel_path}\x1b[0m, already contains {feature} feature.")
// }
// }
// }

/// - adds program dependency to specified Cargo.toml
/// for example, we need to use program entry within the fuzzer
Expand Down
2 changes: 1 addition & 1 deletion crates/explorer/src/parse/associated_token_account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ mod test {
&convert_pubkey(funder),
&convert_pubkey(wallet_address),
&convert_pubkey(mint),
&&spl_token::id(),
&spl_token::id(),
);
let message = Message::new(&[create_ix], None);
let compiled_instruction = convert_compiled_instruction(&message.instructions[0]);
Expand Down

0 comments on commit 61ddbf2

Please sign in to comment.