-
Notifications
You must be signed in to change notification settings - Fork 49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: disallow target account when creating position for integrity pool #506
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,143 @@ | ||
use { | ||
anchor_lang::{ | ||
system_program, | ||
InstructionData, | ||
ToAccountMetas, | ||
}, | ||
integration_tests::{ | ||
assert_anchor_program_error, | ||
setup::{ | ||
setup, | ||
SetupProps, | ||
SetupResult, | ||
}, | ||
staking::{ | ||
helper_functions::initialize_new_stake_account, | ||
instructions::{ | ||
create_position, | ||
update_pool_authority, | ||
}, | ||
pda::{ | ||
get_config_address, | ||
get_stake_account_custody_address, | ||
get_stake_account_metadata_address, | ||
get_target_address, | ||
}, | ||
}, | ||
}, | ||
integrity_pool::utils::types::FRAC_64_MULTIPLIER, | ||
solana_sdk::{ | ||
instruction::Instruction, | ||
signature::Keypair, | ||
signer::Signer, | ||
transaction::Transaction, | ||
}, | ||
staking::error::ErrorCode, | ||
}; | ||
|
||
|
||
#[test] | ||
fn test_pool_authority() { | ||
let SetupResult { | ||
mut svm, | ||
payer, | ||
pyth_token_mint, | ||
publisher_keypair, | ||
pool_data_pubkey: _, | ||
reward_program_authority: _, | ||
maybe_publisher_index: _, | ||
} = setup(SetupProps { | ||
init_config: true, | ||
init_target: true, | ||
init_mint: true, | ||
init_pool_data: true, | ||
init_publishers: true, | ||
}); | ||
|
||
let stake_account_positions = | ||
initialize_new_stake_account(&mut svm, &payer, &pyth_token_mint, true, true); | ||
|
||
let pool_authority = Keypair::new(); | ||
|
||
update_pool_authority(&mut svm, &payer, pool_authority.pubkey()); | ||
|
||
create_position( | ||
&mut svm, | ||
&payer, | ||
stake_account_positions, | ||
staking::state::positions::TargetWithParameters::IntegrityPool { | ||
publisher: publisher_keypair.pubkey(), | ||
}, | ||
Some(&pool_authority), | ||
50 * FRAC_64_MULTIPLIER, | ||
) | ||
.unwrap(); | ||
|
||
assert_anchor_program_error!( | ||
create_position( | ||
&mut svm, | ||
&payer, | ||
stake_account_positions, | ||
staking::state::positions::TargetWithParameters::IntegrityPool { | ||
publisher: publisher_keypair.pubkey(), | ||
}, | ||
None, | ||
50 * FRAC_64_MULTIPLIER, | ||
), | ||
ErrorCode::InvalidPoolAuthority, | ||
0 | ||
); | ||
|
||
create_position( | ||
&mut svm, | ||
&payer, | ||
stake_account_positions, | ||
staking::state::positions::TargetWithParameters::Voting, | ||
None, | ||
10 * FRAC_64_MULTIPLIER, | ||
) | ||
.unwrap(); | ||
|
||
let config_pubkey = get_config_address(); | ||
let stake_account_metadata = get_stake_account_metadata_address(stake_account_positions); | ||
let stake_account_custody = get_stake_account_custody_address(stake_account_positions); | ||
let voting_target_account = get_target_address(); | ||
|
||
let create_position_data = staking::instruction::CreatePosition { | ||
target_with_parameters: staking::state::positions::TargetWithParameters::IntegrityPool { | ||
publisher: publisher_keypair.pubkey(), | ||
}, | ||
amount: 10 * FRAC_64_MULTIPLIER, | ||
}; | ||
|
||
let create_position_accs = staking::accounts::CreatePosition { | ||
config: config_pubkey, | ||
stake_account_metadata, | ||
stake_account_positions, | ||
stake_account_custody, | ||
owner: payer.pubkey(), | ||
target_account: Some(voting_target_account), | ||
pool_authority: Some(pool_authority.pubkey()), | ||
system_program: system_program::ID, | ||
}; | ||
|
||
let create_position_ix = Instruction::new_with_bytes( | ||
staking::ID, | ||
&create_position_data.data(), | ||
create_position_accs.to_account_metas(None), | ||
); | ||
|
||
|
||
let create_position_tx = Transaction::new_signed_with_payer( | ||
&[create_position_ix], | ||
Some(&payer.pubkey()), | ||
&[&payer, &pool_authority], | ||
svm.latest_blockhash(), | ||
); | ||
|
||
assert_anchor_program_error!( | ||
svm.send_transaction(create_position_tx), | ||
ErrorCode::UnexpectedTargetAccount, | ||
0 | ||
); | ||
} |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -82,6 +82,8 @@ pub enum ErrorCode { | |||||
MissingTargetAccount, | ||||||
#[msg("The slash ratio should be between 0 and 1")] // 6038 | ||||||
InvalidSlashRatio, | ||||||
#[msg("Other")] //6039 | ||||||
#[msg("The target account is not allowed for this operation")] // 6039 | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||||||
UnexpectedTargetAccount, | ||||||
#[msg("Other")] //6040 | ||||||
Other, | ||||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -189,6 +189,10 @@ pub mod staking { | |
} | ||
|
||
if let TargetWithParameters::IntegrityPool { .. } = target_with_parameters { | ||
require!( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. need to update There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
maybe_target_account.is_none(), | ||
ErrorCode::UnexpectedTargetAccount | ||
); | ||
require!( | ||
ctx.accounts | ||
.pool_authority | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this test is duplicated below
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the name was wrong, it is actually testing close position. Fixed.