Skip to content

Commit 132e0f9

Browse files
committed
SlotHistory sysvar/call assertion
1 parent d6aad92 commit 132e0f9

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

  • programs/sbf/rust/sysvar/src

programs/sbf/rust/sysvar/src/lib.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,24 @@ pub fn process_instruction(
124124
assert_eq!(rent, sgs_rent);
125125
}
126126

127+
// Slot History
128+
{
129+
msg!("SlotHistory identifier:");
130+
sysvar::slot_history::id().log();
131+
// SlotHistory exceeds the default SBF heap, so inspecting without deserializing.
132+
// Its final `u64` field is `next_slot`.
133+
assert_eq!(accounts[8].data_len(), solana_sysvar::slot_history::SIZE);
134+
let data = accounts[8].data.borrow();
135+
let next_slot = u64::from_le_bytes(*data.last_chunk().unwrap());
136+
assert_eq!(next_slot, Clock::get()?.slot);
137+
// Slot History is not stored in the runtime sysvar cache, so syscall
138+
// `sol_get_sysvar` does not support it.
139+
assert_eq!(
140+
Err(ProgramError::UnsupportedSysvar),
141+
sol_get_sysvar::<SlotHistory>(1)
142+
);
143+
}
144+
127145
Ok(())
128146
}
129147
Some(&1) => {

0 commit comments

Comments
 (0)