Skip to content

Commit

Permalink
BFT-457: Loop in test_encoding
Browse files Browse the repository at this point in the history
  • Loading branch information
aakoshh committed Jun 12, 2024
1 parent 6dd9cd9 commit f418e3b
Showing 1 changed file with 23 additions and 19 deletions.
42 changes: 23 additions & 19 deletions node/libs/protobuf/src/testonly/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,10 @@ pub fn test_encode_random<T: ProtoFmt + std::fmt::Debug + PartialEq>(rng: &mut i
where
Standard: Distribution<T>,
{
let msg = rng.gen::<T>();
test_encode(rng, &msg);
for _ in 0..10 {
let msg = rng.gen::<T>();
test_encode(rng, &msg);
}
}

/// shuffles recursively the order of fields in a protobuf encoding.
Expand Down Expand Up @@ -166,23 +168,25 @@ where
X::Type: std::fmt::Debug + PartialEq,
EncodeDist: Distribution<X::Type>,
{
for required_only in [false, true] {
let want: X::Type = EncodeDist {
required_only,
decimal_fractions: false,
}
.sample(rng);
let got = decode_proto::<X>(&encode_proto::<X>(&want)).unwrap();
assert_eq!(&want, &got, "binary encoding");
let got = decode_yaml::<X>(&encode_yaml::<X>(&want)).unwrap();
assert_eq!(&want, &got, "yaml encoding");

let want: X::Type = EncodeDist {
required_only,
decimal_fractions: true,
for _ in 0..10 {
for required_only in [false, true] {
let want: X::Type = EncodeDist {
required_only,
decimal_fractions: false,
}
.sample(rng);
let got = decode_proto::<X>(&encode_proto::<X>(&want)).unwrap();
assert_eq!(&want, &got, "binary encoding");
let got = decode_yaml::<X>(&encode_yaml::<X>(&want)).unwrap();
assert_eq!(&want, &got, "yaml encoding");

let want: X::Type = EncodeDist {
required_only,
decimal_fractions: true,
}
.sample(rng);
let got = decode_json::<X>(&encode_json::<X>(&want)).unwrap();
assert_eq!(&want, &got, "json encoding");
}
.sample(rng);
let got = decode_json::<X>(&encode_json::<X>(&want)).unwrap();
assert_eq!(&want, &got, "json encoding");
}
}

0 comments on commit f418e3b

Please sign in to comment.