Stake pool: adding pool balance confirmation (Redo of #960) (#1116)
* Added validator stake account list storage, deprecated old tests
* Added join and leave stake pool instructions, error messages refactoring
* Stake pool tests refactoring, tests for join and leave pool added
* Added validator stake account creation instruction, join/leave pool instructions renamed, version field added
* Formatting fixes
* Added update list/pool instructions (no tests yet), updated deposit instruction logic, claim instruction removed, refactoring
* Updated deposit logic and tests, updated withdraw logic and added tests, refactoring
* Stake pool CLI updated to work with new deposit/withdraw instructions, claim usage removed
* Added validator stake account management and balance update commands to the stake pool CLI, updated dependency versions, updated devnet program address
* Merge conflicts fixed
* Removed deprecated tests
* Fixes for review comments
* Additional program id checks across the code
* Formatting errors fixed
* Changed minimum stake balance in CLI, removed deprecated tests, removed check for stake history id
* Added TODO for stake account warmup status check
* Cargo.lock conflict fix
* Formatting fixed
* Update Cargo lock file for CI
* Pin themis version of subtle
Co-authored-by: Yuriy Savchenko <yuriy.savchenko@gmail.com>
2021-01-21 05:48:46 -08:00
|
|
|
#![cfg(feature = "test-bpf")]
|
|
|
|
|
|
|
|
mod helpers;
|
|
|
|
|
|
|
|
use crate::solana_program::pubkey::Pubkey;
|
|
|
|
use helpers::*;
|
|
|
|
|
|
|
|
use bincode::deserialize;
|
2021-03-15 22:38:47 -07:00
|
|
|
use solana_program_test::*;
|
2021-01-27 14:35:25 -08:00
|
|
|
use solana_sdk::{
|
|
|
|
instruction::InstructionError,
|
|
|
|
signature::{Keypair, Signer},
|
|
|
|
transaction::Transaction,
|
|
|
|
transaction::TransactionError,
|
|
|
|
transport::TransportError,
|
|
|
|
};
|
Stake pool: adding pool balance confirmation (Redo of #960) (#1116)
* Added validator stake account list storage, deprecated old tests
* Added join and leave stake pool instructions, error messages refactoring
* Stake pool tests refactoring, tests for join and leave pool added
* Added validator stake account creation instruction, join/leave pool instructions renamed, version field added
* Formatting fixes
* Added update list/pool instructions (no tests yet), updated deposit instruction logic, claim instruction removed, refactoring
* Updated deposit logic and tests, updated withdraw logic and added tests, refactoring
* Stake pool CLI updated to work with new deposit/withdraw instructions, claim usage removed
* Added validator stake account management and balance update commands to the stake pool CLI, updated dependency versions, updated devnet program address
* Merge conflicts fixed
* Removed deprecated tests
* Fixes for review comments
* Additional program id checks across the code
* Formatting errors fixed
* Changed minimum stake balance in CLI, removed deprecated tests, removed check for stake history id
* Added TODO for stake account warmup status check
* Cargo.lock conflict fix
* Formatting fixed
* Update Cargo lock file for CI
* Pin themis version of subtle
Co-authored-by: Yuriy Savchenko <yuriy.savchenko@gmail.com>
2021-01-21 05:48:46 -08:00
|
|
|
use spl_stake_pool::*;
|
|
|
|
|
|
|
|
#[tokio::test]
|
|
|
|
async fn test_create_validator_stake_account() {
|
|
|
|
let (mut banks_client, payer, recent_blockhash) = program_test().start().await;
|
|
|
|
let stake_pool_accounts = StakePoolAccounts::new();
|
|
|
|
stake_pool_accounts
|
|
|
|
.initialize_stake_pool(&mut banks_client, &payer, &recent_blockhash)
|
2021-01-27 14:35:25 -08:00
|
|
|
.await
|
|
|
|
.unwrap();
|
Stake pool: adding pool balance confirmation (Redo of #960) (#1116)
* Added validator stake account list storage, deprecated old tests
* Added join and leave stake pool instructions, error messages refactoring
* Stake pool tests refactoring, tests for join and leave pool added
* Added validator stake account creation instruction, join/leave pool instructions renamed, version field added
* Formatting fixes
* Added update list/pool instructions (no tests yet), updated deposit instruction logic, claim instruction removed, refactoring
* Updated deposit logic and tests, updated withdraw logic and added tests, refactoring
* Stake pool CLI updated to work with new deposit/withdraw instructions, claim usage removed
* Added validator stake account management and balance update commands to the stake pool CLI, updated dependency versions, updated devnet program address
* Merge conflicts fixed
* Removed deprecated tests
* Fixes for review comments
* Additional program id checks across the code
* Formatting errors fixed
* Changed minimum stake balance in CLI, removed deprecated tests, removed check for stake history id
* Added TODO for stake account warmup status check
* Cargo.lock conflict fix
* Formatting fixed
* Update Cargo lock file for CI
* Pin themis version of subtle
Co-authored-by: Yuriy Savchenko <yuriy.savchenko@gmail.com>
2021-01-21 05:48:46 -08:00
|
|
|
|
|
|
|
let validator = Pubkey::new_unique();
|
|
|
|
let user_stake_authority = Keypair::new();
|
|
|
|
let user_withdraw_authority = Keypair::new();
|
|
|
|
|
|
|
|
let (stake_account, _) = processor::Processor::find_stake_address_for_validator(
|
|
|
|
&id(),
|
|
|
|
&validator,
|
|
|
|
&stake_pool_accounts.stake_pool.pubkey(),
|
|
|
|
);
|
|
|
|
|
|
|
|
let mut transaction = Transaction::new_with_payer(
|
|
|
|
&[instruction::create_validator_stake_account(
|
|
|
|
&id(),
|
|
|
|
&stake_pool_accounts.stake_pool.pubkey(),
|
|
|
|
&payer.pubkey(),
|
|
|
|
&stake_account,
|
|
|
|
&validator,
|
|
|
|
&user_stake_authority.pubkey(),
|
|
|
|
&user_withdraw_authority.pubkey(),
|
|
|
|
&solana_program::system_program::id(),
|
|
|
|
&stake::id(),
|
|
|
|
)
|
|
|
|
.unwrap()],
|
|
|
|
Some(&payer.pubkey()),
|
|
|
|
);
|
|
|
|
transaction.sign(&[&payer], recent_blockhash);
|
|
|
|
banks_client.process_transaction(transaction).await.unwrap();
|
|
|
|
|
|
|
|
// Check authorities
|
|
|
|
let stake = get_account(&mut banks_client, &stake_account).await;
|
|
|
|
let stake_state = deserialize::<stake::StakeState>(&stake.data).unwrap();
|
|
|
|
match stake_state {
|
|
|
|
stake::StakeState::Initialized(meta) => {
|
|
|
|
assert_eq!(&meta.authorized.staker, &user_stake_authority.pubkey());
|
|
|
|
assert_eq!(
|
|
|
|
&meta.authorized.withdrawer,
|
|
|
|
&user_withdraw_authority.pubkey()
|
|
|
|
);
|
|
|
|
}
|
|
|
|
_ => panic!(),
|
|
|
|
}
|
|
|
|
}
|
2021-01-27 14:35:25 -08:00
|
|
|
|
|
|
|
#[tokio::test]
|
|
|
|
async fn test_create_validator_stake_account_with_incorrect_address() {
|
|
|
|
let (mut banks_client, payer, recent_blockhash) = program_test().start().await;
|
|
|
|
let stake_pool_accounts = StakePoolAccounts::new();
|
|
|
|
stake_pool_accounts
|
|
|
|
.initialize_stake_pool(&mut banks_client, &payer, &recent_blockhash)
|
|
|
|
.await
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
let validator = Pubkey::new_unique();
|
|
|
|
let user_stake_authority = Keypair::new();
|
|
|
|
let user_withdraw_authority = Keypair::new();
|
|
|
|
let stake_account = Keypair::new();
|
|
|
|
|
|
|
|
let mut transaction = Transaction::new_with_payer(
|
|
|
|
&[instruction::create_validator_stake_account(
|
|
|
|
&id(),
|
|
|
|
&stake_pool_accounts.stake_pool.pubkey(),
|
|
|
|
&payer.pubkey(),
|
|
|
|
&stake_account.pubkey(),
|
|
|
|
&validator,
|
|
|
|
&user_stake_authority.pubkey(),
|
|
|
|
&user_withdraw_authority.pubkey(),
|
|
|
|
&solana_program::system_program::id(),
|
|
|
|
&stake::id(),
|
|
|
|
)
|
|
|
|
.unwrap()],
|
|
|
|
Some(&payer.pubkey()),
|
|
|
|
);
|
|
|
|
transaction.sign(&[&payer], recent_blockhash);
|
|
|
|
let transaction_error = banks_client
|
|
|
|
.process_transaction(transaction)
|
|
|
|
.await
|
|
|
|
.err()
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
match transaction_error {
|
|
|
|
TransportError::TransactionError(TransactionError::InstructionError(
|
|
|
|
_,
|
|
|
|
InstructionError::Custom(error_index),
|
|
|
|
)) => {
|
|
|
|
let program_error = error::StakePoolError::InvalidStakeAccountAddress as u32;
|
|
|
|
assert_eq!(error_index, program_error);
|
|
|
|
}
|
|
|
|
_ => panic!(
|
|
|
|
"Wrong error occurs while try to create validator stake account with incorrect address"
|
|
|
|
),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[tokio::test]
|
|
|
|
async fn test_create_validator_stake_account_with_wrong_system_program() {
|
|
|
|
let (mut banks_client, payer, recent_blockhash) = program_test().start().await;
|
|
|
|
let stake_pool_accounts = StakePoolAccounts::new();
|
|
|
|
stake_pool_accounts
|
|
|
|
.initialize_stake_pool(&mut banks_client, &payer, &recent_blockhash)
|
|
|
|
.await
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
let validator = Pubkey::new_unique();
|
|
|
|
let user_stake_authority = Keypair::new();
|
|
|
|
let user_withdraw_authority = Keypair::new();
|
|
|
|
|
|
|
|
let (stake_account, _) = processor::Processor::find_stake_address_for_validator(
|
|
|
|
&id(),
|
|
|
|
&validator,
|
|
|
|
&stake_pool_accounts.stake_pool.pubkey(),
|
|
|
|
);
|
|
|
|
|
|
|
|
let wrong_system_program = Keypair::new();
|
|
|
|
|
|
|
|
let mut transaction = Transaction::new_with_payer(
|
|
|
|
&[instruction::create_validator_stake_account(
|
|
|
|
&id(),
|
|
|
|
&stake_pool_accounts.stake_pool.pubkey(),
|
|
|
|
&payer.pubkey(),
|
|
|
|
&stake_account,
|
|
|
|
&validator,
|
|
|
|
&user_stake_authority.pubkey(),
|
|
|
|
&user_withdraw_authority.pubkey(),
|
|
|
|
&wrong_system_program.pubkey(),
|
|
|
|
&stake::id(),
|
|
|
|
)
|
|
|
|
.unwrap()],
|
|
|
|
Some(&payer.pubkey()),
|
|
|
|
);
|
|
|
|
transaction.sign(&[&payer], recent_blockhash);
|
|
|
|
let transaction_error = banks_client
|
|
|
|
.process_transaction(transaction)
|
|
|
|
.await
|
|
|
|
.err()
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
match transaction_error {
|
|
|
|
TransportError::TransactionError(TransactionError::InstructionError(_, error)) => {
|
|
|
|
assert_eq!(error, InstructionError::IncorrectProgramId);
|
|
|
|
}
|
|
|
|
_ => panic!(
|
|
|
|
"Wrong error occurs while try to create validator stake account with wrong token program ID"
|
|
|
|
),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[tokio::test]
|
|
|
|
async fn test_create_validator_stake_account_with_wrong_stake_program() {
|
|
|
|
let (mut banks_client, payer, recent_blockhash) = program_test().start().await;
|
|
|
|
let stake_pool_accounts = StakePoolAccounts::new();
|
|
|
|
stake_pool_accounts
|
|
|
|
.initialize_stake_pool(&mut banks_client, &payer, &recent_blockhash)
|
|
|
|
.await
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
let validator = Pubkey::new_unique();
|
|
|
|
let user_stake_authority = Keypair::new();
|
|
|
|
let user_withdraw_authority = Keypair::new();
|
|
|
|
|
|
|
|
let (stake_account, _) = processor::Processor::find_stake_address_for_validator(
|
|
|
|
&id(),
|
|
|
|
&validator,
|
|
|
|
&stake_pool_accounts.stake_pool.pubkey(),
|
|
|
|
);
|
|
|
|
|
|
|
|
let wrong_stake_program = Keypair::new();
|
|
|
|
|
|
|
|
let mut transaction = Transaction::new_with_payer(
|
|
|
|
&[instruction::create_validator_stake_account(
|
|
|
|
&id(),
|
|
|
|
&stake_pool_accounts.stake_pool.pubkey(),
|
|
|
|
&payer.pubkey(),
|
|
|
|
&stake_account,
|
|
|
|
&validator,
|
|
|
|
&user_stake_authority.pubkey(),
|
|
|
|
&user_withdraw_authority.pubkey(),
|
|
|
|
&solana_program::system_program::id(),
|
|
|
|
&wrong_stake_program.pubkey(),
|
|
|
|
)
|
|
|
|
.unwrap()],
|
|
|
|
Some(&payer.pubkey()),
|
|
|
|
);
|
|
|
|
transaction.sign(&[&payer], recent_blockhash);
|
|
|
|
let transaction_error = banks_client
|
|
|
|
.process_transaction(transaction)
|
|
|
|
.await
|
|
|
|
.err()
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
match transaction_error {
|
|
|
|
TransportError::TransactionError(TransactionError::InstructionError(_, error)) => {
|
|
|
|
assert_eq!(error, InstructionError::IncorrectProgramId);
|
|
|
|
}
|
|
|
|
_ => panic!(
|
|
|
|
"Wrong error occurs while try to create validator stake account with wrong stake program ID"
|
|
|
|
),
|
|
|
|
}
|
|
|
|
}
|