bpf.rs 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. use {
  2. agave_feature_set as feature_set,
  3. solana_instruction::{AccountMeta, Instruction},
  4. solana_program_test::ProgramTest,
  5. solana_pubkey::Pubkey,
  6. solana_sdk_ids::bpf_loader,
  7. solana_signer::Signer,
  8. solana_transaction::Transaction,
  9. test_case::test_case,
  10. };
  11. #[tokio::test]
  12. async fn test_add_bpf_program() {
  13. let program_id = Pubkey::new_unique();
  14. let mut program_test = ProgramTest::default();
  15. program_test.prefer_bpf(true);
  16. program_test.add_program("noop_program", program_id, None);
  17. let context = program_test.start_with_context().await;
  18. // Assert the program is a BPF Loader 2 program.
  19. let program_account = context
  20. .banks_client
  21. .get_account(program_id)
  22. .await
  23. .unwrap()
  24. .unwrap();
  25. assert_eq!(program_account.owner, bpf_loader::id());
  26. // Invoke the program.
  27. let instruction = Instruction::new_with_bytes(program_id, &[], Vec::new());
  28. let transaction = Transaction::new_signed_with_payer(
  29. &[instruction],
  30. Some(&context.payer.pubkey()),
  31. &[&context.payer],
  32. context.last_blockhash,
  33. );
  34. context
  35. .banks_client
  36. .process_transaction(transaction)
  37. .await
  38. .unwrap();
  39. }
  40. #[test_case(64, true, true; "success with 64 accounts and without feature")]
  41. #[test_case(65, true, false; "failure with 65 accounts and without feature")]
  42. #[test_case(128, false, true; "success with 128 accounts and with feature")]
  43. #[test_case(129, false, false; "failure with 129 accounts and with feature")]
  44. #[tokio::test]
  45. async fn test_max_accounts(num_accounts: u8, deactivate_feature: bool, expect_success: bool) {
  46. let program_id = Pubkey::new_unique();
  47. let mut program_test = ProgramTest::default();
  48. program_test.prefer_bpf(true);
  49. program_test.add_program("noop_program", program_id, None);
  50. if deactivate_feature {
  51. program_test.deactivate_feature(feature_set::increase_tx_account_lock_limit::id());
  52. }
  53. let context = program_test.start_with_context().await;
  54. // Subtract 2 to account for the program and fee payer
  55. let num_extra_accounts = num_accounts.checked_sub(2).unwrap();
  56. let account_metas = (0..num_extra_accounts)
  57. .map(|_| AccountMeta::new_readonly(Pubkey::new_unique(), false))
  58. .collect::<Vec<_>>();
  59. let instruction = Instruction::new_with_bytes(program_id, &[], account_metas);
  60. let transaction = Transaction::new_signed_with_payer(
  61. &[instruction],
  62. Some(&context.payer.pubkey()),
  63. &[&context.payer],
  64. context.last_blockhash,
  65. );
  66. // Invoke the program.
  67. if expect_success {
  68. context
  69. .banks_client
  70. .process_transaction(transaction)
  71. .await
  72. .unwrap();
  73. } else {
  74. context
  75. .banks_client
  76. .process_transaction(transaction)
  77. .await
  78. .unwrap_err();
  79. }
  80. }