stable_swap/processor/
mod.rs1#[macro_use]
4mod macros;
5
6mod admin;
7mod checks;
8mod logging;
9mod swap;
10mod token;
11mod utils;
12
13#[cfg(test)]
14#[allow(clippy::unwrap_used)]
15mod test_utils;
16
17use crate::instruction::AdminInstruction;
18
19use solana_program::{account_info::AccountInfo, entrypoint::ProgramResult, pubkey::Pubkey};
20
21pub struct Processor {}
23
24impl Processor {
25 pub fn process(program_id: &Pubkey, accounts: &[AccountInfo], input: &[u8]) -> ProgramResult {
27 let instruction = AdminInstruction::unpack(input)?;
28 match instruction {
29 None => swap::process_swap_instruction(program_id, accounts, input),
30 Some(admin_instruction) => {
31 admin::process_admin_instruction(&admin_instruction, accounts)
32 }
33 }
34 }
35}
36
37#[cfg(test)]
38#[allow(clippy::unwrap_used)]
39mod tests {
40 use super::*;
41 use crate::processor::test_utils::*;
42 use solana_program::program_error::ProgramError;
43 use solana_sdk::account::Account;
44 use spl_token::instruction::mint_to;
45
46 #[test]
47 fn test_token_program_id_error() {
48 let swap_key = pubkey_rand();
49 let mut mint = (pubkey_rand(), Account::default());
50 let mut destination = (pubkey_rand(), Account::default());
51 let token_program = (spl_token::id(), Account::default());
52 let (authority_key, nonce) =
53 Pubkey::find_program_address(&[&swap_key.to_bytes()[..]], &SWAP_PROGRAM_ID);
54 let mut authority = (authority_key, Account::default());
55 let swap_bytes = swap_key.to_bytes();
56 let authority_signature_seeds = [&swap_bytes[..32], &[nonce]];
57 let signers = &[&authority_signature_seeds[..]];
58 let ix = mint_to(
59 &token_program.0,
60 &mint.0,
61 &destination.0,
62 &authority.0,
63 &[],
64 10,
65 )
66 .unwrap();
67 let mint = (&mut mint).into();
68 let destination = (&mut destination).into();
69 let authority = (&mut authority).into();
70
71 let err =
72 solana_program::program::invoke_signed(&ix, &[mint, destination, authority], signers)
73 .unwrap_err();
74 assert_eq!(err, ProgramError::InvalidAccountData);
75 }
76}