Skip to content

Commit 35563c9

Browse files
committed
Minor cleanup
1 parent 7bd4b09 commit 35563c9

9 files changed

Lines changed: 31 additions & 16 deletions

File tree

Cargo.lock

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

common/src/chain/transaction/output/htlc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ mod tests {
255255

256256
// Note: rustc_hex::FromHexError's Display implementation differs a bit depending on whether
257257
// the crate's 'std' feature is enabled, so the expected values here may have to be changed
258-
// whenever rustc_hex's configuration changes (which is controller by fixed_hash).
258+
// whenever rustc_hex's configuration changes (which is controller by fixed_hash in this case).
259259
#[rstest]
260260
#[case(
261261
"00000000000000000000000000000000000000000000000000000000000000",

randomness/src/lib.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ impl<'a, R: ?Sized> BoxedRngMutexWrapper<'a, R> {
6868
}
6969
}
7070

71-
impl<'a, R: rand::Rng + ?Sized> rand::TryRng for BoxedRngMutexWrapper<'a, R> {
71+
impl<'a, R: Rng + ?Sized> TryRng for BoxedRngMutexWrapper<'a, R> {
7272
type Error = std::convert::Infallible;
7373

7474
fn try_next_u32(&mut self) -> Result<u32, Self::Error> {
@@ -86,7 +86,7 @@ impl<'a, R: rand::Rng + ?Sized> rand::TryRng for BoxedRngMutexWrapper<'a, R> {
8686
}
8787

8888
// Note: `CryptoRng` is implemented automatically for all `R: TryCryptoRng<Error = Infallible>`.
89-
impl<'a, R: rand::TryCryptoRng<Error = std::convert::Infallible>> rand::TryCryptoRng
89+
impl<'a, R: TryCryptoRng<Error = std::convert::Infallible>> TryCryptoRng
9090
for BoxedRngMutexWrapper<'a, R>
9191
{
9292
}
@@ -120,6 +120,7 @@ mod tests {
120120
}
121121
}
122122

123+
#[allow(dead_code)]
123124
type CryptoRngType = rand::rngs::StdRng;
124125

125126
// Sanity checks

serialization/core/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ parity-scale-codec = { workspace = true, features = ["derive", "chain-error", "s
1010

1111
[dev-dependencies]
1212
randomness = { path = "../../randomness" }
13+
test-utils = { path = "../../test-utils" }
1314

1415
arraytools.workspace = true
1516
hex-literal.workspace = true
1617
rand.workspace = true
18+
rstest.workspace = true

serialization/core/tests/complex_types.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,11 @@ mod utils;
1717

1818
use std::collections::BTreeMap;
1919

20-
use randomness::{make_pseudo_rng, RngExt as _};
20+
use rstest::rstest;
21+
22+
use randomness::RngExt as _;
2123
use serialization_core::{Decode, DecodeAll, Encode};
24+
use test_utils::random::{make_seedable_rng, Seed};
2225
use utils::{OptionWrapper, SimpleWrapper};
2326

2427
#[test]
@@ -62,9 +65,11 @@ fn test_enum_codec_index() {
6265
}
6366
}
6467

65-
#[test]
66-
fn test_scale_structures() {
67-
let mut rng = make_pseudo_rng();
68+
#[rstest]
69+
#[trace]
70+
#[case(test_utils::random::Seed::from_entropy())]
71+
fn test_scale_structures(#[case] seed: Seed) {
72+
let mut rng = make_seedable_rng(seed);
6873

6974
#[derive(Debug, Clone, PartialEq, Eq, Encode, Decode)]
7075
enum TestEnum {

serialization/core/tests/containers.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,11 @@ mod utils;
1717

1818
use std::collections::BTreeMap;
1919

20-
use randomness::{make_pseudo_rng, RngExt as _};
20+
use rstest::rstest;
21+
22+
use randomness::RngExt as _;
2123
use serialization_core::{DecodeAll, Encode};
24+
use test_utils::random::{make_seedable_rng, Seed};
2225
use utils::SimpleWrapper;
2326

2427
#[test]
@@ -92,9 +95,11 @@ fn test_scale_vectors() {
9295
assert_eq!(dec, Some(SimpleWrapper(vector)));
9396
}
9497

95-
#[test]
96-
fn test_scale_btree_map() {
97-
let mut rng = make_pseudo_rng();
98+
#[rstest]
99+
#[trace]
100+
#[case(test_utils::random::Seed::from_entropy())]
101+
fn test_scale_btree_map(#[case] seed: Seed) {
102+
let mut rng = make_seedable_rng(seed);
98103
let mut btree_map = BTreeMap::new();
99104
for _ in 0..1024 {
100105
btree_map.insert(

utils/src/fixed_hash.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
pub use fixed_hash::construct_fixed_hash as construct_fixed_hash_orig;
1717

18-
/// A macro that wraps the namesake one from `fixed_hash`(which is compiled with its `rand` feature
18+
/// A macro that wraps the namesake one from `fixed_hash` (which is compiled with its `rand` feature
1919
/// disabled) and adds custom RNG-related methods to the generated type.
2020
///
2121
/// It's a temporary workaround to avoid creating an RNG adapter every time `random_using` is
@@ -33,8 +33,8 @@ macro_rules! construct_fixed_hash {
3333
}
3434

3535
// This is basically a copy of the similar macro in the fixed_hash src, except that here we use
36-
// rng primitives from `randomness` and omit the `randomize` and `random` methods that would create
37-
// a new rng on the fly (mainly because the RNG that they were creating originally is no longer
36+
// RNG primitives from `randomness` and omit the `randomize` and `random` methods that would create
37+
// a new RNG on the fly (mainly because the RNG that they were creating originally is no longer
3838
// infallible).
3939
#[macro_export]
4040
#[doc(hidden)]

wallet/wallet-controller/src/mnemonic.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
pub use bip39::{Error, Language, Mnemonic};
1717

18-
use randomness::RngExt;
18+
use randomness::RngExt as _;
1919
use wallet_types::seed_phrase::MNEMONIC_24_WORDS_ENTROPY_SIZE;
2020
use zeroize::Zeroize;
2121

wallet/wallet-controller/src/tests/compose_transaction_tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ use common::{
3636
primitives::{Amount, BlockHeight, Id, Idable},
3737
};
3838
use node_comm::{mock::ClonableMockNodeInterface, node_traits::MockNodeInterface};
39-
use randomness::RngExt;
39+
use randomness::RngExt as _;
4040
use test_utils::{
4141
assert_matches_return_val,
4242
random::{gen_random_alnum_string, make_seedable_rng, Seed},

0 commit comments

Comments
 (0)