test(wallet): fix tests helpers to generate unique utxos

This commit is contained in:
志宇 2024-01-16 22:33:42 +08:00
parent 40f0765d30
commit d9501187ef
No known key found for this signature in database
GPG Key ID: F6345C9837C2BDE8

View File

@ -799,13 +799,14 @@ mod test {
fn generate_random_utxos(rng: &mut StdRng, utxos_number: usize) -> Vec<WeightedUtxo> { fn generate_random_utxos(rng: &mut StdRng, utxos_number: usize) -> Vec<WeightedUtxo> {
let mut res = Vec::new(); let mut res = Vec::new();
for _ in 0..utxos_number { for i in 0..utxos_number {
res.push(WeightedUtxo { res.push(WeightedUtxo {
satisfaction_weight: P2WPKH_SATISFACTION_SIZE, satisfaction_weight: P2WPKH_SATISFACTION_SIZE,
utxo: Utxo::Local(LocalOutput { utxo: Utxo::Local(LocalOutput {
outpoint: OutPoint::from_str( outpoint: OutPoint::from_str(&format!(
"ebd9813ecebc57ff8f30797de7c205e3c7498ca950ea4341ee51a685ff2fa30a:0", "ebd9813ecebc57ff8f30797de7c205e3c7498ca950ea4341ee51a685ff2fa30a:{}",
) i
))
.unwrap(), .unwrap(),
txout: TxOut { txout: TxOut {
value: rng.gen_range(0..200000000), value: rng.gen_range(0..200000000),
@ -829,24 +830,26 @@ mod test {
} }
fn generate_same_value_utxos(utxos_value: u64, utxos_number: usize) -> Vec<WeightedUtxo> { fn generate_same_value_utxos(utxos_value: u64, utxos_number: usize) -> Vec<WeightedUtxo> {
let utxo = WeightedUtxo { (0..utxos_number)
satisfaction_weight: P2WPKH_SATISFACTION_SIZE, .map(|i| WeightedUtxo {
utxo: Utxo::Local(LocalOutput { satisfaction_weight: P2WPKH_SATISFACTION_SIZE,
outpoint: OutPoint::from_str( utxo: Utxo::Local(LocalOutput {
"ebd9813ecebc57ff8f30797de7c205e3c7498ca950ea4341ee51a685ff2fa30a:0", outpoint: OutPoint::from_str(&format!(
) "ebd9813ecebc57ff8f30797de7c205e3c7498ca950ea4341ee51a685ff2fa30a:{}",
.unwrap(), i
txout: TxOut { ))
value: utxos_value, .unwrap(),
script_pubkey: ScriptBuf::new(), txout: TxOut {
}, value: utxos_value,
keychain: KeychainKind::External, script_pubkey: ScriptBuf::new(),
is_spent: false, },
derivation_index: 42, keychain: KeychainKind::External,
confirmation_time: ConfirmationTime::Unconfirmed { last_seen: 0 }, is_spent: false,
}), derivation_index: 42,
}; confirmation_time: ConfirmationTime::Unconfirmed { last_seen: 0 },
vec![utxo; utxos_number] }),
})
.collect()
} }
fn sum_random_utxos(mut rng: &mut StdRng, utxos: &mut Vec<WeightedUtxo>) -> u64 { fn sum_random_utxos(mut rng: &mut StdRng, utxos: &mut Vec<WeightedUtxo>) -> u64 {