Skip to content

Commit 313a58e

Browse files
committed
Auto-replace gen_bool->random_bool
1 parent 4b8762f commit 313a58e

32 files changed

Lines changed: 89 additions & 89 deletions

File tree

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ async fn simulation(
309309

310310
// Generate a random chain
311311
for current_height in 0..num_blocks {
312-
let create_reorg = rng.gen_bool(0.1);
312+
let create_reorg = rng.random_bool(0.1);
313313
let height_to_continue_from = if create_reorg {
314314
rng.gen_range(0..=current_height)
315315
} else {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ async fn ok(#[case] seed: Seed) {
6868
let mut input_utxo = tf.genesis().utxos()[0].clone();
6969

7070
for _ in 0..10 {
71-
let (dest, token_ids) = if rng.gen_bool(0.5) {
71+
let (dest, token_ids) = if rng.random_bool(0.5) {
7272
(alice_destination.clone(), &mut alice_token_ids)
7373
} else {
7474
(bob_destination.clone(), &mut bob_token_ids)
@@ -118,7 +118,7 @@ async fn ok(#[case] seed: Seed) {
118118
// Select a random token_id and transfer authority to the other person
119119
let (token_id, dest, dest2, priv_key, token_ids) = if !alice_token_ids
120120
.is_empty()
121-
&& (bob_token_ids.is_empty() || rng.gen_bool(0.5))
121+
&& (bob_token_ids.is_empty() || rng.random_bool(0.5))
122122
{
123123
(
124124
alice_token_ids.remove(rng.gen_range(0..alice_token_ids.len())),

blockprod/src/detail/timestamp_searcher/tests.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ mod collect_search_data {
5858

5959
let mut rng = make_seedable_rng(seed);
6060

61-
let consensus_version = if rng.gen_bool(0.5) {
61+
let consensus_version = if rng.random_bool(0.5) {
6262
PoSConsensusVersion::V0
6363
} else {
6464
PoSConsensusVersion::V1
@@ -537,7 +537,7 @@ mod search {
537537
Amount::from_atoms(staker_balance),
538538
)
539539
.unwrap(),
540-
consensus_version: if rng.gen_bool(0.5) {
540+
consensus_version: if rng.random_bool(0.5) {
541541
PoSConsensusVersion::V0
542542
} else {
543543
PoSConsensusVersion::V1

chainstate/test-framework/src/random_tx_maker.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -605,7 +605,7 @@ impl<'a> RandomTxMaker<'a> {
605605
} else {
606606
(Vec::new(), Vec::new())
607607
}
608-
} else if rng.gen_bool(0.1) {
608+
} else if rng.random_bool(0.1) {
609609
if token_data.can_be_frozen() {
610610
// Freeze
611611
let new_nonce = self.get_next_nonce(AccountType::Token(token_id));
@@ -634,7 +634,7 @@ impl<'a> RandomTxMaker<'a> {
634634
} else {
635635
(Vec::new(), Vec::new())
636636
}
637-
} else if rng.gen_bool(0.1) {
637+
} else if rng.random_bool(0.1) {
638638
// Change token authority
639639
let new_nonce = self.get_next_nonce(AccountType::Token(token_id));
640640
let new_authority =
@@ -658,7 +658,7 @@ impl<'a> RandomTxMaker<'a> {
658658
);
659659

660660
(vec![account_input, fee_input], vec![fee_change_output])
661-
} else if rng.gen_bool(0.1) {
661+
} else if rng.random_bool(0.1) {
662662
// Change token metadata uri
663663
let new_nonce = self.get_next_nonce(AccountType::Token(token_id));
664664
let max_len = self.chainstate.get_chain_config().token_max_uri_len();
@@ -681,7 +681,7 @@ impl<'a> RandomTxMaker<'a> {
681681

682682
(vec![account_input, fee_input], vec![fee_change_output])
683683
} else if !token_data.is_locked() {
684-
if rng.gen_bool(0.9) {
684+
if rng.random_bool(0.9) {
685685
let circulating_supply = tokens_cache.get_circulating_supply(&token_id).unwrap();
686686

687687
// mint
@@ -808,7 +808,7 @@ impl<'a> RandomTxMaker<'a> {
808808
}
809809
TxOutput::CreateStakePool(pool_id, _)
810810
| TxOutput::ProduceBlockFromStake(_, pool_id) => {
811-
if self.staking_pool.is_none_or(|id| id != *pool_id) && rng.gen_bool(0.1) {
811+
if self.staking_pool.is_none_or(|id| id != *pool_id) && rng.random_bool(0.1) {
812812
let staker_balance = pos_accounting_cache
813813
.get_pool_data(*pool_id)
814814
.unwrap()
@@ -1087,7 +1087,7 @@ impl<'a> RandomTxMaker<'a> {
10871087

10881088
TxOutput::CreateStakePool(dummy_pool_id, Box::new(pool_data))
10891089
} else {
1090-
if rng.gen_bool(0.3) {
1090+
if rng.random_bool(0.3) {
10911091
// Send coins to random delegation
10921092
if let Some((delegation_id, _)) = get_random_delegation_data(
10931093
rng,
@@ -1271,7 +1271,7 @@ impl<'a> RandomTxMaker<'a> {
12711271
}
12721272
}
12731273
}
1274-
} else if rng.gen_bool(0.4) && !self.account_command_used {
1274+
} else if rng.random_bool(0.4) && !self.account_command_used {
12751275
// unmint
12761276
let token_data = tokens_cache.get_token_data(&token_id).unwrap();
12771277

@@ -1317,7 +1317,7 @@ impl<'a> RandomTxMaker<'a> {
13171317
self.account_command_used = true;
13181318
}
13191319
}
1320-
} else if rng.gen_bool(0.4) && self.order_can_be_created && atoms > 0 {
1320+
} else if rng.random_bool(0.4) && self.order_can_be_created && atoms > 0 {
13211321
// create order to exchange part of available tokens for coins or other tokens
13221322
let random_token = get_random_token(rng, self.tokens_store, tokens_cache);
13231323
let ask_value = if rng.random::<bool>()

chainstate/test-suite/src/tests/fungible_tokens_v1.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1523,7 +1523,7 @@ fn mint_pseudo_unlimited_supply_max(#[case] seed: Seed) {
15231523
tf.chainstate.get_chain_config().token_supply_change_fee(BlockHeight::zero());
15241524

15251525
let max_amount_to_mint = Amount::from_atoms(i128::MAX as u128);
1526-
let total_supply_atoms = if rng.gen_bool(0.5) {
1526+
let total_supply_atoms = if rng.random_bool(0.5) {
15271527
u128::MAX
15281528
} else {
15291529
rng.gen_range((i128::MAX as u128) + 1..u128::MAX)

chainstate/test-suite/src/tests/get_stake_pool_balances_at_heights.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -169,23 +169,23 @@ fn randomized_test(#[case] seed: Seed) {
169169
did_something = true;
170170
}
171171
1 => {
172-
if rng.gen_bool(0.5) {
172+
if rng.random_bool(0.5) {
173173
if let Some(pool_id) = test_data.random_pool_id(&mut rng) {
174174
test_data.decommission_pool(&mut tf, &mut rng, &pool_id);
175175
did_something = true;
176176
}
177177
}
178178
}
179179
2 => {
180-
if rng.gen_bool(0.5) {
180+
if rng.random_bool(0.5) {
181181
if let Some(pool_id) = test_data.random_pool_id(&mut rng) {
182182
let _ = test_data.create_delegation(&mut tf, &mut rng, &pool_id);
183183
did_something = true;
184184
}
185185
}
186186
}
187187
3 => {
188-
if rng.gen_bool(0.5) {
188+
if rng.random_bool(0.5) {
189189
if let Some((pool_id, delegation_id)) =
190190
test_data.random_pool_and_delegation_id(&mut rng)
191191
{
@@ -200,7 +200,7 @@ fn randomized_test(#[case] seed: Seed) {
200200
}
201201
}
202202
_ => {
203-
if rng.gen_bool(0.5) {
203+
if rng.random_bool(0.5) {
204204
if let Some((pool_id, delegation_id)) =
205205
test_data.random_pool_and_delegation_id(&mut rng)
206206
{
@@ -216,7 +216,7 @@ fn randomized_test(#[case] seed: Seed) {
216216
}
217217
}
218218

219-
if !did_something && rng.gen_bool(0.5) {
219+
if !did_something && rng.random_bool(0.5) {
220220
if let Some(pool_id) = test_data.random_pool_id(&mut rng) {
221221
test_data.produce_trivial_block_with_pool(&mut tf, &mut rng, &pool_id);
222222
did_something = true;

chainstate/test-suite/src/tests/input_commitments.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -464,12 +464,12 @@ fn order_fill(#[case] seed: Seed, #[case] orders_version: OrdersVersion) {
464464
good_fill_order_input_commitment_v1.clone(),
465465
];
466466

467-
let bad_initially_asked = if rng.gen_bool(0.5) {
467+
let bad_initially_asked = if rng.random_bool(0.5) {
468468
OutputValue::Coin(amount_variation(&mut rng, initial_ask_amount))
469469
} else {
470470
OutputValue::TokenV1(token_id, initial_ask_amount)
471471
};
472-
let bad_initially_given = if rng.gen_bool(0.5) {
472+
let bad_initially_given = if rng.random_bool(0.5) {
473473
OutputValue::TokenV1(token_id, amount_variation(&mut rng, initial_give_amount))
474474
} else {
475475
OutputValue::Coin(initial_give_amount)
@@ -721,12 +721,12 @@ fn order_conclude(#[case] seed: Seed, #[case] orders_version: OrdersVersion) {
721721
give_balance,
722722
}];
723723

724-
let bad_initially_asked = if rng.gen_bool(0.5) {
724+
let bad_initially_asked = if rng.random_bool(0.5) {
725725
OutputValue::Coin(amount_variation(&mut rng, initial_ask_amount))
726726
} else {
727727
OutputValue::TokenV1(token_id, initial_ask_amount)
728728
};
729-
let bad_initially_given = if rng.gen_bool(0.5) {
729+
let bad_initially_given = if rng.random_bool(0.5) {
730730
OutputValue::TokenV1(token_id, amount_variation(&mut rng, initial_give_amount))
731731
} else {
732732
OutputValue::Coin(initial_give_amount)
@@ -872,7 +872,7 @@ fn make_conclude_order_input(
872872
}
873873

874874
fn amount_variation(rng: &mut (impl Rng + CryptoRng), amount: Amount) -> Amount {
875-
if rng.gen_bool(0.5) {
875+
if rng.random_bool(0.5) {
876876
(amount - Amount::from_atoms(1)).unwrap()
877877
} else {
878878
(amount + Amount::from_atoms(1)).unwrap()

chainstate/test-suite/src/tests/nft_transfer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ fn nft_zero_transfer(#[case] seed: Seed) {
204204
));
205205
}
206206

207-
if rng.gen_bool(0.5) {
207+
if rng.random_bool(0.5) {
208208
// Also make the actual transfer
209209
tx_builder = tx_builder.add_output(TxOutput::Transfer(
210210
OutputValue::TokenV1(token_id, Amount::from_atoms(1)),

chainstate/test-suite/src/tests/orders_tests.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -235,14 +235,14 @@ fn assert_order_exists(
235235
}
236236

237237
let mut make_different_currency = |currency, other_currency| {
238-
if currency != other_currency && rng.gen_bool(0.5) {
238+
if currency != other_currency && rng.random_bool(0.5) {
239239
return other_currency;
240240
}
241241

242242
match currency {
243243
Currency::Coin => Currency::Token(TokenId::random_using(rng)),
244244
Currency::Token(_) => {
245-
if rng.gen_bool(0.5) {
245+
if rng.random_bool(0.5) {
246246
Currency::Coin
247247
} else {
248248
Currency::Token(TokenId::random_using(rng))
@@ -3527,7 +3527,7 @@ fn order_with_zero_value(#[case] seed: Seed, #[case] version: OrdersVersion) {
35273527
),
35283528
};
35293529

3530-
let (ask, give) = if rng.gen_bool(0.5) {
3530+
let (ask, give) = if rng.random_bool(0.5) {
35313531
(coins, tokens)
35323532
} else {
35333533
(tokens, coins)
@@ -3593,7 +3593,7 @@ fn fill_order_v0_destination_irrelevancy(#[case] seed: Seed) {
35933593
let (sk2, pk2) = PrivateKey::new_from_rng(&mut rng, KeyKind::Secp256k1Schnorr);
35943594
let (_, pk3) = PrivateKey::new_from_rng(&mut rng, KeyKind::Secp256k1Schnorr);
35953595

3596-
let output_destination = if rng.gen_bool(0.5) {
3596+
let output_destination = if rng.random_bool(0.5) {
35973597
Destination::PublicKey(pk3)
35983598
} else {
35993599
Destination::AnyoneCanSpend
@@ -4246,7 +4246,7 @@ fn conclude_and_recreate_in_same_tx_with_same_balances(
42464246
))
42474247
.add_output(TxOutput::CreateOrder(Box::new(new_order_data.clone())));
42484248
// Add coins or tokens to inputs and transfer the same amount in outputs.
4249-
let tx_builder = if rng.gen_bool(0.5) {
4249+
let tx_builder = if rng.random_bool(0.5) {
42504250
tx_builder
42514251
.add_input(tokens_outpoint.into(), InputWitness::NoSignature(None))
42524252
.add_output(TxOutput::Transfer(
@@ -4338,7 +4338,7 @@ fn conclude_and_recreate_in_same_tx_with_different_balances(
43384338
let tokens_amount = tokens_amount_after_order_creation;
43394339

43404340
let (fill_amount, filled_amount) = if fill_after_creation {
4341-
let fill_amount = if increase_give_balance && rng.gen_bool(0.5) {
4341+
let fill_amount = if increase_give_balance && rng.random_bool(0.5) {
43424342
// Fill the order completely.
43434343
orig_ask_amount
43444344
} else {

chainstate/test-suite/src/tests/syncing_tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1233,7 +1233,7 @@ fn preliminary_checks_for_existing_block(#[case] seed: Seed) {
12331233

12341234
// Currently our good blocks are at the CheckBlockOk validation stage.
12351235
// Optionally, force set it to FullyChecked, the expected results remain the same.
1236-
if rng.gen_bool(0.5) {
1236+
if rng.random_bool(0.5) {
12371237
log::debug!("Resetting good block statuses to fully checked");
12381238

12391239
tf.set_block_status(

0 commit comments

Comments
 (0)