Skip to content

Commit bb044d9

Browse files
committed
clippy: Apply test suggestions.
1 parent adc9f8f commit bb044d9

File tree

6 files changed

+23
-39
lines changed

6 files changed

+23
-39
lines changed

src/client/rpc_api.rs

+3-7
Original file line numberDiff line numberDiff line change
@@ -817,9 +817,7 @@ mod tests {
817817
.ledger
818818
.create_txout(Amount::from_sat(1), address.script_pubkey());
819819
let tx = rpc.ledger.create_transaction(vec![], vec![txout]);
820-
if let Ok(()) = rpc.ledger.check_transaction(&tx) {
821-
assert!(false);
822-
};
820+
assert!(rpc.ledger.check_transaction(&tx).is_err());
823821

824822
// Generating blocks should add funds to wallet.
825823
rpc.generate_to_address(101, &address).unwrap();
@@ -830,7 +828,7 @@ mod tests {
830828
txid: rpc
831829
.ledger
832830
._get_transactions()
833-
.get(0)
831+
.first()
834832
.unwrap()
835833
.compute_txid(),
836834
vout: 0,
@@ -842,9 +840,7 @@ mod tests {
842840
.ledger
843841
.create_txout(Amount::from_sat(1), address.script_pubkey());
844842
let tx = rpc.ledger.create_transaction(vec![txin], vec![txout]);
845-
if let Err(e) = rpc.ledger.check_transaction(&tx) {
846-
assert!(false, "{:?}", e);
847-
};
843+
rpc.ledger.check_transaction(&tx).unwrap();
848844
}
849845

850846
#[test]

src/ledger/block.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -340,9 +340,7 @@ mod tests {
340340
assert_eq!(current_height, 1);
341341

342342
assert_eq!(ledger.get_mempool_transactions().len(), 0);
343-
if let Some(_) = ledger.get_mempool_transaction(tx.compute_txid()) {
344-
assert!(false);
345-
}
343+
assert!(ledger.get_mempool_transaction(tx.compute_txid()).is_none());
346344
}
347345

348346
#[test]

src/ledger/script.rs

+12-14
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ mod tests {
181181
assert_eq!(ledger.get_block_height().unwrap(), 3);
182182

183183
let script = Builder::new()
184-
.push_int(0x1 as i64)
184+
.push_int(0x1_i64)
185185
.push_opcode(OP_CSV)
186186
.push_opcode(OP_DROP)
187187
.push_x_only_key(&xonly_pk)
@@ -195,7 +195,7 @@ mod tests {
195195
assert_eq!(ledger.get_block_height().unwrap(), 6);
196196

197197
let script = Builder::new()
198-
.push_int(0x1 as i64)
198+
.push_int(0x1_i64)
199199
.push_opcode(OP_CSV)
200200
.push_opcode(OP_DROP)
201201
.push_x_only_key(&xonly_pk)
@@ -208,22 +208,20 @@ mod tests {
208208
}
209209
assert_eq!(ledger.get_block_height().unwrap(), 9);
210210
let script = Builder::new()
211-
.push_int(0x45 as i64)
211+
.push_int(0x45_i64)
212212
.push_opcode(OP_CSV)
213213
.push_opcode(OP_DROP)
214214
.push_x_only_key(&xonly_pk)
215215
.push_opcode(OP_CHECKSIG)
216216
.into_script();
217-
if let Ok(_) = ledger.check_sequence(utxo, script, 0x46) {
218-
assert!(false);
219-
}
217+
assert!(ledger.check_sequence(utxo, script, 0x46).is_err());
220218

221219
for _ in 0..0x100 {
222220
ledger.mine_block(&credential.address).unwrap();
223221
}
224222
assert_eq!(ledger.get_block_height().unwrap(), 9 + 0x100);
225223
let script = Builder::new()
226-
.push_int(0x100 as i64)
224+
.push_int(0x100_i64)
227225
.push_opcode(OP_CSV)
228226
.push_opcode(OP_DROP)
229227
.push_x_only_key(&xonly_pk)
@@ -271,13 +269,13 @@ mod tests {
271269
.push_x_only_key(&xonly_pk)
272270
.push_opcode(OP_CHECKSIG)
273271
.into_script();
274-
if let Ok(_) = ledger.check_sequence(
275-
utxo,
276-
script,
277-
Sequence::from_512_second_intervals(0x44).to_consensus_u32(),
278-
) {
279-
assert!(false);
280-
};
272+
assert!(ledger
273+
.check_sequence(
274+
utxo,
275+
script,
276+
Sequence::from_512_second_intervals(0x44).to_consensus_u32(),
277+
)
278+
.is_err());
281279

282280
ledger.mine_block(&credential.address).unwrap();
283281

src/ledger/transactions.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,7 @@ mod tests {
422422
let txs = ledger._get_transactions();
423423
assert_eq!(txs.len(), 1);
424424

425-
let tx2 = txs.get(0).unwrap().to_owned();
425+
let tx2 = txs.first().unwrap().to_owned();
426426
assert_eq!(tx, tx2);
427427

428428
let tx2 = ledger.get_transaction(txid).unwrap();
@@ -449,10 +449,8 @@ mod tests {
449449
);
450450

451451
// Input amount is zero. Same transaction should not be accepted, if
452-
// checks are performed..
453-
if let Ok(_) = ledger.add_transaction(tx.clone()) {
454-
assert!(false);
455-
};
452+
// checks are performed.
453+
assert!(ledger.add_transaction(tx.clone()).is_err());
456454

457455
// Create a valid transaction. This should pass checks.
458456
let txin = TxIn {

tests/raw_transactions.rs

+2-6
Original file line numberDiff line numberDiff line change
@@ -273,17 +273,13 @@ fn fund_sign_raw_transaction_with_wallet() {
273273
let tx = common::create_transaction(vec![], vec![txout]);
274274

275275
// Lower input funds should be a problem.
276-
if rpc.send_raw_transaction(&tx).is_ok() {
277-
assert!(false);
278-
};
276+
assert!(rpc.send_raw_transaction(&tx).is_err());
279277

280278
let res = rpc.fund_raw_transaction(&tx, None, None).unwrap();
281279
let tx = bitcoin::consensus::encode::deserialize::<Transaction>(&res.hex).unwrap();
282280

283281
// Not signed inputs should be a problem.
284-
if rpc.send_raw_transaction(&tx).is_ok() {
285-
assert!(false);
286-
};
282+
assert!(rpc.send_raw_transaction(&tx).is_err());
287283

288284
let res = rpc
289285
.sign_raw_transaction_with_wallet(&tx, None, None)

tests/transaction.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ fn use_utxo_from_send_to_address() {
6666
// assert_eq!(rpc.get_balance(None, None).unwrap(), deposit_value * 0x1F);
6767

6868
let tx = rpc.get_raw_transaction(&txid, None).unwrap();
69-
assert_eq!(tx.output.get(0).unwrap().value, deposit_value * 0x1F);
69+
assert_eq!(tx.output.first().unwrap().value, deposit_value * 0x1F);
7070

7171
// Valid tx.
7272
let txin = TxIn {
@@ -84,7 +84,5 @@ fn use_utxo_from_send_to_address() {
8484
deposit_address.script_pubkey(),
8585
);
8686
let tx = common::create_transaction(vec![txin], vec![txout]);
87-
if let Ok(_) = rpc.send_raw_transaction(&tx) {
88-
assert!(false);
89-
};
87+
assert!(rpc.send_raw_transaction(&tx).is_err());
9088
}

0 commit comments

Comments
 (0)