2019-08-15 14:35:48 -07:00
|
|
|
use crate::{
|
|
|
|
config, id,
|
2019-09-26 13:29:29 -07:00
|
|
|
stake_state::{Authorized, Lockup, StakeAccount, StakeAuthorize, StakeState},
|
2019-08-15 14:35:48 -07:00
|
|
|
};
|
2019-04-01 16:45:53 -07:00
|
|
|
use log::*;
|
2019-09-09 18:17:32 -07:00
|
|
|
use num_derive::{FromPrimitive, ToPrimitive};
|
2019-04-01 16:45:53 -07:00
|
|
|
use serde_derive::{Deserialize, Serialize};
|
2019-08-12 20:59:57 -07:00
|
|
|
use solana_sdk::{
|
2019-10-14 15:02:24 -07:00
|
|
|
account::{get_signers, KeyedAccount},
|
2019-08-12 20:59:57 -07:00
|
|
|
instruction::{AccountMeta, Instruction, InstructionError},
|
2019-10-23 19:56:07 -07:00
|
|
|
instruction_processor_utils::{limited_deserialize, next_keyed_account, DecodeError},
|
2019-08-12 20:59:57 -07:00
|
|
|
pubkey::Pubkey,
|
2019-11-04 12:31:24 -08:00
|
|
|
system_instruction,
|
|
|
|
sysvar::{
|
|
|
|
self, clock::Clock, rent::Rent, rewards::Rewards, stake_history::StakeHistory, Sysvar,
|
|
|
|
},
|
2019-08-12 20:59:57 -07:00
|
|
|
};
|
2019-04-01 16:45:53 -07:00
|
|
|
|
2019-09-09 18:17:32 -07:00
|
|
|
/// Reasons the stake might have had an error
|
|
|
|
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, FromPrimitive, ToPrimitive)]
|
|
|
|
pub enum StakeError {
|
|
|
|
NoCreditsToRedeem,
|
2019-09-16 17:47:42 -07:00
|
|
|
LockupInForce,
|
2019-10-15 12:50:31 -07:00
|
|
|
AlreadyDeactivated,
|
2019-10-29 14:42:45 -07:00
|
|
|
TooSoonToRedelegate,
|
2019-10-31 11:07:27 -07:00
|
|
|
InsufficientStake,
|
2019-09-09 18:17:32 -07:00
|
|
|
}
|
|
|
|
impl<E> DecodeError<E> for StakeError {
|
|
|
|
fn type_of() -> &'static str {
|
|
|
|
"StakeError"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
impl std::fmt::Display for StakeError {
|
|
|
|
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
|
|
|
match self {
|
|
|
|
StakeError::NoCreditsToRedeem => write!(f, "not enough credits to redeem"),
|
2019-09-16 17:47:42 -07:00
|
|
|
StakeError::LockupInForce => write!(f, "lockup has not yet expired"),
|
2019-10-15 12:50:31 -07:00
|
|
|
StakeError::AlreadyDeactivated => write!(f, "stake already deactivated"),
|
2019-10-31 11:07:27 -07:00
|
|
|
StakeError::TooSoonToRedelegate => write!(f, "one re-delegation permitted per epoch"),
|
|
|
|
StakeError::InsufficientStake => write!(f, "split amount is more than is staked"),
|
2019-09-09 18:17:32 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
impl std::error::Error for StakeError {}
|
|
|
|
|
2019-09-26 13:29:29 -07:00
|
|
|
#[derive(Serialize, Deserialize, Debug, PartialEq, Clone)]
|
2019-04-01 16:45:53 -07:00
|
|
|
pub enum StakeInstruction {
|
2019-09-26 13:29:29 -07:00
|
|
|
/// `Initialize` a stake with Lockup and Authorized information
|
2019-09-04 13:34:09 -07:00
|
|
|
///
|
2019-10-31 11:07:27 -07:00
|
|
|
/// Expects 2 Accounts:
|
2019-09-26 13:29:29 -07:00
|
|
|
/// 0 - Uninitialized StakeAccount
|
2019-10-31 11:07:27 -07:00
|
|
|
/// 1 - Rent sysvar
|
2019-09-04 13:34:09 -07:00
|
|
|
///
|
2019-09-26 13:29:29 -07:00
|
|
|
/// Authorized carries pubkeys that must sign staker transactions
|
|
|
|
/// and withdrawer transactions.
|
|
|
|
/// Lockup carries information about withdrawal restrictions
|
2019-09-04 13:34:09 -07:00
|
|
|
///
|
2019-09-26 13:29:29 -07:00
|
|
|
Initialize(Authorized, Lockup),
|
2019-09-16 17:47:42 -07:00
|
|
|
|
2019-09-26 13:29:29 -07:00
|
|
|
/// Authorize a key to manage stake or withdrawal
|
|
|
|
/// requires Authorized::staker or Authorized::withdrawer
|
|
|
|
/// signature, depending on which key's being updated
|
2019-09-12 19:03:28 -07:00
|
|
|
///
|
|
|
|
/// Expects 1 Account:
|
2019-09-26 13:29:29 -07:00
|
|
|
/// 0 - StakeAccount to be updated with the Pubkey for
|
|
|
|
/// authorization
|
|
|
|
Authorize(Pubkey, StakeAuthorize),
|
|
|
|
|
2019-09-11 09:48:29 -07:00
|
|
|
/// `Delegate` a stake to a particular vote account
|
2019-09-26 13:29:29 -07:00
|
|
|
/// requires Authorized::staker signature
|
2019-05-21 07:32:38 -07:00
|
|
|
///
|
2019-09-11 09:48:29 -07:00
|
|
|
/// Expects 4 Accounts:
|
2019-09-26 13:29:29 -07:00
|
|
|
/// 0 - Initialized StakeAccount to be delegated
|
2019-06-10 12:17:29 -07:00
|
|
|
/// 1 - VoteAccount to which this Stake will be delegated
|
2019-07-12 16:38:15 -07:00
|
|
|
/// 2 - Clock sysvar Account that carries clock bank epoch
|
2019-08-15 14:35:48 -07:00
|
|
|
/// 3 - Config Account that carries stake config
|
2019-06-10 12:17:29 -07:00
|
|
|
///
|
2019-09-11 09:48:29 -07:00
|
|
|
/// The entire balance of the staking account is staked. DelegateStake
|
|
|
|
/// can be called multiple times, but re-delegation is delayed
|
|
|
|
/// by one epoch
|
2019-06-10 12:17:29 -07:00
|
|
|
///
|
2019-09-11 09:48:29 -07:00
|
|
|
DelegateStake,
|
2019-04-01 16:45:53 -07:00
|
|
|
|
|
|
|
/// Redeem credits in the stake account
|
2019-09-26 13:29:29 -07:00
|
|
|
/// requires Authorized::staker signature
|
2019-05-21 07:32:38 -07:00
|
|
|
///
|
2019-09-11 09:48:29 -07:00
|
|
|
/// Expects 5 Accounts:
|
2019-09-26 13:29:29 -07:00
|
|
|
/// 0 - StakeAccount to be updated with rewards
|
2019-06-21 20:43:24 -07:00
|
|
|
/// 1 - VoteAccount to which the Stake is delegated,
|
|
|
|
/// 2 - RewardsPool Stake Account from which to redeem credits
|
2019-07-12 16:38:15 -07:00
|
|
|
/// 3 - Rewards sysvar Account that carries points values
|
2019-08-12 20:59:57 -07:00
|
|
|
/// 4 - StakeHistory sysvar that carries stake warmup/cooldown history
|
2019-10-31 11:07:27 -07:00
|
|
|
///
|
2019-04-01 16:45:53 -07:00
|
|
|
RedeemVoteCredits,
|
2019-06-21 22:28:34 -07:00
|
|
|
|
2019-10-31 11:07:27 -07:00
|
|
|
/// Split u64 tokens and stake off a stake account into another stake
|
|
|
|
/// account. Requires Authorized::staker signature.
|
|
|
|
///
|
|
|
|
/// The split-off stake account must be Initialized and carry the
|
|
|
|
/// the same values for Lockup and Authorized as the source
|
|
|
|
/// or this instruction will fail.
|
|
|
|
///
|
|
|
|
/// The source stake must be either Initialized or a Stake.
|
|
|
|
///
|
|
|
|
/// Expects 2 Accounts:
|
|
|
|
/// 0 - StakeAccount to be split
|
|
|
|
/// 1 - Initialized StakeAcount that will take the split-off amount
|
|
|
|
///
|
|
|
|
Split(u64),
|
|
|
|
|
2019-06-21 22:28:34 -07:00
|
|
|
/// Withdraw unstaked lamports from the stake account
|
2019-09-26 13:29:29 -07:00
|
|
|
/// requires Authorized::withdrawer signature
|
2019-06-21 22:28:34 -07:00
|
|
|
///
|
2019-09-11 09:48:29 -07:00
|
|
|
/// Expects 4 Accounts:
|
2019-09-26 13:29:29 -07:00
|
|
|
/// 0 - StakeAccount from which to withdraw
|
2019-06-21 22:28:34 -07:00
|
|
|
/// 1 - System account to which the lamports will be transferred,
|
|
|
|
/// 2 - Syscall Account that carries epoch
|
2019-08-12 20:59:57 -07:00
|
|
|
/// 3 - StakeHistory sysvar that carries stake warmup/cooldown history
|
2019-06-21 22:28:34 -07:00
|
|
|
///
|
|
|
|
/// The u64 is the portion of the Stake account balance to be withdrawn,
|
2019-09-26 13:29:29 -07:00
|
|
|
/// must be <= StakeAccount.lamports - staked lamports.
|
2019-06-21 22:28:34 -07:00
|
|
|
Withdraw(u64),
|
2019-06-21 23:45:03 -07:00
|
|
|
|
|
|
|
/// Deactivates the stake in the account
|
2019-09-26 13:29:29 -07:00
|
|
|
/// requires Authorized::staker signature
|
2019-06-21 23:45:03 -07:00
|
|
|
///
|
2019-10-07 15:07:01 -07:00
|
|
|
/// Expects 2 Accounts:
|
2019-09-26 13:29:29 -07:00
|
|
|
/// 0 - Delegate StakeAccount
|
2019-10-07 15:07:01 -07:00
|
|
|
/// 1 - Syscall Account that carries epoch
|
2019-09-11 09:48:29 -07:00
|
|
|
///
|
2019-06-21 23:45:03 -07:00
|
|
|
Deactivate,
|
2019-04-01 16:45:53 -07:00
|
|
|
}
|
|
|
|
|
2019-10-31 11:07:27 -07:00
|
|
|
pub fn initialize(stake_pubkey: &Pubkey, authorized: &Authorized, lockup: &Lockup) -> Instruction {
|
|
|
|
Instruction::new(
|
|
|
|
id(),
|
|
|
|
&StakeInstruction::Initialize(*authorized, *lockup),
|
|
|
|
vec![
|
|
|
|
AccountMeta::new(*stake_pubkey, false),
|
2019-11-05 08:38:35 -08:00
|
|
|
AccountMeta::new_readonly(sysvar::rent::id(), false),
|
2019-10-31 11:07:27 -07:00
|
|
|
],
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2019-09-04 13:34:09 -07:00
|
|
|
pub fn create_stake_account_with_lockup(
|
|
|
|
from_pubkey: &Pubkey,
|
|
|
|
stake_pubkey: &Pubkey,
|
2019-09-26 13:29:29 -07:00
|
|
|
authorized: &Authorized,
|
|
|
|
lockup: &Lockup,
|
2019-09-29 21:18:15 -07:00
|
|
|
lamports: u64,
|
2019-09-04 13:34:09 -07:00
|
|
|
) -> Vec<Instruction> {
|
|
|
|
vec![
|
2019-09-20 14:10:39 -07:00
|
|
|
system_instruction::create_account(
|
2019-09-04 13:34:09 -07:00
|
|
|
from_pubkey,
|
|
|
|
stake_pubkey,
|
|
|
|
lamports,
|
|
|
|
std::mem::size_of::<StakeState>() as u64,
|
|
|
|
&id(),
|
|
|
|
),
|
2019-10-31 11:07:27 -07:00
|
|
|
initialize(stake_pubkey, authorized, lockup),
|
|
|
|
]
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn split(
|
|
|
|
stake_pubkey: &Pubkey,
|
|
|
|
authorized_pubkey: &Pubkey,
|
|
|
|
lamports: u64,
|
|
|
|
split_stake_pubkey: &Pubkey,
|
|
|
|
) -> Vec<Instruction> {
|
|
|
|
vec![
|
|
|
|
system_instruction::create_account(
|
|
|
|
stake_pubkey,
|
|
|
|
split_stake_pubkey,
|
|
|
|
0, // creates an ephemeral, uninitialized Stake
|
|
|
|
std::mem::size_of::<StakeState>() as u64,
|
|
|
|
&id(),
|
|
|
|
),
|
2019-09-04 13:34:09 -07:00
|
|
|
Instruction::new(
|
|
|
|
id(),
|
2019-10-31 11:07:27 -07:00
|
|
|
&StakeInstruction::Split(lamports),
|
|
|
|
metas_with_signer(
|
|
|
|
&[
|
|
|
|
AccountMeta::new(*stake_pubkey, false),
|
|
|
|
AccountMeta::new(*split_stake_pubkey, false),
|
|
|
|
],
|
|
|
|
authorized_pubkey,
|
|
|
|
),
|
2019-09-04 13:34:09 -07:00
|
|
|
),
|
|
|
|
]
|
|
|
|
}
|
|
|
|
|
2019-06-10 12:17:29 -07:00
|
|
|
pub fn create_stake_account(
|
2019-05-23 23:20:04 -07:00
|
|
|
from_pubkey: &Pubkey,
|
2019-09-04 13:34:09 -07:00
|
|
|
stake_pubkey: &Pubkey,
|
2019-09-26 13:29:29 -07:00
|
|
|
authorized: &Authorized,
|
2019-09-29 21:18:15 -07:00
|
|
|
lamports: u64,
|
2019-05-21 07:32:38 -07:00
|
|
|
) -> Vec<Instruction> {
|
2019-09-26 13:29:29 -07:00
|
|
|
create_stake_account_with_lockup(
|
|
|
|
from_pubkey,
|
|
|
|
stake_pubkey,
|
|
|
|
authorized,
|
|
|
|
&Lockup::default(),
|
2019-09-29 21:18:15 -07:00
|
|
|
lamports,
|
2019-09-26 13:29:29 -07:00
|
|
|
)
|
2019-05-21 07:32:38 -07:00
|
|
|
}
|
|
|
|
|
2019-06-10 12:17:29 -07:00
|
|
|
pub fn create_stake_account_and_delegate_stake(
|
|
|
|
from_pubkey: &Pubkey,
|
2019-09-04 13:34:09 -07:00
|
|
|
stake_pubkey: &Pubkey,
|
2019-06-10 12:17:29 -07:00
|
|
|
vote_pubkey: &Pubkey,
|
2019-09-26 13:29:29 -07:00
|
|
|
authorized: &Authorized,
|
2019-09-29 21:18:15 -07:00
|
|
|
lamports: u64,
|
2019-06-10 12:17:29 -07:00
|
|
|
) -> Vec<Instruction> {
|
2019-09-29 21:18:15 -07:00
|
|
|
let mut instructions = create_stake_account(from_pubkey, stake_pubkey, authorized, lamports);
|
|
|
|
instructions.push(delegate_stake(
|
|
|
|
stake_pubkey,
|
|
|
|
&authorized.staker,
|
|
|
|
vote_pubkey,
|
|
|
|
));
|
2019-06-10 12:17:29 -07:00
|
|
|
instructions
|
|
|
|
}
|
|
|
|
|
2019-10-14 15:02:24 -07:00
|
|
|
// for instructions whose authorized signer may already be in account parameters
|
|
|
|
fn metas_with_signer(
|
|
|
|
metas: &[AccountMeta], // parameter metas, in order
|
|
|
|
signer: &Pubkey, // might already appear in parameters
|
2019-09-12 19:03:28 -07:00
|
|
|
) -> Vec<AccountMeta> {
|
2019-10-14 15:02:24 -07:00
|
|
|
let mut metas = metas.to_vec();
|
2019-09-12 19:03:28 -07:00
|
|
|
|
2019-10-14 15:02:24 -07:00
|
|
|
for meta in metas.iter_mut() {
|
|
|
|
if &meta.pubkey == signer {
|
|
|
|
meta.is_signer = true; // found it, we're done
|
|
|
|
return metas;
|
|
|
|
}
|
2019-09-12 19:03:28 -07:00
|
|
|
}
|
|
|
|
|
2019-10-14 15:02:24 -07:00
|
|
|
// signer wasn't in metas, append it after normal parameters
|
2019-11-05 08:38:35 -08:00
|
|
|
metas.push(AccountMeta::new_readonly(*signer, true));
|
2019-09-12 19:03:28 -07:00
|
|
|
|
2019-10-14 15:02:24 -07:00
|
|
|
metas
|
2019-09-12 19:03:28 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn authorize(
|
|
|
|
stake_pubkey: &Pubkey,
|
|
|
|
authorized_pubkey: &Pubkey,
|
|
|
|
new_authorized_pubkey: &Pubkey,
|
2019-09-26 13:29:29 -07:00
|
|
|
stake_authorize: StakeAuthorize,
|
2019-09-12 19:03:28 -07:00
|
|
|
) -> Instruction {
|
2019-10-14 15:02:24 -07:00
|
|
|
let account_metas =
|
|
|
|
metas_with_signer(&[AccountMeta::new(*stake_pubkey, false)], authorized_pubkey);
|
2019-09-12 19:03:28 -07:00
|
|
|
|
|
|
|
Instruction::new(
|
|
|
|
id(),
|
2019-09-26 13:29:29 -07:00
|
|
|
&StakeInstruction::Authorize(*new_authorized_pubkey, stake_authorize),
|
2019-09-12 19:03:28 -07:00
|
|
|
account_metas,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2019-06-21 20:43:24 -07:00
|
|
|
pub fn redeem_vote_credits(stake_pubkey: &Pubkey, vote_pubkey: &Pubkey) -> Instruction {
|
2019-04-03 08:45:57 -07:00
|
|
|
let account_metas = vec![
|
2019-05-23 23:20:04 -07:00
|
|
|
AccountMeta::new(*stake_pubkey, false),
|
2019-11-05 08:38:35 -08:00
|
|
|
AccountMeta::new(*vote_pubkey, false),
|
2019-06-21 20:43:24 -07:00
|
|
|
AccountMeta::new(crate::rewards_pools::random_id(), false),
|
2019-11-05 08:38:35 -08:00
|
|
|
AccountMeta::new_readonly(sysvar::rewards::id(), false),
|
|
|
|
AccountMeta::new_readonly(sysvar::stake_history::id(), false),
|
2019-04-03 08:45:57 -07:00
|
|
|
];
|
|
|
|
Instruction::new(id(), &StakeInstruction::RedeemVoteCredits, account_metas)
|
|
|
|
}
|
2019-04-01 16:45:53 -07:00
|
|
|
|
2019-09-29 21:18:15 -07:00
|
|
|
pub fn delegate_stake(
|
|
|
|
stake_pubkey: &Pubkey,
|
|
|
|
authorized_pubkey: &Pubkey,
|
|
|
|
vote_pubkey: &Pubkey,
|
|
|
|
) -> Instruction {
|
2019-10-14 15:02:24 -07:00
|
|
|
let account_metas = metas_with_signer(
|
2019-09-29 21:18:15 -07:00
|
|
|
&[
|
2019-10-14 15:02:24 -07:00
|
|
|
AccountMeta::new(*stake_pubkey, false),
|
2019-11-05 08:38:35 -08:00
|
|
|
AccountMeta::new_readonly(*vote_pubkey, false),
|
|
|
|
AccountMeta::new_readonly(sysvar::clock::id(), false),
|
|
|
|
AccountMeta::new_readonly(crate::config::id(), false),
|
2019-09-29 21:18:15 -07:00
|
|
|
],
|
2019-10-14 15:02:24 -07:00
|
|
|
authorized_pubkey,
|
2019-09-29 21:18:15 -07:00
|
|
|
);
|
2019-09-11 09:48:29 -07:00
|
|
|
Instruction::new(id(), &StakeInstruction::DelegateStake, account_metas)
|
2019-04-01 16:45:53 -07:00
|
|
|
}
|
|
|
|
|
2019-09-29 21:18:15 -07:00
|
|
|
pub fn withdraw(
|
|
|
|
stake_pubkey: &Pubkey,
|
|
|
|
authorized_pubkey: &Pubkey,
|
|
|
|
to_pubkey: &Pubkey,
|
|
|
|
lamports: u64,
|
|
|
|
) -> Instruction {
|
2019-10-14 15:02:24 -07:00
|
|
|
let account_metas = metas_with_signer(
|
|
|
|
&[
|
|
|
|
AccountMeta::new(*stake_pubkey, false),
|
2019-11-05 08:38:35 -08:00
|
|
|
AccountMeta::new(*to_pubkey, false),
|
|
|
|
AccountMeta::new_readonly(sysvar::clock::id(), false),
|
|
|
|
AccountMeta::new_readonly(sysvar::stake_history::id(), false),
|
2019-10-14 15:02:24 -07:00
|
|
|
],
|
|
|
|
authorized_pubkey,
|
|
|
|
);
|
2019-06-21 22:28:34 -07:00
|
|
|
Instruction::new(id(), &StakeInstruction::Withdraw(lamports), account_metas)
|
|
|
|
}
|
|
|
|
|
2019-10-07 15:07:01 -07:00
|
|
|
pub fn deactivate_stake(stake_pubkey: &Pubkey, authorized_pubkey: &Pubkey) -> Instruction {
|
2019-10-14 15:02:24 -07:00
|
|
|
let account_metas = metas_with_signer(
|
|
|
|
&[
|
|
|
|
AccountMeta::new(*stake_pubkey, false),
|
2019-11-05 08:38:35 -08:00
|
|
|
AccountMeta::new_readonly(sysvar::clock::id(), false),
|
2019-10-14 15:02:24 -07:00
|
|
|
],
|
2019-09-29 21:18:15 -07:00
|
|
|
authorized_pubkey,
|
|
|
|
);
|
2019-06-21 23:45:03 -07:00
|
|
|
Instruction::new(id(), &StakeInstruction::Deactivate, account_metas)
|
|
|
|
}
|
|
|
|
|
2019-04-01 16:45:53 -07:00
|
|
|
pub fn process_instruction(
|
|
|
|
_program_id: &Pubkey,
|
|
|
|
keyed_accounts: &mut [KeyedAccount],
|
|
|
|
data: &[u8],
|
|
|
|
) -> Result<(), InstructionError> {
|
|
|
|
solana_logger::setup();
|
|
|
|
|
|
|
|
trace!("process_instruction: {:?}", data);
|
|
|
|
trace!("keyed_accounts: {:?}", keyed_accounts);
|
|
|
|
|
2019-10-14 15:02:24 -07:00
|
|
|
let signers = get_signers(keyed_accounts);
|
2019-04-01 16:45:53 -07:00
|
|
|
|
2019-10-14 15:02:24 -07:00
|
|
|
let keyed_accounts = &mut keyed_accounts.iter_mut();
|
|
|
|
let me = &mut next_keyed_account(keyed_accounts)?;
|
2019-04-01 16:45:53 -07:00
|
|
|
|
2019-10-23 19:56:07 -07:00
|
|
|
match limited_deserialize(data)? {
|
2019-10-31 11:07:27 -07:00
|
|
|
StakeInstruction::Initialize(authorized, lockup) => me.initialize(
|
|
|
|
&authorized,
|
|
|
|
&lockup,
|
2019-11-04 12:31:24 -08:00
|
|
|
&Rent::from_keyed_account(next_keyed_account(keyed_accounts)?)?,
|
2019-10-31 11:07:27 -07:00
|
|
|
),
|
2019-09-26 13:29:29 -07:00
|
|
|
StakeInstruction::Authorize(authorized_pubkey, stake_authorize) => {
|
2019-10-14 15:02:24 -07:00
|
|
|
me.authorize(&authorized_pubkey, stake_authorize, &signers)
|
2019-09-26 13:29:29 -07:00
|
|
|
}
|
2019-09-11 09:48:29 -07:00
|
|
|
StakeInstruction::DelegateStake => {
|
2019-10-14 15:02:24 -07:00
|
|
|
let vote = next_keyed_account(keyed_accounts)?;
|
2019-06-17 19:34:21 -07:00
|
|
|
|
2019-08-15 14:35:48 -07:00
|
|
|
me.delegate_stake(
|
2019-10-14 15:02:24 -07:00
|
|
|
&vote,
|
2019-11-04 12:31:24 -08:00
|
|
|
&Clock::from_keyed_account(next_keyed_account(keyed_accounts)?)?,
|
2019-10-14 15:02:24 -07:00
|
|
|
&config::from_keyed_account(next_keyed_account(keyed_accounts)?)?,
|
|
|
|
&signers,
|
2019-08-15 14:35:48 -07:00
|
|
|
)
|
2019-04-01 16:45:53 -07:00
|
|
|
}
|
|
|
|
StakeInstruction::RedeemVoteCredits => {
|
2019-10-14 15:02:24 -07:00
|
|
|
let vote = &mut next_keyed_account(keyed_accounts)?;
|
|
|
|
let rewards_pool = &mut next_keyed_account(keyed_accounts)?;
|
2019-06-21 20:43:24 -07:00
|
|
|
|
|
|
|
me.redeem_vote_credits(
|
|
|
|
vote,
|
|
|
|
rewards_pool,
|
2019-11-04 12:31:24 -08:00
|
|
|
&Rewards::from_keyed_account(next_keyed_account(keyed_accounts)?)?,
|
|
|
|
&StakeHistory::from_keyed_account(next_keyed_account(keyed_accounts)?)?,
|
2019-06-21 20:43:24 -07:00
|
|
|
)
|
2019-04-01 16:45:53 -07:00
|
|
|
}
|
2019-10-31 11:07:27 -07:00
|
|
|
StakeInstruction::Split(lamports) => {
|
|
|
|
let split_stake = &mut next_keyed_account(keyed_accounts)?;
|
|
|
|
me.split(lamports, split_stake, &signers)
|
|
|
|
}
|
|
|
|
|
2019-06-21 22:28:34 -07:00
|
|
|
StakeInstruction::Withdraw(lamports) => {
|
2019-10-14 15:02:24 -07:00
|
|
|
let to = &mut next_keyed_account(keyed_accounts)?;
|
2019-06-21 22:28:34 -07:00
|
|
|
me.withdraw(
|
|
|
|
lamports,
|
2019-10-14 15:02:24 -07:00
|
|
|
to,
|
2019-11-04 12:31:24 -08:00
|
|
|
&Clock::from_keyed_account(next_keyed_account(keyed_accounts)?)?,
|
|
|
|
&StakeHistory::from_keyed_account(next_keyed_account(keyed_accounts)?)?,
|
2019-10-14 15:02:24 -07:00
|
|
|
&signers,
|
2019-06-21 22:28:34 -07:00
|
|
|
)
|
|
|
|
}
|
2019-10-14 15:02:24 -07:00
|
|
|
StakeInstruction::Deactivate => me.deactivate_stake(
|
2019-11-04 12:31:24 -08:00
|
|
|
&Clock::from_keyed_account(next_keyed_account(keyed_accounts)?)?,
|
2019-10-14 15:02:24 -07:00
|
|
|
&signers,
|
|
|
|
),
|
2019-04-01 16:45:53 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
mod tests {
|
|
|
|
use super::*;
|
|
|
|
use bincode::serialize;
|
2019-10-30 16:25:12 -07:00
|
|
|
use solana_sdk::{account::Account, rent::Rent, sysvar::stake_history::StakeHistory};
|
2019-04-01 16:45:53 -07:00
|
|
|
|
2019-05-07 17:08:49 -07:00
|
|
|
fn process_instruction(instruction: &Instruction) -> Result<(), InstructionError> {
|
2019-06-17 19:34:21 -07:00
|
|
|
let mut accounts: Vec<_> = instruction
|
|
|
|
.accounts
|
|
|
|
.iter()
|
|
|
|
.map(|meta| {
|
2019-07-12 16:38:15 -07:00
|
|
|
if sysvar::clock::check_id(&meta.pubkey) {
|
2019-11-04 12:31:24 -08:00
|
|
|
sysvar::clock::create_account(1, 0, 0, 0, 0)
|
2019-07-12 16:38:15 -07:00
|
|
|
} else if sysvar::rewards::check_id(&meta.pubkey) {
|
|
|
|
sysvar::rewards::create_account(1, 0.0, 0.0)
|
2019-08-12 20:59:57 -07:00
|
|
|
} else if sysvar::stake_history::check_id(&meta.pubkey) {
|
|
|
|
sysvar::stake_history::create_account(1, &StakeHistory::default())
|
2019-08-15 14:35:48 -07:00
|
|
|
} else if config::check_id(&meta.pubkey) {
|
|
|
|
config::create_account(1, &config::Config::default())
|
2019-10-03 14:22:48 -07:00
|
|
|
} else if sysvar::rent::check_id(&meta.pubkey) {
|
2019-10-30 16:25:12 -07:00
|
|
|
sysvar::rent::create_account(1, &Rent::default())
|
2019-06-17 19:34:21 -07:00
|
|
|
} else {
|
|
|
|
Account::default()
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.collect();
|
|
|
|
|
2019-05-07 17:08:49 -07:00
|
|
|
{
|
|
|
|
let mut keyed_accounts: Vec<_> = instruction
|
|
|
|
.accounts
|
|
|
|
.iter()
|
|
|
|
.zip(accounts.iter_mut())
|
|
|
|
.map(|(meta, account)| KeyedAccount::new(&meta.pubkey, meta.is_signer, account))
|
|
|
|
.collect();
|
2019-05-31 15:29:21 -07:00
|
|
|
super::process_instruction(&Pubkey::default(), &mut keyed_accounts, &instruction.data)
|
2019-05-07 17:08:49 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_stake_process_instruction() {
|
2019-10-31 11:07:27 -07:00
|
|
|
assert_eq!(
|
|
|
|
process_instruction(&initialize(
|
|
|
|
&Pubkey::default(),
|
|
|
|
&Authorized::default(),
|
|
|
|
&Lockup::default()
|
|
|
|
)),
|
|
|
|
Err(InstructionError::InvalidAccountData),
|
|
|
|
);
|
2019-05-07 17:08:49 -07:00
|
|
|
assert_eq!(
|
2019-08-12 20:59:57 -07:00
|
|
|
process_instruction(&redeem_vote_credits(&Pubkey::default(), &Pubkey::default())),
|
2019-05-07 17:08:49 -07:00
|
|
|
Err(InstructionError::InvalidAccountData),
|
|
|
|
);
|
2019-10-31 11:07:27 -07:00
|
|
|
assert_eq!(
|
|
|
|
process_instruction(&authorize(
|
|
|
|
&Pubkey::default(),
|
|
|
|
&Pubkey::default(),
|
|
|
|
&Pubkey::default(),
|
|
|
|
StakeAuthorize::Staker
|
|
|
|
)),
|
|
|
|
Err(InstructionError::InvalidAccountData),
|
|
|
|
);
|
|
|
|
assert_eq!(
|
|
|
|
process_instruction(
|
|
|
|
&split(
|
|
|
|
&Pubkey::default(),
|
|
|
|
&Pubkey::default(),
|
|
|
|
100,
|
|
|
|
&Pubkey::default()
|
|
|
|
)[1]
|
|
|
|
),
|
|
|
|
Err(InstructionError::InvalidAccountData),
|
|
|
|
);
|
2019-05-07 17:08:49 -07:00
|
|
|
assert_eq!(
|
2019-09-29 21:18:15 -07:00
|
|
|
process_instruction(&delegate_stake(
|
|
|
|
&Pubkey::default(),
|
|
|
|
&Pubkey::default(),
|
|
|
|
&Pubkey::default()
|
|
|
|
)),
|
2019-05-07 17:08:49 -07:00
|
|
|
Err(InstructionError::InvalidAccountData),
|
|
|
|
);
|
2019-06-21 22:28:34 -07:00
|
|
|
assert_eq!(
|
2019-09-29 21:18:15 -07:00
|
|
|
process_instruction(&withdraw(
|
|
|
|
&Pubkey::default(),
|
|
|
|
&Pubkey::default(),
|
2019-10-10 14:46:38 -07:00
|
|
|
&Pubkey::new_rand(),
|
2019-09-29 21:18:15 -07:00
|
|
|
100
|
|
|
|
)),
|
2019-06-21 22:28:34 -07:00
|
|
|
Err(InstructionError::InvalidAccountData),
|
|
|
|
);
|
2019-06-21 23:45:03 -07:00
|
|
|
assert_eq!(
|
2019-10-07 15:07:01 -07:00
|
|
|
process_instruction(&deactivate_stake(&Pubkey::default(), &Pubkey::default())),
|
2019-06-21 23:45:03 -07:00
|
|
|
Err(InstructionError::InvalidAccountData),
|
|
|
|
);
|
2019-05-07 17:08:49 -07:00
|
|
|
}
|
|
|
|
|
2019-04-01 16:45:53 -07:00
|
|
|
#[test]
|
|
|
|
fn test_stake_process_instruction_decode_bail() {
|
|
|
|
// these will not call stake_state, have bogus contents
|
|
|
|
|
2019-09-11 09:48:29 -07:00
|
|
|
// gets the "is_empty()" check
|
|
|
|
assert_eq!(
|
|
|
|
super::process_instruction(
|
|
|
|
&Pubkey::default(),
|
|
|
|
&mut [],
|
2019-09-26 13:29:29 -07:00
|
|
|
&serialize(&StakeInstruction::Initialize(
|
|
|
|
Authorized::default(),
|
|
|
|
Lockup::default()
|
|
|
|
))
|
|
|
|
.unwrap(),
|
2019-09-11 09:48:29 -07:00
|
|
|
),
|
2019-10-14 15:02:24 -07:00
|
|
|
Err(InstructionError::NotEnoughAccountKeys),
|
2019-09-11 09:48:29 -07:00
|
|
|
);
|
|
|
|
|
2019-10-31 11:07:27 -07:00
|
|
|
// no account for rent
|
|
|
|
assert_eq!(
|
|
|
|
super::process_instruction(
|
|
|
|
&Pubkey::default(),
|
|
|
|
&mut [KeyedAccount::new(
|
|
|
|
&Pubkey::default(),
|
|
|
|
false,
|
|
|
|
&mut Account::default(),
|
|
|
|
)],
|
|
|
|
&serialize(&StakeInstruction::Initialize(
|
|
|
|
Authorized::default(),
|
|
|
|
Lockup::default()
|
|
|
|
))
|
|
|
|
.unwrap(),
|
|
|
|
),
|
|
|
|
Err(InstructionError::NotEnoughAccountKeys),
|
|
|
|
);
|
|
|
|
|
|
|
|
// rent fails to deserialize
|
|
|
|
assert_eq!(
|
|
|
|
super::process_instruction(
|
|
|
|
&Pubkey::default(),
|
|
|
|
&mut [
|
|
|
|
KeyedAccount::new(&Pubkey::default(), false, &mut Account::default(),),
|
|
|
|
KeyedAccount::new(&sysvar::rent::id(), false, &mut Account::default(),)
|
|
|
|
],
|
|
|
|
&serialize(&StakeInstruction::Initialize(
|
|
|
|
Authorized::default(),
|
|
|
|
Lockup::default()
|
|
|
|
))
|
|
|
|
.unwrap(),
|
|
|
|
),
|
|
|
|
Err(InstructionError::InvalidArgument),
|
|
|
|
);
|
|
|
|
|
|
|
|
// fails to deserialize stake state
|
|
|
|
assert_eq!(
|
|
|
|
super::process_instruction(
|
|
|
|
&Pubkey::default(),
|
|
|
|
&mut [
|
|
|
|
KeyedAccount::new(&Pubkey::default(), false, &mut Account::default(),),
|
|
|
|
KeyedAccount::new(
|
|
|
|
&sysvar::rent::id(),
|
|
|
|
false,
|
|
|
|
&mut sysvar::rent::create_account(0, &Rent::default())
|
|
|
|
)
|
|
|
|
],
|
|
|
|
&serialize(&StakeInstruction::Initialize(
|
|
|
|
Authorized::default(),
|
|
|
|
Lockup::default()
|
|
|
|
))
|
|
|
|
.unwrap(),
|
|
|
|
),
|
|
|
|
Err(InstructionError::InvalidAccountData),
|
|
|
|
);
|
|
|
|
|
2019-09-11 09:48:29 -07:00
|
|
|
// gets the first check in delegate, wrong number of accounts
|
2019-04-01 16:45:53 -07:00
|
|
|
assert_eq!(
|
2019-05-07 17:08:49 -07:00
|
|
|
super::process_instruction(
|
2019-04-01 16:45:53 -07:00
|
|
|
&Pubkey::default(),
|
|
|
|
&mut [KeyedAccount::new(
|
|
|
|
&Pubkey::default(),
|
|
|
|
false,
|
|
|
|
&mut Account::default(),
|
|
|
|
)],
|
2019-09-11 09:48:29 -07:00
|
|
|
&serialize(&StakeInstruction::DelegateStake).unwrap(),
|
2019-04-01 16:45:53 -07:00
|
|
|
),
|
2019-10-14 15:02:24 -07:00
|
|
|
Err(InstructionError::NotEnoughAccountKeys),
|
2019-04-01 16:45:53 -07:00
|
|
|
);
|
|
|
|
|
2019-05-07 17:08:49 -07:00
|
|
|
// gets the sub-check for number of args
|
2019-04-01 16:45:53 -07:00
|
|
|
assert_eq!(
|
2019-05-07 17:08:49 -07:00
|
|
|
super::process_instruction(
|
2019-04-01 16:45:53 -07:00
|
|
|
&Pubkey::default(),
|
2019-06-03 09:04:51 -07:00
|
|
|
&mut [KeyedAccount::new(
|
|
|
|
&Pubkey::default(),
|
|
|
|
false,
|
|
|
|
&mut Account::default()
|
|
|
|
),],
|
2019-09-11 09:48:29 -07:00
|
|
|
&serialize(&StakeInstruction::DelegateStake).unwrap(),
|
2019-04-01 16:45:53 -07:00
|
|
|
),
|
2019-10-14 15:02:24 -07:00
|
|
|
Err(InstructionError::NotEnoughAccountKeys),
|
2019-04-01 16:45:53 -07:00
|
|
|
);
|
|
|
|
|
2019-09-11 09:48:29 -07:00
|
|
|
// catches the number of args check
|
2019-04-01 16:45:53 -07:00
|
|
|
assert_eq!(
|
2019-05-07 17:08:49 -07:00
|
|
|
super::process_instruction(
|
2019-04-01 16:45:53 -07:00
|
|
|
&Pubkey::default(),
|
|
|
|
&mut [
|
|
|
|
KeyedAccount::new(&Pubkey::default(), false, &mut Account::default()),
|
|
|
|
KeyedAccount::new(&Pubkey::default(), false, &mut Account::default()),
|
|
|
|
],
|
|
|
|
&serialize(&StakeInstruction::RedeemVoteCredits).unwrap(),
|
|
|
|
),
|
2019-10-14 15:02:24 -07:00
|
|
|
Err(InstructionError::NotEnoughAccountKeys),
|
2019-04-01 16:45:53 -07:00
|
|
|
);
|
2019-05-07 17:08:49 -07:00
|
|
|
|
2019-09-11 09:48:29 -07:00
|
|
|
// catches the type of args check
|
|
|
|
assert_eq!(
|
|
|
|
super::process_instruction(
|
|
|
|
&Pubkey::default(),
|
|
|
|
&mut [
|
|
|
|
KeyedAccount::new(&Pubkey::default(), false, &mut Account::default()),
|
|
|
|
KeyedAccount::new(&Pubkey::default(), false, &mut Account::default()),
|
|
|
|
KeyedAccount::new(&Pubkey::default(), false, &mut Account::default()),
|
|
|
|
KeyedAccount::new(&Pubkey::default(), false, &mut Account::default()),
|
|
|
|
KeyedAccount::new(&Pubkey::default(), false, &mut Account::default()),
|
|
|
|
],
|
|
|
|
&serialize(&StakeInstruction::RedeemVoteCredits).unwrap(),
|
|
|
|
),
|
|
|
|
Err(InstructionError::InvalidArgument),
|
|
|
|
);
|
|
|
|
|
2019-06-17 19:34:21 -07:00
|
|
|
// gets the check non-deserialize-able account in delegate_stake
|
2019-05-07 17:08:49 -07:00
|
|
|
assert_eq!(
|
|
|
|
super::process_instruction(
|
|
|
|
&Pubkey::default(),
|
|
|
|
&mut [
|
|
|
|
KeyedAccount::new(&Pubkey::default(), true, &mut Account::default()),
|
|
|
|
KeyedAccount::new(&Pubkey::default(), false, &mut Account::default()),
|
2019-06-17 19:34:21 -07:00
|
|
|
KeyedAccount::new(
|
2019-07-12 16:38:15 -07:00
|
|
|
&sysvar::clock::id(),
|
2019-06-17 19:34:21 -07:00
|
|
|
false,
|
2019-11-04 12:31:24 -08:00
|
|
|
&mut sysvar::clock::create_account(1, 0, 0, 0, 0)
|
2019-06-17 19:34:21 -07:00
|
|
|
),
|
2019-08-15 14:35:48 -07:00
|
|
|
KeyedAccount::new(
|
|
|
|
&config::id(),
|
|
|
|
false,
|
|
|
|
&mut config::create_account(1, &config::Config::default())
|
|
|
|
),
|
2019-05-07 17:08:49 -07:00
|
|
|
],
|
2019-09-11 09:48:29 -07:00
|
|
|
&serialize(&StakeInstruction::DelegateStake).unwrap(),
|
2019-05-07 17:08:49 -07:00
|
|
|
),
|
|
|
|
Err(InstructionError::InvalidAccountData),
|
|
|
|
);
|
|
|
|
|
2019-06-21 20:43:24 -07:00
|
|
|
// gets the deserialization checks in redeem_vote_credits
|
2019-05-07 17:08:49 -07:00
|
|
|
assert_eq!(
|
|
|
|
super::process_instruction(
|
|
|
|
&Pubkey::default(),
|
|
|
|
&mut [
|
|
|
|
KeyedAccount::new(&Pubkey::default(), false, &mut Account::default()),
|
|
|
|
KeyedAccount::new(&Pubkey::default(), false, &mut Account::default()),
|
|
|
|
KeyedAccount::new(&Pubkey::default(), false, &mut Account::default()),
|
2019-06-21 20:43:24 -07:00
|
|
|
KeyedAccount::new(
|
2019-07-12 16:38:15 -07:00
|
|
|
&sysvar::rewards::id(),
|
2019-06-21 20:43:24 -07:00
|
|
|
false,
|
2019-07-12 16:38:15 -07:00
|
|
|
&mut sysvar::rewards::create_account(1, 0.0, 0.0)
|
2019-06-21 20:43:24 -07:00
|
|
|
),
|
2019-08-12 20:59:57 -07:00
|
|
|
KeyedAccount::new(
|
|
|
|
&sysvar::stake_history::id(),
|
|
|
|
false,
|
|
|
|
&mut sysvar::stake_history::create_account(1, &StakeHistory::default())
|
|
|
|
),
|
2019-05-07 17:08:49 -07:00
|
|
|
],
|
|
|
|
&serialize(&StakeInstruction::RedeemVoteCredits).unwrap(),
|
|
|
|
),
|
|
|
|
Err(InstructionError::InvalidAccountData),
|
|
|
|
);
|
2019-06-21 22:28:34 -07:00
|
|
|
|
2019-07-12 16:38:15 -07:00
|
|
|
// Tests 3rd keyed account is of correct type (Clock instead of rewards) in withdraw
|
2019-06-21 22:28:34 -07:00
|
|
|
assert_eq!(
|
|
|
|
super::process_instruction(
|
|
|
|
&Pubkey::default(),
|
|
|
|
&mut [
|
|
|
|
KeyedAccount::new(&Pubkey::default(), false, &mut Account::default()),
|
|
|
|
KeyedAccount::new(&Pubkey::default(), false, &mut Account::default()),
|
|
|
|
KeyedAccount::new(
|
2019-07-12 16:38:15 -07:00
|
|
|
&sysvar::rewards::id(),
|
2019-06-21 22:28:34 -07:00
|
|
|
false,
|
2019-07-12 16:38:15 -07:00
|
|
|
&mut sysvar::rewards::create_account(1, 0.0, 0.0)
|
2019-06-21 22:28:34 -07:00
|
|
|
),
|
2019-08-12 20:59:57 -07:00
|
|
|
KeyedAccount::new(
|
|
|
|
&sysvar::stake_history::id(),
|
|
|
|
false,
|
|
|
|
&mut sysvar::stake_history::create_account(1, &StakeHistory::default())
|
|
|
|
),
|
2019-06-21 22:28:34 -07:00
|
|
|
],
|
|
|
|
&serialize(&StakeInstruction::Withdraw(42)).unwrap(),
|
|
|
|
),
|
|
|
|
Err(InstructionError::InvalidArgument),
|
|
|
|
);
|
|
|
|
|
|
|
|
// Tests correct number of accounts are provided in withdraw
|
|
|
|
assert_eq!(
|
|
|
|
super::process_instruction(
|
|
|
|
&Pubkey::default(),
|
2019-10-14 15:02:24 -07:00
|
|
|
&mut [KeyedAccount::new(
|
|
|
|
&Pubkey::default(),
|
|
|
|
false,
|
|
|
|
&mut Account::default()
|
|
|
|
)],
|
2019-06-21 22:28:34 -07:00
|
|
|
&serialize(&StakeInstruction::Withdraw(42)).unwrap(),
|
|
|
|
),
|
2019-10-14 15:02:24 -07:00
|
|
|
Err(InstructionError::NotEnoughAccountKeys),
|
2019-06-21 22:28:34 -07:00
|
|
|
);
|
2019-06-21 23:45:03 -07:00
|
|
|
|
2019-07-12 16:38:15 -07:00
|
|
|
// Tests 2nd keyed account is of correct type (Clock instead of rewards) in deactivate
|
2019-06-21 23:45:03 -07:00
|
|
|
assert_eq!(
|
|
|
|
super::process_instruction(
|
|
|
|
&Pubkey::default(),
|
|
|
|
&mut [
|
|
|
|
KeyedAccount::new(&Pubkey::default(), false, &mut Account::default()),
|
|
|
|
KeyedAccount::new(
|
2019-07-12 16:38:15 -07:00
|
|
|
&sysvar::rewards::id(),
|
2019-06-21 23:45:03 -07:00
|
|
|
false,
|
2019-07-12 16:38:15 -07:00
|
|
|
&mut sysvar::rewards::create_account(1, 0.0, 0.0)
|
2019-06-21 23:45:03 -07:00
|
|
|
),
|
|
|
|
],
|
|
|
|
&serialize(&StakeInstruction::Deactivate).unwrap(),
|
|
|
|
),
|
|
|
|
Err(InstructionError::InvalidArgument),
|
|
|
|
);
|
|
|
|
|
|
|
|
// Tests correct number of accounts are provided in deactivate
|
|
|
|
assert_eq!(
|
|
|
|
super::process_instruction(
|
|
|
|
&Pubkey::default(),
|
2019-10-14 15:02:24 -07:00
|
|
|
&mut [],
|
2019-06-21 23:45:03 -07:00
|
|
|
&serialize(&StakeInstruction::Deactivate).unwrap(),
|
|
|
|
),
|
2019-10-14 15:02:24 -07:00
|
|
|
Err(InstructionError::NotEnoughAccountKeys),
|
2019-06-21 23:45:03 -07:00
|
|
|
);
|
2019-04-01 16:45:53 -07:00
|
|
|
}
|
|
|
|
|
2019-09-09 18:17:32 -07:00
|
|
|
#[test]
|
|
|
|
fn test_custom_error_decode() {
|
|
|
|
use num_traits::FromPrimitive;
|
|
|
|
fn pretty_err<T>(err: InstructionError) -> String
|
|
|
|
where
|
|
|
|
T: 'static + std::error::Error + DecodeError<T> + FromPrimitive,
|
|
|
|
{
|
|
|
|
if let InstructionError::CustomError(code) = err {
|
|
|
|
let specific_error: T = T::decode_custom_error_to_enum(code).unwrap();
|
|
|
|
format!(
|
|
|
|
"{:?}: {}::{:?} - {}",
|
|
|
|
err,
|
|
|
|
T::type_of(),
|
|
|
|
specific_error,
|
|
|
|
specific_error,
|
|
|
|
)
|
|
|
|
} else {
|
|
|
|
"".to_string()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
assert_eq!(
|
|
|
|
"CustomError(0): StakeError::NoCreditsToRedeem - not enough credits to redeem",
|
|
|
|
pretty_err::<StakeError>(StakeError::NoCreditsToRedeem.into())
|
|
|
|
)
|
|
|
|
}
|
2019-04-01 16:45:53 -07:00
|
|
|
}
|