Add wallet deploy unit tests, incl program test fixture

This commit is contained in:
Tyera Eulberg 2019-01-17 09:49:16 -07:00 committed by Grimes
parent b296a9a0c7
commit 2698b7614b
2 changed files with 35 additions and 1 deletions

View File

@ -797,7 +797,7 @@ mod tests {
use solana_sdk::signature::{gen_keypair_file, read_keypair, read_pkcs8, Keypair, KeypairUtil};
use std::fs;
use std::net::{Ipv4Addr, SocketAddr};
use std::path::Path;
use std::path::{Path, PathBuf};
#[test]
fn test_wallet_config_drone_addr() {
@ -1307,6 +1307,40 @@ mod tests {
assert!(process_command(&config).is_err());
}
#[test]
fn test_wallet_deploy() {
let mut pathbuf = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
pathbuf.push("tests");
pathbuf.push("fixtures");
pathbuf.push("noop");
pathbuf.set_extension("so");
// Success case
let mut config = WalletConfig::default();
config.rpc_client = Some(RpcClient::new("succeeds".to_string()));
config.command = WalletCommand::Deploy(pathbuf.to_str().unwrap().to_string());
let result = process_command(&config);
assert!(result.is_ok());
let json: Value = serde_json::from_str(&result.unwrap()).unwrap();
let program_id = json
.as_object()
.unwrap()
.get("programId")
.unwrap()
.as_str()
.unwrap();
let program_id_vec = bs58::decode(program_id).into_vec().unwrap();
assert_eq!(program_id_vec.len(), mem::size_of::<Pubkey>());
// Failure cases
config.rpc_client = Some(RpcClient::new("airdrop".to_string()));
assert!(process_command(&config).is_err());
config.command = WalletCommand::Deploy("bad/file/location.so".to_string());
assert!(process_command(&config).is_err());
}
fn tmp_file_path(name: &str) -> String {
use std::env;
let out_dir = env::var("OUT_DIR").unwrap_or_else(|_| "target".to_string());

BIN
wallet/tests/fixtures/noop.so vendored Executable file

Binary file not shown.