Skip to content
This repository has been archived by the owner on Jan 13, 2025. It is now read-only.

Commit

Permalink
Fix buffer-authority signer parsing in program write-buffer (error on…
Browse files Browse the repository at this point in the history
… Pubkey input)
  • Loading branch information
Tyera Eulberg committed Jan 3, 2023
1 parent c4cbb52 commit 78fe289
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 36 deletions.
39 changes: 13 additions & 26 deletions cli/src/program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ pub enum ProgramCliCommand {
program_location: String,
buffer_signer_index: Option<SignerIndex>,
buffer_pubkey: Option<Pubkey>,
buffer_authority_signer_index: Option<SignerIndex>,
buffer_authority_signer_index: SignerIndex,
max_len: Option<usize>,
skip_fee_check: bool,
},
Expand Down Expand Up @@ -502,19 +502,9 @@ pub fn parse_program_subcommand(
pubkey_of_signer(matches, "buffer", wallet_manager)?
};

let buffer_authority_pubkey =
if let Ok((buffer_authority_signer, Some(buffer_authority_pubkey))) =
signer_of(matches, "buffer_authority", wallet_manager)
{
bulk_signers.push(buffer_authority_signer);
Some(buffer_authority_pubkey)
} else {
Some(
default_signer
.signer_from_path(matches, wallet_manager)?
.pubkey(),
)
};
let (buffer_authority, buffer_authority_pubkey) =
signer_of(matches, "buffer_authority", wallet_manager)?;
bulk_signers.push(buffer_authority);

let max_len = value_of(matches, "max_len");

Expand All @@ -527,7 +517,8 @@ pub fn parse_program_subcommand(
buffer_signer_index: signer_info.index_of_or_none(buffer_pubkey),
buffer_pubkey,
buffer_authority_signer_index: signer_info
.index_of_or_none(buffer_authority_pubkey),
.index_of(buffer_authority_pubkey)
.unwrap(),
max_len,
skip_fee_check,
}),
Expand Down Expand Up @@ -1057,7 +1048,7 @@ fn process_write_buffer(
program_location: &str,
buffer_signer_index: Option<SignerIndex>,
buffer_pubkey: Option<Pubkey>,
buffer_authority_signer_index: Option<SignerIndex>,
buffer_authority_signer_index: SignerIndex,
max_len: Option<usize>,
skip_fee_check: bool,
) -> ProcessResult {
Expand All @@ -1073,11 +1064,7 @@ fn process_write_buffer(
buffer_keypair.pubkey(),
)
};
let buffer_authority = if let Some(i) = buffer_authority_signer_index {
config.signers[i]
} else {
config.signers[0]
};
let buffer_authority = config.signers[buffer_authority_signer_index];

