Skip to content

Commit

Permalink
clippy and compile fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
sdbondi committed Jan 12, 2022
1 parent 774c5c0 commit a368749
Show file tree
Hide file tree
Showing 7 changed files with 125 additions and 75 deletions.
6 changes: 4 additions & 2 deletions base_layer/core/src/covenants/fields.rs
Original file line number Diff line number Diff line change
Expand Up @@ -345,8 +345,10 @@ mod test {

#[test]
fn get_field_value_ref() {
let mut features = OutputFeatures::default();
features.maturity = 42;
let features = OutputFeatures {
maturity: 42,
..Default::default()
};
let output = create_outputs(1, UtxoTestParams {
features: features.clone(),
..Default::default()
Expand Down
6 changes: 3 additions & 3 deletions base_layer/core/src/transactions/transaction/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -545,11 +545,11 @@ mod validate_internal_consistency {

test_case(
&UtxoTestParams {
covenant: covenant.clone(),
covenant,
..Default::default()
},
&UtxoTestParams {
features: features.clone(),
features,
..Default::default()
},
0,
Expand Down Expand Up @@ -594,7 +594,7 @@ mod validate_internal_consistency {
// Pass because height == 100
test_case(
&UtxoTestParams {
covenant: covenant.clone(),
covenant,
..Default::default()
},
&UtxoTestParams::default(),
Expand Down
52 changes: 28 additions & 24 deletions base_layer/wallet/src/transaction_service/storage/sqlite_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1999,14 +1999,17 @@ mod test {
transaction::{TransactionDirection, TransactionStatus, TxId},
types::{HashDigest, PrivateKey, PublicKey, Signature},
};
use tari_core::transactions::{
tari_amount::MicroTari,
test_helpers::{create_unblinded_output, TestParams},
transaction::{OutputFeatures, Transaction},
transaction_protocol::sender::TransactionSenderMessage,
CryptoFactories,
ReceiverTransactionProtocol,
SenderTransactionProtocol,
use tari_core::{
covenants::Covenant,
transactions::{
tari_amount::MicroTari,
test_helpers::{create_unblinded_output, TestParams},
transaction::{OutputFeatures, Transaction},
transaction_protocol::sender::TransactionSenderMessage,
CryptoFactories,
ReceiverTransactionProtocol,
SenderTransactionProtocol,
},
};
use tari_crypto::{
keys::{PublicKey as PublicKeyTrait, SecretKey as SecretKeyTrait},
Expand Down Expand Up @@ -2078,13 +2081,14 @@ mod test {
PrivateKey::random(&mut OsRng),
Default::default(),
PrivateKey::random(&mut OsRng),
Covenant::default(),
)
.with_change_script(script!(Nop), ExecutionStack::default(), PrivateKey::random(&mut OsRng));

let mut stp = builder.build::<HashDigest>(&factories, None, Some(u64::MAX)).unwrap();
let mut stp = builder.build::<HashDigest>(&factories, None, u64::MAX).unwrap();

let outbound_tx1 = OutboundTransaction {
tx_id: 1.into(),
tx_id: 1u64.into(),
destination_public_key: PublicKey::from_secret_key(&PrivateKey::random(&mut OsRng)),
amount,
fee: stp.get_fee_amount().unwrap(),
Expand All @@ -2099,7 +2103,7 @@ mod test {
};

let outbound_tx2 = OutboundTransactionSql::try_from(OutboundTransaction {
tx_id: 2.into(),
tx_id: 2u64.into(),
destination_public_key: PublicKey::from_secret_key(&PrivateKey::random(&mut OsRng)),
amount,
fee: stp.get_fee_amount().unwrap(),
Expand Down Expand Up @@ -2140,7 +2144,7 @@ mod test {
);

let inbound_tx1 = InboundTransaction {
tx_id: 2.into(),
tx_id: 2u64.into(),
source_public_key: PublicKey::from_secret_key(&PrivateKey::random(&mut OsRng)),
amount,
receiver_protocol: rtp.clone(),
Expand All @@ -2153,7 +2157,7 @@ mod test {
last_send_timestamp: None,
};
let inbound_tx2 = InboundTransaction {
tx_id: 3.into(),
tx_id: 3u64.into(),
source_public_key: PublicKey::from_secret_key(&PrivateKey::random(&mut OsRng)),
amount,
receiver_protocol: rtp,
Expand Down Expand Up @@ -2195,7 +2199,7 @@ mod test {
);

let completed_tx1 = CompletedTransaction {
tx_id: 2.into(),
tx_id: 2u64.into(),
source_public_key: PublicKey::from_secret_key(&PrivateKey::random(&mut OsRng)),
destination_public_key: PublicKey::from_secret_key(&PrivateKey::random(&mut OsRng)),
amount,
Expand All @@ -2216,7 +2220,7 @@ mod test {
mined_in_block: None,
};
let completed_tx2 = CompletedTransaction {
tx_id: 3.into(),
tx_id: 3u64.into(),
source_public_key: PublicKey::from_secret_key(&PrivateKey::random(&mut OsRng)),
destination_public_key: PublicKey::from_secret_key(&PrivateKey::random(&mut OsRng)),
amount,
Expand Down Expand Up @@ -2346,7 +2350,7 @@ mod test {
assert!(CompletedTransactionSql::find_by_cancelled(completed_tx1.tx_id, true, &conn).is_ok());

let coinbase_tx1 = CompletedTransaction {
tx_id: 101.into(),
tx_id: 101u64.into(),
source_public_key: PublicKey::from_secret_key(&PrivateKey::random(&mut OsRng)),
destination_public_key: PublicKey::from_secret_key(&PrivateKey::random(&mut OsRng)),
amount,
Expand All @@ -2368,7 +2372,7 @@ mod test {
};

let coinbase_tx2 = CompletedTransaction {
tx_id: 102.into(),
tx_id: 102u64.into(),
source_public_key: PublicKey::from_secret_key(&PrivateKey::random(&mut OsRng)),
destination_public_key: PublicKey::from_secret_key(&PrivateKey::random(&mut OsRng)),
amount,
Expand All @@ -2390,7 +2394,7 @@ mod test {
};

let coinbase_tx3 = CompletedTransaction {
tx_id: 103.into(),
tx_id: 103u64.into(),
source_public_key: PublicKey::from_secret_key(&PrivateKey::random(&mut OsRng)),
destination_public_key: PublicKey::from_secret_key(&PrivateKey::random(&mut OsRng)),
amount,
Expand Down Expand Up @@ -2450,7 +2454,7 @@ mod test {
let cipher = Aes256Gcm::new(key);

let inbound_tx = InboundTransaction {
tx_id: 1.into(),
tx_id: 1u64.into(),
source_public_key: PublicKey::from_secret_key(&PrivateKey::random(&mut OsRng)),
amount: MicroTari::from(100),
receiver_protocol: ReceiverTransactionProtocol::new_placeholder(),
Expand All @@ -2472,7 +2476,7 @@ mod test {
assert_eq!(inbound_tx, decrypted_inbound_tx);

let outbound_tx = OutboundTransaction {
tx_id: 2.into(),
tx_id: 2u64.into(),
destination_public_key: PublicKey::from_secret_key(&PrivateKey::random(&mut OsRng)),
amount: MicroTari::from(100),
fee: MicroTari::from(10),
Expand All @@ -2496,7 +2500,7 @@ mod test {
assert_eq!(outbound_tx, decrypted_outbound_tx);

let completed_tx = CompletedTransaction {
tx_id: 3.into(),
tx_id: 3u64.into(),
source_public_key: PublicKey::from_secret_key(&PrivateKey::random(&mut OsRng)),
destination_public_key: PublicKey::from_secret_key(&PrivateKey::random(&mut OsRng)),
amount: MicroTari::from(100),
Expand Down Expand Up @@ -2554,7 +2558,7 @@ mod test {
embedded_migrations::run_with_output(&conn, &mut std::io::stdout()).expect("Migration failed");

let inbound_tx = InboundTransaction {
tx_id: 1.into(),
tx_id: 1u64.into(),
source_public_key: PublicKey::from_secret_key(&PrivateKey::random(&mut OsRng)),
amount: MicroTari::from(100),
receiver_protocol: ReceiverTransactionProtocol::new_placeholder(),
Expand All @@ -2570,7 +2574,7 @@ mod test {
inbound_tx_sql.commit(&conn).unwrap();

let outbound_tx = OutboundTransaction {
tx_id: 2.into(),
tx_id: 2u64.into(),
destination_public_key: PublicKey::from_secret_key(&PrivateKey::random(&mut OsRng)),
amount: MicroTari::from(100),
fee: MicroTari::from(10),
Expand All @@ -2587,7 +2591,7 @@ mod test {
outbound_tx_sql.commit(&conn).unwrap();

let completed_tx = CompletedTransaction {
tx_id: 3.into(),
tx_id: 3u64.into(),
source_public_key: PublicKey::from_secret_key(&PrivateKey::random(&mut OsRng)),
destination_public_key: PublicKey::from_secret_key(&PrivateKey::random(&mut OsRng)),
amount: MicroTari::from(100),
Expand Down
34 changes: 29 additions & 5 deletions base_layer/wallet/tests/output_manager_service_tests/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ use tari_core::{
base_node::rpc::BaseNodeWalletRpcServer,
blocks::BlockHeader,
consensus::{ConsensusConstantsBuilder, ConsensusEncodingSized},
covenants::Covenant,
proto::base_node::{QueryDeletedResponse, UtxoQueryResponse, UtxoQueryResponses},
transactions::{
fee::Fee,
Expand Down Expand Up @@ -304,14 +305,15 @@ fn generate_sender_transaction_message(amount: MicroTari) -> (TxId, TransactionS
PrivateKey::random(&mut OsRng),
OutputFeatures::default(),
PrivateKey::random(&mut OsRng),
Covenant::default(),
)
.with_change_script(
script!(Nop),
inputs!(PublicKey::from_secret_key(&script_private_key)),
script_private_key,
);

let mut stp = builder.build::<Blake256>(&factories, None, Some(u64::MAX)).unwrap();
let mut stp = builder.build::<Blake256>(&factories, None, u64::MAX).unwrap();
let tx_id = stp.get_tx_id().unwrap();
(
tx_id,
Expand Down Expand Up @@ -396,6 +398,7 @@ async fn test_utxo_selection_no_chain_metadata() {
None,
"".to_string(),
script!(Nop),
Covenant::default(),
)
.await
.unwrap_err();
Expand Down Expand Up @@ -423,6 +426,7 @@ async fn test_utxo_selection_no_chain_metadata() {
None,
"".to_string(),
script!(Nop),
Covenant::default(),
)
.await
.unwrap();
Expand Down Expand Up @@ -502,6 +506,7 @@ async fn test_utxo_selection_with_chain_metadata() {
None,
"".to_string(),
script!(Nop),
Covenant::default(),
)
.await
.unwrap_err();
Expand Down Expand Up @@ -558,6 +563,7 @@ async fn test_utxo_selection_with_chain_metadata() {
None,
"".to_string(),
script!(Nop),
Covenant::default(),
)
.await
.unwrap();
Expand All @@ -584,6 +590,7 @@ async fn test_utxo_selection_with_chain_metadata() {
None,
"".to_string(),
script!(Nop),
Covenant::default(),
)
.await
.unwrap();
Expand Down Expand Up @@ -628,6 +635,7 @@ async fn send_not_enough_funds() {
None,
"".to_string(),
script!(Nop),
Covenant::default(),
)
.await
{
Expand Down Expand Up @@ -681,6 +689,7 @@ async fn send_no_change() {
None,
"".to_string(),
script!(Nop),
Covenant::default(),
)
.await
.unwrap();
Expand Down Expand Up @@ -736,6 +745,7 @@ async fn send_not_enough_for_change() {
None,
"".to_string(),
script!(Nop),
Covenant::default(),
)
.await
{
Expand Down Expand Up @@ -772,6 +782,7 @@ async fn cancel_transaction() {
None,
"".to_string(),
script!(Nop),
Covenant::default(),
)
.await
.unwrap();
Expand Down Expand Up @@ -850,6 +861,7 @@ async fn test_get_balance() {
None,
"".to_string(),
script!(Nop),
Covenant::default(),
)
.await
.unwrap();
Expand Down Expand Up @@ -896,6 +908,7 @@ async fn sending_transaction_with_short_term_clear() {
None,
"".to_string(),
script!(Nop),
Covenant::default(),
)
.await
.unwrap();
Expand Down Expand Up @@ -923,6 +936,7 @@ async fn sending_transaction_with_short_term_clear() {
None,
"".to_string(),
script!(Nop),
Covenant::default(),
)
.await
.unwrap();
Expand Down Expand Up @@ -1030,13 +1044,22 @@ async fn handle_coinbase() {
let fees3 = MicroTari::from(500);
let value3 = reward3 + fees3;

let _ = oms.get_coinbase_transaction(1.into(), reward1, fees1, 1).await.unwrap();
let _ = oms
.get_coinbase_transaction(1u64.into(), reward1, fees1, 1)
.await
.unwrap();
assert_eq!(oms.get_unspent_outputs().await.unwrap().len(), 0);
assert_eq!(oms.get_balance().await.unwrap().pending_incoming_balance, value1);
let _tx2 = oms.get_coinbase_transaction(2.into(), reward2, fees2, 1).await.unwrap();
let _tx2 = oms
.get_coinbase_transaction(2u64.into(), reward2, fees2, 1)
.await
.unwrap();
assert_eq!(oms.get_unspent_outputs().await.unwrap().len(), 0);
assert_eq!(oms.get_balance().await.unwrap().pending_incoming_balance, value2);
let tx3 = oms.get_coinbase_transaction(3.into(), reward3, fees3, 2).await.unwrap();
let tx3 = oms
.get_coinbase_transaction(3u64.into(), reward3, fees3, 2)
.await
.unwrap();
assert_eq!(oms.get_unspent_outputs().await.unwrap().len(), 0);
assert_eq!(
oms.get_balance().await.unwrap().pending_incoming_balance,
Expand Down Expand Up @@ -1185,6 +1208,7 @@ async fn test_txo_validation() {
None,
"".to_string(),
script!(Nop),
Covenant::default(),
)
.await
.unwrap();
Expand All @@ -1194,7 +1218,7 @@ async fn test_txo_validation() {

let _ = oms.get_recipient_transaction(sender_message).await.unwrap();

oms.get_coinbase_transaction(6.into(), MicroTari::from(15_000_000), MicroTari::from(1_000_000), 2)
oms.get_coinbase_transaction(6u64.into(), MicroTari::from(15_000_000), MicroTari::from(1_000_000), 2)
.await
.unwrap();

Expand Down
Loading

0 comments on commit a368749

Please sign in to comment.