diff --git a/transaction-status/src/parse_associated_token.rs b/transaction-status/src/parse_associated_token.rs index 71f67a8ee47f53..a86ec079435456 100644 --- a/transaction-status/src/parse_associated_token.rs +++ b/transaction-status/src/parse_associated_token.rs @@ -51,6 +51,7 @@ fn check_num_associated_token_accounts( mod test { use { super::*, + solana_account_decoder::parse_token::pubkey_from_spl_token, spl_associated_token_account::{ create_associated_token_account, solana_program::{ @@ -74,6 +75,14 @@ mod test { } } + fn convert_account_keys(message: &Message) -> Vec { + message + .account_keys + .iter() + .map(pubkey_from_spl_token) + .collect() + } + #[test] fn test_parse_associated_token() { let mut keys: Vec = vec![]; @@ -87,7 +96,7 @@ mod test { &convert_pubkey(keys[2]), ); let message = Message::new(&[create_ix], None); - let compiled_instruction = convert_compiled_instruction(&message.instructions[0]); + let mut compiled_instruction = convert_compiled_instruction(&message.instructions[0]); assert_eq!( parse_associated_token(&compiled_instruction, &keys).unwrap(), ParsedInstructionEnum { @@ -103,5 +112,10 @@ mod test { }) } ); + compiled_instruction.accounts.pop(); + assert!( + parse_associated_token(&compiled_instruction, &convert_account_keys(&message),) + .is_err() + ); } } diff --git a/transaction-status/src/parse_bpf_loader.rs b/transaction-status/src/parse_bpf_loader.rs index b78392fdde0032..07f194153200e3 100644 --- a/transaction-status/src/parse_bpf_loader.rs +++ b/transaction-status/src/parse_bpf_loader.rs @@ -22,20 +22,26 @@ pub fn parse_bpf_loader( )); } match bpf_loader_instruction { - LoaderInstruction::Write { offset, bytes } => Ok(ParsedInstructionEnum { - instruction_type: "write".to_string(), - info: json!({ - "offset": offset, - "bytes": base64::encode(bytes), - "account": account_keys[instruction.accounts[0] as usize].to_string(), - }), - }), - LoaderInstruction::Finalize => Ok(ParsedInstructionEnum { - instruction_type: "finalize".to_string(), - info: json!({ - "account": account_keys[instruction.accounts[0] as usize].to_string(), - }), - }), + LoaderInstruction::Write { offset, bytes } => { + check_num_bpf_loader_accounts(&instruction.accounts, 1)?; + Ok(ParsedInstructionEnum { + instruction_type: "write".to_string(), + info: json!({ + "offset": offset, + "bytes": base64::encode(bytes), + "account": account_keys[instruction.accounts[0] as usize].to_string(), + }), + }) + } + LoaderInstruction::Finalize => { + check_num_bpf_loader_accounts(&instruction.accounts, 2)?; + Ok(ParsedInstructionEnum { + instruction_type: "finalize".to_string(), + info: json!({ + "account": account_keys[instruction.accounts[0] as usize].to_string(), + }), + }) + } } } @@ -147,6 +153,10 @@ pub fn parse_bpf_upgradeable_loader( } } +fn check_num_bpf_loader_accounts(accounts: &[u8], num: usize) -> Result<(), ParseInstructionError> { + check_num_accounts(accounts, num, ParsableProgram::BpfLoader) +} + fn check_num_bpf_upgradeable_loader_accounts( accounts: &[u8], num: usize, @@ -178,7 +188,7 @@ mod test { offset, bytes.clone(), ); - let message = Message::new(&[instruction], Some(&fee_payer)); + let mut message = Message::new(&[instruction], Some(&fee_payer)); assert_eq!( parse_bpf_loader(&message.instructions[0], &account_keys).unwrap(), ParsedInstructionEnum { @@ -191,9 +201,11 @@ mod test { } ); assert!(parse_bpf_loader(&message.instructions[0], &missing_account_keys).is_err()); + message.instructions[0].accounts.pop(); + assert!(parse_bpf_loader(&message.instructions[0], &account_keys,).is_err()); let instruction = solana_sdk::loader_instruction::finalize(&account_pubkey, &program_id); - let message = Message::new(&[instruction], Some(&fee_payer)); + let mut message = Message::new(&[instruction], Some(&fee_payer)); assert_eq!( parse_bpf_loader(&message.instructions[0], &account_keys).unwrap(), ParsedInstructionEnum { @@ -204,6 +216,8 @@ mod test { } ); assert!(parse_bpf_loader(&message.instructions[0], &missing_account_keys).is_err()); + message.instructions[0].accounts.pop(); + assert!(parse_bpf_loader(&message.instructions[0], &account_keys).is_err()); let bad_compiled_instruction = CompiledInstruction { program_id_index: 3, @@ -235,7 +249,7 @@ mod test { max_data_len, ) .unwrap(); - let message = Message::new(&instructions, None); + let mut message = Message::new(&instructions, None); assert_eq!( parse_bpf_upgradeable_loader(&message.instructions[1], &message.account_keys).unwrap(), ParsedInstructionEnum { @@ -251,6 +265,10 @@ mod test { &message.account_keys[0..2] ) .is_err()); + let keys = message.account_keys.clone(); + message.instructions[1].accounts.pop(); + message.instructions[1].accounts.pop(); + assert!(parse_bpf_upgradeable_loader(&message.instructions[1], &keys,).is_err()); } #[test] @@ -266,7 +284,7 @@ mod test { offset, bytes.clone(), ); - let message = Message::new(&[instruction], None); + let mut message = Message::new(&[instruction], None); assert_eq!( parse_bpf_upgradeable_loader(&message.instructions[0], &message.account_keys).unwrap(), ParsedInstructionEnum { @@ -284,6 +302,9 @@ mod test { &message.account_keys[0..1] ) .is_err()); + let keys = message.account_keys.clone(); + message.instructions[0].accounts.pop(); + assert!(parse_bpf_upgradeable_loader(&message.instructions[0], &keys,).is_err()); } #[test] @@ -308,7 +329,7 @@ mod test { max_data_len, ) .unwrap(); - let message = Message::new(&instructions, None); + let mut message = Message::new(&instructions, None); assert_eq!( parse_bpf_upgradeable_loader(&message.instructions[1], &message.account_keys).unwrap(), ParsedInstructionEnum { @@ -331,6 +352,9 @@ mod test { &message.account_keys[0..7] ) .is_err()); + let keys = message.account_keys.clone(); + message.instructions[1].accounts.pop(); + assert!(parse_bpf_upgradeable_loader(&message.instructions[1], &keys,).is_err()); } #[test] @@ -350,7 +374,7 @@ mod test { &authority_address, &spill_address, ); - let message = Message::new(&[instruction], None); + let mut message = Message::new(&[instruction], None); assert_eq!( parse_bpf_upgradeable_loader(&message.instructions[0], &message.account_keys).unwrap(), ParsedInstructionEnum { @@ -371,6 +395,9 @@ mod test { &message.account_keys[0..6] ) .is_err()); + let keys = message.account_keys.clone(); + message.instructions[0].accounts.pop(); + assert!(parse_bpf_upgradeable_loader(&message.instructions[0], &keys,).is_err()); } #[test] @@ -383,7 +410,7 @@ mod test { ¤t_authority_address, &new_authority_address, ); - let message = Message::new(&[instruction], None); + let mut message = Message::new(&[instruction], None); assert_eq!( parse_bpf_upgradeable_loader(&message.instructions[0], &message.account_keys).unwrap(), ParsedInstructionEnum { @@ -400,6 +427,10 @@ mod test { &message.account_keys[0..1] ) .is_err()); + let keys = message.account_keys.clone(); + message.instructions[0].accounts.pop(); + message.instructions[0].accounts.pop(); + assert!(parse_bpf_upgradeable_loader(&message.instructions[0], &keys,).is_err()); } #[test] @@ -416,7 +447,7 @@ mod test { ¤t_authority_address, Some(&new_authority_address), ); - let message = Message::new(&[instruction], None); + let mut message = Message::new(&[instruction], None); assert_eq!( parse_bpf_upgradeable_loader(&message.instructions[0], &message.account_keys).unwrap(), ParsedInstructionEnum { @@ -433,13 +464,17 @@ mod test { &message.account_keys[0..1] ) .is_err()); + let keys = message.account_keys.clone(); + message.instructions[0].accounts.pop(); + message.instructions[0].accounts.pop(); + assert!(parse_bpf_upgradeable_loader(&message.instructions[0], &keys,).is_err()); let instruction = bpf_loader_upgradeable::set_upgrade_authority( &program_address, ¤t_authority_address, None, ); - let message = Message::new(&[instruction], None); + let mut message = Message::new(&[instruction], None); assert_eq!( parse_bpf_upgradeable_loader(&message.instructions[0], &message.account_keys).unwrap(), ParsedInstructionEnum { @@ -456,6 +491,9 @@ mod test { &message.account_keys[0..1] ) .is_err()); + let keys = message.account_keys.clone(); + message.instructions[0].accounts.pop(); + assert!(parse_bpf_upgradeable_loader(&message.instructions[0], &keys,).is_err()); } #[test] @@ -465,7 +503,7 @@ mod test { let authority_address = Pubkey::new_unique(); let instruction = bpf_loader_upgradeable::close(&close_address, &recipient_address, &authority_address); - let message = Message::new(&[instruction], None); + let mut message = Message::new(&[instruction], None); assert_eq!( parse_bpf_upgradeable_loader(&message.instructions[0], &message.account_keys).unwrap(), ParsedInstructionEnum { @@ -482,5 +520,8 @@ mod test { &message.account_keys[0..1] ) .is_err()); + let keys = message.account_keys.clone(); + message.instructions[0].accounts.pop(); + assert!(parse_bpf_upgradeable_loader(&message.instructions[0], &keys,).is_err()); } } diff --git a/transaction-status/src/parse_stake.rs b/transaction-status/src/parse_stake.rs index 65b794828f49c7..e80e9a5f54f5b8 100644 --- a/transaction-status/src/parse_stake.rs +++ b/transaction-status/src/parse_stake.rs @@ -313,7 +313,7 @@ mod test { &lockup, lamports, ); - let message = Message::new(&instructions, None); + let mut message = Message::new(&instructions, None); assert_eq!( parse_stake(&message.instructions[1], &message.account_keys).unwrap(), ParsedInstructionEnum { @@ -334,6 +334,9 @@ mod test { } ); assert!(parse_stake(&message.instructions[1], &message.account_keys[0..2]).is_err()); + let keys = message.account_keys.clone(); + message.instructions[0].accounts.pop(); + assert!(parse_stake(&message.instructions[0], &keys).is_err()); } #[test] @@ -349,7 +352,7 @@ mod test { StakeAuthorize::Staker, None, ); - let message = Message::new(&[instruction], None); + let mut message = Message::new(&[instruction], None); assert_eq!( parse_stake(&message.instructions[0], &message.account_keys).unwrap(), ParsedInstructionEnum { @@ -364,6 +367,10 @@ mod test { } ); assert!(parse_stake(&message.instructions[0], &message.account_keys[0..2]).is_err()); + let keys = message.account_keys.clone(); + message.instructions[0].accounts.pop(); + message.instructions[0].accounts.pop(); + assert!(parse_stake(&message.instructions[0], &keys).is_err()); let instruction = instruction::authorize( &stake_pubkey, @@ -372,7 +379,7 @@ mod test { StakeAuthorize::Withdrawer, Some(&custodian_pubkey), ); - let message = Message::new(&[instruction], None); + let mut message = Message::new(&[instruction], None); assert_eq!( parse_stake(&message.instructions[0], &message.account_keys).unwrap(), ParsedInstructionEnum { @@ -388,6 +395,10 @@ mod test { } ); assert!(parse_stake(&message.instructions[0], &message.account_keys[0..2]).is_err()); + let keys = message.account_keys.clone(); + message.instructions[0].accounts.pop(); + message.instructions[0].accounts.pop(); + assert!(parse_stake(&message.instructions[0], &keys).is_err()); } #[test] @@ -397,7 +408,7 @@ mod test { let vote_pubkey = Pubkey::new_unique(); let instruction = instruction::delegate_stake(&stake_pubkey, &authorized_pubkey, &vote_pubkey); - let message = Message::new(&[instruction], None); + let mut message = Message::new(&[instruction], None); assert_eq!( parse_stake(&message.instructions[0], &message.account_keys).unwrap(), ParsedInstructionEnum { @@ -413,6 +424,9 @@ mod test { } ); assert!(parse_stake(&message.instructions[0], &message.account_keys[0..5]).is_err()); + let keys = message.account_keys.clone(); + message.instructions[0].accounts.pop(); + assert!(parse_stake(&message.instructions[0], &keys).is_err()); } #[test] @@ -427,7 +441,7 @@ mod test { lamports, &split_stake_pubkey, ); - let message = Message::new(&instructions, None); + let mut message = Message::new(&instructions, None); assert_eq!( parse_stake(&message.instructions[2], &message.account_keys).unwrap(), ParsedInstructionEnum { @@ -441,6 +455,9 @@ mod test { } ); assert!(parse_stake(&message.instructions[2], &message.account_keys[0..2]).is_err()); + let keys = message.account_keys.clone(); + message.instructions[0].accounts.pop(); + assert!(parse_stake(&message.instructions[0], &keys).is_err()); } #[test] @@ -479,7 +496,7 @@ mod test { lamports, Some(&custodian_pubkey), ); - let message = Message::new(&[instruction], None); + let mut message = Message::new(&[instruction], None); assert_eq!( parse_stake(&message.instructions[0], &message.account_keys).unwrap(), ParsedInstructionEnum { @@ -496,6 +513,10 @@ mod test { } ); assert!(parse_stake(&message.instructions[0], &message.account_keys[0..4]).is_err()); + let keys = message.account_keys.clone(); + message.instructions[0].accounts.pop(); + message.instructions[0].accounts.pop(); + assert!(parse_stake(&message.instructions[0], &keys).is_err()); } #[test] @@ -503,7 +524,7 @@ mod test { let stake_pubkey = Pubkey::new_unique(); let authorized_pubkey = Pubkey::new_unique(); let instruction = instruction::deactivate_stake(&stake_pubkey, &authorized_pubkey); - let message = Message::new(&[instruction], None); + let mut message = Message::new(&[instruction], None); assert_eq!( parse_stake(&message.instructions[0], &message.account_keys).unwrap(), ParsedInstructionEnum { @@ -516,6 +537,9 @@ mod test { } ); assert!(parse_stake(&message.instructions[0], &message.account_keys[0..2]).is_err()); + let keys = message.account_keys.clone(); + message.instructions[0].accounts.pop(); + assert!(parse_stake(&message.instructions[0], &keys).is_err()); } #[test] @@ -528,7 +552,7 @@ mod test { &source_stake_pubkey, &authorized_pubkey, ); - let message = Message::new(&instructions, None); + let mut message = Message::new(&instructions, None); assert_eq!( parse_stake(&message.instructions[0], &message.account_keys).unwrap(), ParsedInstructionEnum { @@ -543,6 +567,9 @@ mod test { } ); assert!(parse_stake(&message.instructions[0], &message.account_keys[0..4]).is_err()); + let keys = message.account_keys.clone(); + message.instructions[0].accounts.pop(); + assert!(parse_stake(&message.instructions[0], &keys).is_err()); } #[test] @@ -563,7 +590,7 @@ mod test { StakeAuthorize::Staker, None, ); - let message = Message::new(&[instruction], None); + let mut message = Message::new(&[instruction], None); assert_eq!( parse_stake(&message.instructions[0], &message.account_keys).unwrap(), ParsedInstructionEnum { @@ -580,6 +607,10 @@ mod test { } ); assert!(parse_stake(&message.instructions[0], &message.account_keys[0..2]).is_err()); + let keys = message.account_keys.clone(); + message.instructions[0].accounts.pop(); + message.instructions[0].accounts.pop(); + assert!(parse_stake(&message.instructions[0], &keys).is_err()); let instruction = instruction::authorize_with_seed( &stake_pubkey, @@ -590,7 +621,7 @@ mod test { StakeAuthorize::Withdrawer, Some(&custodian_pubkey), ); - let message = Message::new(&[instruction], None); + let mut message = Message::new(&[instruction], None); assert_eq!( parse_stake(&message.instructions[0], &message.account_keys).unwrap(), ParsedInstructionEnum { @@ -608,6 +639,11 @@ mod test { } ); assert!(parse_stake(&message.instructions[0], &message.account_keys[0..3]).is_err()); + let keys = message.account_keys.clone(); + message.instructions[0].accounts.pop(); + message.instructions[0].accounts.pop(); + message.instructions[0].accounts.pop(); + assert!(parse_stake(&message.instructions[0], &keys).is_err()); } #[test] @@ -670,7 +706,7 @@ mod test { custodian: Some(custodian), }; let instruction = instruction::set_lockup(&keys[1], &lockup, &keys[0]); - let message = Message::new(&[instruction], None); + let mut message = Message::new(&[instruction], None); assert_eq!( parse_stake(&message.instructions[0], &keys[0..2]).unwrap(), ParsedInstructionEnum { @@ -688,6 +724,9 @@ mod test { ); assert!(parse_stake(&message.instructions[0], &keys[0..1]).is_err()); + let keys = message.account_keys.clone(); + message.instructions[0].accounts.pop(); + assert!(parse_stake(&message.instructions[0], &keys).is_err()); let lockup = LockupArgs { unix_timestamp: Some(unix_timestamp), @@ -716,7 +755,7 @@ mod test { custodian: None, }; let instruction = instruction::set_lockup_checked(&keys[1], &lockup, &keys[0]); - let message = Message::new(&[instruction], None); + let mut message = Message::new(&[instruction], None); assert_eq!( parse_stake(&message.instructions[0], &keys[0..2]).unwrap(), ParsedInstructionEnum { @@ -732,6 +771,9 @@ mod test { } ); assert!(parse_stake(&message.instructions[0], &keys[0..1]).is_err()); + let keys = message.account_keys.clone(); + message.instructions[0].accounts.pop(); + assert!(parse_stake(&message.instructions[0], &keys).is_err()); let lockup = LockupArgs { unix_timestamp: Some(unix_timestamp), @@ -739,7 +781,7 @@ mod test { custodian: Some(keys[1]), }; let instruction = instruction::set_lockup_checked(&keys[2], &lockup, &keys[0]); - let message = Message::new(&[instruction], None); + let mut message = Message::new(&[instruction], None); assert_eq!( parse_stake(&message.instructions[0], &keys[0..3]).unwrap(), ParsedInstructionEnum { @@ -756,6 +798,10 @@ mod test { } ); assert!(parse_stake(&message.instructions[0], &keys[0..2]).is_err()); + let keys = message.account_keys.clone(); + message.instructions[0].accounts.pop(); + message.instructions[0].accounts.pop(); + assert!(parse_stake(&message.instructions[0], &keys).is_err()); } #[test] @@ -771,7 +817,7 @@ mod test { let instructions = instruction::create_account_checked(&from_pubkey, &stake_pubkey, &authorized, lamports); - let message = Message::new(&instructions, None); + let mut message = Message::new(&instructions, None); assert_eq!( parse_stake(&message.instructions[1], &message.account_keys).unwrap(), ParsedInstructionEnum { @@ -785,6 +831,9 @@ mod test { } ); assert!(parse_stake(&message.instructions[1], &message.account_keys[0..3]).is_err()); + let keys = message.account_keys.clone(); + message.instructions[0].accounts.pop(); + assert!(parse_stake(&message.instructions[0], &keys).is_err()); } #[test] @@ -801,7 +850,7 @@ mod test { StakeAuthorize::Staker, None, ); - let message = Message::new(&[instruction], None); + let mut message = Message::new(&[instruction], None); assert_eq!( parse_stake(&message.instructions[0], &message.account_keys).unwrap(), ParsedInstructionEnum { @@ -816,6 +865,10 @@ mod test { } ); assert!(parse_stake(&message.instructions[0], &message.account_keys[0..3]).is_err()); + let keys = message.account_keys.clone(); + message.instructions[0].accounts.pop(); + message.instructions[0].accounts.pop(); + assert!(parse_stake(&message.instructions[0], &keys).is_err()); let instruction = instruction::authorize_checked( &stake_pubkey, @@ -824,7 +877,7 @@ mod test { StakeAuthorize::Withdrawer, Some(&custodian_pubkey), ); - let message = Message::new(&[instruction], None); + let mut message = Message::new(&[instruction], None); assert_eq!( parse_stake(&message.instructions[0], &message.account_keys).unwrap(), ParsedInstructionEnum { @@ -840,6 +893,10 @@ mod test { } ); assert!(parse_stake(&message.instructions[0], &message.account_keys[0..4]).is_err()); + let keys = message.account_keys.clone(); + message.instructions[0].accounts.pop(); + message.instructions[0].accounts.pop(); + assert!(parse_stake(&message.instructions[0], &keys).is_err()); } #[test] @@ -860,7 +917,7 @@ mod test { StakeAuthorize::Staker, None, ); - let message = Message::new(&[instruction], None); + let mut message = Message::new(&[instruction], None); assert_eq!( parse_stake(&message.instructions[0], &message.account_keys).unwrap(), ParsedInstructionEnum { @@ -877,6 +934,10 @@ mod test { } ); assert!(parse_stake(&message.instructions[0], &message.account_keys[0..3]).is_err()); + let keys = message.account_keys.clone(); + message.instructions[0].accounts.pop(); + message.instructions[0].accounts.pop(); + assert!(parse_stake(&message.instructions[0], &keys).is_err()); let instruction = instruction::authorize_checked_with_seed( &stake_pubkey, @@ -887,7 +948,7 @@ mod test { StakeAuthorize::Withdrawer, Some(&custodian_pubkey), ); - let message = Message::new(&[instruction], None); + let mut message = Message::new(&[instruction], None); assert_eq!( parse_stake(&message.instructions[0], &message.account_keys).unwrap(), ParsedInstructionEnum { @@ -905,5 +966,9 @@ mod test { } ); assert!(parse_stake(&message.instructions[0], &message.account_keys[0..4]).is_err()); + let keys = message.account_keys.clone(); + message.instructions[0].accounts.pop(); + message.instructions[0].accounts.pop(); + assert!(parse_stake(&message.instructions[0], &keys).is_err()); } } diff --git a/transaction-status/src/parse_system.rs b/transaction-status/src/parse_system.rs index e48517c2c13c3c..95109002bbf9a1 100644 --- a/transaction-status/src/parse_system.rs +++ b/transaction-status/src/parse_system.rs @@ -122,7 +122,7 @@ pub fn parse_system( }) } SystemInstruction::AuthorizeNonceAccount(authority) => { - check_num_system_accounts(&instruction.accounts, 1)?; + check_num_system_accounts(&instruction.accounts, 2)?; Ok(ParsedInstructionEnum { instruction_type: "authorizeNonce".to_string(), info: json!({ @@ -228,7 +228,7 @@ mod test { space, &owner_pubkey, ); - let message = Message::new(&[instruction], None); + let mut message = Message::new(&[instruction], None); assert_eq!( parse_system(&message.instructions[0], &message.account_keys).unwrap(), ParsedInstructionEnum { @@ -243,6 +243,9 @@ mod test { } ); assert!(parse_system(&message.instructions[0], &message.account_keys[0..1]).is_err()); + let keys = message.account_keys.clone(); + message.instructions[0].accounts.pop(); + assert!(parse_system(&message.instructions[0], &keys).is_err()); } #[test] @@ -250,7 +253,7 @@ mod test { let account_pubkey = Pubkey::new_unique(); let owner_pubkey = Pubkey::new_unique(); let instruction = system_instruction::assign(&account_pubkey, &owner_pubkey); - let message = Message::new(&[instruction], None); + let mut message = Message::new(&[instruction], None); assert_eq!( parse_system(&message.instructions[0], &message.account_keys).unwrap(), ParsedInstructionEnum { @@ -262,6 +265,9 @@ mod test { } ); assert!(parse_system(&message.instructions[0], &[]).is_err()); + let keys = message.account_keys.clone(); + message.instructions[0].accounts.pop(); + assert!(parse_system(&message.instructions[0], &keys).is_err()); } #[test] @@ -270,7 +276,7 @@ mod test { let from_pubkey = Pubkey::new_unique(); let to_pubkey = Pubkey::new_unique(); let instruction = system_instruction::transfer(&from_pubkey, &to_pubkey, lamports); - let message = Message::new(&[instruction], None); + let mut message = Message::new(&[instruction], None); assert_eq!( parse_system(&message.instructions[0], &message.account_keys).unwrap(), ParsedInstructionEnum { @@ -283,6 +289,9 @@ mod test { } ); assert!(parse_system(&message.instructions[0], &message.account_keys[0..1]).is_err()); + let keys = message.account_keys.clone(); + message.instructions[0].accounts.pop(); + assert!(parse_system(&message.instructions[0], &keys).is_err()); } #[test] @@ -303,7 +312,7 @@ mod test { space, &owner_pubkey, ); - let message = Message::new(&[instruction], None); + let mut message = Message::new(&[instruction], None); assert_eq!( parse_system(&message.instructions[0], &message.account_keys).unwrap(), ParsedInstructionEnum { @@ -320,6 +329,10 @@ mod test { } ); assert!(parse_system(&message.instructions[0], &message.account_keys[0..1]).is_err()); + let keys = message.account_keys.clone(); + message.instructions[0].accounts.pop(); + message.instructions[0].accounts.pop(); + assert!(parse_system(&message.instructions[0], &keys).is_err()); } #[test] @@ -327,7 +340,7 @@ mod test { let space = 128; let account_pubkey = Pubkey::new_unique(); let instruction = system_instruction::allocate(&account_pubkey, space); - let message = Message::new(&[instruction], None); + let mut message = Message::new(&[instruction], None); assert_eq!( parse_system(&message.instructions[0], &message.account_keys).unwrap(), ParsedInstructionEnum { @@ -339,6 +352,9 @@ mod test { } ); assert!(parse_system(&message.instructions[0], &[]).is_err()); + let keys = message.account_keys.clone(); + message.instructions[0].accounts.pop(); + assert!(parse_system(&message.instructions[0], &keys).is_err()); } #[test] @@ -355,7 +371,7 @@ mod test { space, &owner_pubkey, ); - let message = Message::new(&[instruction], None); + let mut message = Message::new(&[instruction], None); assert_eq!( parse_system(&message.instructions[0], &message.account_keys).unwrap(), ParsedInstructionEnum { @@ -370,6 +386,9 @@ mod test { } ); assert!(parse_system(&message.instructions[0], &message.account_keys[0..1]).is_err()); + let keys = message.account_keys.clone(); + message.instructions[0].accounts.pop(); + assert!(parse_system(&message.instructions[0], &keys).is_err()); } #[test] @@ -384,7 +403,7 @@ mod test { seed, &owner_pubkey, ); - let message = Message::new(&[instruction], None); + let mut message = Message::new(&[instruction], None); assert_eq!( parse_system(&message.instructions[0], &message.account_keys).unwrap(), ParsedInstructionEnum { @@ -398,6 +417,9 @@ mod test { } ); assert!(parse_system(&message.instructions[0], &message.account_keys[0..1]).is_err()); + let keys = message.account_keys.clone(); + message.instructions[0].accounts.pop(); + assert!(parse_system(&message.instructions[0], &keys).is_err()); } #[test] @@ -416,7 +438,7 @@ mod test { &to_pubkey, lamports, ); - let message = Message::new(&[instruction], None); + let mut message = Message::new(&[instruction], None); assert_eq!( parse_system(&message.instructions[0], &message.account_keys).unwrap(), ParsedInstructionEnum { @@ -432,6 +454,9 @@ mod test { } ); assert!(parse_system(&message.instructions[0], &message.account_keys[0..2]).is_err()); + let keys = message.account_keys.clone(); + message.instructions[0].accounts.pop(); + assert!(parse_system(&message.instructions[0], &keys).is_err()); } #[test] @@ -441,7 +466,7 @@ mod test { let instruction = system_instruction::advance_nonce_account(&nonce_pubkey, &authorized_pubkey); - let message = Message::new(&[instruction], None); + let mut message = Message::new(&[instruction], None); assert_eq!( parse_system(&message.instructions[0], &message.account_keys).unwrap(), ParsedInstructionEnum { @@ -454,6 +479,9 @@ mod test { } ); assert!(parse_system(&message.instructions[0], &message.account_keys[0..2]).is_err()); + let keys = message.account_keys.clone(); + message.instructions[0].accounts.pop(); + assert!(parse_system(&message.instructions[0], &keys).is_err()); } #[test] @@ -469,7 +497,7 @@ mod test { &to_pubkey, lamports, ); - let message = Message::new(&[instruction], None); + let mut message = Message::new(&[instruction], None); assert_eq!( parse_system(&message.instructions[0], &message.account_keys).unwrap(), ParsedInstructionEnum { @@ -485,6 +513,9 @@ mod test { } ); assert!(parse_system(&message.instructions[0], &message.account_keys[0..4]).is_err()); + let keys = message.account_keys.clone(); + message.instructions[0].accounts.pop(); + assert!(parse_system(&message.instructions[0], &keys).is_err()); } #[test] @@ -500,7 +531,7 @@ mod test { &authorized_pubkey, lamports, ); - let message = Message::new(&instructions, None); + let mut message = Message::new(&instructions, None); assert_eq!( parse_system(&message.instructions[1], &message.account_keys).unwrap(), ParsedInstructionEnum { @@ -514,6 +545,9 @@ mod test { } ); assert!(parse_system(&message.instructions[1], &message.account_keys[0..3]).is_err()); + let keys = message.account_keys.clone(); + message.instructions[0].accounts.pop(); + assert!(parse_system(&message.instructions[0], &keys).is_err()); } #[test] @@ -527,7 +561,7 @@ mod test { &authorized_pubkey, &new_authority_pubkey, ); - let message = Message::new(&[instruction], None); + let mut message = Message::new(&[instruction], None); assert_eq!( parse_system(&message.instructions[0], &message.account_keys).unwrap(), ParsedInstructionEnum { @@ -540,5 +574,8 @@ mod test { } ); assert!(parse_system(&message.instructions[0], &message.account_keys[0..1]).is_err()); + let keys = message.account_keys.clone(); + message.instructions[0].accounts.pop(); + assert!(parse_system(&message.instructions[0], &keys).is_err()); } } diff --git a/transaction-status/src/parse_vote.rs b/transaction-status/src/parse_vote.rs index 9dc1dd32496251..751936b9e8acb1 100644 --- a/transaction-status/src/parse_vote.rs +++ b/transaction-status/src/parse_vote.rs @@ -176,7 +176,7 @@ mod test { &vote_init, lamports, ); - let message = Message::new(&instructions, None); + let mut message = Message::new(&instructions, None); assert_eq!( parse_vote(&message.instructions[1], &message.account_keys).unwrap(), ParsedInstructionEnum { @@ -193,6 +193,9 @@ mod test { } ); assert!(parse_vote(&message.instructions[1], &message.account_keys[0..3]).is_err()); + let keys = message.account_keys.clone(); + message.instructions[0].accounts.pop(); + assert!(parse_vote(&message.instructions[0], &keys).is_err()); } #[test] @@ -207,7 +210,7 @@ mod test { &new_authorized_pubkey, authority_type, ); - let message = Message::new(&[instruction], None); + let mut message = Message::new(&[instruction], None); assert_eq!( parse_vote(&message.instructions[0], &message.account_keys).unwrap(), ParsedInstructionEnum { @@ -222,6 +225,9 @@ mod test { } ); assert!(parse_vote(&message.instructions[0], &message.account_keys[0..2]).is_err()); + let keys = message.account_keys.clone(); + message.instructions[0].accounts.pop(); + assert!(parse_vote(&message.instructions[0], &keys).is_err()); } #[test] @@ -236,7 +242,7 @@ mod test { let vote_pubkey = Pubkey::new_unique(); let authorized_voter_pubkey = Pubkey::new_unique(); let instruction = vote_instruction::vote(&vote_pubkey, &authorized_voter_pubkey, vote); - let message = Message::new(&[instruction], None); + let mut message = Message::new(&[instruction], None); assert_eq!( parse_vote(&message.instructions[0], &message.account_keys).unwrap(), ParsedInstructionEnum { @@ -255,6 +261,9 @@ mod test { } ); assert!(parse_vote(&message.instructions[0], &message.account_keys[0..3]).is_err()); + let keys = message.account_keys.clone(); + message.instructions[0].accounts.pop(); + assert!(parse_vote(&message.instructions[0], &keys).is_err()); } #[test] @@ -269,7 +278,7 @@ mod test { lamports, &to_pubkey, ); - let message = Message::new(&[instruction], None); + let mut message = Message::new(&[instruction], None); assert_eq!( parse_vote(&message.instructions[0], &message.account_keys).unwrap(), ParsedInstructionEnum { @@ -283,6 +292,9 @@ mod test { } ); assert!(parse_vote(&message.instructions[0], &message.account_keys[0..2]).is_err()); + let keys = message.account_keys.clone(); + message.instructions[0].accounts.pop(); + assert!(parse_vote(&message.instructions[0], &keys).is_err()); } #[test] @@ -295,7 +307,7 @@ mod test { &authorized_withdrawer_pubkey, &node_pubkey, ); - let message = Message::new(&[instruction], None); + let mut message = Message::new(&[instruction], None); assert_eq!( parse_vote(&message.instructions[0], &message.account_keys).unwrap(), ParsedInstructionEnum { @@ -308,6 +320,9 @@ mod test { } ); assert!(parse_vote(&message.instructions[0], &message.account_keys[0..2]).is_err()); + let keys = message.account_keys.clone(); + message.instructions[0].accounts.pop(); + assert!(parse_vote(&message.instructions[0], &keys).is_err()); } #[test] @@ -320,7 +335,7 @@ mod test { &authorized_withdrawer_pubkey, commission, ); - let message = Message::new(&[instruction], None); + let mut message = Message::new(&[instruction], None); assert_eq!( parse_vote(&message.instructions[0], &message.account_keys).unwrap(), ParsedInstructionEnum { @@ -333,6 +348,9 @@ mod test { } ); assert!(parse_vote(&message.instructions[0], &message.account_keys[0..1]).is_err()); + let keys = message.account_keys.clone(); + message.instructions[0].accounts.pop(); + assert!(parse_vote(&message.instructions[0], &keys).is_err()); } #[test] @@ -349,7 +367,7 @@ mod test { let proof_hash = Hash::new_from_array([2; 32]); let instruction = vote_instruction::vote_switch(&vote_pubkey, &authorized_voter_pubkey, vote, proof_hash); - let message = Message::new(&[instruction], None); + let mut message = Message::new(&[instruction], None); assert_eq!( parse_vote(&message.instructions[0], &message.account_keys).unwrap(), ParsedInstructionEnum { @@ -369,6 +387,9 @@ mod test { } ); assert!(parse_vote(&message.instructions[0], &message.account_keys[0..3]).is_err()); + let keys = message.account_keys.clone(); + message.instructions[0].accounts.pop(); + assert!(parse_vote(&message.instructions[0], &keys).is_err()); } #[test] @@ -383,7 +404,7 @@ mod test { &new_authorized_pubkey, authority_type, ); - let message = Message::new(&[instruction], None); + let mut message = Message::new(&[instruction], None); assert_eq!( parse_vote(&message.instructions[0], &message.account_keys).unwrap(), ParsedInstructionEnum { @@ -398,5 +419,8 @@ mod test { } ); assert!(parse_vote(&message.instructions[0], &message.account_keys[0..3]).is_err()); + let keys = message.account_keys.clone(); + message.instructions[0].accounts.pop(); + assert!(parse_vote(&message.instructions[0], &keys).is_err()); } }