Manually camelCase solana program json (#14907) (#14936)

This commit is contained in:
Tyera Eulberg
2021-01-29 15:52:26 -07:00
committed by GitHub
parent 7ad9870071
commit af04a265dd
3 changed files with 38 additions and 39 deletions

View File

@ -2729,7 +2729,7 @@ mod tests {
let program_id = json let program_id = json
.as_object() .as_object()
.unwrap() .unwrap()
.get("ProgramId") .get("programId")
.unwrap() .unwrap()
.as_str() .as_str()
.unwrap(); .unwrap();

View File

@ -10,7 +10,7 @@ use bincode::serialize;
use bip39::{Language, Mnemonic, MnemonicType, Seed}; use bip39::{Language, Mnemonic, MnemonicType, Seed};
use clap::{App, AppSettings, Arg, ArgMatches, SubCommand}; use clap::{App, AppSettings, Arg, ArgMatches, SubCommand};
use log::*; use log::*;
use serde_json::{self, json}; use serde_json::{self, json, Value};
use solana_bpf_loader_program::{bpf_verifier, BPFError, ThisInstructionMeter}; use solana_bpf_loader_program::{bpf_verifier, BPFError, ThisInstructionMeter};
use solana_clap_utils::{self, input_parsers::*, input_validators::*, keypair::*}; use solana_clap_utils::{self, input_parsers::*, input_validators::*, keypair::*};
use solana_cli_output::display::new_spinner_progress_bar; use solana_cli_output::display::new_spinner_progress_bar;
@ -863,7 +863,7 @@ fn process_set_authority(
) )
.map_err(|e| format!("Setting authority failed: {}", e))?; .map_err(|e| format!("Setting authority failed: {}", e))?;
Ok(option_pubkey_to_string("Authority", new_authority)) Ok(option_pubkey_to_string("authority", new_authority).to_string())
} }
fn process_get_authority( fn process_get_authority(
@ -889,10 +889,11 @@ fn process_get_authority(
.. ..
}) = account.state() }) = account.state()
{ {
Ok(option_pubkey_to_string( let mut value =
"Program upgrade authority", option_pubkey_to_string("authority", upgrade_authority_address);
upgrade_authority_address, let map = value.as_object_mut().unwrap();
)) map.insert("accountType".to_string(), json!("program".to_string()));
Ok(value.to_string())
} else { } else {
Err("Invalid associated ProgramData account found for the program".into()) Err("Invalid associated ProgramData account found for the program".into())
} }
@ -904,10 +905,10 @@ fn process_get_authority(
} }
} else if let Ok(UpgradeableLoaderState::Buffer { authority_address }) = account.state() } else if let Ok(UpgradeableLoaderState::Buffer { authority_address }) = account.state()
{ {
Ok(option_pubkey_to_string( let mut value = option_pubkey_to_string("authority", authority_address);
"Buffer authority", let map = value.as_object_mut().unwrap();
authority_address, map.insert("accountType".to_string(), json!("buffer".to_string()));
)) Ok(value.to_string())
} else { } else {
Err("Not a buffer or program account".into()) Err("Not a buffer or program account".into())
} }
@ -1117,12 +1118,12 @@ fn do_process_program_write_and_deploy(
if let Some(program_signers) = program_signers { if let Some(program_signers) = program_signers {
Ok(json!({ Ok(json!({
"ProgramId": format!("{}", program_signers[0].pubkey()), "programId": format!("{}", program_signers[0].pubkey()),
}) })
.to_string()) .to_string())
} else { } else {
Ok(json!({ Ok(json!({
"Buffer": format!("{}", buffer_pubkey), "buffer": format!("{}", buffer_pubkey),
}) })
.to_string()) .to_string())
} }
@ -1441,16 +1442,14 @@ fn report_ephemeral_mnemonic(words: usize, mnemonic: bip39::Mnemonic) {
); );
} }
fn option_pubkey_to_string(tag: &str, option: Option<Pubkey>) -> String { fn option_pubkey_to_string(tag: &str, option: Option<Pubkey>) -> Value {
match option { match option {
Some(pubkey) => json!({ Some(pubkey) => json!({
tag: format!("{:?}", pubkey), tag: format!("{:?}", pubkey),
}) }),
.to_string(),
None => json!({ None => json!({
tag: "None", tag: "none",
}) }),
.to_string(),
} }
} }
@ -2249,7 +2248,7 @@ mod tests {
let program_id = json let program_id = json
.as_object() .as_object()
.unwrap() .unwrap()
.get("ProgramId") .get("programId")
.unwrap() .unwrap()
.as_str() .as_str()
.unwrap(); .unwrap();

View File

@ -63,7 +63,7 @@ fn test_cli_program_deploy_non_upgradeable() {
let program_id_str = json let program_id_str = json
.as_object() .as_object()
.unwrap() .unwrap()
.get("ProgramId") .get("programId")
.unwrap() .unwrap()
.as_str() .as_str()
.unwrap(); .unwrap();
@ -195,7 +195,7 @@ fn test_cli_program_deploy_no_authority() {
let program_id_str = json let program_id_str = json
.as_object() .as_object()
.unwrap() .unwrap()
.get("ProgramId") .get("programId")
.unwrap() .unwrap()
.as_str() .as_str()
.unwrap(); .unwrap();
@ -279,7 +279,7 @@ fn test_cli_program_deploy_with_authority() {
let program_pubkey_str = json let program_pubkey_str = json
.as_object() .as_object()
.unwrap() .unwrap()
.get("ProgramId") .get("programId")
.unwrap() .unwrap()
.as_str() .as_str()
.unwrap(); .unwrap();
@ -325,7 +325,7 @@ fn test_cli_program_deploy_with_authority() {
let program_pubkey_str = json let program_pubkey_str = json
.as_object() .as_object()
.unwrap() .unwrap()
.get("ProgramId") .get("programId")
.unwrap() .unwrap()
.as_str() .as_str()
.unwrap(); .unwrap();
@ -393,7 +393,7 @@ fn test_cli_program_deploy_with_authority() {
let new_upgrade_authority_str = json let new_upgrade_authority_str = json
.as_object() .as_object()
.unwrap() .unwrap()
.get("Authority") .get("authority")
.unwrap() .unwrap()
.as_str() .as_str()
.unwrap(); .unwrap();
@ -444,7 +444,7 @@ fn test_cli_program_deploy_with_authority() {
let authority_pubkey_str = json let authority_pubkey_str = json
.as_object() .as_object()
.unwrap() .unwrap()
.get("Program upgrade authority") .get("authority")
.unwrap() .unwrap()
.as_str() .as_str()
.unwrap(); .unwrap();
@ -465,11 +465,11 @@ fn test_cli_program_deploy_with_authority() {
let new_upgrade_authority_str = json let new_upgrade_authority_str = json
.as_object() .as_object()
.unwrap() .unwrap()
.get("Authority") .get("authority")
.unwrap() .unwrap()
.as_str() .as_str()
.unwrap(); .unwrap();
assert_eq!(new_upgrade_authority_str, "None"); assert_eq!(new_upgrade_authority_str, "none");
// Upgrade with no authority // Upgrade with no authority
config.signers = vec![&keypair, &new_upgrade_authority]; config.signers = vec![&keypair, &new_upgrade_authority];
@ -504,7 +504,7 @@ fn test_cli_program_deploy_with_authority() {
let program_pubkey_str = json let program_pubkey_str = json
.as_object() .as_object()
.unwrap() .unwrap()
.get("ProgramId") .get("programId")
.unwrap() .unwrap()
.as_str() .as_str()
.unwrap(); .unwrap();
@ -532,11 +532,11 @@ fn test_cli_program_deploy_with_authority() {
let authority_pubkey_str = json let authority_pubkey_str = json
.as_object() .as_object()
.unwrap() .unwrap()
.get("Program upgrade authority") .get("authority")
.unwrap() .unwrap()
.as_str() .as_str()
.unwrap(); .unwrap();
assert_eq!("None", authority_pubkey_str); assert_eq!("none", authority_pubkey_str);
} }
#[test] #[test]
@ -597,7 +597,7 @@ fn test_cli_program_write_buffer() {
let buffer_pubkey_str = json let buffer_pubkey_str = json
.as_object() .as_object()
.unwrap() .unwrap()
.get("Buffer") .get("buffer")
.unwrap() .unwrap()
.as_str() .as_str()
.unwrap(); .unwrap();
@ -630,7 +630,7 @@ fn test_cli_program_write_buffer() {
let buffer_pubkey_str = json let buffer_pubkey_str = json
.as_object() .as_object()
.unwrap() .unwrap()
.get("Buffer") .get("buffer")
.unwrap() .unwrap()
.as_str() .as_str()
.unwrap(); .unwrap();
@ -661,7 +661,7 @@ fn test_cli_program_write_buffer() {
let authority_pubkey_str = json let authority_pubkey_str = json
.as_object() .as_object()
.unwrap() .unwrap()
.get("Buffer authority") .get("authority")
.unwrap() .unwrap()
.as_str() .as_str()
.unwrap(); .unwrap();
@ -686,7 +686,7 @@ fn test_cli_program_write_buffer() {
let buffer_pubkey_str = json let buffer_pubkey_str = json
.as_object() .as_object()
.unwrap() .unwrap()
.get("Buffer") .get("buffer")
.unwrap() .unwrap()
.as_str() .as_str()
.unwrap(); .unwrap();
@ -723,7 +723,7 @@ fn test_cli_program_write_buffer() {
let buffer_pubkey_str = json let buffer_pubkey_str = json
.as_object() .as_object()
.unwrap() .unwrap()
.get("Buffer") .get("buffer")
.unwrap() .unwrap()
.as_str() .as_str()
.unwrap(); .unwrap();
@ -751,7 +751,7 @@ fn test_cli_program_write_buffer() {
let authority_pubkey_str = json let authority_pubkey_str = json
.as_object() .as_object()
.unwrap() .unwrap()
.get("Buffer authority") .get("authority")
.unwrap() .unwrap()
.as_str() .as_str()
.unwrap(); .unwrap();
@ -831,7 +831,7 @@ fn test_cli_program_set_buffer_authority() {
let new_buffer_authority_str = json let new_buffer_authority_str = json
.as_object() .as_object()
.unwrap() .unwrap()
.get("Authority") .get("authority")
.unwrap() .unwrap()
.as_str() .as_str()
.unwrap(); .unwrap();
@ -858,7 +858,7 @@ fn test_cli_program_set_buffer_authority() {
let buffer_authority_str = json let buffer_authority_str = json
.as_object() .as_object()
.unwrap() .unwrap()
.get("Authority") .get("authority")
.unwrap() .unwrap()
.as_str() .as_str()
.unwrap(); .unwrap();