Add error reporting to system program (#15644)
This commit is contained in:
@ -1,6 +1,6 @@
|
||||
use crate::{
|
||||
account_utils::State as AccountUtilsState, keyed_account::KeyedAccount,
|
||||
nonce_account::create_account,
|
||||
account_utils::State as AccountUtilsState, ic_msg, keyed_account::KeyedAccount,
|
||||
nonce_account::create_account, process_instruction::InvokeContext,
|
||||
};
|
||||
use solana_program::{
|
||||
instruction::{checked_add, InstructionError},
|
||||
@ -16,6 +16,7 @@ pub trait NonceKeyedAccount {
|
||||
&self,
|
||||
recent_blockhashes: &RecentBlockhashes,
|
||||
signers: &HashSet<Pubkey>,
|
||||
invoke_context: &mut dyn InvokeContext,
|
||||
) -> Result<(), InstructionError>;
|
||||
fn withdraw_nonce_account(
|
||||
&self,
|
||||
@ -24,17 +25,20 @@ pub trait NonceKeyedAccount {
|
||||
recent_blockhashes: &RecentBlockhashes,
|
||||
rent: &Rent,
|
||||
signers: &HashSet<Pubkey>,
|
||||
invoke_context: &mut dyn InvokeContext,
|
||||
) -> Result<(), InstructionError>;
|
||||
fn initialize_nonce_account(
|
||||
&self,
|
||||
nonce_authority: &Pubkey,
|
||||
recent_blockhashes: &RecentBlockhashes,
|
||||
rent: &Rent,
|
||||
invoke_context: &mut dyn InvokeContext,
|
||||
) -> Result<(), InstructionError>;
|
||||
fn authorize_nonce_account(
|
||||
&self,
|
||||
nonce_authority: &Pubkey,
|
||||
signers: &HashSet<Pubkey>,
|
||||
invoke_context: &mut dyn InvokeContext,
|
||||
) -> Result<(), InstructionError>;
|
||||
}
|
||||
|
||||
@ -43,8 +47,13 @@ impl<'a> NonceKeyedAccount for KeyedAccount<'a> {
|
||||
&self,
|
||||
recent_blockhashes: &RecentBlockhashes,
|
||||
signers: &HashSet<Pubkey>,
|
||||
invoke_context: &mut dyn InvokeContext,
|
||||
) -> Result<(), InstructionError> {
|
||||
if recent_blockhashes.is_empty() {
|
||||
ic_msg!(
|
||||
invoke_context,
|
||||
"Advance nonce account: recent blockhash list is empty",
|
||||
);
|
||||
return Err(NonceError::NoRecentBlockhashes.into());
|
||||
}
|
||||
|
||||
@ -52,10 +61,19 @@ impl<'a> NonceKeyedAccount for KeyedAccount<'a> {
|
||||
match state {
|
||||
State::Initialized(data) => {
|
||||
if !signers.contains(&data.authority) {
|
||||
ic_msg!(
|
||||
invoke_context,
|
||||
"Advance nonce account: Account {} must be a signer",
|
||||
data.authority
|
||||
);
|
||||
return Err(InstructionError::MissingRequiredSignature);
|
||||
}
|
||||
let recent_blockhash = recent_blockhashes[0].blockhash;
|
||||
if data.blockhash == recent_blockhash {
|
||||
ic_msg!(
|
||||
invoke_context,
|
||||
"Advance nonce account: nonce can only advance once per slot"
|
||||
);
|
||||
return Err(NonceError::NotExpired.into());
|
||||
}
|
||||
|
||||
@ -66,7 +84,14 @@ impl<'a> NonceKeyedAccount for KeyedAccount<'a> {
|
||||
};
|
||||
self.set_state(&Versions::new_current(State::Initialized(new_data)))
|
||||
}
|
||||
_ => Err(NonceError::BadAccountState.into()),
|
||||
_ => {
|
||||
ic_msg!(
|
||||
invoke_context,
|
||||
"Advance nonce account: Account {} state is invalid",
|
||||
self.unsigned_key()
|
||||
);
|
||||
Err(NonceError::BadAccountState.into())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -77,10 +102,17 @@ impl<'a> NonceKeyedAccount for KeyedAccount<'a> {
|
||||
recent_blockhashes: &RecentBlockhashes,
|
||||
rent: &Rent,
|
||||
signers: &HashSet<Pubkey>,
|
||||
invoke_context: &mut dyn InvokeContext,
|
||||
) -> Result<(), InstructionError> {
|
||||
let signer = match AccountUtilsState::<Versions>::state(self)?.convert_to_current() {
|
||||
State::Uninitialized => {
|
||||
if lamports > self.lamports()? {
|
||||
ic_msg!(
|
||||
invoke_context,
|
||||
"Withdraw nonce account: insufficient lamports {}, need {}",
|
||||
self.lamports()?,
|
||||
lamports,
|
||||
);
|
||||
return Err(InstructionError::InsufficientFunds);
|
||||
}
|
||||
*self.unsigned_key()
|
||||
@ -88,12 +120,23 @@ impl<'a> NonceKeyedAccount for KeyedAccount<'a> {
|
||||
State::Initialized(ref data) => {
|
||||
if lamports == self.lamports()? {
|
||||
if data.blockhash == recent_blockhashes[0].blockhash {
|
||||
ic_msg!(
|
||||
invoke_context,
|
||||
"Withdraw nonce account: nonce can only advance once per slot"
|
||||
);
|
||||
return Err(NonceError::NotExpired.into());
|
||||
}
|
||||
self.set_state(&Versions::new_current(State::Uninitialized))?;
|
||||
} else {
|
||||
let min_balance = rent.minimum_balance(self.data_len()?);
|
||||
if checked_add(lamports, min_balance)? > self.lamports()? {
|
||||
let amount = checked_add(lamports, min_balance)?;
|
||||
if amount > self.lamports()? {
|
||||
ic_msg!(
|
||||
invoke_context,
|
||||
"Withdraw nonce account: insufficient lamports {}, need {}",
|
||||
self.lamports()?,
|
||||
amount,
|
||||
);
|
||||
return Err(InstructionError::InsufficientFunds);
|
||||
}
|
||||
}
|
||||
@ -102,6 +145,11 @@ impl<'a> NonceKeyedAccount for KeyedAccount<'a> {
|
||||
};
|
||||
|
||||
if !signers.contains(&signer) {
|
||||
ic_msg!(
|
||||
invoke_context,
|
||||
"Withdraw nonce account: Account {} must sign",
|
||||
signer
|
||||
);
|
||||
return Err(InstructionError::MissingRequiredSignature);
|
||||
}
|
||||
|
||||
@ -116,8 +164,13 @@ impl<'a> NonceKeyedAccount for KeyedAccount<'a> {
|
||||
nonce_authority: &Pubkey,
|
||||
recent_blockhashes: &RecentBlockhashes,
|
||||
rent: &Rent,
|
||||
invoke_context: &mut dyn InvokeContext,
|
||||
) -> Result<(), InstructionError> {
|
||||
if recent_blockhashes.is_empty() {
|
||||
ic_msg!(
|
||||
invoke_context,
|
||||
"Initialize nonce account: recent blockhash list is empty",
|
||||
);
|
||||
return Err(NonceError::NoRecentBlockhashes.into());
|
||||
}
|
||||
|
||||
@ -125,6 +178,12 @@ impl<'a> NonceKeyedAccount for KeyedAccount<'a> {
|
||||
State::Uninitialized => {
|
||||
let min_balance = rent.minimum_balance(self.data_len()?);
|
||||
if self.lamports()? < min_balance {
|
||||
ic_msg!(
|
||||
invoke_context,
|
||||
"Initialize nonce account: insufficient lamports {}, need {}",
|
||||
self.lamports()?,
|
||||
min_balance
|
||||
);
|
||||
return Err(InstructionError::InsufficientFunds);
|
||||
}
|
||||
let data = nonce::state::Data {
|
||||
@ -134,7 +193,14 @@ impl<'a> NonceKeyedAccount for KeyedAccount<'a> {
|
||||
};
|
||||
self.set_state(&Versions::new_current(State::Initialized(data)))
|
||||
}
|
||||
_ => Err(NonceError::BadAccountState.into()),
|
||||
_ => {
|
||||
ic_msg!(
|
||||
invoke_context,
|
||||
"Initialize nonce account: Account {} state is invalid",
|
||||
self.unsigned_key()
|
||||
);
|
||||
Err(NonceError::BadAccountState.into())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -142,10 +208,16 @@ impl<'a> NonceKeyedAccount for KeyedAccount<'a> {
|
||||
&self,
|
||||
nonce_authority: &Pubkey,
|
||||
signers: &HashSet<Pubkey>,
|
||||
invoke_context: &mut dyn InvokeContext,
|
||||
) -> Result<(), InstructionError> {
|
||||
match AccountUtilsState::<Versions>::state(self)?.convert_to_current() {
|
||||
State::Initialized(data) => {
|
||||
if !signers.contains(&data.authority) {
|
||||
ic_msg!(
|
||||
invoke_context,
|
||||
"Authorize nonce account: Account {} must sign",
|
||||
data.authority
|
||||
);
|
||||
return Err(InstructionError::MissingRequiredSignature);
|
||||
}
|
||||
let new_data = nonce::state::Data {
|
||||
@ -154,7 +226,14 @@ impl<'a> NonceKeyedAccount for KeyedAccount<'a> {
|
||||
};
|
||||
self.set_state(&Versions::new_current(State::Initialized(new_data)))
|
||||
}
|
||||
_ => Err(NonceError::BadAccountState.into()),
|
||||
_ => {
|
||||
ic_msg!(
|
||||
invoke_context,
|
||||
"Authorize nonce account: Account {} state is invalid",
|
||||
self.unsigned_key()
|
||||
);
|
||||
Err(NonceError::BadAccountState.into())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -178,6 +257,7 @@ mod test {
|
||||
keyed_account::KeyedAccount,
|
||||
nonce::{self, State},
|
||||
nonce_account::verify_nonce_account,
|
||||
process_instruction::MockInvokeContext,
|
||||
system_instruction::NonceError,
|
||||
sysvar::recent_blockhashes::create_test_recent_blockhashes,
|
||||
};
|
||||
@ -210,7 +290,12 @@ mod test {
|
||||
let recent_blockhashes = create_test_recent_blockhashes(95);
|
||||
let authorized = keyed_account.unsigned_key();
|
||||
keyed_account
|
||||
.initialize_nonce_account(&authorized, &recent_blockhashes, &rent)
|
||||
.initialize_nonce_account(
|
||||
&authorized,
|
||||
&recent_blockhashes,
|
||||
&rent,
|
||||
&mut MockInvokeContext::default(),
|
||||
)
|
||||
.unwrap();
|
||||
let state = AccountUtilsState::<Versions>::state(keyed_account)
|
||||
.unwrap()
|
||||
@ -224,7 +309,11 @@ mod test {
|
||||
assert_eq!(state, State::Initialized(data.clone()));
|
||||
let recent_blockhashes = create_test_recent_blockhashes(63);
|
||||
keyed_account
|
||||
.advance_nonce_account(&recent_blockhashes, &signers)
|
||||
.advance_nonce_account(
|
||||
&recent_blockhashes,
|
||||
&signers,
|
||||
&mut MockInvokeContext::default(),
|
||||
)
|
||||
.unwrap();
|
||||
let state = AccountUtilsState::<Versions>::state(keyed_account)
|
||||
.unwrap()
|
||||
@ -238,7 +327,11 @@ mod test {
|
||||
assert_eq!(state, State::Initialized(data.clone()));
|
||||
let recent_blockhashes = create_test_recent_blockhashes(31);
|
||||
keyed_account
|
||||
.advance_nonce_account(&recent_blockhashes, &signers)
|
||||
.advance_nonce_account(
|
||||
&recent_blockhashes,
|
||||
&signers,
|
||||
&mut MockInvokeContext::default(),
|
||||
)
|
||||
.unwrap();
|
||||
let state = AccountUtilsState::<Versions>::state(keyed_account)
|
||||
.unwrap()
|
||||
@ -263,6 +356,7 @@ mod test {
|
||||
&recent_blockhashes,
|
||||
&rent,
|
||||
&signers,
|
||||
&mut MockInvokeContext::default(),
|
||||
)
|
||||
.unwrap();
|
||||
// Empties Account balance
|
||||
@ -292,7 +386,12 @@ mod test {
|
||||
let recent_blockhashes = create_test_recent_blockhashes(31);
|
||||
let authority = *nonce_account.unsigned_key();
|
||||
nonce_account
|
||||
.initialize_nonce_account(&authority, &recent_blockhashes, &rent)
|
||||
.initialize_nonce_account(
|
||||
&authority,
|
||||
&recent_blockhashes,
|
||||
&rent,
|
||||
&mut MockInvokeContext::default(),
|
||||
)
|
||||
.unwrap();
|
||||
let pubkey = nonce_account.account.borrow().owner;
|
||||
let nonce_account = KeyedAccount::new(&pubkey, false, nonce_account.account);
|
||||
@ -307,7 +406,11 @@ mod test {
|
||||
assert_eq!(state, State::Initialized(data));
|
||||
let signers = HashSet::new();
|
||||
let recent_blockhashes = create_test_recent_blockhashes(0);
|
||||
let result = nonce_account.advance_nonce_account(&recent_blockhashes, &signers);
|
||||
let result = nonce_account.advance_nonce_account(
|
||||
&recent_blockhashes,
|
||||
&signers,
|
||||
&mut MockInvokeContext::default(),
|
||||
);
|
||||
assert_eq!(result, Err(InstructionError::MissingRequiredSignature),);
|
||||
})
|
||||
}
|
||||
@ -325,10 +428,19 @@ mod test {
|
||||
let recent_blockhashes = create_test_recent_blockhashes(0);
|
||||
let authorized = *keyed_account.unsigned_key();
|
||||
keyed_account
|
||||
.initialize_nonce_account(&authorized, &recent_blockhashes, &rent)
|
||||
.initialize_nonce_account(
|
||||
&authorized,
|
||||
&recent_blockhashes,
|
||||
&rent,
|
||||
&mut MockInvokeContext::default(),
|
||||
)
|
||||
.unwrap();
|
||||
let recent_blockhashes = vec![].into_iter().collect();
|
||||
let result = keyed_account.advance_nonce_account(&recent_blockhashes, &signers);
|
||||
let result = keyed_account.advance_nonce_account(
|
||||
&recent_blockhashes,
|
||||
&signers,
|
||||
&mut MockInvokeContext::default(),
|
||||
);
|
||||
assert_eq!(result, Err(NonceError::NoRecentBlockhashes.into()));
|
||||
})
|
||||
}
|
||||
@ -346,9 +458,18 @@ mod test {
|
||||
let recent_blockhashes = create_test_recent_blockhashes(63);
|
||||
let authorized = *keyed_account.unsigned_key();
|
||||
keyed_account
|
||||
.initialize_nonce_account(&authorized, &recent_blockhashes, &rent)
|
||||
.initialize_nonce_account(
|
||||
&authorized,
|
||||
&recent_blockhashes,
|
||||
&rent,
|
||||
&mut MockInvokeContext::default(),
|
||||
)
|
||||
.unwrap();
|
||||
let result = keyed_account.advance_nonce_account(&recent_blockhashes, &signers);
|
||||
let result = keyed_account.advance_nonce_account(
|
||||
&recent_blockhashes,
|
||||
&signers,
|
||||
&mut MockInvokeContext::default(),
|
||||
);
|
||||
assert_eq!(result, Err(NonceError::NotExpired.into()));
|
||||
})
|
||||
}
|
||||
@ -364,7 +485,11 @@ mod test {
|
||||
let mut signers = HashSet::new();
|
||||
signers.insert(*keyed_account.signer_key().unwrap());
|
||||
let recent_blockhashes = create_test_recent_blockhashes(63);
|
||||
let result = keyed_account.advance_nonce_account(&recent_blockhashes, &signers);
|
||||
let result = keyed_account.advance_nonce_account(
|
||||
&recent_blockhashes,
|
||||
&signers,
|
||||
&mut MockInvokeContext::default(),
|
||||
);
|
||||
assert_eq!(result, Err(NonceError::BadAccountState.into()));
|
||||
})
|
||||
}
|
||||
@ -383,12 +508,21 @@ mod test {
|
||||
let recent_blockhashes = create_test_recent_blockhashes(63);
|
||||
let authorized = *nonce_authority.unsigned_key();
|
||||
nonce_account
|
||||
.initialize_nonce_account(&authorized, &recent_blockhashes, &rent)
|
||||
.initialize_nonce_account(
|
||||
&authorized,
|
||||
&recent_blockhashes,
|
||||
&rent,
|
||||
&mut MockInvokeContext::default(),
|
||||
)
|
||||
.unwrap();
|
||||
let mut signers = HashSet::new();
|
||||
signers.insert(*nonce_authority.signer_key().unwrap());
|
||||
let recent_blockhashes = create_test_recent_blockhashes(31);
|
||||
let result = nonce_account.advance_nonce_account(&recent_blockhashes, &signers);
|
||||
let result = nonce_account.advance_nonce_account(
|
||||
&recent_blockhashes,
|
||||
&signers,
|
||||
&mut MockInvokeContext::default(),
|
||||
);
|
||||
assert_eq!(result, Ok(()));
|
||||
});
|
||||
});
|
||||
@ -408,9 +542,18 @@ mod test {
|
||||
let recent_blockhashes = create_test_recent_blockhashes(63);
|
||||
let authorized = *nonce_authority.unsigned_key();
|
||||
nonce_account
|
||||
.initialize_nonce_account(&authorized, &recent_blockhashes, &rent)
|
||||
.initialize_nonce_account(
|
||||
&authorized,
|
||||
&recent_blockhashes,
|
||||
&rent,
|
||||
&mut MockInvokeContext::default(),
|
||||
)
|
||||
.unwrap();
|
||||
let result = nonce_account.advance_nonce_account(&recent_blockhashes, &signers);
|
||||
let result = nonce_account.advance_nonce_account(
|
||||
&recent_blockhashes,
|
||||
&signers,
|
||||
&mut MockInvokeContext::default(),
|
||||
);
|
||||
assert_eq!(result, Err(InstructionError::MissingRequiredSignature),);
|
||||
});
|
||||
});
|
||||
@ -443,6 +586,7 @@ mod test {
|
||||
&recent_blockhashes,
|
||||
&rent,
|
||||
&signers,
|
||||
&mut MockInvokeContext::default(),
|
||||
)
|
||||
.unwrap();
|
||||
let state = AccountUtilsState::<Versions>::state(nonce_keyed)
|
||||
@ -481,6 +625,7 @@ mod test {
|
||||
&recent_blockhashes,
|
||||
&rent,
|
||||
&signers,
|
||||
&mut MockInvokeContext::default(),
|
||||
);
|
||||
assert_eq!(result, Err(InstructionError::MissingRequiredSignature),);
|
||||
})
|
||||
@ -510,6 +655,7 @@ mod test {
|
||||
&recent_blockhashes,
|
||||
&rent,
|
||||
&signers,
|
||||
&mut MockInvokeContext::default(),
|
||||
);
|
||||
assert_eq!(result, Err(InstructionError::InsufficientFunds));
|
||||
})
|
||||
@ -539,6 +685,7 @@ mod test {
|
||||
&recent_blockhashes,
|
||||
&rent,
|
||||
&signers,
|
||||
&mut MockInvokeContext::default(),
|
||||
)
|
||||
.unwrap();
|
||||
let state = AccountUtilsState::<Versions>::state(nonce_keyed)
|
||||
@ -558,6 +705,7 @@ mod test {
|
||||
&recent_blockhashes,
|
||||
&rent,
|
||||
&signers,
|
||||
&mut MockInvokeContext::default(),
|
||||
)
|
||||
.unwrap();
|
||||
let state = AccountUtilsState::<Versions>::state(nonce_keyed)
|
||||
@ -583,7 +731,12 @@ mod test {
|
||||
let recent_blockhashes = create_test_recent_blockhashes(31);
|
||||
let authority = *nonce_keyed.unsigned_key();
|
||||
nonce_keyed
|
||||
.initialize_nonce_account(&authority, &recent_blockhashes, &rent)
|
||||
.initialize_nonce_account(
|
||||
&authority,
|
||||
&recent_blockhashes,
|
||||
&rent,
|
||||
&mut MockInvokeContext::default(),
|
||||
)
|
||||
.unwrap();
|
||||
let state = AccountUtilsState::<Versions>::state(nonce_keyed)
|
||||
.unwrap()
|
||||
@ -606,6 +759,7 @@ mod test {
|
||||
&recent_blockhashes,
|
||||
&rent,
|
||||
&signers,
|
||||
&mut MockInvokeContext::default(),
|
||||
)
|
||||
.unwrap();
|
||||
let state = AccountUtilsState::<Versions>::state(nonce_keyed)
|
||||
@ -631,6 +785,7 @@ mod test {
|
||||
&recent_blockhashes,
|
||||
&rent,
|
||||
&signers,
|
||||
&mut MockInvokeContext::default(),
|
||||
)
|
||||
.unwrap();
|
||||
let state = AccountUtilsState::<Versions>::state(nonce_keyed)
|
||||
@ -654,7 +809,12 @@ mod test {
|
||||
let recent_blockhashes = create_test_recent_blockhashes(0);
|
||||
let authorized = *nonce_keyed.unsigned_key();
|
||||
nonce_keyed
|
||||
.initialize_nonce_account(&authorized, &recent_blockhashes, &rent)
|
||||
.initialize_nonce_account(
|
||||
&authorized,
|
||||
&recent_blockhashes,
|
||||
&rent,
|
||||
&mut MockInvokeContext::default(),
|
||||
)
|
||||
.unwrap();
|
||||
with_test_keyed_account(42, false, |to_keyed| {
|
||||
let mut signers = HashSet::new();
|
||||
@ -666,6 +826,7 @@ mod test {
|
||||
&recent_blockhashes,
|
||||
&rent,
|
||||
&signers,
|
||||
&mut MockInvokeContext::default(),
|
||||
);
|
||||
assert_eq!(result, Err(NonceError::NotExpired.into()));
|
||||
})
|
||||
@ -683,7 +844,12 @@ mod test {
|
||||
let recent_blockhashes = create_test_recent_blockhashes(95);
|
||||
let authorized = *nonce_keyed.unsigned_key();
|
||||
nonce_keyed
|
||||
.initialize_nonce_account(&authorized, &recent_blockhashes, &rent)
|
||||
.initialize_nonce_account(
|
||||
&authorized,
|
||||
&recent_blockhashes,
|
||||
&rent,
|
||||
&mut MockInvokeContext::default(),
|
||||
)
|
||||
.unwrap();
|
||||
with_test_keyed_account(42, false, |to_keyed| {
|
||||
let recent_blockhashes = create_test_recent_blockhashes(63);
|
||||
@ -696,6 +862,7 @@ mod test {
|
||||
&recent_blockhashes,
|
||||
&rent,
|
||||
&signers,
|
||||
&mut MockInvokeContext::default(),
|
||||
);
|
||||
assert_eq!(result, Err(InstructionError::InsufficientFunds));
|
||||
})
|
||||
@ -713,7 +880,12 @@ mod test {
|
||||
let recent_blockhashes = create_test_recent_blockhashes(95);
|
||||
let authorized = *nonce_keyed.unsigned_key();
|
||||
nonce_keyed
|
||||
.initialize_nonce_account(&authorized, &recent_blockhashes, &rent)
|
||||
.initialize_nonce_account(
|
||||
&authorized,
|
||||
&recent_blockhashes,
|
||||
&rent,
|
||||
&mut MockInvokeContext::default(),
|
||||
)
|
||||
.unwrap();
|
||||
with_test_keyed_account(42, false, |to_keyed| {
|
||||
let recent_blockhashes = create_test_recent_blockhashes(63);
|
||||
@ -726,6 +898,7 @@ mod test {
|
||||
&recent_blockhashes,
|
||||
&rent,
|
||||
&signers,
|
||||
&mut MockInvokeContext::default(),
|
||||
);
|
||||
assert_eq!(result, Err(InstructionError::InsufficientFunds));
|
||||
})
|
||||
@ -743,7 +916,12 @@ mod test {
|
||||
let recent_blockhashes = create_test_recent_blockhashes(95);
|
||||
let authorized = *nonce_keyed.unsigned_key();
|
||||
nonce_keyed
|
||||
.initialize_nonce_account(&authorized, &recent_blockhashes, &rent)
|
||||
.initialize_nonce_account(
|
||||
&authorized,
|
||||
&recent_blockhashes,
|
||||
&rent,
|
||||
&mut MockInvokeContext::default(),
|
||||
)
|
||||
.unwrap();
|
||||
with_test_keyed_account(55, false, |to_keyed| {
|
||||
let recent_blockhashes = create_test_recent_blockhashes(63);
|
||||
@ -756,6 +934,7 @@ mod test {
|
||||
&recent_blockhashes,
|
||||
&rent,
|
||||
&signers,
|
||||
&mut MockInvokeContext::default(),
|
||||
);
|
||||
assert_eq!(result, Err(InstructionError::InsufficientFunds));
|
||||
})
|
||||
@ -778,8 +957,12 @@ mod test {
|
||||
signers.insert(*keyed_account.signer_key().unwrap());
|
||||
let recent_blockhashes = create_test_recent_blockhashes(0);
|
||||
let authority = *keyed_account.unsigned_key();
|
||||
let result =
|
||||
keyed_account.initialize_nonce_account(&authority, &recent_blockhashes, &rent);
|
||||
let result = keyed_account.initialize_nonce_account(
|
||||
&authority,
|
||||
&recent_blockhashes,
|
||||
&rent,
|
||||
&mut MockInvokeContext::default(),
|
||||
);
|
||||
let data = nonce::state::Data {
|
||||
authority,
|
||||
blockhash: recent_blockhashes[0].blockhash,
|
||||
@ -805,8 +988,12 @@ mod test {
|
||||
signers.insert(*keyed_account.signer_key().unwrap());
|
||||
let recent_blockhashes = vec![].into_iter().collect();
|
||||
let authorized = *keyed_account.unsigned_key();
|
||||
let result =
|
||||
keyed_account.initialize_nonce_account(&authorized, &recent_blockhashes, &rent);
|
||||
let result = keyed_account.initialize_nonce_account(
|
||||
&authorized,
|
||||
&recent_blockhashes,
|
||||
&rent,
|
||||
&mut MockInvokeContext::default(),
|
||||
);
|
||||
assert_eq!(result, Err(NonceError::NoRecentBlockhashes.into()));
|
||||
})
|
||||
}
|
||||
@ -822,11 +1009,20 @@ mod test {
|
||||
let recent_blockhashes = create_test_recent_blockhashes(31);
|
||||
let authorized = *keyed_account.unsigned_key();
|
||||
keyed_account
|
||||
.initialize_nonce_account(&authorized, &recent_blockhashes, &rent)
|
||||
.initialize_nonce_account(
|
||||
&authorized,
|
||||
&recent_blockhashes,
|
||||
&rent,
|
||||
&mut MockInvokeContext::default(),
|
||||
)
|
||||
.unwrap();
|
||||
let recent_blockhashes = create_test_recent_blockhashes(0);
|
||||
let result =
|
||||
keyed_account.initialize_nonce_account(&authorized, &recent_blockhashes, &rent);
|
||||
let result = keyed_account.initialize_nonce_account(
|
||||
&authorized,
|
||||
&recent_blockhashes,
|
||||
&rent,
|
||||
&mut MockInvokeContext::default(),
|
||||
);
|
||||
assert_eq!(result, Err(NonceError::BadAccountState.into()));
|
||||
})
|
||||
}
|
||||
@ -841,8 +1037,12 @@ mod test {
|
||||
with_test_keyed_account(min_lamports - 42, true, |keyed_account| {
|
||||
let recent_blockhashes = create_test_recent_blockhashes(63);
|
||||
let authorized = *keyed_account.unsigned_key();
|
||||
let result =
|
||||
keyed_account.initialize_nonce_account(&authorized, &recent_blockhashes, &rent);
|
||||
let result = keyed_account.initialize_nonce_account(
|
||||
&authorized,
|
||||
&recent_blockhashes,
|
||||
&rent,
|
||||
&mut MockInvokeContext::default(),
|
||||
);
|
||||
assert_eq!(result, Err(InstructionError::InsufficientFunds));
|
||||
})
|
||||
}
|
||||
@ -860,7 +1060,12 @@ mod test {
|
||||
let recent_blockhashes = create_test_recent_blockhashes(31);
|
||||
let authorized = *nonce_account.unsigned_key();
|
||||
nonce_account
|
||||
.initialize_nonce_account(&authorized, &recent_blockhashes, &rent)
|
||||
.initialize_nonce_account(
|
||||
&authorized,
|
||||
&recent_blockhashes,
|
||||
&rent,
|
||||
&mut MockInvokeContext::default(),
|
||||
)
|
||||
.unwrap();
|
||||
let authority = Pubkey::default();
|
||||
let data = nonce::state::Data {
|
||||
@ -868,7 +1073,11 @@ mod test {
|
||||
blockhash: recent_blockhashes[0].blockhash,
|
||||
fee_calculator: recent_blockhashes[0].fee_calculator.clone(),
|
||||
};
|
||||
let result = nonce_account.authorize_nonce_account(&Pubkey::default(), &signers);
|
||||
let result = nonce_account.authorize_nonce_account(
|
||||
&Pubkey::default(),
|
||||
&signers,
|
||||
&mut MockInvokeContext::default(),
|
||||
);
|
||||
assert_eq!(result, Ok(()));
|
||||
let state = AccountUtilsState::<Versions>::state(nonce_account)
|
||||
.unwrap()
|
||||
@ -887,7 +1096,11 @@ mod test {
|
||||
with_test_keyed_account(min_lamports + 42, true, |nonce_account| {
|
||||
let mut signers = HashSet::new();
|
||||
signers.insert(*nonce_account.signer_key().unwrap());
|
||||
let result = nonce_account.authorize_nonce_account(&Pubkey::default(), &signers);
|
||||
let result = nonce_account.authorize_nonce_account(
|
||||
&Pubkey::default(),
|
||||
&signers,
|
||||
&mut MockInvokeContext::default(),
|
||||
);
|
||||
assert_eq!(result, Err(NonceError::BadAccountState.into()));
|
||||
})
|
||||
}
|
||||
@ -905,9 +1118,18 @@ mod test {
|
||||
let recent_blockhashes = create_test_recent_blockhashes(31);
|
||||
let authorized = &Pubkey::default().clone();
|
||||
nonce_account
|
||||
.initialize_nonce_account(&authorized, &recent_blockhashes, &rent)
|
||||
.initialize_nonce_account(
|
||||
&authorized,
|
||||
&recent_blockhashes,
|
||||
&rent,
|
||||
&mut MockInvokeContext::default(),
|
||||
)
|
||||
.unwrap();
|
||||
let result = nonce_account.authorize_nonce_account(&Pubkey::default(), &signers);
|
||||
let result = nonce_account.authorize_nonce_account(
|
||||
&Pubkey::default(),
|
||||
&signers,
|
||||
&mut MockInvokeContext::default(),
|
||||
);
|
||||
assert_eq!(result, Err(InstructionError::MissingRequiredSignature));
|
||||
})
|
||||
}
|
||||
@ -923,7 +1145,12 @@ mod test {
|
||||
let recent_blockhashes = create_test_recent_blockhashes(0);
|
||||
let authorized = nonce_account.unsigned_key();
|
||||
nonce_account
|
||||
.initialize_nonce_account(&authorized, &recent_blockhashes, &Rent::free())
|
||||
.initialize_nonce_account(
|
||||
&authorized,
|
||||
&recent_blockhashes,
|
||||
&Rent::free(),
|
||||
&mut MockInvokeContext::default(),
|
||||
)
|
||||
.unwrap();
|
||||
assert!(verify_nonce_account(
|
||||
&nonce_account.account.borrow(),
|
||||
@ -953,7 +1180,12 @@ mod test {
|
||||
let recent_blockhashes = create_test_recent_blockhashes(0);
|
||||
let authorized = nonce_account.unsigned_key();
|
||||
nonce_account
|
||||
.initialize_nonce_account(&authorized, &recent_blockhashes, &Rent::free())
|
||||
.initialize_nonce_account(
|
||||
&authorized,
|
||||
&recent_blockhashes,
|
||||
&Rent::free(),
|
||||
&mut MockInvokeContext::default(),
|
||||
)
|
||||
.unwrap();
|
||||
assert!(!verify_nonce_account(
|
||||
&nonce_account.account.borrow(),
|
||||
|
Reference in New Issue
Block a user