From 32d422d21d81e57b3f383ddee2a42867ff2486f3 Mon Sep 17 00:00:00 2001 From: Hardhat Chad Date: Tue, 2 Apr 2024 05:35:45 +0000 Subject: [PATCH] remove unused mint account from claim ix --- src/instruction.rs | 10 ++++------ src/processor/claim.rs | 9 ++++----- tests/test_mine.rs | 32 ++++++++++++++++++++++++++++++++ 3 files changed, 40 insertions(+), 11 deletions(-) diff --git a/src/instruction.rs b/src/instruction.rs index df9208a..6c88c2d 100644 --- a/src/instruction.rs +++ b/src/instruction.rs @@ -49,11 +49,10 @@ pub enum OreInstruction { #[account(0, name = "ore_program", desc = "Ore program")] #[account(1, name = "signer", desc = "Signer", signer)] #[account(2, name = "beneficiary", desc = "Beneficiary token account", writable)] - #[account(3, name = "mint", desc = "Ore token mint account")] - #[account(4, name = "proof", desc = "Ore proof account", writable)] - #[account(5, name = "treasury", desc = "Ore treasury account", writable)] - #[account(6, name = "treasury_tokens", desc = "Ore treasury token account", writable)] - #[account(7, name = "token_program", desc = "SPL token program")] + #[account(3, name = "proof", desc = "Ore proof account", writable)] + #[account(4, name = "treasury", desc = "Ore treasury account", writable)] + #[account(5, name = "treasury_tokens", desc = "Ore treasury token account", writable)] + #[account(6, name = "token_program", desc = "SPL token program")] Claim = 3, #[account(0, name = "ore_program", desc = "Ore program")] @@ -245,7 +244,6 @@ pub fn claim(signer: Pubkey, beneficiary: Pubkey, amount: u64) -> Instruction { accounts: vec![ AccountMeta::new(signer, true), AccountMeta::new(beneficiary, false), - AccountMeta::new(MINT_ADDRESS, false), AccountMeta::new(proof, false), AccountMeta::new(TREASURY_ADDRESS, false), AccountMeta::new(treasury_tokens, false), diff --git a/src/processor/claim.rs b/src/processor/claim.rs index a96199a..616a393 100644 --- a/src/processor/claim.rs +++ b/src/processor/claim.rs @@ -9,7 +9,7 @@ use crate::{ loaders::*, state::{Proof, Treasury}, utils::AccountDeserialize, - TREASURY, + MINT_ADDRESS, TREASURY, }; /// Claim distributes owed token rewards from the treasury to the miner. Its responsibilies include: @@ -31,20 +31,19 @@ pub fn process_claim<'a, 'info>( let amount = u64::from_le_bytes(args.amount); // Load accounts - let [signer, beneficiary_info, mint_info, proof_info, treasury_info, treasury_tokens_info, token_program] = + let [signer, beneficiary_info, proof_info, treasury_info, treasury_tokens_info, token_program] = accounts else { return Err(ProgramError::NotEnoughAccountKeys); }; load_signer(signer)?; - load_token_account(beneficiary_info, None, mint_info.key, true)?; - load_mint(mint_info, true)?; + load_token_account(beneficiary_info, None, &MINT_ADDRESS, true)?; load_proof(proof_info, signer.key, true)?; load_treasury(treasury_info, true)?; load_token_account( treasury_tokens_info, Some(treasury_info.key), - mint_info.key, + &MINT_ADDRESS, true, )?; load_program(token_program, spl_token::id())?; diff --git a/tests/test_mine.rs b/tests/test_mine.rs index 8ae0eff..727eb2a 100644 --- a/tests/test_mine.rs +++ b/tests/test_mine.rs @@ -301,6 +301,38 @@ async fn test_claim_too_large() { assert!(res.is_err()); } +#[tokio::test] +async fn test_claim_other_proof() { + // Setup + let (mut banks, payer, alt_payer, blockhash) = + setup_program_test_env(true, ClockState::Normal).await; + + // Submit register tx + let ix = ore::instruction::register(payer.pubkey()); + let tx = Transaction::new_signed_with_payer(&[ix], Some(&payer.pubkey()), &[&payer], blockhash); + let res = banks.process_transaction(tx).await; + assert!(res.is_ok()); + + // Submit claim tx + let beneficiary = get_associated_token_address(&alt_payer.pubkey(), &ore::MINT_ADDRESS); + let token_ix = create_associated_token_account( + &alt_payer.pubkey(), + &alt_payer.pubkey(), + &ore::MINT_ADDRESS, + &spl_token::id(), + ); + let mut ix = ore::instruction::claim(payer.pubkey(), beneficiary, 0); + ix.accounts[0].pubkey = alt_payer.pubkey(); + let tx = Transaction::new_signed_with_payer( + &[token_ix, ix], + Some(&alt_payer.pubkey()), + &[&alt_payer], + blockhash, + ); + let res = banks.process_transaction(tx).await; + assert!(res.is_err()); +} + #[tokio::test] async fn test_mine_not_enough_accounts() { // Setup