diff --git a/apps/src/lib/cli.rs b/apps/src/lib/cli.rs index 93c08c60300..c408b015a82 100644 --- a/apps/src/lib/cli.rs +++ b/apps/src/lib/cli.rs @@ -2810,7 +2810,12 @@ pub mod args { "The maximum amount of gas needed to run transaction", ), ) - .arg(EXPIRATION_OPT.def().about("The expiration datetime of the transaction, after which the tx won't be accepted anymore. All of these examples are equivalent:\n2012-12-12T12:12:12Z\n2012-12-12 12:12:12Z\n2012- 12-12T12: 12:12Z")) + .arg(EXPIRATION_OPT.def().about( + "The expiration datetime of the transaction, after which the \ + tx won't be accepted anymore. All of these examples are \ + equivalent:\n2012-12-12T12:12:12Z\n2012-12-12 \ + 12:12:12Z\n2012- 12-12T12: 12:12Z", + )) .arg( SIGNING_KEY_OPT .def() diff --git a/apps/src/lib/client/rpc.rs b/apps/src/lib/client/rpc.rs index 6c1ad987d8b..2230fb037ad 100644 --- a/apps/src/lib/client/rpc.rs +++ b/apps/src/lib/client/rpc.rs @@ -1755,9 +1755,9 @@ pub async fn query_bonded_stake(ctx: Context, args: args::QueryBondedStake) { }; let is_active = validator_set.active.contains(&weighted); if !is_active { - debug_assert!(validator_set - .inactive - .contains(&weighted)); + debug_assert!( + validator_set.inactive.contains(&weighted) + ); } println!( "Validator {} is {}, bonded stake: {}", diff --git a/apps/src/lib/node/ledger/shell/prepare_proposal.rs b/apps/src/lib/node/ledger/shell/prepare_proposal.rs index 6e170a76a63..a3e82a16172 100644 --- a/apps/src/lib/node/ledger/shell/prepare_proposal.rs +++ b/apps/src/lib/node/ledger/shell/prepare_proposal.rs @@ -55,7 +55,7 @@ where .into_iter() .map(|tx_bytes| { match Tx::try_from(tx_bytes.as_slice()) { - Ok(tx) => { + Ok(tx) => { let tx_expiration = tx.expiration; if let Ok(TxType::Wrapper(_)) = process_tx(tx) { // Check tx expiration against proposed block @@ -65,40 +65,31 @@ where Some(&block_time) => { match TryInto::::try_into(block_time.to_owned()) { Ok(datetime) => { - -if datetime > exp { - record::remove(tx_bytes) - } else { - record::keep(tx_bytes) - } + if datetime > exp { + record::remove(tx_bytes) + } else { + record::keep(tx_bytes) + } }, Err(_) => { - - // Default to last block datetime which has already been checked by mempool_validate, so accept the tx - record::keep(tx_bytes) + // Default to last block datetime which has already been checked by mempool_validate, so accept the tx + record::keep(tx_bytes) } } }, None => { - - // Default to last block datetime which has already been checked by mempool_validate, so accept the tx - record::keep(tx_bytes) + // Default to last block datetime which has already been checked by mempool_validate, so accept the tx + record::keep(tx_bytes) } } }, None => record::keep(tx_bytes) } - - - } else { + } else { record::remove(tx_bytes) } } Err(_) => record::remove(tx_bytes), - - - - } }) .take_while(|tx_record| { @@ -129,21 +120,19 @@ if datetime > exp { Some(block_time) => { match TryInto::::try_into(block_time.to_owned()) { Ok(datetime) => { - -if datetime > exp { None - } else { - Some(tx_bytes) - } + if datetime > exp { + None + } else { + Some(tx_bytes) + } }, Err(_) => { - // Default to last block datetime which has already been checked by mempool_validate, so accept the tx Some(tx_bytes) } } }, None => { - // Default to last block datetime which has already been checked by mempool_validate, so accept the tx Some(tx_bytes) } @@ -151,9 +140,7 @@ if datetime > exp { None }, None => Some(tx_bytes) } - - - } else { + } else { None } } @@ -440,54 +427,53 @@ mod test_prepare_proposal { /// Test that expired wrapper transactions are not included in the block #[test] fn test_expired_wrapper_tx() { - -let (shell, _) = TestShell::new(); + let (shell, _) = TestShell::new(); let keypair = gen_keypair(); let tx_time = DateTimeUtc::now(); -let tx = Tx::new( - "wasm_code".as_bytes().to_owned(), - Some("transaction data".as_bytes().to_owned()), - shell.chain_id.clone(), - None, - ); - let wrapper_tx = WrapperTx::new( - Fee { - amount: 0.into(), - token: shell.wl_storage.storage.native_token.clone(), - }, - &keypair, - 0.into(), - tx, - Default::default(), - #[cfg(not(feature = "mainnet"))] - None, - ); - let wrapper = wrapper_tx - .sign(&keypair, shell.chain_id.clone(), Some(tx_time)) - .expect("Test failed"); + let tx = Tx::new( + "wasm_code".as_bytes().to_owned(), + Some("transaction data".as_bytes().to_owned()), + shell.chain_id.clone(), + None, + ); + let wrapper_tx = WrapperTx::new( + Fee { + amount: 0.into(), + token: shell.wl_storage.storage.native_token.clone(), + }, + &keypair, + 0.into(), + tx, + Default::default(), + #[cfg(not(feature = "mainnet"))] + None, + ); + let wrapper = wrapper_tx + .sign(&keypair, shell.chain_id.clone(), Some(tx_time)) + .expect("Test failed"); -let time = DateTimeUtc::now(); -let mut block_time = namada::core::tendermint_proto::google::protobuf::Timestamp::default(); - block_time.seconds = -time.0.timestamp(); - block_time.nanos = -time.0.timestamp_subsec_nanos() as i32; - let req = RequestPrepareProposal { + let time = DateTimeUtc::now(); + let block_time = + namada::core::tendermint_proto::google::protobuf::Timestamp { + seconds: time.0.timestamp(), + nanos: time.0.timestamp_subsec_nanos() as i32, + }; + let req = RequestPrepareProposal { txs: vec![wrapper.to_bytes()], max_tx_bytes: 0, - time: Some(block_time) , - ..Default::default() + time: Some(block_time), + ..Default::default() }; #[cfg(feature = "abcipp")] assert_eq!( shell.prepare_proposal(req).tx_records, vec![record::remove(tx.to_bytes())] ); - #[cfg(not(feature = "abcipp"))] + #[cfg(not(feature = "abcipp"))] { let result = shell.prepare_proposal(req); eprintln!("Proposal: {:?}", result.txs); - assert!(result.txs.is_empty()); + assert!(result.txs.is_empty()); } } } diff --git a/apps/src/lib/node/ledger/shell/process_proposal.rs b/apps/src/lib/node/ledger/shell/process_proposal.rs index 031fffc3175..164249f96da 100644 --- a/apps/src/lib/node/ledger/shell/process_proposal.rs +++ b/apps/src/lib/node/ledger/shell/process_proposal.rs @@ -1424,7 +1424,7 @@ mod test_process_proposal { }, &keypair, 0.into(), - tx.clone(), + tx, Default::default(), #[cfg(not(feature = "mainnet"))] None, diff --git a/apps/src/lib/node/ledger/shims/abcipp_shim.rs b/apps/src/lib/node/ledger/shims/abcipp_shim.rs index e6d07ce85cd..bc44437c552 100644 --- a/apps/src/lib/node/ledger/shims/abcipp_shim.rs +++ b/apps/src/lib/node/ledger/shims/abcipp_shim.rs @@ -145,18 +145,26 @@ impl AbcippShim { Ok(t) => t, Err(_) => { // Default to last committed block time - self.service.wl_storage - .storage - .get_last_block_timestamp() - .expect("Failed to retrieve last block timestamp") + self.service + .wl_storage + .storage + .get_last_block_timestamp() + .expect( + "Failed to retrieve last block \ + timestamp", + ) } }, None => { // Default to last committed block time - self.service.wl_storage - .storage - .get_last_block_timestamp() - .expect("Failed to retrieve last block timestamp") + self.service + .wl_storage + .storage + .get_last_block_timestamp() + .expect( + "Failed to retrieve last block \ + timestamp", + ) } }, None => { diff --git a/core/src/ledger/storage/mod.rs b/core/src/ledger/storage/mod.rs index 8887e5c59d8..1633affb6cc 100644 --- a/core/src/ledger/storage/mod.rs +++ b/core/src/ledger/storage/mod.rs @@ -736,7 +736,7 @@ where Ok(self .db .read_block_header(last_block_height)? - .map_or_else(|| DateTimeUtc::now(), |header| header.time)) + .map_or_else(DateTimeUtc::now, |header| header.time)) } /// Initialize a new epoch when the current epoch is finished. Returns diff --git a/core/src/proto/mod.rs b/core/src/proto/mod.rs index cda7c8f1acd..39e18f23b7c 100644 --- a/core/src/proto/mod.rs +++ b/core/src/proto/mod.rs @@ -7,10 +7,11 @@ pub use types::{Dkg, Error, Signed, SignedTxData, Tx}; #[cfg(test)] mod tests { + use std::time::SystemTime; + use data_encoding::HEXLOWER; use generated::types::Tx; use prost::Message; - use std::time::SystemTime; use super::*; use crate::types::chain::ChainId; diff --git a/core/src/types/transaction/decrypted.rs b/core/src/types/transaction/decrypted.rs index f8c4327cdb2..34071791682 100644 --- a/core/src/types/transaction/decrypted.rs +++ b/core/src/types/transaction/decrypted.rs @@ -93,9 +93,10 @@ pub mod decrypted_tx { .try_to_vec() .expect("Encrypting transaction should not fail"), ), - // If undecrytable we cannot extract the ChainId and expiration. - // If instead the tx gets decrypted successfully, the correct - // chain id and expiration are serialized inside the data field + // If undecrytable we cannot extract the ChainId and + // expiration. If instead the tx gets decrypted + // successfully, the correct chain id and + // expiration are serialized inside the data field // of the Tx, while the ones available // in the chain_id and expiration field are just placeholders ChainId(String::new()), diff --git a/core/src/types/transaction/mod.rs b/core/src/types/transaction/mod.rs index 2b9a805a095..dd67a81028e 100644 --- a/core/src/types/transaction/mod.rs +++ b/core/src/types/transaction/mod.rs @@ -246,7 +246,8 @@ pub mod tx_types { vec![], Some(ty.try_to_vec().unwrap()), ChainId(String::new()), /* No need to provide a valid - * ChainId or expiration when casting back from + * ChainId or expiration when + * casting back from * TxType */ None, ) diff --git a/shared/src/ledger/ibc/vp/mod.rs b/shared/src/ledger/ibc/vp/mod.rs index 01fceea7b47..8294b934ac2 100644 --- a/shared/src/ledger/ibc/vp/mod.rs +++ b/shared/src/ledger/ibc/vp/mod.rs @@ -626,9 +626,14 @@ mod tests { let ibc = Ibc { ctx }; // this should return true because state has been stored - assert!(ibc - .validate_tx(tx.data.as_ref().unwrap(), &keys_changed, &verifiers) - .expect("validation failed")); + assert!( + ibc.validate_tx( + tx.data.as_ref().unwrap(), + &keys_changed, + &verifiers + ) + .expect("validation failed") + ); } #[test] @@ -745,9 +750,14 @@ mod tests { ); let ibc = Ibc { ctx }; // this should return true because state has been stored - assert!(ibc - .validate_tx(tx.data.as_ref().unwrap(), &keys_changed, &verifiers) - .expect("validation failed")); + assert!( + ibc.validate_tx( + tx.data.as_ref().unwrap(), + &keys_changed, + &verifiers + ) + .expect("validation failed") + ); } #[test] @@ -801,9 +811,14 @@ mod tests { ); let ibc = Ibc { ctx }; // this should return true because state has been stored - assert!(ibc - .validate_tx(tx.data.as_ref().unwrap(), &keys_changed, &verifiers) - .expect("validation failed")); + assert!( + ibc.validate_tx( + tx.data.as_ref().unwrap(), + &keys_changed, + &verifiers + ) + .expect("validation failed") + ); } #[test] @@ -938,9 +953,14 @@ mod tests { ); let ibc = Ibc { ctx }; // this should return true because state has been stored - assert!(ibc - .validate_tx(tx.data.as_ref().unwrap(), &keys_changed, &verifiers) - .expect("validation failed")); + assert!( + ibc.validate_tx( + tx.data.as_ref().unwrap(), + &keys_changed, + &verifiers + ) + .expect("validation failed") + ); } #[test] @@ -1022,9 +1042,14 @@ mod tests { vp_wasm_cache, ); let ibc = Ibc { ctx }; - assert!(ibc - .validate_tx(tx.data.as_ref().unwrap(), &keys_changed, &verifiers) - .expect("validation failed")); + assert!( + ibc.validate_tx( + tx.data.as_ref().unwrap(), + &keys_changed, + &verifiers + ) + .expect("validation failed") + ); } #[test] @@ -1094,9 +1119,14 @@ mod tests { vp_wasm_cache, ); let ibc = Ibc { ctx }; - assert!(ibc - .validate_tx(tx.data.as_ref().unwrap(), &keys_changed, &verifiers) - .expect("validation failed")); + assert!( + ibc.validate_tx( + tx.data.as_ref().unwrap(), + &keys_changed, + &verifiers + ) + .expect("validation failed") + ); } #[test] @@ -1152,9 +1182,14 @@ mod tests { vp_wasm_cache, ); let ibc = Ibc { ctx }; - assert!(ibc - .validate_tx(tx.data.as_ref().unwrap(), &keys_changed, &verifiers) - .expect("validation failed")); + assert!( + ibc.validate_tx( + tx.data.as_ref().unwrap(), + &keys_changed, + &verifiers + ) + .expect("validation failed") + ); } #[test] @@ -1229,9 +1264,14 @@ mod tests { vp_wasm_cache, ); let ibc = Ibc { ctx }; - assert!(ibc - .validate_tx(tx.data.as_ref().unwrap(), &keys_changed, &verifiers) - .expect("validation failed")); + assert!( + ibc.validate_tx( + tx.data.as_ref().unwrap(), + &keys_changed, + &verifiers + ) + .expect("validation failed") + ); } #[test] @@ -1314,9 +1354,14 @@ mod tests { vp_wasm_cache, ); let ibc = Ibc { ctx }; - assert!(ibc - .validate_tx(tx.data.as_ref().unwrap(), &keys_changed, &verifiers) - .expect("validation failed")); + assert!( + ibc.validate_tx( + tx.data.as_ref().unwrap(), + &keys_changed, + &verifiers + ) + .expect("validation failed") + ); } #[test] @@ -1396,9 +1441,14 @@ mod tests { vp_wasm_cache, ); let ibc = Ibc { ctx }; - assert!(ibc - .validate_tx(tx.data.as_ref().unwrap(), &keys_changed, &verifiers) - .expect("validation failed")); + assert!( + ibc.validate_tx( + tx.data.as_ref().unwrap(), + &keys_changed, + &verifiers + ) + .expect("validation failed") + ); } #[test] @@ -1433,9 +1483,14 @@ mod tests { vp_wasm_cache, ); let ibc = Ibc { ctx }; - assert!(ibc - .validate_tx(tx.data.as_ref().unwrap(), &keys_changed, &verifiers) - .expect("validation failed")); + assert!( + ibc.validate_tx( + tx.data.as_ref().unwrap(), + &keys_changed, + &verifiers + ) + .expect("validation failed") + ); } #[test] @@ -1473,9 +1528,14 @@ mod tests { ); let ibc = Ibc { ctx }; - assert!(ibc - .validate_tx(tx.data.as_ref().unwrap(), &keys_changed, &verifiers) - .expect("validation failed")); + assert!( + ibc.validate_tx( + tx.data.as_ref().unwrap(), + &keys_changed, + &verifiers + ) + .expect("validation failed") + ); } #[test] @@ -1552,9 +1612,14 @@ mod tests { vp_wasm_cache, ); let ibc = Ibc { ctx }; - assert!(ibc - .validate_tx(tx.data.as_ref().unwrap(), &keys_changed, &verifiers) - .expect("validation failed")); + assert!( + ibc.validate_tx( + tx.data.as_ref().unwrap(), + &keys_changed, + &verifiers + ) + .expect("validation failed") + ); } #[test] @@ -1638,9 +1703,14 @@ mod tests { vp_wasm_cache, ); let ibc = Ibc { ctx }; - assert!(ibc - .validate_tx(tx.data.as_ref().unwrap(), &keys_changed, &verifiers) - .expect("validation failed")); + assert!( + ibc.validate_tx( + tx.data.as_ref().unwrap(), + &keys_changed, + &verifiers + ) + .expect("validation failed") + ); } #[test] @@ -1729,9 +1799,14 @@ mod tests { vp_wasm_cache, ); let ibc = Ibc { ctx }; - assert!(ibc - .validate_tx(tx.data.as_ref().unwrap(), &keys_changed, &verifiers) - .expect("validation failed")); + assert!( + ibc.validate_tx( + tx.data.as_ref().unwrap(), + &keys_changed, + &verifiers + ) + .expect("validation failed") + ); } #[test] @@ -1812,9 +1887,14 @@ mod tests { vp_wasm_cache, ); let ibc = Ibc { ctx }; - assert!(ibc - .validate_tx(tx.data.as_ref().unwrap(), &keys_changed, &verifiers) - .expect("validation failed")); + assert!( + ibc.validate_tx( + tx.data.as_ref().unwrap(), + &keys_changed, + &verifiers + ) + .expect("validation failed") + ); } #[test] @@ -1902,9 +1982,14 @@ mod tests { ); let ibc = Ibc { ctx }; - assert!(ibc - .validate_tx(tx.data.as_ref().unwrap(), &keys_changed, &verifiers) - .expect("validation failed")); + assert!( + ibc.validate_tx( + tx.data.as_ref().unwrap(), + &keys_changed, + &verifiers + ) + .expect("validation failed") + ); } #[test] @@ -1948,8 +2033,13 @@ mod tests { ); let ibc = Ibc { ctx }; - assert!(ibc - .validate_tx(tx.data.as_ref().unwrap(), &keys_changed, &verifiers) - .expect("validation failed")); + assert!( + ibc.validate_tx( + tx.data.as_ref().unwrap(), + &keys_changed, + &verifiers + ) + .expect("validation failed") + ); } } diff --git a/tests/src/vm_host_env/mod.rs b/tests/src/vm_host_env/mod.rs index 0c0a21e4080..0332474bdfd 100644 --- a/tests/src/vm_host_env/mod.rs +++ b/tests/src/vm_host_env/mod.rs @@ -135,11 +135,13 @@ mod tests { // Trying to delete a validity predicate should fail let key = storage::Key::validity_predicate(&test_account); - assert!(panic::catch_unwind(|| { tx::ctx().delete(&key).unwrap() }) - .err() - .map(|a| a.downcast_ref::().cloned().unwrap()) - .unwrap() - .contains("CannotDeleteVp")); + assert!( + panic::catch_unwind(|| { tx::ctx().delete(&key).unwrap() }) + .err() + .map(|a| a.downcast_ref::().cloned().unwrap()) + .unwrap() + .contains("CannotDeleteVp") + ); } #[test] @@ -466,17 +468,21 @@ mod tests { .expect("decoding signed data we just signed") }); assert_eq!(&signed_tx_data.data, data); - assert!(vp::CTX - .verify_tx_signature(&pk, &signed_tx_data.sig) - .unwrap()); + assert!( + vp::CTX + .verify_tx_signature(&pk, &signed_tx_data.sig) + .unwrap() + ); let other_keypair = key::testing::keypair_2(); - assert!(!vp::CTX - .verify_tx_signature( - &other_keypair.ref_to(), - &signed_tx_data.sig - ) - .unwrap()); + assert!( + !vp::CTX + .verify_tx_signature( + &other_keypair.ref_to(), + &signed_tx_data.sig + ) + .unwrap() + ); } } diff --git a/wasm/wasm_source/src/tx_bond.rs b/wasm/wasm_source/src/tx_bond.rs index b94e6f92870..ec2fb7a86ba 100644 --- a/wasm/wasm_source/src/tx_bond.rs +++ b/wasm/wasm_source/src/tx_bond.rs @@ -93,7 +93,7 @@ mod tests { let tx_code = vec![]; let tx_data = bond.try_to_vec().unwrap(); - let tx = Tx::new(tx_code, Some(tx_data), ChainId::default()); + let tx = Tx::new(tx_code, Some(tx_data), ChainId::default(), None); let signed_tx = tx.sign(&key); let tx_data = signed_tx.data.unwrap(); diff --git a/wasm/wasm_source/src/tx_change_validator_commission.rs b/wasm/wasm_source/src/tx_change_validator_commission.rs index ede50c696c7..5b68a87fe64 100644 --- a/wasm/wasm_source/src/tx_change_validator_commission.rs +++ b/wasm/wasm_source/src/tx_change_validator_commission.rs @@ -80,7 +80,7 @@ mod tests { let tx_code = vec![]; let tx_data = commission_change.try_to_vec().unwrap(); - let tx = Tx::new(tx_code, Some(tx_data), ChainId::default()); + let tx = Tx::new(tx_code, Some(tx_data), ChainId::default(), None); let signed_tx = tx.sign(&key); let tx_data = signed_tx.data.unwrap(); diff --git a/wasm/wasm_source/src/tx_unbond.rs b/wasm/wasm_source/src/tx_unbond.rs index bb038e84a94..e465badb41f 100644 --- a/wasm/wasm_source/src/tx_unbond.rs +++ b/wasm/wasm_source/src/tx_unbond.rs @@ -116,7 +116,7 @@ mod tests { let tx_code = vec![]; let tx_data = unbond.try_to_vec().unwrap(); - let tx = Tx::new(tx_code, Some(tx_data), ChainId::default()); + let tx = Tx::new(tx_code, Some(tx_data), ChainId::default(), None); let signed_tx = tx.sign(&key); let tx_data = signed_tx.data.unwrap(); diff --git a/wasm/wasm_source/src/tx_withdraw.rs b/wasm/wasm_source/src/tx_withdraw.rs index 8103ae55049..5cf800cc984 100644 --- a/wasm/wasm_source/src/tx_withdraw.rs +++ b/wasm/wasm_source/src/tx_withdraw.rs @@ -146,7 +146,7 @@ mod tests { let tx_code = vec![]; let tx_data = withdraw.try_to_vec().unwrap(); - let tx = Tx::new(tx_code, Some(tx_data), ChainId::default()); + let tx = Tx::new(tx_code, Some(tx_data), ChainId::default(), None); let signed_tx = tx.sign(&key); let tx_data = signed_tx.data.unwrap();