jito-foundation / stakenet

Jito StakeNet
https://www.jito.network/stakenet/
Apache License 2.0
50 stars 19 forks source link

Feature: Add tests to ensure the field layout in ValidatorHistoryEntry never changes #7

Open buffalu opened 9 months ago

buffalu commented 9 months ago

Is your feature request related to a problem? Please describe. During a previous refactor, the engineers of this program accidentally re-arranged fields in the ValidatorHistoryEntry and corrupted data. It was fixed, but easy to do again in the future.

Describe the solution you'd like Add tests to ensure the field layout of the ValidatorHistoryAccount doesn't change if fields are added, removed, or changed.

hydrogenbond007 commented 9 months ago

@buffalu gib issue

hydrogenbond007 commented 9 months ago

Update -> Adding assert fields in the test but getting error "no rules expected this token in macro call"

mod layout_tests { use super::*; use static_assertions::assert_fields; use std::mem::{align_of, size_of};

#[test]
fn test_validator_history_layout() {
    assert_fields!(
        ValidatorHistory,
        struct_version: u32,
        vote_account: Pubkey,
        index: u32,
        bump: u8,
        _padding0: [u8; 7],
        last_ip_timestamp: u64,
        last_version_timestamp: u64,
        _padding1: [u8; 232],
        history: CircBuf,
    );

    assert_eq!(size_of::<ValidatorHistory>(), 65848);
    assert_eq!(align_of::<ValidatorHistory>(), 8);
}

}