splits test_shred_variant_compat into separate test-cases (#35306)
This commit is contained in:
parent
c8ee4f59ad
commit
0ab425b43b
|
@ -1102,10 +1102,10 @@ mod tests {
|
||||||
super::*,
|
super::*,
|
||||||
assert_matches::assert_matches,
|
assert_matches::assert_matches,
|
||||||
bincode::serialized_size,
|
bincode::serialized_size,
|
||||||
itertools::iproduct,
|
|
||||||
rand::Rng,
|
rand::Rng,
|
||||||
rand_chacha::{rand_core::SeedableRng, ChaChaRng},
|
rand_chacha::{rand_core::SeedableRng, ChaChaRng},
|
||||||
solana_sdk::{shred_version, signature::Signer, signer::keypair::keypair_from_seed},
|
solana_sdk::{shred_version, signature::Signer, signer::keypair::keypair_from_seed},
|
||||||
|
test_case::test_case,
|
||||||
};
|
};
|
||||||
|
|
||||||
const SIZE_OF_SHRED_INDEX: usize = 4;
|
const SIZE_OF_SHRED_INDEX: usize = 4;
|
||||||
|
@ -1466,72 +1466,13 @@ mod tests {
|
||||||
bincode::deserialize::<ShredVariant>(&[0b1010_0101]),
|
bincode::deserialize::<ShredVariant>(&[0b1010_0101]),
|
||||||
Ok(ShredVariant::LegacyData)
|
Ok(ShredVariant::LegacyData)
|
||||||
);
|
);
|
||||||
// Merkle coding shred.
|
}
|
||||||
assert_eq!(
|
|
||||||
u8::from(ShredVariant::MerkleCode {
|
#[test_case(false, 0b0100_0000)]
|
||||||
proof_size: 5,
|
#[test_case(true, 0b0110_0000)]
|
||||||
chained: false,
|
fn test_shred_variant_compat_merkle_code(chained: bool, byte: u8) {
|
||||||
}),
|
for proof_size in 0..=15u8 {
|
||||||
0b0100_0101
|
let byte = byte | proof_size;
|
||||||
);
|
|
||||||
assert_eq!(
|
|
||||||
u8::from(ShredVariant::MerkleCode {
|
|
||||||
proof_size: 5,
|
|
||||||
chained: true,
|
|
||||||
}),
|
|
||||||
0b0110_0101
|
|
||||||
);
|
|
||||||
for chained in [false, true] {
|
|
||||||
assert_eq!(
|
|
||||||
ShredType::from(ShredVariant::MerkleCode {
|
|
||||||
proof_size: 5,
|
|
||||||
chained,
|
|
||||||
}),
|
|
||||||
ShredType::Code
|
|
||||||
);
|
|
||||||
}
|
|
||||||
assert_matches!(
|
|
||||||
ShredVariant::try_from(0b0100_0101),
|
|
||||||
Ok(ShredVariant::MerkleCode {
|
|
||||||
proof_size: 5,
|
|
||||||
chained: false,
|
|
||||||
})
|
|
||||||
);
|
|
||||||
assert_matches!(
|
|
||||||
ShredVariant::try_from(0b0110_0101),
|
|
||||||
Ok(ShredVariant::MerkleCode {
|
|
||||||
proof_size: 5,
|
|
||||||
chained: true,
|
|
||||||
})
|
|
||||||
);
|
|
||||||
let buf = bincode::serialize(&ShredVariant::MerkleCode {
|
|
||||||
proof_size: 5,
|
|
||||||
chained: false,
|
|
||||||
})
|
|
||||||
.unwrap();
|
|
||||||
assert_eq!(buf, vec![0b0100_0101]);
|
|
||||||
assert_matches!(
|
|
||||||
bincode::deserialize::<ShredVariant>(&[0b0100_0101]),
|
|
||||||
Ok(ShredVariant::MerkleCode {
|
|
||||||
proof_size: 5,
|
|
||||||
chained: false,
|
|
||||||
})
|
|
||||||
);
|
|
||||||
let buf = bincode::serialize(&ShredVariant::MerkleCode {
|
|
||||||
proof_size: 5,
|
|
||||||
chained: true,
|
|
||||||
})
|
|
||||||
.unwrap();
|
|
||||||
assert_eq!(buf, vec![0b0110_0101]);
|
|
||||||
assert_matches!(
|
|
||||||
bincode::deserialize::<ShredVariant>(&[0b0110_0101]),
|
|
||||||
Ok(ShredVariant::MerkleCode {
|
|
||||||
proof_size: 5,
|
|
||||||
chained: true,
|
|
||||||
})
|
|
||||||
);
|
|
||||||
for (proof_size, chained) in iproduct!(0..=15u8, [false, true]) {
|
|
||||||
let byte = proof_size | if chained { 0b0110_0000 } else { 0b0100_0000 };
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
u8::from(ShredVariant::MerkleCode {
|
u8::from(ShredVariant::MerkleCode {
|
||||||
proof_size,
|
proof_size,
|
||||||
|
@ -1567,72 +1508,13 @@ mod tests {
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
// Merkle data shred.
|
}
|
||||||
assert_eq!(
|
|
||||||
u8::from(ShredVariant::MerkleData {
|
#[test_case(false, 0b1000_0000)]
|
||||||
proof_size: 10,
|
#[test_case(true, 0b1001_0000)]
|
||||||
chained: false,
|
fn test_shred_variant_compat_merkle_data(chained: bool, byte: u8) {
|
||||||
}),
|
for proof_size in 0..=15u8 {
|
||||||
0b1000_1010
|
let byte = byte | proof_size;
|
||||||
);
|
|
||||||
assert_eq!(
|
|
||||||
u8::from(ShredVariant::MerkleData {
|
|
||||||
proof_size: 10,
|
|
||||||
chained: true,
|
|
||||||
}),
|
|
||||||
0b1001_1010
|
|
||||||
);
|
|
||||||
for chained in [false, true] {
|
|
||||||
assert_eq!(
|
|
||||||
ShredType::from(ShredVariant::MerkleData {
|
|
||||||
proof_size: 10,
|
|
||||||
chained,
|
|
||||||
}),
|
|
||||||
ShredType::Data
|
|
||||||
);
|
|
||||||
}
|
|
||||||
assert_matches!(
|
|
||||||
ShredVariant::try_from(0b1000_1010),
|
|
||||||
Ok(ShredVariant::MerkleData {
|
|
||||||
proof_size: 10,
|
|
||||||
chained: false,
|
|
||||||
})
|
|
||||||
);
|
|
||||||
assert_matches!(
|
|
||||||
ShredVariant::try_from(0b1001_1010),
|
|
||||||
Ok(ShredVariant::MerkleData {
|
|
||||||
proof_size: 10,
|
|
||||||
chained: true,
|
|
||||||
})
|
|
||||||
);
|
|
||||||
let buf = bincode::serialize(&ShredVariant::MerkleData {
|
|
||||||
proof_size: 10,
|
|
||||||
chained: false,
|
|
||||||
})
|
|
||||||
.unwrap();
|
|
||||||
assert_eq!(buf, vec![0b1000_1010]);
|
|
||||||
assert_matches!(
|
|
||||||
bincode::deserialize::<ShredVariant>(&[0b1000_1010]),
|
|
||||||
Ok(ShredVariant::MerkleData {
|
|
||||||
proof_size: 10,
|
|
||||||
chained: false,
|
|
||||||
})
|
|
||||||
);
|
|
||||||
let buf = bincode::serialize(&ShredVariant::MerkleData {
|
|
||||||
proof_size: 10,
|
|
||||||
chained: true,
|
|
||||||
})
|
|
||||||
.unwrap();
|
|
||||||
assert_eq!(buf, vec![0b1001_1010]);
|
|
||||||
assert_matches!(
|
|
||||||
bincode::deserialize::<ShredVariant>(&[0b1001_1010]),
|
|
||||||
Ok(ShredVariant::MerkleData {
|
|
||||||
proof_size: 10,
|
|
||||||
chained: true,
|
|
||||||
})
|
|
||||||
);
|
|
||||||
for (proof_size, chained) in iproduct!(0..=15u8, [false, true]) {
|
|
||||||
let byte = proof_size | if chained { 0b1001_0000 } else { 0b1000_0000 };
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
u8::from(ShredVariant::MerkleData {
|
u8::from(ShredVariant::MerkleData {
|
||||||
proof_size,
|
proof_size,
|
||||||
|
|
Loading…
Reference in New Issue