|
1 | 1 | use { |
2 | 2 | anchor_lang::{prelude::AccountMeta, InstructionData}, |
3 | | - pyth_lazer_solana_contract::{ed25519_program_args, ANCHOR_DISCRIMINATOR_BYTES}, |
| 3 | + pyth_lazer_solana_contract::ed25519_program_args, |
4 | 4 | solana_program_test::{BanksClient, BanksClientError, ProgramTest}, |
5 | 5 | solana_sdk::{ |
6 | | - account::Account, |
7 | 6 | ed25519_program, |
8 | 7 | hash::Hash, |
9 | 8 | instruction::{Instruction, InstructionError}, |
10 | | - pubkey::{Pubkey, PUBKEY_BYTES}, |
| 9 | + pubkey::Pubkey, |
11 | 10 | signature::Keypair, |
12 | 11 | signer::Signer, |
13 | | - system_instruction, system_program, system_transaction, sysvar, |
| 12 | + system_instruction, system_program, sysvar, |
14 | 13 | transaction::{Transaction, TransactionError}, |
15 | 14 | }, |
16 | 15 | std::env, |
@@ -293,129 +292,3 @@ async fn test_rejects_wrong_offset() { |
293 | 292 | )) |
294 | 293 | )); |
295 | 294 | } |
296 | | - |
297 | | -#[tokio::test] |
298 | | -async fn test_migrate_from_0_1_0() { |
299 | | - let mut program_test = program_test(); |
300 | | - // Create a storage PDA account with the data that was produced by the program v0.1.0. |
301 | | - let mut old_storage_data = hex::decode( |
302 | | - "d175ffb9c4af4409aa4dcb5d31150b162b664abd843cb231cee5c0ebf759ce371d9cb36ffc653796\ |
303 | | - 0174313a6525edf99936aa1477e94c72bc5cc617b21745f5f03296f3154461f214ffffffffffffff7\ |
304 | | - f00000000000000000000000000000000000000000000000000000000000000000000000000000000", |
305 | | - ) |
306 | | - .unwrap(); |
307 | | - let top_authority = Keypair::new(); |
308 | | - // Replace top authority pubkey in storage PDA data to allow successful migration. |
309 | | - old_storage_data[ANCHOR_DISCRIMINATOR_BYTES..ANCHOR_DISCRIMINATOR_BYTES + PUBKEY_BYTES] |
310 | | - .copy_from_slice(&top_authority.pubkey().to_bytes()); |
311 | | - program_test.add_account( |
312 | | - pyth_lazer_solana_contract::STORAGE_ID, |
313 | | - Account { |
314 | | - lamports: 1733040, |
315 | | - data: old_storage_data, |
316 | | - owner: pyth_lazer_solana_contract::ID, |
317 | | - executable: false, |
318 | | - rent_epoch: 18446744073709551615, |
319 | | - }, |
320 | | - ); |
321 | | - let mut setup = Setup::with_program_test(program_test).await; |
322 | | - let treasury = setup.create_treasury().await; |
323 | | - |
324 | | - // Make sure storage PDA will be rent-exempt after resize. |
325 | | - let tx_transfer = system_transaction::transfer( |
326 | | - &setup.payer, |
327 | | - &pyth_lazer_solana_contract::STORAGE_ID, |
328 | | - 10_000_000, |
329 | | - setup.recent_blockhash, |
330 | | - ); |
331 | | - setup |
332 | | - .banks_client |
333 | | - .process_transaction(tx_transfer) |
334 | | - .await |
335 | | - .unwrap(); |
336 | | - |
337 | | - let mut transaction_migrate_contract = Transaction::new_with_payer( |
338 | | - &[Instruction::new_with_bytes( |
339 | | - pyth_lazer_solana_contract::ID, |
340 | | - &pyth_lazer_solana_contract::instruction::MigrateFrom010 { treasury }.data(), |
341 | | - vec![ |
342 | | - AccountMeta::new(top_authority.pubkey(), true), |
343 | | - AccountMeta::new(pyth_lazer_solana_contract::STORAGE_ID, false), |
344 | | - AccountMeta::new_readonly(system_program::ID, false), |
345 | | - ], |
346 | | - )], |
347 | | - Some(&setup.payer.pubkey()), |
348 | | - ); |
349 | | - transaction_migrate_contract.sign(&[&setup.payer, &top_authority], setup.recent_blockhash); |
350 | | - setup |
351 | | - .banks_client |
352 | | - .process_transaction(transaction_migrate_contract) |
353 | | - .await |
354 | | - .unwrap(); |
355 | | - |
356 | | - let message = hex::decode( |
357 | | - "b9011a82e5cddee2c1bd364c8c57e1c98a6a28d194afcad410ff412226c8b2ae931ff59a57147cb47c7307\ |
358 | | - afc2a0a1abec4dd7e835a5b7113cf5aeac13a745c6bed6c60074313a6525edf99936aa1477e94c72bc5cc61\ |
359 | | - 7b21745f5f03296f3154461f2141c0075d3c7931c9773f30a240600010102000000010000e1f50500000000", |
360 | | - ) |
361 | | - .unwrap(); |
362 | | - |
363 | | - // The contract will recognize the trusted signer without calling `set_trusted` |
364 | | - // because it was present in the original storage PDA data. |
365 | | - setup.verify_message(&message, treasury).await; |
366 | | -} |
367 | | - |
368 | | -#[tokio::test] |
369 | | -async fn test_disallows_extra_migrate() { |
370 | | - let mut setup = Setup::new().await; |
371 | | - let treasury = setup.create_treasury().await; |
372 | | - |
373 | | - let mut transaction_init_contract = Transaction::new_with_payer( |
374 | | - &[Instruction::new_with_bytes( |
375 | | - pyth_lazer_solana_contract::ID, |
376 | | - &pyth_lazer_solana_contract::instruction::Initialize { |
377 | | - top_authority: setup.payer.pubkey(), |
378 | | - treasury, |
379 | | - } |
380 | | - .data(), |
381 | | - vec![ |
382 | | - AccountMeta::new(setup.payer.pubkey(), true), |
383 | | - AccountMeta::new(pyth_lazer_solana_contract::STORAGE_ID, false), |
384 | | - AccountMeta::new_readonly(system_program::ID, false), |
385 | | - ], |
386 | | - )], |
387 | | - Some(&setup.payer.pubkey()), |
388 | | - ); |
389 | | - transaction_init_contract.sign(&[&setup.payer], setup.recent_blockhash); |
390 | | - setup |
391 | | - .banks_client |
392 | | - .process_transaction(transaction_init_contract) |
393 | | - .await |
394 | | - .unwrap(); |
395 | | - |
396 | | - let mut transaction_migrate_contract = Transaction::new_with_payer( |
397 | | - &[Instruction::new_with_bytes( |
398 | | - pyth_lazer_solana_contract::ID, |
399 | | - &pyth_lazer_solana_contract::instruction::MigrateFrom010 { treasury }.data(), |
400 | | - vec![ |
401 | | - AccountMeta::new(setup.payer.pubkey(), true), |
402 | | - AccountMeta::new(pyth_lazer_solana_contract::STORAGE_ID, false), |
403 | | - AccountMeta::new_readonly(system_program::ID, false), |
404 | | - ], |
405 | | - )], |
406 | | - Some(&setup.payer.pubkey()), |
407 | | - ); |
408 | | - transaction_migrate_contract.sign(&[&setup.payer], setup.recent_blockhash); |
409 | | - let err = setup |
410 | | - .banks_client |
411 | | - .process_transaction(transaction_migrate_contract) |
412 | | - .await |
413 | | - .unwrap_err(); |
414 | | - assert!(matches!( |
415 | | - err, |
416 | | - BanksClientError::TransactionError(TransactionError::InstructionError( |
417 | | - 0, |
418 | | - InstructionError::InvalidAccountData |
419 | | - )) |
420 | | - )); |
421 | | -} |
0 commit comments