@ -122,7 +122,7 @@ fn test_proof_bounds() {
|
|||||||
Hash::default(),
|
Hash::default(),
|
||||||
);
|
);
|
||||||
// the proof is for segment 0, need to move the slot into segment 2
|
// the proof is for segment 0, need to move the slot into segment 2
|
||||||
let mut current_account = current::create_account(1);
|
let mut current_account = current::create_account(1, 0, 0, 0);
|
||||||
Current::to(
|
Current::to(
|
||||||
&Current {
|
&Current {
|
||||||
slot: SLOTS_PER_SEGMENT * 2,
|
slot: SLOTS_PER_SEGMENT * 2,
|
||||||
@ -152,7 +152,7 @@ fn test_serialize_overflow() {
|
|||||||
let tick_pubkey = Pubkey::new_rand();
|
let tick_pubkey = Pubkey::new_rand();
|
||||||
let mut keyed_accounts = Vec::new();
|
let mut keyed_accounts = Vec::new();
|
||||||
let mut user_account = Account::default();
|
let mut user_account = Account::default();
|
||||||
let mut current_account = current::create_account(1);
|
let mut current_account = current::create_account(1, 0, 0, 0);
|
||||||
keyed_accounts.push(KeyedAccount::new(&pubkey, true, &mut user_account));
|
keyed_accounts.push(KeyedAccount::new(&pubkey, true, &mut user_account));
|
||||||
keyed_accounts.push(KeyedAccount::new(&tick_pubkey, false, &mut current_account));
|
keyed_accounts.push(KeyedAccount::new(&tick_pubkey, false, &mut current_account));
|
||||||
|
|
||||||
@ -181,7 +181,7 @@ fn test_invalid_accounts_len() {
|
|||||||
Hash::default(),
|
Hash::default(),
|
||||||
);
|
);
|
||||||
// move tick height into segment 1
|
// move tick height into segment 1
|
||||||
let mut current_account = current::create_account(1);
|
let mut current_account = current::create_account(1, 0, 0, 0);
|
||||||
Current::to(
|
Current::to(
|
||||||
&Current {
|
&Current {
|
||||||
slot: 16,
|
slot: 16,
|
||||||
@ -240,7 +240,7 @@ fn test_submit_mining_ok() {
|
|||||||
Hash::default(),
|
Hash::default(),
|
||||||
);
|
);
|
||||||
// move slot into segment 1
|
// move slot into segment 1
|
||||||
let mut current_account = current::create_account(1);
|
let mut current_account = current::create_account(1, 0, 0, 0);
|
||||||
Current::to(
|
Current::to(
|
||||||
&Current {
|
&Current {
|
||||||
slot: SLOTS_PER_SEGMENT,
|
slot: SLOTS_PER_SEGMENT,
|
||||||
|
@ -32,7 +32,7 @@ use solana_sdk::inflation::Inflation;
|
|||||||
use solana_sdk::native_loader;
|
use solana_sdk::native_loader;
|
||||||
use solana_sdk::pubkey::Pubkey;
|
use solana_sdk::pubkey::Pubkey;
|
||||||
use solana_sdk::signature::{Keypair, Signature};
|
use solana_sdk::signature::{Keypair, Signature};
|
||||||
use solana_sdk::syscall::current::{self, Current};
|
use solana_sdk::syscall::current;
|
||||||
use solana_sdk::syscall::fees::{self, Fees};
|
use solana_sdk::syscall::fees::{self, Fees};
|
||||||
use solana_sdk::syscall::slot_hashes::{self, SlotHashes};
|
use solana_sdk::syscall::slot_hashes::{self, SlotHashes};
|
||||||
use solana_sdk::syscall::tick_height::{self, TickHeight};
|
use solana_sdk::syscall::tick_height::{self, TickHeight};
|
||||||
@ -402,15 +402,15 @@ impl Bank {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn update_current(&self) {
|
fn update_current(&self) {
|
||||||
let mut account = current::create_account(1);
|
self.store_account(
|
||||||
let current = Current {
|
¤t::id(),
|
||||||
slot: self.slot,
|
¤t::create_account(
|
||||||
epoch: self.epoch_schedule.get_epoch(self.slot),
|
1,
|
||||||
stakers_epoch: self.epoch_schedule.get_stakers_epoch(self.slot),
|
self.slot,
|
||||||
};
|
self.epoch_schedule.get_epoch(self.slot),
|
||||||
current.to(&mut account).unwrap();
|
self.epoch_schedule.get_stakers_epoch(self.slot),
|
||||||
|
),
|
||||||
self.store_account(¤t::id(), &account);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn update_slot_hashes(&self) {
|
fn update_slot_hashes(&self) {
|
||||||
|
@ -46,6 +46,20 @@ impl Account {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn new_data<T: serde::Serialize>(
|
||||||
|
lamports: u64,
|
||||||
|
state: &T,
|
||||||
|
owner: &Pubkey,
|
||||||
|
) -> Result<Account, bincode::Error> {
|
||||||
|
let data = bincode::serialize(state)?;
|
||||||
|
Ok(Account {
|
||||||
|
lamports,
|
||||||
|
data,
|
||||||
|
owner: *owner,
|
||||||
|
executable: false,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
pub fn deserialize_data<T: serde::de::DeserializeOwned>(&self) -> Result<T, bincode::Error> {
|
pub fn deserialize_data<T: serde::de::DeserializeOwned>(&self) -> Result<T, bincode::Error> {
|
||||||
bincode::deserialize(&self.data)
|
bincode::deserialize(&self.data)
|
||||||
}
|
}
|
||||||
|
@ -32,8 +32,17 @@ impl Current {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn create_account(lamports: u64) -> Account {
|
pub fn create_account(lamports: u64, slot: u64, epoch: u64, stakers_epoch: u64) -> Account {
|
||||||
Account::new(lamports, Current::size_of(), &syscall::id())
|
Account::new_data(
|
||||||
|
lamports,
|
||||||
|
&Current {
|
||||||
|
slot,
|
||||||
|
epoch,
|
||||||
|
stakers_epoch,
|
||||||
|
},
|
||||||
|
&syscall::id(),
|
||||||
|
)
|
||||||
|
.unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
@ -42,7 +51,7 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_create_account() {
|
fn test_create_account() {
|
||||||
let account = create_account(1);
|
let account = create_account(1, 0, 0, 0);
|
||||||
let current = Current::from(&account).unwrap();
|
let current = Current::from(&account).unwrap();
|
||||||
assert_eq!(current, Current::default());
|
assert_eq!(current, Current::default());
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user