|
7 | 7 | state::{MAX_NAME_LENGTH, MAX_SYMBOL_LENGTH, MAX_URI_LENGTH}, |
8 | 8 | utils::puffed_out_string, |
9 | 9 | }, |
| 10 | + solana_program::{instruction::InstructionError, pubkey::Pubkey}, |
10 | 11 | solana_program_test::*, |
11 | 12 | solana_sdk::{ |
12 | | - signature::Signer, |
13 | | - transaction::Transaction, |
| 13 | + signature::{Keypair, Signer}, |
| 14 | + transaction::{Transaction, TransactionError}, |
| 15 | + }, |
| 16 | + spl_stake_pool::{ |
| 17 | + error::StakePoolError::{SignatureMissing, WrongManager}, |
| 18 | + instruction, MINIMUM_RESERVE_LAMPORTS, |
14 | 19 | }, |
15 | | - spl_stake_pool::{instruction, MINIMUM_RESERVE_LAMPORTS}, |
16 | 20 | }; |
17 | 21 |
|
18 | 22 | async fn setup() -> (ProgramTestContext, StakePoolAccounts) { |
@@ -106,3 +110,89 @@ async fn success_update_pool_token_metadata() { |
106 | 110 | assert_eq!(metadata.data.symbol.to_string(), puffed_symbol); |
107 | 111 | assert_eq!(metadata.data.uri.to_string(), puffed_uri); |
108 | 112 | } |
| 113 | + |
| 114 | +#[tokio::test] |
| 115 | +async fn fail_manager_did_not_sign() { |
| 116 | + let (mut context, stake_pool_accounts) = setup().await; |
| 117 | + |
| 118 | + let updated_name = "updated_name"; |
| 119 | + let updated_symbol = "USYM"; |
| 120 | + let updated_uri = "updated_uri"; |
| 121 | + |
| 122 | + let mut ix = instruction::update_token_metadata( |
| 123 | + &spl_stake_pool::id(), |
| 124 | + &stake_pool_accounts.stake_pool.pubkey(), |
| 125 | + &stake_pool_accounts.manager.pubkey(), |
| 126 | + &stake_pool_accounts.pool_mint.pubkey(), |
| 127 | + updated_name.to_string(), |
| 128 | + updated_symbol.to_string(), |
| 129 | + updated_uri.to_string(), |
| 130 | + ); |
| 131 | + ix.accounts[1].is_signer = false; |
| 132 | + |
| 133 | + let transaction = Transaction::new_signed_with_payer( |
| 134 | + &[ix], |
| 135 | + Some(&context.payer.pubkey()), |
| 136 | + &[&context.payer], |
| 137 | + context.last_blockhash, |
| 138 | + ); |
| 139 | + |
| 140 | + let error = context |
| 141 | + .banks_client |
| 142 | + .process_transaction(transaction) |
| 143 | + .await |
| 144 | + .err() |
| 145 | + .unwrap() |
| 146 | + .unwrap(); |
| 147 | + |
| 148 | + match error { |
| 149 | + TransactionError::InstructionError(_, InstructionError::Custom(error_index)) => { |
| 150 | + let program_error = SignatureMissing as u32; |
| 151 | + assert_eq!(error_index, program_error); |
| 152 | + } |
| 153 | + _ => panic!("Wrong error occurs while manager signature missing"), |
| 154 | + } |
| 155 | +} |
| 156 | + |
| 157 | +#[tokio::test] |
| 158 | +async fn fail_wrong_manager_signed() { |
| 159 | + let (mut context, stake_pool_accounts) = setup().await; |
| 160 | + |
| 161 | + let updated_name = "updated_name"; |
| 162 | + let updated_symbol = "USYM"; |
| 163 | + let updated_uri = "updated_uri"; |
| 164 | + |
| 165 | + let random_keypair = Keypair::new(); |
| 166 | + let ix = instruction::update_token_metadata( |
| 167 | + &spl_stake_pool::id(), |
| 168 | + &stake_pool_accounts.stake_pool.pubkey(), |
| 169 | + &random_keypair.pubkey(), |
| 170 | + &stake_pool_accounts.pool_mint.pubkey(), |
| 171 | + updated_name.to_string(), |
| 172 | + updated_symbol.to_string(), |
| 173 | + updated_uri.to_string(), |
| 174 | + ); |
| 175 | + |
| 176 | + let transaction = Transaction::new_signed_with_payer( |
| 177 | + &[ix], |
| 178 | + Some(&context.payer.pubkey()), |
| 179 | + &[&context.payer, &random_keypair], |
| 180 | + context.last_blockhash, |
| 181 | + ); |
| 182 | + |
| 183 | + let error = context |
| 184 | + .banks_client |
| 185 | + .process_transaction(transaction) |
| 186 | + .await |
| 187 | + .err() |
| 188 | + .unwrap() |
| 189 | + .unwrap(); |
| 190 | + |
| 191 | + match error { |
| 192 | + TransactionError::InstructionError(_, InstructionError::Custom(error_index)) => { |
| 193 | + let program_error = WrongManager as u32; |
| 194 | + assert_eq!(error_index, program_error); |
| 195 | + } |
| 196 | + _ => panic!("Wrong error occurs while signing with the wrong manager"), |
| 197 | + } |
| 198 | +} |
0 commit comments