Skip to content

Commit

Permalink
rename: StaticAccountKeysMeta
Browse files Browse the repository at this point in the history
  • Loading branch information
apfitzge committed Aug 7, 2024
1 parent b76362e commit 59cdc7c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion transaction-view/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ pub mod result;
#[allow(dead_code)]
mod signature_meta;
#[allow(dead_code)]
mod static_accounts_meta;
mod static_account_keys_meta;
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ use {

/// Contains meta-data about the static account keys in a transaction packet.
#[derive(Default)]
pub struct StaticAccountMeta {
pub struct StaticAccountKeysMeta {
/// The number of static accounts in the transaction.
pub(crate) num_static_accounts: u16,
/// The offset to the first static account in the transaction.
pub(crate) offset: u16,
}

impl StaticAccountMeta {
impl StaticAccountKeysMeta {
pub fn try_new(bytes: &[u8], offset: &mut usize) -> Result<Self> {
// The packet has a maximum length of 1232 bytes.
// This means the maximum number of 32 byte keys is 38.
Expand Down Expand Up @@ -53,14 +53,14 @@ mod tests {
fn test_zero_accounts() {
let bytes = bincode::serialize(&ShortVec(Vec::<Pubkey>::new())).unwrap();
let mut offset = 0;
assert!(StaticAccountMeta::try_new(&bytes, &mut offset).is_err());
assert!(StaticAccountKeysMeta::try_new(&bytes, &mut offset).is_err());
}

#[test]
fn test_one_account() {
let bytes = bincode::serialize(&ShortVec(vec![Pubkey::default()])).unwrap();
let mut offset = 0;
let meta = StaticAccountMeta::try_new(&bytes, &mut offset).unwrap();
let meta = StaticAccountKeysMeta::try_new(&bytes, &mut offset).unwrap();
assert_eq!(meta.num_static_accounts, 1);
assert_eq!(meta.offset, 1);
assert_eq!(offset, 1 + core::mem::size_of::<Pubkey>());
Expand All @@ -71,7 +71,7 @@ mod tests {
let signatures = vec![Pubkey::default(); 38];
let bytes = bincode::serialize(&ShortVec(signatures)).unwrap();
let mut offset = 0;
let meta = StaticAccountMeta::try_new(&bytes, &mut offset).unwrap();
let meta = StaticAccountKeysMeta::try_new(&bytes, &mut offset).unwrap();
assert_eq!(meta.num_static_accounts, 38);
assert_eq!(meta.offset, 1);
assert_eq!(offset, 1 + 38 * core::mem::size_of::<Pubkey>());
Expand All @@ -82,14 +82,14 @@ mod tests {
let signatures = vec![Pubkey::default(); 39];
let bytes = bincode::serialize(&ShortVec(signatures)).unwrap();
let mut offset = 0;
assert!(StaticAccountMeta::try_new(&bytes, &mut offset).is_err());
assert!(StaticAccountKeysMeta::try_new(&bytes, &mut offset).is_err());
}

#[test]
fn test_u16_max_accounts() {
let signatures = vec![Pubkey::default(); u16::MAX as usize];
let bytes = bincode::serialize(&ShortVec(signatures)).unwrap();
let mut offset = 0;
assert!(StaticAccountMeta::try_new(&bytes, &mut offset).is_err());
assert!(StaticAccountKeysMeta::try_new(&bytes, &mut offset).is_err());
}
}

0 comments on commit 59cdc7c

Please sign in to comment.