assign.rs 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. mod setup;
  2. use {
  3. mollusk_svm::result::Check, solana_account::Account, solana_program_error::ProgramError,
  4. solana_pubkey::Pubkey, solana_system_interface::instruction::assign,
  5. };
  6. const OWNER: Pubkey = Pubkey::new_from_array([8; 32]);
  7. #[test]
  8. fn fail_account_not_signer() {
  9. let mollusk = setup::setup();
  10. let pubkey = Pubkey::new_unique();
  11. let mut instruction = assign(&pubkey, &OWNER);
  12. instruction.accounts[0].is_signer = false;
  13. mollusk.process_and_validate_instruction(
  14. &instruction,
  15. &[(pubkey, Account::default())],
  16. &[Check::err(ProgramError::MissingRequiredSignature)],
  17. );
  18. }
  19. #[test]
  20. fn success() {
  21. let mollusk = setup::setup();
  22. let pubkey = Pubkey::new_unique();
  23. mollusk.process_and_validate_instruction(
  24. &assign(&pubkey, &OWNER),
  25. &[(pubkey, Account::default())],
  26. &[
  27. Check::success(),
  28. Check::account(&pubkey).owner(&OWNER).build(),
  29. ],
  30. );
  31. }
  32. #[test]
  33. fn success_already_assigned() {
  34. let mollusk = setup::setup();
  35. let pubkey = Pubkey::new_unique();
  36. let account = Account {
  37. owner: OWNER, // Already assigned
  38. ..Account::default()
  39. };
  40. mollusk.process_and_validate_instruction(
  41. &assign(&pubkey, &OWNER),
  42. &[(pubkey, account)],
  43. &[
  44. Check::success(),
  45. Check::account(&pubkey).owner(&OWNER).build(),
  46. ],
  47. );
  48. }