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

Pr/ocms bd v2 #2

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
35 changes: 34 additions & 1 deletion clap-utils/src/input_validators.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ use {
},
std::{fmt::Display, ops::RangeBounds, str::FromStr},
};
use solana_sdk::bs58;
use solana_sdk::offchain_message::Version as OffchainMessageVersion;

fn is_parsable_generic<U, T>(string: T) -> Result<(), String>
where
Expand Down Expand Up @@ -278,7 +280,8 @@ pub fn is_amount<T>(amount: T) -> Result<(), String>
where
T: AsRef<str> + Display,
{
if amount.as_ref().parse::<u64>().is_ok() || amount.as_ref().parse::<f64>().is_ok() {
let amount = amount.as_ref();
if amount.parse::<u64>().is_ok() || amount.parse::<f64>().is_ok() {
Ok(())
} else {
Err(format!(
Expand Down Expand Up @@ -379,6 +382,25 @@ where
}
}

pub fn is_valid_offchain_message_version<T>(value: T) -> Result<(), String>
where T: AsRef<str> + Display {
let value = value.as_ref();
match value.parse::<OffchainMessageVersion>() {
Err(_) => Err("Must be valid header version (unsigned integer)".to_string()),
Ok(_) => { Ok(()) }
}
}

pub fn is_base_58_string<T>(value: T) -> Result<(), String>
where T: AsRef<str> + Display {
let value = value.as_ref();
if bs58::decode(value).into_vec().is_err() {
Err("Application domain must be valid Base58 string".to_string())
} else {
Ok(())
}
}

pub fn is_derived_address_seed<T>(value: T) -> Result<(), String>
where
T: AsRef<str> + Display,
Expand Down Expand Up @@ -425,6 +447,17 @@ where
mod tests {
use super::*;

#[test]
fn test_is_base_58(){
assert_eq!(is_base_58_string("6sBFcNXUTq9GY3"), Ok(()));
assert_eq!(is_base_58_string(""), Ok(()));

assert!(is_base_58_string("invalid").is_err());
assert!(is_base_58_string(" ").is_err());
assert!(is_base_58_string("012345").is_err());
}


#[test]
fn test_is_derivation() {
assert_eq!(is_derivation("2"), Ok(()));
Expand Down
12 changes: 9 additions & 3 deletions cli/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1752,6 +1752,7 @@ mod tests {
},
solana_transaction_status::TransactionConfirmationStatus,
};
use solana_sdk::offchain_message::{ApplicationDomain, Version};

fn make_tmp_path(name: &str) -> String {
let out_dir = std::env::var("FARF_DIR").unwrap_or_else(|_| "farf".to_string());
Expand Down Expand Up @@ -2013,14 +2014,18 @@ mod tests {
"sign-offchain-message",
"Test Message",
]);
let message = OffchainMessage::new(0, b"Test Message").unwrap();

let keypair_signers = read_keypair_file(&keypair_file).unwrap();

let message = OffchainMessage::new(Version::V0, b"Test Message", vec![keypair_signers.pubkey()], ApplicationDomain::default()).unwrap();

assert_eq!(
parse_command(&test_sign_offchain, &default_signer, &mut None).unwrap(),
CliCommandInfo {
command: CliCommand::SignOffchainMessage {
message: message.clone()
},
signers: vec![read_keypair_file(&keypair_file).unwrap().into()],
signers: vec![keypair_signers.into()],
}
);

Expand Down Expand Up @@ -2403,7 +2408,8 @@ mod tests {
config.command = CliCommand::GetTransactionCount;
assert!(process_command(&config).is_err());

let message = OffchainMessage::new(0, b"Test Message").unwrap();
let message = OffchainMessage::new(Version::V0, b"Test Message", vec![keypair.pubkey()], ApplicationDomain::default()).unwrap();

config.command = CliCommand::SignOffchainMessage {
message: message.clone(),
};
Expand Down
6 changes: 3 additions & 3 deletions cli/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
use {
clap::{crate_description, crate_name, value_t_or_exit, ArgMatches},
clap::{ArgMatches, crate_description, crate_name, value_t_or_exit},
console::style,
solana_clap_utils::{
DisplayError,
input_validators::normalize_to_url_if_moniker,
keypair::{CliSigners, DefaultSigner},
DisplayError,
},
solana_cli::{
clap_app::get_clap_app,
cli::{parse_command, process_command, CliCommandInfo, CliConfig},
cli::{CliCommandInfo, CliConfig, parse_command, process_command},
},
solana_cli_config::{Config, ConfigInput},
solana_cli_output::{
Expand Down
Loading