assert-type-assumptions (#23996)

This commit is contained in:
Jack May
2022-03-30 08:28:49 -07:00
committed by GitHub
parent 1fb82d7924
commit 37497657c6
7 changed files with 174 additions and 8 deletions

View File

@ -3642,6 +3642,7 @@ dependencies = [
"lazy_static",
"libsecp256k1 0.6.0",
"log",
"memoffset",
"num-derive",
"num-traits",
"parking_lot",

View File

@ -4,7 +4,8 @@
extern crate solana_program;
use solana_program::{
account_info::AccountInfo, bpf_loader, entrypoint::ProgramResult, log::*, msg, pubkey::Pubkey,
account_info::AccountInfo, bpf_loader, entrypoint::ProgramResult, log::*, msg,
program::check_type_assumptions, pubkey::Pubkey,
};
#[derive(Debug, PartialEq)]
@ -70,6 +71,8 @@ pub fn process_instruction(
assert!(1.9986f64 < num && num < 2.0f64);
}
check_type_assumptions();
sol_log_compute_units();
Ok(())
}

View File

@ -1428,7 +1428,7 @@ fn assert_instruction_count() {
("sanity", 2378),
("sanity++", 2278),
("secp256k1_recover", 25383),
("sha", 1895),
("sha", 1355),
("struct_pass", 108),
("struct_ret", 122),
]);
@ -1448,9 +1448,9 @@ fn assert_instruction_count() {
("solana_bpf_rust_noop", 315),
("solana_bpf_rust_param_passing", 146),
("solana_bpf_rust_rand", 418),
("solana_bpf_rust_sanity", 9128),
("solana_bpf_rust_sanity", 52170),
("solana_bpf_rust_secp256k1_recover", 25707),
("solana_bpf_rust_sha", 27033),
("solana_bpf_rust_sha", 25338),
]);
}

View File

@ -3541,6 +3541,7 @@ mod tests {
bpf_loader,
fee_calculator::FeeCalculator,
hash::hashv,
program::check_type_assumptions,
sysvar::{clock::Clock, epoch_schedule::EpochSchedule, rent::Rent},
transaction_context::TransactionContext,
},
@ -4906,9 +4907,6 @@ mod tests {
#[test]
fn test_check_type_assumptions() {
// Code in this file assumes that u64 and usize are the same
assert_eq!(size_of::<u64>(), size_of::<usize>());
// Code in this file assumes that u8 is byte aligned
assert_eq!(1, align_of::<u8>());
check_type_assumptions();
}
}