Skip to content

Commit 49a7ba0

Browse files
committed
Auto-replace gen->random
1 parent 6df4a99 commit 49a7ba0

143 files changed

Lines changed: 683 additions & 683 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

api-server/scanner-lib/src/sync/tests/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1159,7 +1159,7 @@ async fn check_all_destinations_are_tracked(#[case] seed: Seed) {
11591159
let public_key_dest = Destination::PublicKey(pub_key.clone());
11601160
let public_key_hash_dest = Destination::PublicKeyHash((&pub_key).into());
11611161
let classic_multisig_dest = Destination::ClassicMultisig((&pub_key).into());
1162-
let script_dest = Destination::ScriptHash(Id::new(H256::from_slice(&rng.gen::<[u8; 32]>())));
1162+
let script_dest = Destination::ScriptHash(Id::new(H256::from_slice(&rng.random::<[u8; 32]>())));
11631163

11641164
let with_public_key = TxOutput::Transfer(
11651165
OutputValue::Coin(Amount::from_atoms(1)),

api-server/stack-test-suite/tests/v2/helpers.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ pub fn prepare_stake_pool(
5151
amount_to_stake,
5252
Destination::PublicKey(pk),
5353
vrf_pk,
54-
Destination::PublicKeyHash(PublicKeyHash::from_low_u64_ne(rng.gen::<u64>())),
54+
Destination::PublicKeyHash(PublicKeyHash::from_low_u64_ne(rng.random::<u64>())),
5555
PerThousand::new(margin_ratio_per_thousand).unwrap(),
5656
Amount::ZERO,
5757
);

api-server/storage-test-suite/src/basic.rs

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -556,7 +556,7 @@ where
556556
{
557557
let height1_u64 = rng.gen_range::<u64, _>(1..i64::MAX as u64);
558558
let height1 = height1_u64.into();
559-
let random_block_timestamp = BlockTimestamp::from_int_seconds(rng.gen::<u64>());
559+
let random_block_timestamp = BlockTimestamp::from_int_seconds(rng.random::<u64>());
560560
let aux_data1 =
561561
BlockAuxData::new(owning_block1.into(), height1, random_block_timestamp);
562562
db_tx.set_block_aux_data(owning_block1, &aux_data1).await.unwrap();
@@ -602,7 +602,7 @@ where
602602
let mut db_tx = storage.transaction_rw().await.unwrap();
603603

604604
let random_block_id = Id::<Block>::random_using(&mut rng);
605-
let random_block_timestamp = BlockTimestamp::from_int_seconds(rng.gen::<u64>());
605+
let random_block_timestamp = BlockTimestamp::from_int_seconds(rng.random::<u64>());
606606
let block = db_tx.get_block_aux_data(random_block_id).await.unwrap();
607607
assert!(block.is_none());
608608

@@ -619,7 +619,7 @@ where
619619
// Test overwrite
620620
let height2_u64 = rng.gen_range::<u64, _>(1..i64::MAX as u64);
621621
let height2 = height2_u64.into();
622-
let random_block_timestamp = BlockTimestamp::from_int_seconds(rng.gen::<u64>());
622+
let random_block_timestamp = BlockTimestamp::from_int_seconds(rng.random::<u64>());
623623
let aux_data2 =
624624
BlockAuxData::new(existing_block_id.into(), height2, random_block_timestamp);
625625
db_tx.set_block_aux_data(existing_block_id, &aux_data2).await.unwrap();
@@ -652,7 +652,7 @@ where
652652
let random_tx_id = Id::<Transaction>::random_using(&mut rng);
653653
let outpoint = UtxoOutPoint::new(
654654
OutPointSourceId::Transaction(random_tx_id),
655-
rng.gen::<u32>(),
655+
rng.random::<u32>(),
656656
);
657657
let output = TxOutput::Transfer(
658658
OutputValue::Coin(Amount::from_atoms(rng.gen_range(1..1000))),
@@ -768,7 +768,7 @@ where
768768
let random_tx_id = Id::<Transaction>::random_using(&mut rng);
769769
let outpoint = UtxoOutPoint::new(
770770
OutPointSourceId::Transaction(random_tx_id),
771-
rng.gen::<u32>(),
771+
rng.random::<u32>(),
772772
);
773773
let output = TxOutput::Transfer(
774774
OutputValue::Coin(Amount::from_atoms(rng.gen_range(1..1000))),
@@ -820,7 +820,7 @@ where
820820
let random_tx_id = Id::<Transaction>::random_using(&mut rng);
821821
let locked_outpoint = UtxoOutPoint::new(
822822
OutPointSourceId::Transaction(random_tx_id),
823-
rng.gen::<u32>(),
823+
rng.random::<u32>(),
824824
);
825825
let locked_output = TxOutput::Transfer(
826826
OutputValue::Coin(Amount::from_atoms(rng.gen_range(1..1000))),
@@ -879,7 +879,7 @@ where
879879
let random_tx_id = Id::<Transaction>::random_using(&mut rng);
880880
let outpoint2 = UtxoOutPoint::new(
881881
OutPointSourceId::Transaction(random_tx_id),
882-
rng.gen::<u32>(),
882+
rng.random::<u32>(),
883883
);
884884
let output2 = TxOutput::Transfer(
885885
OutputValue::Coin(Amount::from_atoms(rng.gen_range(1..1000))),
@@ -1118,10 +1118,10 @@ where
11181118

11191119
{
11201120
let random_pool_id = PoolId::random_using(&mut rng);
1121-
let random_block_height = BlockHeight::new(rng.gen::<u32>() as u64);
1121+
let random_block_height = BlockHeight::new(rng.random::<u32>() as u64);
11221122
let (_, vrf_pk) = VRFPrivateKey::new_from_rng(&mut rng, VRFKeyKind::Schnorrkel);
1123-
let amount_to_stake = Amount::from_atoms(rng.gen::<u128>());
1124-
let cost_per_block = Amount::from_atoms(rng.gen::<u128>());
1123+
let amount_to_stake = Amount::from_atoms(rng.random::<u128>());
1124+
let cost_per_block = Amount::from_atoms(rng.random::<u128>());
11251125

11261126
let (_, pk) = PrivateKey::new_from_rng(&mut rng, KeyKind::Secp256k1Schnorr);
11271127

@@ -1152,13 +1152,13 @@ where
11521152
let (_, vrf_pk) = VRFPrivateKey::new_from_rng(&mut rng, VRFKeyKind::Schnorrkel);
11531153
let (_, pk) = PrivateKey::new_from_rng(&mut rng, KeyKind::Secp256k1Schnorr);
11541154
let amount_to_stake = {
1155-
let mut amount_to_stake = Amount::from_atoms(rng.gen::<u128>());
1155+
let mut amount_to_stake = Amount::from_atoms(rng.random::<u128>());
11561156
while amount_to_stake == random_pool_data.staker_balance().unwrap() {
1157-
amount_to_stake = Amount::from_atoms(rng.gen::<u128>());
1157+
amount_to_stake = Amount::from_atoms(rng.random::<u128>());
11581158
}
11591159
amount_to_stake
11601160
};
1161-
let cost_per_block = Amount::from_atoms(rng.gen::<u128>());
1161+
let cost_per_block = Amount::from_atoms(rng.random::<u128>());
11621162
let margin_ratio_per_thousand = rng.gen_range(1..=1000);
11631163
let random_pool_data2 = PoolData::new(
11641164
Destination::PublicKey(pk),
@@ -1169,9 +1169,9 @@ where
11691169
cost_per_block,
11701170
);
11711171
let random_block_height2 = {
1172-
let mut height = BlockHeight::new(rng.gen::<u32>() as u64);
1172+
let mut height = BlockHeight::new(rng.random::<u32>() as u64);
11731173
while height == random_block_height {
1174-
height = BlockHeight::new(rng.gen::<u32>() as u64)
1174+
height = BlockHeight::new(rng.random::<u32>() as u64)
11751175
}
11761176
height
11771177
};
@@ -1220,8 +1220,8 @@ where
12201220
// update the first one
12211221
let (_, vrf_pk) = VRFPrivateKey::new_from_rng(&mut rng, VRFKeyKind::Schnorrkel);
12221222
let (_, pk) = PrivateKey::new_from_rng(&mut rng, KeyKind::Secp256k1Schnorr);
1223-
let amount_to_stake = Amount::from_atoms(rng.gen::<u128>());
1224-
let cost_per_block = Amount::from_atoms(rng.gen::<u128>());
1223+
let amount_to_stake = Amount::from_atoms(rng.random::<u128>());
1224+
let cost_per_block = Amount::from_atoms(rng.random::<u128>());
12251225
let margin_ratio_per_thousand = rng.gen_range(1..=1000);
12261226
let random_pool_data_new = PoolData::new(
12271227
Destination::PublicKey(pk.clone()),
@@ -1346,10 +1346,10 @@ where
13461346
let (_, pk) = PrivateKey::new_from_rng(&mut rng, KeyKind::Secp256k1Schnorr);
13471347
let random_pool_id = PoolId::random_using(&mut rng);
13481348
let random_pool_id2 = PoolId::random_using(&mut rng);
1349-
let random_balance = Amount::from_atoms(rng.gen::<u128>());
1350-
let random_balance2 = Amount::from_atoms(rng.gen::<u128>());
1351-
let random_nonce = AccountNonce::new(rng.gen::<u64>());
1352-
let random_nonce2 = AccountNonce::new(rng.gen::<u64>());
1349+
let random_balance = Amount::from_atoms(rng.random::<u128>());
1350+
let random_balance2 = Amount::from_atoms(rng.random::<u128>());
1351+
let random_nonce = AccountNonce::new(rng.random::<u64>());
1352+
let random_nonce2 = AccountNonce::new(rng.random::<u64>());
13531353

13541354
let random_delegation = Delegation::new(
13551355
random_block_height,
@@ -1406,8 +1406,8 @@ where
14061406
assert_eq!(delegation, &random_delegation2);
14071407

14081408
// update delegation on new height
1409-
let random_balance = Amount::from_atoms(rng.gen::<u128>());
1410-
let random_nonce = AccountNonce::new(rng.gen::<u64>());
1409+
let random_balance = Amount::from_atoms(rng.random::<u128>());
1410+
let random_nonce = AccountNonce::new(rng.random::<u64>());
14111411

14121412
let random_delegation_new = Delegation::new(
14131413
random_block_height,
@@ -2176,7 +2176,7 @@ fn random_order(
21762176
initially_asked: ask_amount,
21772177
ask_balance: ask_amount,
21782178
is_frozen: false,
2179-
next_nonce: AccountNonce::new(rng.gen::<u64>()),
2179+
next_nonce: AccountNonce::new(rng.random::<u64>()),
21802180
};
21812181
(order_id, order)
21822182
}

blockprod/src/detail/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ impl CustomId {
9797

9898
pub fn new_from_rng(rng: &mut impl Rng) -> Self {
9999
Self {
100-
data: rng.gen::<[u8; JOBKEY_DEFAULT_LEN]>().into(),
100+
data: rng.random::<[u8; JOBKEY_DEFAULT_LEN]>().into(),
101101
}
102102
}
103103

blockprod/src/detail/tests.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1854,7 +1854,7 @@ mod produce_block {
18541854
.expect("Error initializing blockprod");
18551855

18561856
let mut rng = make_seedable_rng(seed);
1857-
let jobs_to_create = rng.gen::<usize>() % 20 + 1;
1857+
let jobs_to_create = rng.random::<usize>() % 20 + 1;
18581858

18591859
for _ in 0..jobs_to_create {
18601860
let (_block, job) = block_production
@@ -1891,7 +1891,7 @@ mod process_block_with_custom_id {
18911891

18921892
let mut rng = make_seedable_rng(seed);
18931893

1894-
let jobs_to_create = rng.gen::<usize>() % 20 + 1;
1894+
let jobs_to_create = rng.random::<usize>() % 20 + 1;
18951895

18961896
let block_production = BlockProduction::new(
18971897
chain_config,
@@ -1913,7 +1913,7 @@ mod process_block_with_custom_id {
19131913
});
19141914

19151915
let produce_blocks_futures_iter = (0..jobs_to_create).map(|_| {
1916-
let id: Vec<u8> = (0..1024).map(|_| rng.gen::<u8>()).collect();
1916+
let id: Vec<u8> = (0..1024).map(|_| rng.random::<u8>()).collect();
19171917

19181918
block_production.produce_block_with_custom_id(
19191919
GenerateBlockInputData::None,
@@ -1951,7 +1951,7 @@ mod process_block_with_custom_id {
19511951

19521952
let mut rng = make_seedable_rng(seed);
19531953

1954-
let jobs_to_create = 10 + rng.gen::<usize>() % 20 + 1;
1954+
let jobs_to_create = 10 + rng.random::<usize>() % 20 + 1;
19551955

19561956
let block_production = BlockProduction::new(
19571957
chain_config,
@@ -1972,7 +1972,7 @@ mod process_block_with_custom_id {
19721972
shutdown_trigger.initiate();
19731973
});
19741974

1975-
let id: Vec<u8> = (0..1024).map(|_| rng.gen::<u8>()).collect();
1975+
let id: Vec<u8> = (0..1024).map(|_| rng.random::<u8>()).collect();
19761976

19771977
// The following is a race between the successive
19781978
// calls to produce_block_with_custom_id() and the job
@@ -2104,7 +2104,7 @@ mod stop_all_jobs {
21042104
.expect("Error initializing blockprod");
21052105

21062106
let mut mock_job_manager = Box::<MockJobManager>::default();
2107-
let return_value = make_seedable_rng(seed).gen();
2107+
let return_value = make_seedable_rng(seed).random();
21082108
let expected_value = return_value;
21092109

21102110
mock_job_manager
@@ -2226,7 +2226,7 @@ mod stop_job {
22262226
.expect("Error initializing blockprod");
22272227

22282228
let mut job_keys = Vec::new();
2229-
let jobs_to_create = rng.gen::<usize>() % 20 + 1;
2229+
let jobs_to_create = rng.random::<usize>() % 20 + 1;
22302230

22312231
for _ in 1..=jobs_to_create {
22322232
let (job_key, _stop_last_used_block_timestamp, _stop_job_cancel_receiver) =

blockprod/src/detail/timestamp_searcher/tests.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -521,15 +521,15 @@ mod search {
521521

522522
let mut data = Vec::with_capacity(items_count);
523523
for i in 0..items_count {
524-
let min_timestamp = rng.gen::<u32>() as u64;
524+
let min_timestamp = rng.random::<u32>() as u64;
525525
let max_timestamp = min_timestamp + rng.gen_range(1..10);
526526
let staker_balance = rng.gen_range(1..u32::MAX) as u128;
527-
let total_balance = staker_balance + rng.gen::<u32>() as u128;
527+
let total_balance = staker_balance + rng.random::<u32>() as u128;
528528

529529
data.push(SearchDataForHeight {
530530
sealed_epoch_randomness: PoSRandomness::new(H256::random_using(&mut rng)),
531531
epoch_index: i as u64,
532-
target_required: Uint256::from_u64(rng.gen()).into(),
532+
target_required: Uint256::from_u64(rng.random()).into(),
533533
min_timestamp: BlockTimestamp::from_int_seconds(min_timestamp),
534534
max_timestamp: BlockTimestamp::from_int_seconds(max_timestamp),
535535
pool_balances: NonZeroPoolBalances::new(

chainstate/constraints-value-accumulator/src/tests/homomorphism.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ fn accumulators_homomorphism(#[case] seed: Seed) {
110110
let tokens_db = tokens_accounting::TokensAccountingDB::new(&tokens_store);
111111

112112
let (decommission_tx, decommission_tx_inputs_utxos) = {
113-
let decommission_pool_utxo = if rng.gen::<bool>() {
113+
let decommission_pool_utxo = if rng.random::<bool>() {
114114
TxOutput::CreateStakePool(pool_id, Box::new(stake_pool_data))
115115
} else {
116116
TxOutput::ProduceBlockFromStake(Destination::AnyoneCanSpend, pool_id)

chainstate/db-dumper/src/dumper_lib/tests/mod.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -386,10 +386,10 @@ impl TestBlockInputInfo {
386386
height,
387387
is_mainchain,
388388
parent_id: Id::random_using(rng),
389-
timestamp: BlockTimestamp::from_int_seconds(rng.gen()),
389+
timestamp: BlockTimestamp::from_int_seconds(rng.random()),
390390
pool_id: PoolId::random_using(rng),
391391
target: gen_target(rng),
392-
chain_trust: Uint256::from_bytes(rng.gen()),
392+
chain_trust: Uint256::from_bytes(rng.random()),
393393
status: BlockStatusOutput::iter().choose(rng).unwrap(),
394394
}
395395
}
@@ -502,17 +502,17 @@ fn make_consensus_data(pool_id: PoolId, compact_target: Compact) -> ConsensusDat
502502
fn bogus_vrf_return(rng: &mut (impl Rng + CryptoRng)) -> VRFReturn {
503503
let (vrf_sk, _) = VRFPrivateKey::new_from_rng(rng, VRFKeyKind::Schnorrkel);
504504
let vrf_transcript = construct_transcript(
505-
rng.gen(),
506-
&rng.gen(),
507-
BlockTimestamp::from_int_seconds(rng.gen()),
505+
rng.random(),
506+
&rng.random(),
507+
BlockTimestamp::from_int_seconds(rng.random()),
508508
)
509509
.with_rng(rng);
510510

511511
vrf_sk.produce_vrf_data(vrf_transcript)
512512
}
513513

514514
fn gen_compact_target(rng: &mut (impl Rng + CryptoRng)) -> Compact {
515-
let target = Uint256::from_bytes(rng.gen());
515+
let target = Uint256::from_bytes(rng.random());
516516
target.into()
517517
}
518518

chainstate/src/detail/bootstrap.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -276,10 +276,10 @@ mod tests {
276276

277277
{
278278
let header = BootstrapFileHeader {
279-
file_magic_bytes: rng.gen(),
280-
chain_magic_bytes: MagicBytes::new(rng.gen()),
281-
file_format_version: rng.gen(),
282-
blocks_count: rng.gen(),
279+
file_magic_bytes: rng.random(),
280+
chain_magic_bytes: MagicBytes::new(rng.random()),
281+
file_format_version: rng.random(),
282+
blocks_count: rng.random(),
283283
};
284284

285285
let encoded_size = header.encoded_size();

chainstate/src/detail/orphan_blocks/pool.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -183,8 +183,8 @@ mod tests {
183183

184184
Block::new(
185185
vec![SignedTransaction::new(tx, vec![]).expect("invalid witness count")],
186-
prev_block_id.unwrap_or_else(|| H256::from_low_u64_be(rng.gen()).into()),
187-
BlockTimestamp::from_int_seconds(rng.gen()),
186+
prev_block_id.unwrap_or_else(|| H256::from_low_u64_be(rng.random()).into()),
187+
BlockTimestamp::from_int_seconds(rng.random()),
188188
ConsensusData::None,
189189
BlockReward::new(Vec::new()),
190190
)
@@ -220,7 +220,7 @@ mod tests {
220220
prev_block_id: Option<Id<Block>>,
221221
) -> Vec<Block> {
222222
let prev_block_id =
223-
prev_block_id.unwrap_or_else(|| H256::from_low_u64_be(rng.gen()).into());
223+
prev_block_id.unwrap_or_else(|| H256::from_low_u64_be(rng.random()).into());
224224

225225
(0..count).map(|_| gen_block_from_id(rng, Some(prev_block_id.into()))).collect()
226226
}

0 commit comments

Comments
 (0)