@@ -17,7 +17,7 @@ pub mod message;
|
||||
pub mod move_loader;
|
||||
pub mod native_loader;
|
||||
pub mod native_token;
|
||||
pub mod nonce_state;
|
||||
pub mod nonce;
|
||||
pub mod packet;
|
||||
pub mod poh_config;
|
||||
pub mod program_utils;
|
||||
|
@@ -1,49 +1,16 @@
|
||||
use crate::{
|
||||
account::{Account, KeyedAccount},
|
||||
account_utils::State,
|
||||
hash::Hash,
|
||||
account::{self, KeyedAccount},
|
||||
account_utils::State as AccountUtilsState,
|
||||
instruction::InstructionError,
|
||||
nonce::{self, state::Versions, State},
|
||||
pubkey::Pubkey,
|
||||
system_instruction::NonceError,
|
||||
system_program,
|
||||
sysvar::{recent_blockhashes::RecentBlockhashes, rent::Rent},
|
||||
};
|
||||
use serde_derive::{Deserialize, Serialize};
|
||||
use std::{cell::RefCell, collections::HashSet};
|
||||
|
||||
#[derive(Debug, Default, Serialize, Deserialize, PartialEq, Clone, Copy)]
|
||||
pub struct Meta {
|
||||
pub nonce_authority: Pubkey,
|
||||
}
|
||||
|
||||
impl Meta {
|
||||
pub fn new(nonce_authority: &Pubkey) -> Self {
|
||||
Self {
|
||||
nonce_authority: *nonce_authority,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, PartialEq, Clone, Copy)]
|
||||
pub enum NonceState {
|
||||
Uninitialized,
|
||||
Initialized(Meta, Hash),
|
||||
}
|
||||
|
||||
impl Default for NonceState {
|
||||
fn default() -> Self {
|
||||
NonceState::Uninitialized
|
||||
}
|
||||
}
|
||||
|
||||
impl NonceState {
|
||||
pub fn size() -> usize {
|
||||
bincode::serialized_size(&NonceState::Initialized(Meta::default(), Hash::default()))
|
||||
.unwrap() as usize
|
||||
}
|
||||
}
|
||||
|
||||
pub trait NonceAccount {
|
||||
pub trait Account {
|
||||
fn advance_nonce_account(
|
||||
&self,
|
||||
recent_blockhashes: &RecentBlockhashes,
|
||||
@@ -70,7 +37,7 @@ pub trait NonceAccount {
|
||||
) -> Result<(), InstructionError>;
|
||||
}
|
||||
|
||||
impl<'a> NonceAccount for KeyedAccount<'a> {
|
||||
impl<'a> Account for KeyedAccount<'a> {
|
||||
fn advance_nonce_account(
|
||||
&self,
|
||||
recent_blockhashes: &RecentBlockhashes,
|
||||
@@ -80,20 +47,26 @@ impl<'a> NonceAccount for KeyedAccount<'a> {
|
||||
return Err(NonceError::NoRecentBlockhashes.into());
|
||||
}
|
||||
|
||||
let meta = match self.state()? {
|
||||
NonceState::Initialized(meta, ref hash) => {
|
||||
if !signers.contains(&meta.nonce_authority) {
|
||||
let state = AccountUtilsState::<Versions>::state(self)?.convert_to_current();
|
||||
match state {
|
||||
State::Initialized(data) => {
|
||||
if !signers.contains(&data.authority) {
|
||||
return Err(InstructionError::MissingRequiredSignature);
|
||||
}
|
||||
if *hash == recent_blockhashes[0] {
|
||||
let recent_blockhash = recent_blockhashes[0].blockhash;
|
||||
if data.blockhash == recent_blockhash {
|
||||
return Err(NonceError::NotExpired.into());
|
||||
}
|
||||
meta
|
||||
}
|
||||
_ => return Err(NonceError::BadAccountState.into()),
|
||||
};
|
||||
|
||||
self.set_state(&NonceState::Initialized(meta, recent_blockhashes[0]))
|
||||
let new_data = nonce::state::Data {
|
||||
blockhash: recent_blockhash,
|
||||
fee_calculator: recent_blockhashes[0].fee_calculator.clone(),
|
||||
..data
|
||||
};
|
||||
self.set_state(&Versions::new_current(State::Initialized(new_data)))
|
||||
}
|
||||
_ => Err(NonceError::BadAccountState.into()),
|
||||
}
|
||||
}
|
||||
|
||||
fn withdraw_nonce_account(
|
||||
@@ -104,16 +77,16 @@ impl<'a> NonceAccount for KeyedAccount<'a> {
|
||||
rent: &Rent,
|
||||
signers: &HashSet<Pubkey>,
|
||||
) -> Result<(), InstructionError> {
|
||||
let signer = match self.state()? {
|
||||
NonceState::Uninitialized => {
|
||||
let signer = match AccountUtilsState::<Versions>::state(self)?.convert_to_current() {
|
||||
State::Uninitialized => {
|
||||
if lamports > self.lamports()? {
|
||||
return Err(InstructionError::InsufficientFunds);
|
||||
}
|
||||
*self.unsigned_key()
|
||||
}
|
||||
NonceState::Initialized(meta, ref hash) => {
|
||||
State::Initialized(ref data) => {
|
||||
if lamports == self.lamports()? {
|
||||
if *hash == recent_blockhashes[0] {
|
||||
if data.blockhash == recent_blockhashes[0].blockhash {
|
||||
return Err(NonceError::NotExpired.into());
|
||||
}
|
||||
} else {
|
||||
@@ -122,7 +95,7 @@ impl<'a> NonceAccount for KeyedAccount<'a> {
|
||||
return Err(InstructionError::InsufficientFunds);
|
||||
}
|
||||
}
|
||||
meta.nonce_authority
|
||||
data.authority
|
||||
}
|
||||
};
|
||||
|
||||
@@ -146,18 +119,21 @@ impl<'a> NonceAccount for KeyedAccount<'a> {
|
||||
return Err(NonceError::NoRecentBlockhashes.into());
|
||||
}
|
||||
|
||||
let meta = match self.state()? {
|
||||
NonceState::Uninitialized => {
|
||||
match AccountUtilsState::<Versions>::state(self)?.convert_to_current() {
|
||||
State::Uninitialized => {
|
||||
let min_balance = rent.minimum_balance(self.data_len()?);
|
||||
if self.lamports()? < min_balance {
|
||||
return Err(InstructionError::InsufficientFunds);
|
||||
}
|
||||
Meta::new(nonce_authority)
|
||||
let data = nonce::state::Data {
|
||||
authority: *nonce_authority,
|
||||
blockhash: recent_blockhashes[0].blockhash,
|
||||
fee_calculator: recent_blockhashes[0].fee_calculator.clone(),
|
||||
};
|
||||
self.set_state(&Versions::new_current(State::Initialized(data)))
|
||||
}
|
||||
_ => return Err(NonceError::BadAccountState.into()),
|
||||
};
|
||||
|
||||
self.set_state(&NonceState::Initialized(meta, recent_blockhashes[0]))
|
||||
_ => Err(NonceError::BadAccountState.into()),
|
||||
}
|
||||
}
|
||||
|
||||
fn authorize_nonce_account(
|
||||
@@ -165,24 +141,28 @@ impl<'a> NonceAccount for KeyedAccount<'a> {
|
||||
nonce_authority: &Pubkey,
|
||||
signers: &HashSet<Pubkey>,
|
||||
) -> Result<(), InstructionError> {
|
||||
match self.state()? {
|
||||
NonceState::Initialized(meta, nonce) => {
|
||||
if !signers.contains(&meta.nonce_authority) {
|
||||
match AccountUtilsState::<Versions>::state(self)?.convert_to_current() {
|
||||
State::Initialized(data) => {
|
||||
if !signers.contains(&data.authority) {
|
||||
return Err(InstructionError::MissingRequiredSignature);
|
||||
}
|
||||
self.set_state(&NonceState::Initialized(Meta::new(nonce_authority), nonce))
|
||||
let new_data = nonce::state::Data {
|
||||
authority: *nonce_authority,
|
||||
..data
|
||||
};
|
||||
self.set_state(&Versions::new_current(State::Initialized(new_data)))
|
||||
}
|
||||
_ => Err(NonceError::BadAccountState.into()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn create_account(lamports: u64) -> RefCell<Account> {
|
||||
pub fn create_account(lamports: u64) -> RefCell<account::Account> {
|
||||
RefCell::new(
|
||||
Account::new_data_with_space(
|
||||
account::Account::new_data_with_space(
|
||||
lamports,
|
||||
&NonceState::Uninitialized,
|
||||
NonceState::size(),
|
||||
&Versions::new_current(State::Uninitialized),
|
||||
State::size(),
|
||||
&system_program::id(),
|
||||
)
|
||||
.expect("nonce_account"),
|
||||
@@ -206,6 +186,8 @@ mod test {
|
||||
use super::*;
|
||||
use crate::{
|
||||
account::KeyedAccount,
|
||||
account_utils::State as AccountUtilsState,
|
||||
nonce::{self, State},
|
||||
system_instruction::NonceError,
|
||||
sysvar::recent_blockhashes::{create_test_recent_blockhashes, RecentBlockhashes},
|
||||
};
|
||||
@@ -213,13 +195,7 @@ mod test {
|
||||
|
||||
#[test]
|
||||
fn default_is_uninitialized() {
|
||||
assert_eq!(NonceState::default(), NonceState::Uninitialized)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn new_meta() {
|
||||
let nonce_authority = Pubkey::default();
|
||||
assert_eq!(Meta::new(&nonce_authority), Meta { nonce_authority });
|
||||
assert_eq!(State::default(), State::Uninitialized)
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -228,39 +204,62 @@ mod test {
|
||||
lamports_per_byte_year: 42,
|
||||
..Rent::default()
|
||||
};
|
||||
let min_lamports = rent.minimum_balance(NonceState::size());
|
||||
let min_lamports = rent.minimum_balance(State::size());
|
||||
with_test_keyed_account(min_lamports + 42, true, |keyed_account| {
|
||||
let meta = Meta::new(&keyed_account.unsigned_key());
|
||||
let data = nonce::state::Data {
|
||||
authority: *keyed_account.unsigned_key(),
|
||||
..nonce::state::Data::default()
|
||||
};
|
||||
let mut signers = HashSet::new();
|
||||
signers.insert(keyed_account.signer_key().unwrap().clone());
|
||||
let state: NonceState = keyed_account.state().unwrap();
|
||||
let state = AccountUtilsState::<Versions>::state(keyed_account)
|
||||
.unwrap()
|
||||
.convert_to_current();
|
||||
// New is in Uninitialzed state
|
||||
assert_eq!(state, NonceState::Uninitialized);
|
||||
assert_eq!(state, State::Uninitialized);
|
||||
let recent_blockhashes = create_test_recent_blockhashes(95);
|
||||
let authorized = keyed_account.unsigned_key().clone();
|
||||
keyed_account
|
||||
.initialize_nonce_account(&authorized, &recent_blockhashes, &rent)
|
||||
.unwrap();
|
||||
let state: NonceState = keyed_account.state().unwrap();
|
||||
let stored = recent_blockhashes[0];
|
||||
let state = AccountUtilsState::<Versions>::state(keyed_account)
|
||||
.unwrap()
|
||||
.convert_to_current();
|
||||
let data = nonce::state::Data {
|
||||
blockhash: recent_blockhashes[0].blockhash,
|
||||
fee_calculator: recent_blockhashes[0].fee_calculator.clone(),
|
||||
..data.clone()
|
||||
};
|
||||
// First nonce instruction drives state from Uninitialized to Initialized
|
||||
assert_eq!(state, NonceState::Initialized(meta, stored));
|
||||
assert_eq!(state, State::Initialized(data.clone()));
|
||||
let recent_blockhashes = create_test_recent_blockhashes(63);
|
||||
keyed_account
|
||||
.advance_nonce_account(&recent_blockhashes, &signers)
|
||||
.unwrap();
|
||||
let state: NonceState = keyed_account.state().unwrap();
|
||||
let stored = recent_blockhashes[0];
|
||||
let state = AccountUtilsState::<Versions>::state(keyed_account)
|
||||
.unwrap()
|
||||
.convert_to_current();
|
||||
let data = nonce::state::Data {
|
||||
blockhash: recent_blockhashes[0].blockhash,
|
||||
fee_calculator: recent_blockhashes[0].fee_calculator.clone(),
|
||||
..data.clone()
|
||||
};
|
||||
// Second nonce instruction consumes and replaces stored nonce
|
||||
assert_eq!(state, NonceState::Initialized(meta, stored));
|
||||
assert_eq!(state, State::Initialized(data.clone()));
|
||||
let recent_blockhashes = create_test_recent_blockhashes(31);
|
||||
keyed_account
|
||||
.advance_nonce_account(&recent_blockhashes, &signers)
|
||||
.unwrap();
|
||||
let state: NonceState = keyed_account.state().unwrap();
|
||||
let stored = recent_blockhashes[0];
|
||||
let state = AccountUtilsState::<Versions>::state(keyed_account)
|
||||
.unwrap()
|
||||
.convert_to_current();
|
||||
let data = nonce::state::Data {
|
||||
blockhash: recent_blockhashes[0].blockhash,
|
||||
fee_calculator: recent_blockhashes[0].fee_calculator.clone(),
|
||||
..data.clone()
|
||||
};
|
||||
// Third nonce instruction for fun and profit
|
||||
assert_eq!(state, NonceState::Initialized(meta, stored));
|
||||
assert_eq!(state, State::Initialized(data.clone()));
|
||||
with_test_keyed_account(42, false, |to_keyed| {
|
||||
let recent_blockhashes = create_test_recent_blockhashes(0);
|
||||
let withdraw_lamports = keyed_account.account.borrow().lamports;
|
||||
@@ -276,12 +275,12 @@ mod test {
|
||||
&signers,
|
||||
)
|
||||
.unwrap();
|
||||
// Empties NonceAccount balance
|
||||
// Empties Account balance
|
||||
assert_eq!(
|
||||
keyed_account.account.borrow().lamports,
|
||||
expect_nonce_lamports
|
||||
);
|
||||
// NonceAccount balance goes to `to`
|
||||
// Account balance goes to `to`
|
||||
assert_eq!(to_keyed.account.borrow().lamports, expect_to_lamports);
|
||||
})
|
||||
})
|
||||
@@ -293,19 +292,24 @@ mod test {
|
||||
lamports_per_byte_year: 42,
|
||||
..Rent::default()
|
||||
};
|
||||
let min_lamports = rent.minimum_balance(NonceState::size());
|
||||
let min_lamports = rent.minimum_balance(State::size());
|
||||
with_test_keyed_account(min_lamports + 42, true, |nonce_account| {
|
||||
let recent_blockhashes = create_test_recent_blockhashes(31);
|
||||
let stored = recent_blockhashes[0];
|
||||
let authorized = nonce_account.unsigned_key().clone();
|
||||
let meta = Meta::new(&authorized);
|
||||
let authority = nonce_account.unsigned_key().clone();
|
||||
nonce_account
|
||||
.initialize_nonce_account(&authorized, &recent_blockhashes, &rent)
|
||||
.initialize_nonce_account(&authority, &recent_blockhashes, &rent)
|
||||
.unwrap();
|
||||
let pubkey = nonce_account.account.borrow().owner.clone();
|
||||
let nonce_account = KeyedAccount::new(&pubkey, false, nonce_account.account);
|
||||
let state: NonceState = nonce_account.state().unwrap();
|
||||
assert_eq!(state, NonceState::Initialized(meta, stored));
|
||||
let state = AccountUtilsState::<Versions>::state(&nonce_account)
|
||||
.unwrap()
|
||||
.convert_to_current();
|
||||
let data = nonce::state::Data {
|
||||
authority,
|
||||
blockhash: recent_blockhashes[0].blockhash,
|
||||
fee_calculator: recent_blockhashes[0].fee_calculator.clone(),
|
||||
};
|
||||
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);
|
||||
@@ -319,7 +323,7 @@ mod test {
|
||||
lamports_per_byte_year: 42,
|
||||
..Rent::default()
|
||||
};
|
||||
let min_lamports = rent.minimum_balance(NonceState::size());
|
||||
let min_lamports = rent.minimum_balance(State::size());
|
||||
with_test_keyed_account(min_lamports + 42, true, |keyed_account| {
|
||||
let mut signers = HashSet::new();
|
||||
signers.insert(keyed_account.signer_key().unwrap().clone());
|
||||
@@ -340,7 +344,7 @@ mod test {
|
||||
lamports_per_byte_year: 42,
|
||||
..Rent::default()
|
||||
};
|
||||
let min_lamports = rent.minimum_balance(NonceState::size());
|
||||
let min_lamports = rent.minimum_balance(State::size());
|
||||
with_test_keyed_account(min_lamports + 42, true, |keyed_account| {
|
||||
let mut signers = HashSet::new();
|
||||
signers.insert(keyed_account.signer_key().unwrap().clone());
|
||||
@@ -360,7 +364,7 @@ mod test {
|
||||
lamports_per_byte_year: 42,
|
||||
..Rent::default()
|
||||
};
|
||||
let min_lamports = rent.minimum_balance(NonceState::size());
|
||||
let min_lamports = rent.minimum_balance(State::size());
|
||||
with_test_keyed_account(min_lamports + 42, true, |keyed_account| {
|
||||
let mut signers = HashSet::new();
|
||||
signers.insert(keyed_account.signer_key().unwrap().clone());
|
||||
@@ -376,7 +380,7 @@ mod test {
|
||||
lamports_per_byte_year: 42,
|
||||
..Rent::default()
|
||||
};
|
||||
let min_lamports = rent.minimum_balance(NonceState::size());
|
||||
let min_lamports = rent.minimum_balance(State::size());
|
||||
with_test_keyed_account(min_lamports + 42, true, |nonce_account| {
|
||||
with_test_keyed_account(42, true, |nonce_authority| {
|
||||
let mut signers = HashSet::new();
|
||||
@@ -401,7 +405,7 @@ mod test {
|
||||
lamports_per_byte_year: 42,
|
||||
..Rent::default()
|
||||
};
|
||||
let min_lamports = rent.minimum_balance(NonceState::size());
|
||||
let min_lamports = rent.minimum_balance(State::size());
|
||||
with_test_keyed_account(min_lamports + 42, true, |nonce_account| {
|
||||
with_test_keyed_account(42, false, |nonce_authority| {
|
||||
let mut signers = HashSet::new();
|
||||
@@ -423,10 +427,12 @@ mod test {
|
||||
lamports_per_byte_year: 42,
|
||||
..Rent::default()
|
||||
};
|
||||
let min_lamports = rent.minimum_balance(NonceState::size());
|
||||
let min_lamports = rent.minimum_balance(State::size());
|
||||
with_test_keyed_account(min_lamports + 42, true, |nonce_keyed| {
|
||||
let state: NonceState = nonce_keyed.state().unwrap();
|
||||
assert_eq!(state, NonceState::Uninitialized);
|
||||
let state = AccountUtilsState::<Versions>::state(nonce_keyed)
|
||||
.unwrap()
|
||||
.convert_to_current();
|
||||
assert_eq!(state, State::Uninitialized);
|
||||
with_test_keyed_account(42, false, |to_keyed| {
|
||||
let mut signers = HashSet::new();
|
||||
signers.insert(nonce_keyed.signer_key().unwrap().clone());
|
||||
@@ -444,13 +450,15 @@ mod test {
|
||||
&signers,
|
||||
)
|
||||
.unwrap();
|
||||
let state: NonceState = nonce_keyed.state().unwrap();
|
||||
let state = AccountUtilsState::<Versions>::state(nonce_keyed)
|
||||
.unwrap()
|
||||
.convert_to_current();
|
||||
// Withdraw instruction...
|
||||
// Deinitializes NonceAccount state
|
||||
assert_eq!(state, NonceState::Uninitialized);
|
||||
// Empties NonceAccount balance
|
||||
// Deinitializes Account state
|
||||
assert_eq!(state, State::Uninitialized);
|
||||
// Empties Account balance
|
||||
assert_eq!(nonce_keyed.account.borrow().lamports, expect_nonce_lamports);
|
||||
// NonceAccount balance goes to `to`
|
||||
// Account balance goes to `to`
|
||||
assert_eq!(to_keyed.account.borrow().lamports, expect_to_lamports);
|
||||
})
|
||||
})
|
||||
@@ -462,10 +470,12 @@ mod test {
|
||||
lamports_per_byte_year: 42,
|
||||
..Rent::default()
|
||||
};
|
||||
let min_lamports = rent.minimum_balance(NonceState::size());
|
||||
let min_lamports = rent.minimum_balance(State::size());
|
||||
with_test_keyed_account(min_lamports + 42, false, |nonce_keyed| {
|
||||
let state: NonceState = nonce_keyed.state().unwrap();
|
||||
assert_eq!(state, NonceState::Uninitialized);
|
||||
let state = AccountUtilsState::<Versions>::state(nonce_keyed)
|
||||
.unwrap()
|
||||
.convert_to_current();
|
||||
assert_eq!(state, State::Uninitialized);
|
||||
with_test_keyed_account(42, false, |to_keyed| {
|
||||
let signers = HashSet::new();
|
||||
let recent_blockhashes = create_test_recent_blockhashes(0);
|
||||
@@ -488,10 +498,12 @@ mod test {
|
||||
lamports_per_byte_year: 42,
|
||||
..Rent::default()
|
||||
};
|
||||
let min_lamports = rent.minimum_balance(NonceState::size());
|
||||
let min_lamports = rent.minimum_balance(State::size());
|
||||
with_test_keyed_account(min_lamports + 42, true, |nonce_keyed| {
|
||||
let state: NonceState = nonce_keyed.state().unwrap();
|
||||
assert_eq!(state, NonceState::Uninitialized);
|
||||
let state = AccountUtilsState::<Versions>::state(nonce_keyed)
|
||||
.unwrap()
|
||||
.convert_to_current();
|
||||
assert_eq!(state, State::Uninitialized);
|
||||
with_test_keyed_account(42, false, |to_keyed| {
|
||||
let mut signers = HashSet::new();
|
||||
signers.insert(nonce_keyed.signer_key().unwrap().clone());
|
||||
@@ -515,7 +527,7 @@ mod test {
|
||||
lamports_per_byte_year: 42,
|
||||
..Rent::default()
|
||||
};
|
||||
let min_lamports = rent.minimum_balance(NonceState::size());
|
||||
let min_lamports = rent.minimum_balance(State::size());
|
||||
with_test_keyed_account(min_lamports + 42, true, |nonce_keyed| {
|
||||
with_test_keyed_account(42, false, |to_keyed| {
|
||||
let mut signers = HashSet::new();
|
||||
@@ -534,8 +546,10 @@ mod test {
|
||||
&signers,
|
||||
)
|
||||
.unwrap();
|
||||
let state: NonceState = nonce_keyed.state().unwrap();
|
||||
assert_eq!(state, NonceState::Uninitialized);
|
||||
let state = AccountUtilsState::<Versions>::state(nonce_keyed)
|
||||
.unwrap()
|
||||
.convert_to_current();
|
||||
assert_eq!(state, State::Uninitialized);
|
||||
assert_eq!(nonce_keyed.account.borrow().lamports, nonce_expect_lamports);
|
||||
assert_eq!(to_keyed.account.borrow().lamports, to_expect_lamports);
|
||||
let withdraw_lamports = nonce_keyed.account.borrow().lamports;
|
||||
@@ -551,8 +565,10 @@ mod test {
|
||||
&signers,
|
||||
)
|
||||
.unwrap();
|
||||
let state: NonceState = nonce_keyed.state().unwrap();
|
||||
assert_eq!(state, NonceState::Uninitialized);
|
||||
let state = AccountUtilsState::<Versions>::state(nonce_keyed)
|
||||
.unwrap()
|
||||
.convert_to_current();
|
||||
assert_eq!(state, State::Uninitialized);
|
||||
assert_eq!(nonce_keyed.account.borrow().lamports, nonce_expect_lamports);
|
||||
assert_eq!(to_keyed.account.borrow().lamports, to_expect_lamports);
|
||||
})
|
||||
@@ -565,19 +581,24 @@ mod test {
|
||||
lamports_per_byte_year: 42,
|
||||
..Rent::default()
|
||||
};
|
||||
let min_lamports = rent.minimum_balance(NonceState::size());
|
||||
let min_lamports = rent.minimum_balance(State::size());
|
||||
with_test_keyed_account(min_lamports + 42, true, |nonce_keyed| {
|
||||
let mut signers = HashSet::new();
|
||||
signers.insert(nonce_keyed.signer_key().unwrap().clone());
|
||||
let recent_blockhashes = create_test_recent_blockhashes(31);
|
||||
let authorized = nonce_keyed.unsigned_key().clone();
|
||||
let meta = Meta::new(&authorized);
|
||||
let authority = nonce_keyed.unsigned_key().clone();
|
||||
nonce_keyed
|
||||
.initialize_nonce_account(&authorized, &recent_blockhashes, &rent)
|
||||
.initialize_nonce_account(&authority, &recent_blockhashes, &rent)
|
||||
.unwrap();
|
||||
let state: NonceState = nonce_keyed.state().unwrap();
|
||||
let stored = recent_blockhashes[0];
|
||||
assert_eq!(state, NonceState::Initialized(meta, stored));
|
||||
let state = AccountUtilsState::<Versions>::state(nonce_keyed)
|
||||
.unwrap()
|
||||
.convert_to_current();
|
||||
let data = nonce::state::Data {
|
||||
authority,
|
||||
blockhash: recent_blockhashes[0].blockhash,
|
||||
fee_calculator: recent_blockhashes[0].fee_calculator.clone(),
|
||||
};
|
||||
assert_eq!(state, State::Initialized(data.clone()));
|
||||
with_test_keyed_account(42, false, |to_keyed| {
|
||||
let withdraw_lamports = nonce_keyed.account.borrow().lamports - min_lamports;
|
||||
let nonce_expect_lamports =
|
||||
@@ -592,9 +613,15 @@ mod test {
|
||||
&signers,
|
||||
)
|
||||
.unwrap();
|
||||
let state: NonceState = nonce_keyed.state().unwrap();
|
||||
let stored = recent_blockhashes[0];
|
||||
assert_eq!(state, NonceState::Initialized(meta, stored));
|
||||
let state = AccountUtilsState::<Versions>::state(nonce_keyed)
|
||||
.unwrap()
|
||||
.convert_to_current();
|
||||
let data = nonce::state::Data {
|
||||
blockhash: recent_blockhashes[0].blockhash,
|
||||
fee_calculator: recent_blockhashes[0].fee_calculator.clone(),
|
||||
..data.clone()
|
||||
};
|
||||
assert_eq!(state, State::Initialized(data));
|
||||
assert_eq!(nonce_keyed.account.borrow().lamports, nonce_expect_lamports);
|
||||
assert_eq!(to_keyed.account.borrow().lamports, to_expect_lamports);
|
||||
let recent_blockhashes = create_test_recent_blockhashes(0);
|
||||
@@ -623,7 +650,7 @@ mod test {
|
||||
lamports_per_byte_year: 42,
|
||||
..Rent::default()
|
||||
};
|
||||
let min_lamports = rent.minimum_balance(NonceState::size());
|
||||
let min_lamports = rent.minimum_balance(State::size());
|
||||
with_test_keyed_account(min_lamports + 42, true, |nonce_keyed| {
|
||||
let recent_blockhashes = create_test_recent_blockhashes(0);
|
||||
let authorized = nonce_keyed.unsigned_key().clone();
|
||||
@@ -652,7 +679,7 @@ mod test {
|
||||
lamports_per_byte_year: 42,
|
||||
..Rent::default()
|
||||
};
|
||||
let min_lamports = rent.minimum_balance(NonceState::size());
|
||||
let min_lamports = rent.minimum_balance(State::size());
|
||||
with_test_keyed_account(min_lamports + 42, true, |nonce_keyed| {
|
||||
let recent_blockhashes = create_test_recent_blockhashes(95);
|
||||
let authorized = nonce_keyed.unsigned_key().clone();
|
||||
@@ -682,7 +709,7 @@ mod test {
|
||||
lamports_per_byte_year: 42,
|
||||
..Rent::default()
|
||||
};
|
||||
let min_lamports = rent.minimum_balance(NonceState::size());
|
||||
let min_lamports = rent.minimum_balance(State::size());
|
||||
with_test_keyed_account(min_lamports + 42, true, |nonce_keyed| {
|
||||
let recent_blockhashes = create_test_recent_blockhashes(95);
|
||||
let authorized = nonce_keyed.unsigned_key().clone();
|
||||
@@ -712,21 +739,28 @@ mod test {
|
||||
lamports_per_byte_year: 42,
|
||||
..Rent::default()
|
||||
};
|
||||
let min_lamports = rent.minimum_balance(NonceState::size());
|
||||
let min_lamports = rent.minimum_balance(State::size());
|
||||
with_test_keyed_account(min_lamports + 42, true, |keyed_account| {
|
||||
let state: NonceState = keyed_account.state().unwrap();
|
||||
assert_eq!(state, NonceState::Uninitialized);
|
||||
let state = AccountUtilsState::<Versions>::state(keyed_account)
|
||||
.unwrap()
|
||||
.convert_to_current();
|
||||
assert_eq!(state, State::Uninitialized);
|
||||
let mut signers = HashSet::new();
|
||||
signers.insert(keyed_account.signer_key().unwrap().clone());
|
||||
let recent_blockhashes = create_test_recent_blockhashes(0);
|
||||
let stored = recent_blockhashes[0];
|
||||
let authorized = keyed_account.unsigned_key().clone();
|
||||
let meta = Meta::new(&authorized);
|
||||
let authority = keyed_account.unsigned_key().clone();
|
||||
let result =
|
||||
keyed_account.initialize_nonce_account(&authorized, &recent_blockhashes, &rent);
|
||||
keyed_account.initialize_nonce_account(&authority, &recent_blockhashes, &rent);
|
||||
let data = nonce::state::Data {
|
||||
authority,
|
||||
blockhash: recent_blockhashes[0].blockhash,
|
||||
fee_calculator: recent_blockhashes[0].fee_calculator.clone(),
|
||||
};
|
||||
assert_eq!(result, Ok(()));
|
||||
let state: NonceState = keyed_account.state().unwrap();
|
||||
assert_eq!(state, NonceState::Initialized(meta, stored));
|
||||
let state = AccountUtilsState::<Versions>::state(keyed_account)
|
||||
.unwrap()
|
||||
.convert_to_current();
|
||||
assert_eq!(state, State::Initialized(data));
|
||||
})
|
||||
}
|
||||
|
||||
@@ -736,7 +770,7 @@ mod test {
|
||||
lamports_per_byte_year: 42,
|
||||
..Rent::default()
|
||||
};
|
||||
let min_lamports = rent.minimum_balance(NonceState::size());
|
||||
let min_lamports = rent.minimum_balance(State::size());
|
||||
with_test_keyed_account(min_lamports + 42, true, |keyed_account| {
|
||||
let mut signers = HashSet::new();
|
||||
signers.insert(keyed_account.signer_key().unwrap().clone());
|
||||
@@ -754,7 +788,7 @@ mod test {
|
||||
lamports_per_byte_year: 42,
|
||||
..Rent::default()
|
||||
};
|
||||
let min_lamports = rent.minimum_balance(NonceState::size());
|
||||
let min_lamports = rent.minimum_balance(State::size());
|
||||
with_test_keyed_account(min_lamports + 42, true, |keyed_account| {
|
||||
let recent_blockhashes = create_test_recent_blockhashes(31);
|
||||
let authorized = keyed_account.unsigned_key().clone();
|
||||
@@ -774,7 +808,7 @@ mod test {
|
||||
lamports_per_byte_year: 42,
|
||||
..Rent::default()
|
||||
};
|
||||
let min_lamports = rent.minimum_balance(NonceState::size());
|
||||
let min_lamports = rent.minimum_balance(State::size());
|
||||
with_test_keyed_account(min_lamports - 42, true, |keyed_account| {
|
||||
let recent_blockhashes = create_test_recent_blockhashes(63);
|
||||
let authorized = keyed_account.unsigned_key().clone();
|
||||
@@ -790,22 +824,27 @@ mod test {
|
||||
lamports_per_byte_year: 42,
|
||||
..Rent::default()
|
||||
};
|
||||
let min_lamports = rent.minimum_balance(NonceState::size());
|
||||
let min_lamports = rent.minimum_balance(State::size());
|
||||
with_test_keyed_account(min_lamports + 42, true, |nonce_account| {
|
||||
let mut signers = HashSet::new();
|
||||
signers.insert(nonce_account.signer_key().unwrap().clone());
|
||||
let recent_blockhashes = create_test_recent_blockhashes(31);
|
||||
let stored = recent_blockhashes[0];
|
||||
let authorized = nonce_account.unsigned_key().clone();
|
||||
nonce_account
|
||||
.initialize_nonce_account(&authorized, &recent_blockhashes, &rent)
|
||||
.unwrap();
|
||||
let authorized = &Pubkey::default().clone();
|
||||
let meta = Meta::new(&authorized);
|
||||
let authority = Pubkey::default();
|
||||
let data = nonce::state::Data {
|
||||
authority,
|
||||
blockhash: recent_blockhashes[0].blockhash,
|
||||
fee_calculator: recent_blockhashes[0].fee_calculator.clone(),
|
||||
};
|
||||
let result = nonce_account.authorize_nonce_account(&Pubkey::default(), &signers);
|
||||
assert_eq!(result, Ok(()));
|
||||
let state: NonceState = nonce_account.state().unwrap();
|
||||
assert_eq!(state, NonceState::Initialized(meta, stored));
|
||||
let state = AccountUtilsState::<Versions>::state(nonce_account)
|
||||
.unwrap()
|
||||
.convert_to_current();
|
||||
assert_eq!(state, State::Initialized(data));
|
||||
})
|
||||
}
|
||||
|
||||
@@ -815,7 +854,7 @@ mod test {
|
||||
lamports_per_byte_year: 42,
|
||||
..Rent::default()
|
||||
};
|
||||
let min_lamports = rent.minimum_balance(NonceState::size());
|
||||
let min_lamports = rent.minimum_balance(State::size());
|
||||
with_test_keyed_account(min_lamports + 42, true, |nonce_account| {
|
||||
let mut signers = HashSet::new();
|
||||
signers.insert(nonce_account.signer_key().unwrap().clone());
|
||||
@@ -830,7 +869,7 @@ mod test {
|
||||
lamports_per_byte_year: 42,
|
||||
..Rent::default()
|
||||
};
|
||||
let min_lamports = rent.minimum_balance(NonceState::size());
|
||||
let min_lamports = rent.minimum_balance(State::size());
|
||||
with_test_keyed_account(min_lamports + 42, true, |nonce_account| {
|
||||
let mut signers = HashSet::new();
|
||||
signers.insert(nonce_account.signer_key().unwrap().clone());
|
4
sdk/src/nonce/mod.rs
Normal file
4
sdk/src/nonce/mod.rs
Normal file
@@ -0,0 +1,4 @@
|
||||
pub mod account;
|
||||
pub use account::{create_account, Account};
|
||||
pub mod state;
|
||||
pub use state::State;
|
39
sdk/src/nonce/state/current.rs
Normal file
39
sdk/src/nonce/state/current.rs
Normal file
@@ -0,0 +1,39 @@
|
||||
use super::Versions;
|
||||
use crate::{fee_calculator::FeeCalculator, hash::Hash, pubkey::Pubkey};
|
||||
use serde_derive::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Debug, Default, Serialize, Deserialize, PartialEq, Clone)]
|
||||
pub struct Data {
|
||||
pub authority: Pubkey,
|
||||
pub blockhash: Hash,
|
||||
pub fee_calculator: FeeCalculator,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, PartialEq, Clone)]
|
||||
pub enum State {
|
||||
Uninitialized,
|
||||
Initialized(Data),
|
||||
}
|
||||
|
||||
impl Default for State {
|
||||
fn default() -> Self {
|
||||
State::Uninitialized
|
||||
}
|
||||
}
|
||||
|
||||
impl State {
|
||||
pub fn size() -> usize {
|
||||
let data = Versions::new_current(State::Initialized(Data::default()));
|
||||
bincode::serialized_size(&data).unwrap() as usize
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn default_is_uninitialized() {
|
||||
assert_eq!(State::default(), State::Uninitialized)
|
||||
}
|
||||
}
|
21
sdk/src/nonce/state/mod.rs
Normal file
21
sdk/src/nonce/state/mod.rs
Normal file
@@ -0,0 +1,21 @@
|
||||
mod current;
|
||||
pub use current::{Data, State};
|
||||
|
||||
use serde_derive::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, PartialEq, Clone)]
|
||||
pub enum Versions {
|
||||
Current(Box<State>),
|
||||
}
|
||||
|
||||
impl Versions {
|
||||
pub fn new_current(state: State) -> Self {
|
||||
Self::Current(Box::new(state))
|
||||
}
|
||||
|
||||
pub fn convert_to_current(self) -> State {
|
||||
match self {
|
||||
Self::Current(state) => *state,
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,7 +1,7 @@
|
||||
use crate::{
|
||||
hash::hashv,
|
||||
instruction::{AccountMeta, Instruction, WithSigner},
|
||||
nonce_state::NonceState,
|
||||
nonce,
|
||||
program_utils::DecodeError,
|
||||
pubkey::Pubkey,
|
||||
system_program,
|
||||
@@ -322,7 +322,7 @@ pub fn create_nonce_account_with_seed(
|
||||
base,
|
||||
seed,
|
||||
lamports,
|
||||
NonceState::size() as u64,
|
||||
nonce::State::size() as u64,
|
||||
&system_program::id(),
|
||||
),
|
||||
Instruction::new(
|
||||
@@ -348,7 +348,7 @@ pub fn create_nonce_account(
|
||||
from_pubkey,
|
||||
nonce_pubkey,
|
||||
lamports,
|
||||
NonceState::size() as u64,
|
||||
nonce::State::size() as u64,
|
||||
&system_program::id(),
|
||||
),
|
||||
Instruction::new(
|
||||
|
@@ -1,21 +1,61 @@
|
||||
use crate::{
|
||||
account::Account,
|
||||
declare_sysvar_id,
|
||||
fee_calculator::FeeCalculator,
|
||||
hash::{hash, Hash},
|
||||
sysvar::Sysvar,
|
||||
};
|
||||
use bincode::serialize;
|
||||
use std::{collections::BinaryHeap, iter::FromIterator, ops::Deref};
|
||||
use std::{cmp::Ordering, collections::BinaryHeap, iter::FromIterator, ops::Deref};
|
||||
|
||||
const MAX_ENTRIES: usize = 32;
|
||||
|
||||
crate::declare_sysvar_id!(
|
||||
declare_sysvar_id!(
|
||||
"SysvarRecentB1ockHashes11111111111111111111",
|
||||
RecentBlockhashes
|
||||
);
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Serialize, Deserialize, Debug, PartialEq)]
|
||||
pub struct RecentBlockhashes(Vec<Hash>);
|
||||
#[derive(Serialize, Deserialize, Clone, Debug, Default, PartialEq)]
|
||||
pub struct Entry {
|
||||
pub blockhash: Hash,
|
||||
pub fee_calculator: FeeCalculator,
|
||||
}
|
||||
|
||||
impl Entry {
|
||||
pub fn new(blockhash: &Hash, fee_calculator: &FeeCalculator) -> Self {
|
||||
Self {
|
||||
blockhash: *blockhash,
|
||||
fee_calculator: fee_calculator.clone(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct IterItem<'a>(pub u64, pub &'a Hash, pub &'a FeeCalculator);
|
||||
|
||||
impl<'a> Eq for IterItem<'a> {}
|
||||
|
||||
impl<'a> PartialEq for IterItem<'a> {
|
||||
fn eq(&self, other: &Self) -> bool {
|
||||
self.0 == other.0
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Ord for IterItem<'a> {
|
||||
fn cmp(&self, other: &Self) -> Ordering {
|
||||
self.0.cmp(&other.0)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> PartialOrd for IterItem<'a> {
|
||||
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
|
||||
Some(self.cmp(other))
|
||||
}
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
|
||||
pub struct RecentBlockhashes(Vec<Entry>);
|
||||
|
||||
impl Default for RecentBlockhashes {
|
||||
fn default() -> Self {
|
||||
@@ -23,14 +63,14 @@ impl Default for RecentBlockhashes {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> FromIterator<&'a Hash> for RecentBlockhashes {
|
||||
impl<'a> FromIterator<IterItem<'a>> for RecentBlockhashes {
|
||||
fn from_iter<I>(iter: I) -> Self
|
||||
where
|
||||
I: IntoIterator<Item = &'a Hash>,
|
||||
I: IntoIterator<Item = IterItem<'a>>,
|
||||
{
|
||||
let mut new = Self::default();
|
||||
for i in iter {
|
||||
new.0.push(*i)
|
||||
new.0.push(Entry::new(i.1, i.2))
|
||||
}
|
||||
new
|
||||
}
|
||||
@@ -67,12 +107,12 @@ impl<T: Ord> Iterator for IntoIterSorted<T> {
|
||||
impl Sysvar for RecentBlockhashes {
|
||||
fn size_of() -> usize {
|
||||
// hard-coded so that we don't have to construct an empty
|
||||
1032 // golden, update if MAX_ENTRIES changes
|
||||
1288 // golden, update if MAX_ENTRIES changes
|
||||
}
|
||||
}
|
||||
|
||||
impl Deref for RecentBlockhashes {
|
||||
type Target = Vec<Hash>;
|
||||
type Target = Vec<Entry>;
|
||||
fn deref(&self) -> &Self::Target {
|
||||
&self.0
|
||||
}
|
||||
@@ -84,18 +124,18 @@ pub fn create_account(lamports: u64) -> Account {
|
||||
|
||||
pub fn update_account<'a, I>(account: &mut Account, recent_blockhash_iter: I) -> Option<()>
|
||||
where
|
||||
I: IntoIterator<Item = (u64, &'a Hash)>,
|
||||
I: IntoIterator<Item = IterItem<'a>>,
|
||||
{
|
||||
let sorted = BinaryHeap::from_iter(recent_blockhash_iter);
|
||||
let sorted_iter = IntoIterSorted { inner: sorted };
|
||||
let recent_blockhash_iter = sorted_iter.take(MAX_ENTRIES).map(|(_, hash)| hash);
|
||||
let recent_blockhash_iter = sorted_iter.take(MAX_ENTRIES);
|
||||
let recent_blockhashes = RecentBlockhashes::from_iter(recent_blockhash_iter);
|
||||
recent_blockhashes.to_account(account)
|
||||
}
|
||||
|
||||
pub fn create_account_with_data<'a, I>(lamports: u64, recent_blockhash_iter: I) -> Account
|
||||
where
|
||||
I: IntoIterator<Item = (u64, &'a Hash)>,
|
||||
I: IntoIterator<Item = IterItem<'a>>,
|
||||
{
|
||||
let mut account = create_account(lamports);
|
||||
update_account(&mut account, recent_blockhash_iter).unwrap();
|
||||
@@ -103,10 +143,20 @@ where
|
||||
}
|
||||
|
||||
pub fn create_test_recent_blockhashes(start: usize) -> RecentBlockhashes {
|
||||
let bhq: Vec<_> = (start..start + (MAX_ENTRIES - 1))
|
||||
.map(|i| hash(&serialize(&i).unwrap()))
|
||||
let blocks: Vec<_> = (start..start + MAX_ENTRIES)
|
||||
.map(|i| {
|
||||
(
|
||||
i as u64,
|
||||
hash(&bincode::serialize(&i).unwrap()),
|
||||
FeeCalculator::new(i as u64 * 100),
|
||||
)
|
||||
})
|
||||
.collect();
|
||||
RecentBlockhashes::from_iter(bhq.iter())
|
||||
let bhq: Vec<_> = blocks
|
||||
.iter()
|
||||
.map(|(i, hash, fee_calc)| IterItem(*i, hash, fee_calc))
|
||||
.collect();
|
||||
RecentBlockhashes::from_iter(bhq.into_iter())
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
@@ -118,9 +168,10 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_size_of() {
|
||||
let entry = Entry::new(&Hash::default(), &FeeCalculator::default());
|
||||
assert_eq!(
|
||||
bincode::serialized_size(&RecentBlockhashes(vec![Hash::default(); MAX_ENTRIES]))
|
||||
.unwrap() as usize,
|
||||
bincode::serialized_size(&RecentBlockhashes(vec![entry; MAX_ENTRIES])).unwrap()
|
||||
as usize,
|
||||
RecentBlockhashes::size_of()
|
||||
);
|
||||
}
|
||||
@@ -135,8 +186,11 @@ mod tests {
|
||||
#[test]
|
||||
fn test_create_account_full() {
|
||||
let def_hash = Hash::default();
|
||||
let account =
|
||||
create_account_with_data(42, vec![(0u64, &def_hash); MAX_ENTRIES].into_iter());
|
||||
let def_fees = FeeCalculator::default();
|
||||
let account = create_account_with_data(
|
||||
42,
|
||||
vec![IterItem(0u64, &def_hash, &def_fees); MAX_ENTRIES].into_iter(),
|
||||
);
|
||||
let recent_blockhashes = RecentBlockhashes::from_account(&account).unwrap();
|
||||
assert_eq!(recent_blockhashes.len(), MAX_ENTRIES);
|
||||
}
|
||||
@@ -144,15 +198,19 @@ mod tests {
|
||||
#[test]
|
||||
fn test_create_account_truncate() {
|
||||
let def_hash = Hash::default();
|
||||
let account =
|
||||
create_account_with_data(42, vec![(0u64, &def_hash); MAX_ENTRIES + 1].into_iter());
|
||||
let def_fees = FeeCalculator::default();
|
||||
let account = create_account_with_data(
|
||||
42,
|
||||
vec![IterItem(0u64, &def_hash, &def_fees); MAX_ENTRIES + 1].into_iter(),
|
||||
);
|
||||
let recent_blockhashes = RecentBlockhashes::from_account(&account).unwrap();
|
||||
assert_eq!(recent_blockhashes.len(), MAX_ENTRIES);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_create_account_unsorted() {
|
||||
let mut unsorted_recent_blockhashes: Vec<_> = (0..MAX_ENTRIES)
|
||||
let def_fees = FeeCalculator::default();
|
||||
let mut unsorted_blocks: Vec<_> = (0..MAX_ENTRIES)
|
||||
.map(|i| {
|
||||
(i as u64, {
|
||||
// create hash with visibly recognizable ordering
|
||||
@@ -162,20 +220,26 @@ mod tests {
|
||||
})
|
||||
})
|
||||
.collect();
|
||||
unsorted_recent_blockhashes.shuffle(&mut thread_rng());
|
||||
unsorted_blocks.shuffle(&mut thread_rng());
|
||||
|
||||
let account = create_account_with_data(
|
||||
42,
|
||||
unsorted_recent_blockhashes
|
||||
unsorted_blocks
|
||||
.iter()
|
||||
.map(|(i, hash)| (*i, hash)),
|
||||
.map(|(i, hash)| IterItem(*i, hash, &def_fees)),
|
||||
);
|
||||
let recent_blockhashes = RecentBlockhashes::from_account(&account).unwrap();
|
||||
|
||||
let mut expected_recent_blockhashes: Vec<_> =
|
||||
(unsorted_recent_blockhashes.into_iter().map(|(_, b)| b)).collect();
|
||||
expected_recent_blockhashes.sort();
|
||||
expected_recent_blockhashes.reverse();
|
||||
let mut unsorted_recent_blockhashes: Vec<_> = unsorted_blocks
|
||||
.iter()
|
||||
.map(|(i, hash)| IterItem(*i, hash, &def_fees))
|
||||
.collect();
|
||||
unsorted_recent_blockhashes.sort();
|
||||
unsorted_recent_blockhashes.reverse();
|
||||
let expected_recent_blockhashes: Vec<_> = (unsorted_recent_blockhashes
|
||||
.into_iter()
|
||||
.map(|IterItem(_, b, f)| Entry::new(b, f)))
|
||||
.collect();
|
||||
|
||||
assert_eq!(*recent_blockhashes, expected_recent_blockhashes);
|
||||
}
|
||||
|
Reference in New Issue
Block a user