if let Some(account) = rpc_client
.get_account_with_commitment(&buffer_pubkey, config.commitment)?
Expand Down Expand Up @@ -2555,7 +2542,7 @@ mod tests {
program_location: "/Users/test/program.so".to_string(),
buffer_signer_index: None,
buffer_pubkey: None,
buffer_authority_signer_index: Some(0),
buffer_authority_signer_index: 0,
max_len: None,
skip_fee_check: false,
}),
Expand All @@ -2579,7 +2566,7 @@ mod tests {
program_location: "/Users/test/program.so".to_string(),
buffer_signer_index: None,
buffer_pubkey: None,
buffer_authority_signer_index: Some(0),
buffer_authority_signer_index: 0,
max_len: Some(42),
skip_fee_check: false,
}),
Expand All @@ -2606,7 +2593,7 @@ mod tests {
program_location: "/Users/test/program.so".to_string(),
buffer_signer_index: Some(1),
buffer_pubkey: Some(buffer_keypair.pubkey()),
buffer_authority_signer_index: Some(0),
buffer_authority_signer_index: 0,
max_len: None,
skip_fee_check: false,
}),
Expand Down Expand Up @@ -2636,7 +2623,7 @@ mod tests {
program_location: "/Users/test/program.so".to_string(),
buffer_signer_index: None,
buffer_pubkey: None,
buffer_authority_signer_index: Some(1),
buffer_authority_signer_index: 1,
max_len: None,
skip_fee_check: false,
}),
Expand Down Expand Up @@ -2671,7 +2658,7 @@ mod tests {
program_location: "/Users/test/program.so".to_string(),
buffer_signer_index: Some(1),
buffer_pubkey: Some(buffer_keypair.pubkey()),
buffer_authority_signer_index: Some(2),
buffer_authority_signer_index: 2,
max_len: None,
skip_fee_check: false,
}),
Expand Down
20 changes: 10 additions & 10 deletions cli/tests/program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -778,7 +778,7 @@ fn test_cli_program_write_buffer() {
program_location: noop_path.to_str().unwrap().to_string(),
buffer_signer_index: None,
buffer_pubkey: None,
buffer_authority_signer_index: None,
buffer_authority_signer_index: 0,
max_len: None,
skip_fee_check: false,
});
Expand Down Expand Up @@ -813,7 +813,7 @@ fn test_cli_program_write_buffer() {
program_location: noop_path.to_str().unwrap().to_string(),
buffer_signer_index: Some(1),
buffer_pubkey: Some(buffer_keypair.pubkey()),
buffer_authority_signer_index: None,
buffer_authority_signer_index: 0,
max_len: Some(max_len),
skip_fee_check: false,
});
Expand Down Expand Up @@ -875,7 +875,7 @@ fn test_cli_program_write_buffer() {
program_location: noop_path.to_str().unwrap().to_string(),
buffer_signer_index: Some(1),
buffer_pubkey: Some(buffer_keypair.pubkey()),
buffer_authority_signer_index: Some(2),
buffer_authority_signer_index: 2,
max_len: None,
skip_fee_check: false,
});
Expand Down Expand Up @@ -913,7 +913,7 @@ fn test_cli_program_write_buffer() {
program_location: noop_path.to_str().unwrap().to_string(),
buffer_signer_index: None,
buffer_pubkey: None,
buffer_authority_signer_index: Some(2),
buffer_authority_signer_index: 2,
max_len: None,
skip_fee_check: false,
});
Expand Down Expand Up @@ -987,7 +987,7 @@ fn test_cli_program_write_buffer() {
program_location: noop_path.to_str().unwrap().to_string(),
buffer_signer_index: None,
buffer_pubkey: None,
buffer_authority_signer_index: None,
buffer_authority_signer_index: 0,
max_len: None,
skip_fee_check: false,
});
Expand Down Expand Up @@ -1028,7 +1028,7 @@ fn test_cli_program_write_buffer() {
program_location: noop_path.to_str().unwrap().to_string(),
buffer_signer_index: Some(1),
buffer_pubkey: Some(buffer_keypair.pubkey()),
buffer_authority_signer_index: None,
buffer_authority_signer_index: 0,
max_len: None, //Some(max_len),
skip_fee_check: false,
});
Expand Down Expand Up @@ -1100,7 +1100,7 @@ fn test_cli_program_set_buffer_authority() {
program_location: noop_path.to_str().unwrap().to_string(),
buffer_signer_index: Some(1),
buffer_pubkey: Some(buffer_keypair.pubkey()),
buffer_authority_signer_index: None,
buffer_authority_signer_index: 0,
max_len: None,
skip_fee_check: false,
});
Expand Down Expand Up @@ -1216,7 +1216,7 @@ fn test_cli_program_mismatch_buffer_authority() {
program_location: noop_path.to_str().unwrap().to_string(),
buffer_signer_index: Some(1),
buffer_pubkey: Some(buffer_keypair.pubkey()),
buffer_authority_signer_index: Some(2),
buffer_authority_signer_index: 2,
max_len: None,
skip_fee_check: false,
});
Expand Down Expand Up @@ -1312,7 +1312,7 @@ fn test_cli_program_show() {
program_location: noop_path.to_str().unwrap().to_string(),
buffer_signer_index: Some(1),
buffer_pubkey: Some(buffer_keypair.pubkey()),
buffer_authority_signer_index: Some(2),
buffer_authority_signer_index: 2,
max_len: None,
skip_fee_check: false,
});
Expand Down Expand Up @@ -1499,7 +1499,7 @@ fn test_cli_program_dump() {
program_location: noop_path.to_str().unwrap().to_string(),
buffer_signer_index: Some(1),
buffer_pubkey: Some(buffer_keypair.pubkey()),
buffer_authority_signer_index: Some(2),
buffer_authority_signer_index: 2,
max_len: None,
skip_fee_check: false,
});
Expand Down

0 comments on commit 78fe289

Please sign in to comment.