Skip to content

Commit

Permalink
feat: add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
keyvankhademi committed Sep 3, 2024
1 parent 72f3d27 commit 9525b45
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 3 deletions.
38 changes: 35 additions & 3 deletions staking/integration-tests/src/integrity_pool/instructions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ pub fn create_pool_data_account(
svm.latest_blockhash(),
);

svm.send_transaction(initialize_pool_tx.clone())
svm.send_transaction(initialize_pool_tx)
}

pub fn update_y(
Expand Down Expand Up @@ -164,7 +164,39 @@ pub fn update_y(
svm.latest_blockhash(),
);

svm.send_transaction(update_y_tx.clone())
svm.send_transaction(update_y_tx)
}

pub fn update_pyth_token_mint(
svm: &mut litesvm::LiteSVM,
payer: &Keypair,
reward_program_authority: &Keypair,
pyth_token_mint: Pubkey,
) -> TransactionResult {
let pool_config_pubkey = get_pool_config_address();

let instruction_data = integrity_pool::instruction::UpdatePythTokenMint { pyth_token_mint };

let instruction_accs = integrity_pool::accounts::UpdatePythTokenMint {
pool_config: pool_config_pubkey,
reward_program_authority: reward_program_authority.pubkey(),
system_program: system_program::ID,
};

let instruction = Instruction::new_with_bytes(
integrity_pool::ID,
&instruction_data.data(),
instruction_accs.to_account_metas(None),
);

let transaction = Transaction::new_signed_with_payer(
&[instruction],
Some(&payer.pubkey()),
&[payer, reward_program_authority],
svm.latest_blockhash(),
);

svm.send_transaction(transaction)
}

pub fn update_delegation_fee(
Expand Down Expand Up @@ -199,7 +231,7 @@ pub fn update_delegation_fee(
svm.latest_blockhash(),
);

svm.send_transaction(update_delegation_fee_tx.clone())
svm.send_transaction(update_delegation_fee_tx)
}


Expand Down
39 changes: 39 additions & 0 deletions staking/integration-tests/tests/initialize_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use {
integrity_pool::{
instructions::{
create_pool_data_account,
update_pyth_token_mint,
update_y,
},
pda::get_pool_config_address,
Expand Down Expand Up @@ -116,3 +117,41 @@ fn test_update_y() {
0
);
}

#[test]
fn test_update_pyth_token_mint() {
let SetupResult {
mut svm,
payer,
pyth_token_mint,
reward_program_authority,
..
} = setup(SetupProps {
init_config: true,
init_target: true,
init_mint: true,
init_pool_data: true,
init_publishers: true,
reward_amount_override: None,
});

let pool_config_pubkey = get_pool_config_address();
let pool_config: PoolConfig = fetch_account_data(&mut svm, &pool_config_pubkey);

assert!(pool_config.pyth_token_mint == pyth_token_mint.pubkey());

let new_mint = Pubkey::new_unique();
update_pyth_token_mint(&mut svm, &payer, &reward_program_authority, new_mint).unwrap();

let pool_config: PoolConfig = fetch_account_data(&mut svm, &pool_config_pubkey);
assert!(pool_config.pyth_token_mint == new_mint);

// Trying to update the pyth token mint without the correct authority should fail
let wrong_authority = Keypair::new();

assert_anchor_program_error!(
update_pyth_token_mint(&mut svm, &payer, &wrong_authority, new_mint),
IntegrityPoolError::InvalidRewardProgramAuthority,
0
);
}

0 comments on commit 9525b45

Please sign in to comment.