|
1 | 1 | use { |
2 | 2 | anchor_lang::{prelude::AccountMeta, InstructionData}, |
3 | 3 | pyth_lazer_solana_contract::{ed25519_program_args, ANCHOR_DISCRIMINATOR_BYTES}, |
4 | | - solana_program_test::{BanksClient, ProgramTest}, |
| 4 | + solana_program_test::{BanksClient, BanksClientError, ProgramTest}, |
5 | 5 | solana_sdk::{ |
6 | 6 | account::Account, |
7 | 7 | ed25519_program, |
8 | 8 | hash::Hash, |
9 | | - instruction::Instruction, |
| 9 | + instruction::{Instruction, InstructionError}, |
10 | 10 | pubkey::{Pubkey, PUBKEY_BYTES}, |
11 | 11 | signature::Keypair, |
12 | 12 | signer::Signer, |
13 | 13 | system_instruction, system_program, system_transaction, sysvar, |
14 | | - transaction::Transaction, |
| 14 | + transaction::{Transaction, TransactionError}, |
15 | 15 | }, |
16 | 16 | std::env, |
17 | 17 | }; |
@@ -277,3 +277,58 @@ async fn test_migrate_from_0_1_0() { |
277 | 277 | // because it was present in the original storage PDA data. |
278 | 278 | setup.verify_message(&message, treasury).await; |
279 | 279 | } |
| 280 | + |
| 281 | +#[tokio::test] |
| 282 | +async fn test_disallows_extra_migrate() { |
| 283 | + let mut setup = Setup::new().await; |
| 284 | + let treasury = setup.create_treasury().await; |
| 285 | + |
| 286 | + let mut transaction_init_contract = Transaction::new_with_payer( |
| 287 | + &[Instruction::new_with_bytes( |
| 288 | + pyth_lazer_solana_contract::ID, |
| 289 | + &pyth_lazer_solana_contract::instruction::Initialize { |
| 290 | + top_authority: setup.payer.pubkey(), |
| 291 | + treasury, |
| 292 | + } |
| 293 | + .data(), |
| 294 | + vec![ |
| 295 | + AccountMeta::new(setup.payer.pubkey(), true), |
| 296 | + AccountMeta::new(pyth_lazer_solana_contract::STORAGE_ID, false), |
| 297 | + AccountMeta::new_readonly(system_program::ID, false), |
| 298 | + ], |
| 299 | + )], |
| 300 | + Some(&setup.payer.pubkey()), |
| 301 | + ); |
| 302 | + transaction_init_contract.sign(&[&setup.payer], setup.recent_blockhash); |
| 303 | + setup |
| 304 | + .banks_client |
| 305 | + .process_transaction(transaction_init_contract) |
| 306 | + .await |
| 307 | + .unwrap(); |
| 308 | + |
| 309 | + let mut transaction_migrate_contract = Transaction::new_with_payer( |
| 310 | + &[Instruction::new_with_bytes( |
| 311 | + pyth_lazer_solana_contract::ID, |
| 312 | + &pyth_lazer_solana_contract::instruction::MigrateFrom010 { treasury }.data(), |
| 313 | + vec![ |
| 314 | + AccountMeta::new(setup.payer.pubkey(), true), |
| 315 | + AccountMeta::new(pyth_lazer_solana_contract::STORAGE_ID, false), |
| 316 | + AccountMeta::new_readonly(system_program::ID, false), |
| 317 | + ], |
| 318 | + )], |
| 319 | + Some(&setup.payer.pubkey()), |
| 320 | + ); |
| 321 | + transaction_migrate_contract.sign(&[&setup.payer], setup.recent_blockhash); |
| 322 | + let err = setup |
| 323 | + .banks_client |
| 324 | + .process_transaction(transaction_migrate_contract) |
| 325 | + .await |
| 326 | + .unwrap_err(); |
| 327 | + assert!(matches!( |
| 328 | + err, |
| 329 | + BanksClientError::TransactionError(TransactionError::InstructionError( |
| 330 | + 0, |
| 331 | + InstructionError::InvalidAccountData |
| 332 | + )) |
| 333 | + )); |
| 334 | +} |
0 commit comments