Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
buffalu opened this issue Dec 19, 2023 · 2 comments

Comments

@buffalu
Copy link
Collaborator

buffalu commented Dec 19, 2023

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.

@buffalu buffalu changed the title Feature: Add tests to ensure the layout of fields in ValidatorHistoryEntry never changes Feature: Add tests to ensure the field layout in ValidatorHistoryEntry never changes Dec 19, 2023
@hydrogenbond007
Copy link

@buffalu gib issue

@hydrogenbond007
Copy link

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);
}

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants