-
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
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,214 @@ | ||
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::{ | ||
close_position, | ||
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 | ||
); | ||
|
||
assert_anchor_program_error!( | ||
close_position( | ||
&mut svm, | ||
&payer, | ||
stake_account_positions, | ||
staking::state::positions::TargetWithParameters::IntegrityPool { | ||
publisher: publisher_keypair.pubkey(), | ||
}, | ||
None, | ||
50 * FRAC_64_MULTIPLIER, | ||
1, | ||
), | ||
ErrorCode::InvalidPoolAuthority, | ||
0 | ||
); | ||
|
||
assert_anchor_program_error!( | ||
close_position( | ||
&mut svm, | ||
&payer, | ||
stake_account_positions, | ||
staking::state::positions::TargetWithParameters::IntegrityPool { | ||
publisher: publisher_keypair.pubkey(), | ||
}, | ||
Some(&Keypair::new()), | ||
50 * FRAC_64_MULTIPLIER, | ||
1, | ||
), | ||
ErrorCode::InvalidPoolAuthority, | ||
0 | ||
); | ||
|
||
let close_position_data = staking::instruction::ClosePosition { | ||
target_with_parameters: staking::state::positions::TargetWithParameters::IntegrityPool { | ||
publisher: publisher_keypair.pubkey(), | ||
}, | ||
amount: 10 * FRAC_64_MULTIPLIER, | ||
index: 1, | ||
}; | ||
|
||
let close_position_accs = staking::accounts::ClosePosition { | ||
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 close_position_ix = Instruction::new_with_bytes( | ||
staking::ID, | ||
&close_position_data.data(), | ||
close_position_accs.to_account_metas(None), | ||
); | ||
|
||
let close_position_tx = Transaction::new_signed_with_payer( | ||
&[close_position_ix], | ||
Some(&payer.pubkey()), | ||
&[&payer, &pool_authority], | ||
svm.latest_blockhash(), | ||
); | ||
|
||
assert_anchor_program_error!( | ||
svm.send_transaction(close_position_tx), | ||
ErrorCode::UnexpectedTargetAccount, | ||
0 | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
@@ -299,6 +303,10 @@ pub mod staking { | |
} | ||
|
||
if let TargetWithParameters::IntegrityPool { .. } = target_with_parameters { | ||
require!( | ||
maybe_target_account.is_none(), | ||
ErrorCode::UnexpectedTargetAccount | ||
); | ||
require!( | ||
ctx.accounts | ||
.pool_authority | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.