Skip to content

Commit

Permalink
transaction-status: Remove conversions between spl re-exports and loc…
Browse files Browse the repository at this point in the history
…al sdk (solana-labs#33456)

* transaction-status: Remove `convert_pubkey`

Ran `git g -l convert_pubkey | xargs sed -i'' -re 's/convert_pubkey\(([^)]+)\)/\1/g'`

* Remove convert_compiled_instruction

Ran `git g -l convert_compiled_instruction | xargs sed -i'' -re 's/convert_compiled_instruction\(([^)]+)\)/\1/g'`

* Cleanup + clippy

* Remove instruction conversions in new extensions

* Run clippy --fix
  • Loading branch information
joncinque authored Sep 29, 2023
1 parent 4866789 commit d519592
Show file tree
Hide file tree
Showing 11 changed files with 528 additions and 849 deletions.
116 changes: 42 additions & 74 deletions transaction-status/src/parse_associated_token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,48 +94,26 @@ mod test {
use spl_associated_token_account::create_associated_token_account as create_associated_token_account_deprecated;
use {
super::*,
solana_sdk::{message::Message, sysvar},
spl_associated_token_account::{
get_associated_token_address, get_associated_token_address_with_program_id,
instruction::{
create_associated_token_account, create_associated_token_account_idempotent,
recover_nested,
},
solana_program::{
instruction::CompiledInstruction as SplAssociatedTokenCompiledInstruction,
message::Message, pubkey::Pubkey as SplAssociatedTokenPubkey, sysvar,
},
},
};

fn convert_pubkey(pubkey: Pubkey) -> SplAssociatedTokenPubkey {
SplAssociatedTokenPubkey::new_from_array(pubkey.to_bytes())
}

fn convert_compiled_instruction(
instruction: &SplAssociatedTokenCompiledInstruction,
) -> CompiledInstruction {
CompiledInstruction {
program_id_index: instruction.program_id_index,
accounts: instruction.accounts.clone(),
data: instruction.data.clone(),
}
}

#[test]
fn test_parse_create_deprecated() {
let funder = Pubkey::new_unique();
let wallet_address = Pubkey::new_unique();
let mint = Pubkey::new_unique();
let associated_account_address =
get_associated_token_address(&convert_pubkey(wallet_address), &convert_pubkey(mint));
let associated_account_address = get_associated_token_address(&wallet_address, &mint);
#[allow(deprecated)]
let create_ix = create_associated_token_account_deprecated(
&convert_pubkey(funder),
&convert_pubkey(wallet_address),
&convert_pubkey(mint),
);
let message = Message::new(&[create_ix], None);
let mut compiled_instruction = convert_compiled_instruction(&message.instructions[0]);
let create_ix = create_associated_token_account_deprecated(&funder, &wallet_address, &mint);
let mut message = Message::new(&[create_ix], None);
let compiled_instruction = &mut message.instructions[0];
let expected_parsed_ix = ParsedInstructionEnum {
instruction_type: "create".to_string(),
info: json!({
Expand All @@ -149,7 +127,7 @@ mod test {
};
assert_eq!(
parse_associated_token(
&compiled_instruction,
compiled_instruction,
&AccountKeys::new(&message.account_keys, None)
)
.unwrap(),
Expand All @@ -165,7 +143,7 @@ mod test {
compiled_instruction.accounts.remove(rent_account_index);
assert_eq!(
parse_associated_token(
&compiled_instruction,
compiled_instruction,
&AccountKeys::new(&message.account_keys, None)
)
.unwrap(),
Expand All @@ -175,7 +153,7 @@ mod test {
// after popping another account, parsing should fail
compiled_instruction.accounts.pop();
assert!(parse_associated_token(
&compiled_instruction,
compiled_instruction,
&AccountKeys::new(&message.account_keys, None)
)
.is_err());
Expand All @@ -187,22 +165,15 @@ mod test {
let wallet_address = Pubkey::new_unique();
let mint = Pubkey::new_unique();
let token_program_id = Pubkey::new_unique();
let associated_account_address = get_associated_token_address_with_program_id(
&convert_pubkey(wallet_address),
&convert_pubkey(mint),
&convert_pubkey(token_program_id),
);
let create_ix = create_associated_token_account(
&convert_pubkey(funder),
&convert_pubkey(wallet_address),
&convert_pubkey(mint),
&convert_pubkey(token_program_id),
);
let message = Message::new(&[create_ix], None);
let mut compiled_instruction = convert_compiled_instruction(&message.instructions[0]);
let associated_account_address =
get_associated_token_address_with_program_id(&wallet_address, &mint, &token_program_id);
let create_ix =
create_associated_token_account(&funder, &wallet_address, &mint, &token_program_id);
let mut message = Message::new(&[create_ix], None);
let compiled_instruction = &mut message.instructions[0];
assert_eq!(
parse_associated_token(
&compiled_instruction,
compiled_instruction,
&AccountKeys::new(&message.account_keys, None)
)
.unwrap(),
Expand All @@ -220,7 +191,7 @@ mod test {
);
compiled_instruction.accounts.pop();
assert!(parse_associated_token(
&compiled_instruction,
compiled_instruction,
&AccountKeys::new(&message.account_keys, None)
)
.is_err());
Expand All @@ -232,22 +203,19 @@ mod test {
let wallet_address = Pubkey::new_unique();
let mint = Pubkey::new_unique();
let token_program_id = Pubkey::new_unique();
let associated_account_address = get_associated_token_address_with_program_id(
&convert_pubkey(wallet_address),
&convert_pubkey(mint),
&convert_pubkey(token_program_id),
);
let associated_account_address =
get_associated_token_address_with_program_id(&wallet_address, &mint, &token_program_id);
let create_ix = create_associated_token_account_idempotent(
&convert_pubkey(funder),
&convert_pubkey(wallet_address),
&convert_pubkey(mint),
&convert_pubkey(token_program_id),
&funder,
&wallet_address,
&mint,
&token_program_id,
);
let message = Message::new(&[create_ix], None);
let mut compiled_instruction = convert_compiled_instruction(&message.instructions[0]);
let mut message = Message::new(&[create_ix], None);
let compiled_instruction = &mut message.instructions[0];
assert_eq!(
parse_associated_token(
&compiled_instruction,
compiled_instruction,
&AccountKeys::new(&message.account_keys, None)
)
.unwrap(),
Expand All @@ -265,7 +233,7 @@ mod test {
);
compiled_instruction.accounts.pop();
assert!(parse_associated_token(
&compiled_instruction,
compiled_instruction,
&AccountKeys::new(&message.account_keys, None)
)
.is_err());
Expand All @@ -278,31 +246,31 @@ mod test {
let nested_mint = Pubkey::new_unique();
let token_program_id = Pubkey::new_unique();
let owner_associated_account_address = get_associated_token_address_with_program_id(
&convert_pubkey(wallet_address),
&convert_pubkey(owner_mint),
&convert_pubkey(token_program_id),
&wallet_address,
&owner_mint,
&token_program_id,
);
let nested_associated_account_address = get_associated_token_address_with_program_id(
&owner_associated_account_address,
&convert_pubkey(nested_mint),
&convert_pubkey(token_program_id),
&nested_mint,
&token_program_id,
);
let destination_associated_account_address = get_associated_token_address_with_program_id(
&convert_pubkey(wallet_address),
&convert_pubkey(nested_mint),
&convert_pubkey(token_program_id),
&wallet_address,
&nested_mint,
&token_program_id,
);
let recover_ix = recover_nested(
&convert_pubkey(wallet_address),
&convert_pubkey(owner_mint),
&convert_pubkey(nested_mint),
&convert_pubkey(token_program_id),
&wallet_address,
&owner_mint,
&nested_mint,
&token_program_id,
);
let message = Message::new(&[recover_ix], None);
let mut compiled_instruction = convert_compiled_instruction(&message.instructions[0]);
let mut message = Message::new(&[recover_ix], None);
let compiled_instruction = &mut message.instructions[0];
assert_eq!(
parse_associated_token(
&compiled_instruction,
compiled_instruction,
&AccountKeys::new(&message.account_keys, None)
)
.unwrap(),
Expand All @@ -321,7 +289,7 @@ mod test {
);
compiled_instruction.accounts.pop();
assert!(parse_associated_token(
&compiled_instruction,
compiled_instruction,
&AccountKeys::new(&message.account_keys, None)
)
.is_err());
Expand Down
Loading

0 comments on commit d519592

Please sign in to comment.