runtime: add test_type_layout (#29987)
adds unit test asserting the type layout of structures in append_vec --------- Co-authored-by: Richard Patel <ripatel@jumptrading.com> Co-authored-by: brooks <brooks@solana.com>
This commit is contained in:
parent
4dbde40e10
commit
1ca78845bb
|
@ -1103,7 +1103,7 @@ dependencies = [
|
||||||
"cfg-if 1.0.0",
|
"cfg-if 1.0.0",
|
||||||
"crossbeam-utils",
|
"crossbeam-utils",
|
||||||
"lazy_static",
|
"lazy_static",
|
||||||
"memoffset",
|
"memoffset 0.6.4",
|
||||||
"scopeguard",
|
"scopeguard",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -2772,6 +2772,15 @@ dependencies = [
|
||||||
"autocfg",
|
"autocfg",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "memoffset"
|
||||||
|
version = "0.8.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "d61c719bcfbcf5d62b3a09efa6088de8c54bc0bfcd3ea7ae39fcc186108b8de1"
|
||||||
|
dependencies = [
|
||||||
|
"autocfg",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "merlin"
|
name = "merlin"
|
||||||
version = "3.0.0"
|
version = "3.0.0"
|
||||||
|
@ -2899,7 +2908,7 @@ dependencies = [
|
||||||
"bitflags",
|
"bitflags",
|
||||||
"cfg-if 1.0.0",
|
"cfg-if 1.0.0",
|
||||||
"libc",
|
"libc",
|
||||||
"memoffset",
|
"memoffset 0.6.4",
|
||||||
"pin-utils",
|
"pin-utils",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -6006,7 +6015,7 @@ dependencies = [
|
||||||
"libc",
|
"libc",
|
||||||
"libsecp256k1",
|
"libsecp256k1",
|
||||||
"log",
|
"log",
|
||||||
"memoffset",
|
"memoffset 0.6.4",
|
||||||
"num-derive",
|
"num-derive",
|
||||||
"num-traits",
|
"num-traits",
|
||||||
"parking_lot 0.12.1",
|
"parking_lot 0.12.1",
|
||||||
|
@ -6059,7 +6068,7 @@ dependencies = [
|
||||||
"libc",
|
"libc",
|
||||||
"libsecp256k1",
|
"libsecp256k1",
|
||||||
"log",
|
"log",
|
||||||
"memoffset",
|
"memoffset 0.8.0",
|
||||||
"num-bigint 0.4.3",
|
"num-bigint 0.4.3",
|
||||||
"num-derive",
|
"num-derive",
|
||||||
"num-traits",
|
"num-traits",
|
||||||
|
@ -6393,6 +6402,7 @@ dependencies = [
|
||||||
"lru",
|
"lru",
|
||||||
"lz4",
|
"lz4",
|
||||||
"memmap2",
|
"memmap2",
|
||||||
|
"memoffset 0.8.0",
|
||||||
"num-derive",
|
"num-derive",
|
||||||
"num-traits",
|
"num-traits",
|
||||||
"num_cpus",
|
"num_cpus",
|
||||||
|
|
|
@ -971,7 +971,7 @@ dependencies = [
|
||||||
"cfg-if 1.0.0",
|
"cfg-if 1.0.0",
|
||||||
"crossbeam-utils",
|
"crossbeam-utils",
|
||||||
"lazy_static",
|
"lazy_static",
|
||||||
"memoffset",
|
"memoffset 0.6.4",
|
||||||
"scopeguard",
|
"scopeguard",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -2538,6 +2538,15 @@ dependencies = [
|
||||||
"autocfg",
|
"autocfg",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "memoffset"
|
||||||
|
version = "0.8.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "d61c719bcfbcf5d62b3a09efa6088de8c54bc0bfcd3ea7ae39fcc186108b8de1"
|
||||||
|
dependencies = [
|
||||||
|
"autocfg",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "merlin"
|
name = "merlin"
|
||||||
version = "3.0.0"
|
version = "3.0.0"
|
||||||
|
@ -2665,7 +2674,7 @@ dependencies = [
|
||||||
"bitflags",
|
"bitflags",
|
||||||
"cfg-if 1.0.0",
|
"cfg-if 1.0.0",
|
||||||
"libc",
|
"libc",
|
||||||
"memoffset",
|
"memoffset 0.6.4",
|
||||||
"pin-utils",
|
"pin-utils",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -5006,7 +5015,7 @@ dependencies = [
|
||||||
"libc",
|
"libc",
|
||||||
"libsecp256k1 0.6.0",
|
"libsecp256k1 0.6.0",
|
||||||
"log",
|
"log",
|
||||||
"memoffset",
|
"memoffset 0.6.4",
|
||||||
"num-derive",
|
"num-derive",
|
||||||
"num-traits",
|
"num-traits",
|
||||||
"parking_lot 0.12.1",
|
"parking_lot 0.12.1",
|
||||||
|
@ -5057,7 +5066,7 @@ dependencies = [
|
||||||
"libc",
|
"libc",
|
||||||
"libsecp256k1 0.6.0",
|
"libsecp256k1 0.6.0",
|
||||||
"log",
|
"log",
|
||||||
"memoffset",
|
"memoffset 0.8.0",
|
||||||
"num-bigint 0.4.3",
|
"num-bigint 0.4.3",
|
||||||
"num-derive",
|
"num-derive",
|
||||||
"num-traits",
|
"num-traits",
|
||||||
|
|
|
@ -73,6 +73,7 @@ name = "solana_runtime"
|
||||||
assert_matches = "1.5.0"
|
assert_matches = "1.5.0"
|
||||||
ed25519-dalek = "=1.0.1"
|
ed25519-dalek = "=1.0.1"
|
||||||
libsecp256k1 = "0.6.0"
|
libsecp256k1 = "0.6.0"
|
||||||
|
memoffset = "0.8"
|
||||||
rand_chacha = "0.2.2"
|
rand_chacha = "0.2.2"
|
||||||
solana-logger = { path = "../logger", version = "=1.15.0" }
|
solana-logger = { path = "../logger", version = "=1.15.0" }
|
||||||
static_assertions = "1.1.0"
|
static_assertions = "1.1.0"
|
||||||
|
|
|
@ -703,6 +703,7 @@ pub mod tests {
|
||||||
super::{test_utils::*, *},
|
super::{test_utils::*, *},
|
||||||
crate::accounts_db::INCLUDE_SLOT_IN_HASH_TESTS,
|
crate::accounts_db::INCLUDE_SLOT_IN_HASH_TESTS,
|
||||||
assert_matches::assert_matches,
|
assert_matches::assert_matches,
|
||||||
|
memoffset::offset_of,
|
||||||
rand::{thread_rng, Rng},
|
rand::{thread_rng, Rng},
|
||||||
solana_sdk::{
|
solana_sdk::{
|
||||||
account::{accounts_equal, WritableAccount},
|
account::{accounts_equal, WritableAccount},
|
||||||
|
@ -1274,4 +1275,18 @@ pub mod tests {
|
||||||
let result = AppendVec::new_from_file(path, accounts_len);
|
let result = AppendVec::new_from_file(path, accounts_len);
|
||||||
assert_matches!(result, Err(ref message) if message.to_string().starts_with("incorrect layout/length/data"));
|
assert_matches!(result, Err(ref message) if message.to_string().starts_with("incorrect layout/length/data"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_type_layout() {
|
||||||
|
assert_eq!(offset_of!(StoredMeta, write_version_obsolete), 0x00);
|
||||||
|
assert_eq!(offset_of!(StoredMeta, data_len), 0x08);
|
||||||
|
assert_eq!(offset_of!(StoredMeta, pubkey), 0x10);
|
||||||
|
assert_eq!(mem::size_of::<StoredMeta>(), 0x30);
|
||||||
|
|
||||||
|
assert_eq!(offset_of!(AccountMeta, lamports), 0x00);
|
||||||
|
assert_eq!(offset_of!(AccountMeta, rent_epoch), 0x08);
|
||||||
|
assert_eq!(offset_of!(AccountMeta, owner), 0x10);
|
||||||
|
assert_eq!(offset_of!(AccountMeta, executable), 0x30);
|
||||||
|
assert_eq!(mem::size_of::<AccountMeta>(), 0x38);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,7 +21,7 @@ bytemuck = { version = "1.8.0", features = ["derive"] }
|
||||||
itertools = "0.10.5"
|
itertools = "0.10.5"
|
||||||
lazy_static = "1.4.0"
|
lazy_static = "1.4.0"
|
||||||
log = "0.4.17"
|
log = "0.4.17"
|
||||||
memoffset = "0.6"
|
memoffset = "0.8"
|
||||||
num-derive = "0.3"
|
num-derive = "0.3"
|
||||||
num-traits = { version = "0.2", default-features = true, features = ["i128", "std"] }
|
num-traits = { version = "0.2", default-features = true, features = ["i128", "std"] }
|
||||||
rustversion = "1.0.7"
|
rustversion = "1.0.7"
|
||||||
|
|
Loading…
Reference in New Issue