@ -921,10 +921,10 @@ mod tests {
|
||||
nonce.pubkey(),
|
||||
Account::new_data(
|
||||
min_balance * 2,
|
||||
&nonce::State::Initialized(
|
||||
nonce::state::Meta::new(&Pubkey::default()),
|
||||
Hash::default(),
|
||||
),
|
||||
&nonce::State::Initialized(nonce::state::Data {
|
||||
authority: Pubkey::default(),
|
||||
blockhash: Hash::default(),
|
||||
}),
|
||||
&system_program::id(),
|
||||
)
|
||||
.unwrap(),
|
||||
|
@ -3417,10 +3417,10 @@ mod tests {
|
||||
let nonce = Keypair::new();
|
||||
let nonce_account = Account::new_data(
|
||||
min_balance + 42,
|
||||
&nonce::State::Initialized(
|
||||
nonce::state::Meta::new(&Pubkey::default()),
|
||||
Hash::default(),
|
||||
),
|
||||
&nonce::State::Initialized(nonce::state::Data {
|
||||
authority: Pubkey::default(),
|
||||
blockhash: Hash::default(),
|
||||
}),
|
||||
&system_program::id(),
|
||||
)
|
||||
.unwrap();
|
||||
@ -5101,7 +5101,7 @@ mod tests {
|
||||
let state =
|
||||
StateMut::<nonce::state::Versions>::state(&acc).map(|v| v.convert_to_current());
|
||||
match state {
|
||||
Ok(nonce::State::Initialized(_meta, hash)) => Some(hash),
|
||||
Ok(nonce::State::Initialized(ref data)) => Some(data.blockhash),
|
||||
_ => None,
|
||||
}
|
||||
})
|
||||
@ -5276,10 +5276,10 @@ mod tests {
|
||||
let nonce = Keypair::new();
|
||||
let nonce_account = Account::new_data(
|
||||
42424242,
|
||||
&nonce::State::Initialized(
|
||||
nonce::state::Meta::new(&Pubkey::default()),
|
||||
Hash::default(),
|
||||
),
|
||||
&nonce::State::Initialized(nonce::state::Data {
|
||||
authority: Pubkey::default(),
|
||||
blockhash: Hash::default(),
|
||||
}),
|
||||
&system_program::id(),
|
||||
)
|
||||
.unwrap();
|
||||
|
@ -3,7 +3,7 @@ use solana_sdk::{
|
||||
account_utils::StateMut,
|
||||
hash::Hash,
|
||||
instruction::CompiledInstruction,
|
||||
nonce::{state::Versions, State},
|
||||
nonce::{self, state::Versions, State},
|
||||
program_utils::limited_deserialize,
|
||||
pubkey::Pubkey,
|
||||
system_instruction::SystemInstruction,
|
||||
@ -40,7 +40,7 @@ pub fn get_nonce_pubkey_from_instruction<'a>(
|
||||
|
||||
pub fn verify_nonce_account(acc: &Account, hash: &Hash) -> bool {
|
||||
match StateMut::<Versions>::state(acc).map(|v| v.convert_to_current()) {
|
||||
Ok(State::Initialized(_meta, ref nonce)) => hash == nonce,
|
||||
Ok(State::Initialized(ref data)) => *hash == data.blockhash,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
@ -63,8 +63,11 @@ pub fn prepare_if_nonce_account(
|
||||
let state = StateMut::<Versions>::state(nonce_acc)
|
||||
.unwrap()
|
||||
.convert_to_current();
|
||||
if let State::Initialized(meta, _) = state {
|
||||
let new_data = Versions::new_current(State::Initialized(meta, *last_blockhash));
|
||||
if let State::Initialized(ref data) = state {
|
||||
let new_data = Versions::new_current(State::Initialized(nonce::state::Data {
|
||||
blockhash: *last_blockhash,
|
||||
..*data
|
||||
}));
|
||||
account.set_state(&new_data).unwrap();
|
||||
}
|
||||
}
|
||||
@ -79,7 +82,7 @@ mod tests {
|
||||
account_utils::State as AccountUtilsState,
|
||||
hash::Hash,
|
||||
instruction::InstructionError,
|
||||
nonce::{self, account::with_test_keyed_account, Account as NonceAccount},
|
||||
nonce::{self, account::with_test_keyed_account, Account as NonceAccount, State},
|
||||
pubkey::Pubkey,
|
||||
signature::{Keypair, Signer},
|
||||
system_instruction,
|
||||
@ -241,10 +244,10 @@ mod tests {
|
||||
}
|
||||
|
||||
fn create_accounts_prepare_if_nonce_account() -> (Pubkey, Account, Account, Hash) {
|
||||
let data = Versions::new_current(State::Initialized(
|
||||
nonce::state::Meta::new(&Pubkey::default()),
|
||||
Hash::default(),
|
||||
));
|
||||
let data = Versions::new_current(State::Initialized(nonce::state::Data {
|
||||
authority: Pubkey::default(),
|
||||
blockhash: Hash::default(),
|
||||
}));
|
||||
let account = Account::new_data(42, &data, &system_program::id()).unwrap();
|
||||
let pre_account = Account {
|
||||
lamports: 43,
|
||||
@ -296,10 +299,10 @@ mod tests {
|
||||
let post_account_pubkey = pre_account_pubkey;
|
||||
|
||||
let mut expect_account = post_account.clone();
|
||||
let data = Versions::new_current(State::Initialized(
|
||||
nonce::state::Meta::new(&Pubkey::default()),
|
||||
last_blockhash,
|
||||
));
|
||||
let data = Versions::new_current(State::Initialized(nonce::state::Data {
|
||||
authority: Pubkey::default(),
|
||||
blockhash: last_blockhash,
|
||||
}));
|
||||
expect_account.set_state(&data).unwrap();
|
||||
|
||||
assert!(run_prepare_if_nonce_account_test(
|
||||
@ -356,8 +359,10 @@ mod tests {
|
||||
let mut expect_account = pre_account.clone();
|
||||
expect_account
|
||||
.set_state(&Versions::new_current(State::Initialized(
|
||||
nonce::state::Meta::new(&Pubkey::default()),
|
||||
last_blockhash,
|
||||
nonce::state::Data {
|
||||
authority: Pubkey::default(),
|
||||
blockhash: last_blockhash,
|
||||
},
|
||||
)))
|
||||
.unwrap();
|
||||
|
||||
|
@ -306,7 +306,7 @@ pub fn get_system_account_kind(account: &Account) -> Option<SystemAccountKind> {
|
||||
if system_program::check_id(&account.owner) {
|
||||
if account.data.is_empty() {
|
||||
Some(SystemAccountKind::System)
|
||||
} else if let Ok(nonce::State::Initialized(_, _)) = account.state() {
|
||||
} else if let Ok(nonce::State::Initialized(_)) = account.state() {
|
||||
Some(SystemAccountKind::Nonce)
|
||||
} else {
|
||||
None
|
||||
@ -733,10 +733,10 @@ mod tests {
|
||||
let nonce = Pubkey::new_rand();
|
||||
let nonce_account = Account::new_ref_data(
|
||||
42,
|
||||
&nonce::State::Initialized(
|
||||
nonce::state::Meta::new(&Pubkey::default()),
|
||||
Hash::default(),
|
||||
),
|
||||
&nonce::State::Initialized(nonce::state::Data {
|
||||
authority: Pubkey::default(),
|
||||
blockhash: Hash::default(),
|
||||
}),
|
||||
&system_program::id(),
|
||||
)
|
||||
.unwrap();
|
||||
@ -875,7 +875,10 @@ mod tests {
|
||||
let from = Pubkey::new_rand();
|
||||
let from_account = Account::new_ref_data(
|
||||
100,
|
||||
&nonce::State::Initialized(nonce::state::Meta::new(&from), Hash::default()),
|
||||
&nonce::State::Initialized(nonce::state::Data {
|
||||
authority: from,
|
||||
blockhash: Hash::default(),
|
||||
}),
|
||||
&system_program::id(),
|
||||
)
|
||||
.unwrap();
|
||||
@ -1368,10 +1371,10 @@ mod tests {
|
||||
fn test_get_system_account_kind_nonce_ok() {
|
||||
let nonce_account = Account::new_data(
|
||||
42,
|
||||
&nonce::State::Initialized(
|
||||
nonce::state::Meta::new(&Pubkey::default()),
|
||||
Hash::default(),
|
||||
),
|
||||
&nonce::State::Initialized(nonce::state::Data {
|
||||
authority: Pubkey::default(),
|
||||
blockhash: Hash::default(),
|
||||
}),
|
||||
&system_program::id(),
|
||||
)
|
||||
.unwrap();
|
||||
@ -1399,10 +1402,10 @@ mod tests {
|
||||
fn test_get_system_account_kind_nonsystem_owner_with_nonce_data_fail() {
|
||||
let nonce_account = Account::new_data(
|
||||
42,
|
||||
&nonce::State::Initialized(
|
||||
nonce::state::Meta::new(&Pubkey::default()),
|
||||
Hash::default(),
|
||||
),
|
||||
&nonce::State::Initialized(nonce::state::Data {
|
||||
authority: Pubkey::default(),
|
||||
blockhash: Hash::default(),
|
||||
}),
|
||||
&Pubkey::new_rand(),
|
||||
)
|
||||
.unwrap();
|
||||
|
Reference in New Issue
Block a user