Skip to content

Commit

Permalink
clippy: Apply test suggestions.
Browse files Browse the repository at this point in the history
  • Loading branch information
ceyhunsen committed Sep 6, 2024
1 parent adc9f8f commit bb044d9
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 39 deletions.
10 changes: 3 additions & 7 deletions src/client/rpc_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -817,9 +817,7 @@ mod tests {
.ledger
.create_txout(Amount::from_sat(1), address.script_pubkey());
let tx = rpc.ledger.create_transaction(vec![], vec![txout]);
if let Ok(()) = rpc.ledger.check_transaction(&tx) {
assert!(false);
};
assert!(rpc.ledger.check_transaction(&tx).is_err());

// Generating blocks should add funds to wallet.
rpc.generate_to_address(101, &address).unwrap();
Expand All @@ -830,7 +828,7 @@ mod tests {
txid: rpc
.ledger
._get_transactions()
.get(0)
.first()
.unwrap()
.compute_txid(),
vout: 0,
Expand All @@ -842,9 +840,7 @@ mod tests {
.ledger
.create_txout(Amount::from_sat(1), address.script_pubkey());
let tx = rpc.ledger.create_transaction(vec![txin], vec![txout]);
if let Err(e) = rpc.ledger.check_transaction(&tx) {
assert!(false, "{:?}", e);
};
rpc.ledger.check_transaction(&tx).unwrap();
}

#[test]
Expand Down
4 changes: 1 addition & 3 deletions src/ledger/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -340,9 +340,7 @@ mod tests {
assert_eq!(current_height, 1);

assert_eq!(ledger.get_mempool_transactions().len(), 0);
if let Some(_) = ledger.get_mempool_transaction(tx.compute_txid()) {
assert!(false);
}
assert!(ledger.get_mempool_transaction(tx.compute_txid()).is_none());
}

#[test]
Expand Down
26 changes: 12 additions & 14 deletions src/ledger/script.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ mod tests {
assert_eq!(ledger.get_block_height().unwrap(), 3);

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

let script = Builder::new()
.push_int(0x1 as i64)
.push_int(0x1_i64)
.push_opcode(OP_CSV)
.push_opcode(OP_DROP)
.push_x_only_key(&xonly_pk)
Expand All @@ -208,22 +208,20 @@ mod tests {
}
assert_eq!(ledger.get_block_height().unwrap(), 9);
let script = Builder::new()
.push_int(0x45 as i64)
.push_int(0x45_i64)
.push_opcode(OP_CSV)
.push_opcode(OP_DROP)
.push_x_only_key(&xonly_pk)
.push_opcode(OP_CHECKSIG)
.into_script();
if let Ok(_) = ledger.check_sequence(utxo, script, 0x46) {
assert!(false);
}
assert!(ledger.check_sequence(utxo, script, 0x46).is_err());

for _ in 0..0x100 {
ledger.mine_block(&credential.address).unwrap();
}
assert_eq!(ledger.get_block_height().unwrap(), 9 + 0x100);
let script = Builder::new()
.push_int(0x100 as i64)
.push_int(0x100_i64)
.push_opcode(OP_CSV)
.push_opcode(OP_DROP)
.push_x_only_key(&xonly_pk)
Expand Down Expand Up @@ -271,13 +269,13 @@ mod tests {
.push_x_only_key(&xonly_pk)
.push_opcode(OP_CHECKSIG)
.into_script();
if let Ok(_) = ledger.check_sequence(
utxo,
script,
Sequence::from_512_second_intervals(0x44).to_consensus_u32(),
) {
assert!(false);
};
assert!(ledger
.check_sequence(
utxo,
script,
Sequence::from_512_second_intervals(0x44).to_consensus_u32(),
)
.is_err());

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

Expand Down
8 changes: 3 additions & 5 deletions src/ledger/transactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ mod tests {
let txs = ledger._get_transactions();
assert_eq!(txs.len(), 1);

let tx2 = txs.get(0).unwrap().to_owned();
let tx2 = txs.first().unwrap().to_owned();
assert_eq!(tx, tx2);

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

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

// Create a valid transaction. This should pass checks.
let txin = TxIn {
Expand Down
8 changes: 2 additions & 6 deletions tests/raw_transactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -273,17 +273,13 @@ fn fund_sign_raw_transaction_with_wallet() {
let tx = common::create_transaction(vec![], vec![txout]);

// Lower input funds should be a problem.
if rpc.send_raw_transaction(&tx).is_ok() {
assert!(false);
};
assert!(rpc.send_raw_transaction(&tx).is_err());

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

// Not signed inputs should be a problem.
if rpc.send_raw_transaction(&tx).is_ok() {
assert!(false);
};
assert!(rpc.send_raw_transaction(&tx).is_err());

let res = rpc
.sign_raw_transaction_with_wallet(&tx, None, None)
Expand Down
6 changes: 2 additions & 4 deletions tests/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ fn use_utxo_from_send_to_address() {
// assert_eq!(rpc.get_balance(None, None).unwrap(), deposit_value * 0x1F);

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

// Valid tx.
let txin = TxIn {
Expand All @@ -84,7 +84,5 @@ fn use_utxo_from_send_to_address() {
deposit_address.script_pubkey(),
);
let tx = common::create_transaction(vec![txin], vec![txout]);
if let Ok(_) = rpc.send_raw_transaction(&tx) {
assert!(false);
};
assert!(rpc.send_raw_transaction(&tx).is_err());
}

0 comments on commit bb044d9

Please sign in to comment.