From 5d275c3aa1acda7c74a45fbd6f71a8c704416bcc Mon Sep 17 00:00:00 2001 From: Marco Granelli Date: Sat, 20 May 2023 19:34:03 +0200 Subject: [PATCH] Clippy + fmt --- .../lib/node/ledger/shell/finalize_block.rs | 34 ++-- .../lib/node/ledger/shell/process_proposal.rs | 39 ++-- apps/src/lib/wasm_loader/mod.rs | 4 +- benches/mod.rs | 2 +- benches/native_vps.rs | 48 ++--- benches/process_wrapper.rs | 3 +- benches/vps.rs | 158 ++++++++-------- shared/src/ledger/ibc/vp/mod.rs | 169 +++++++++++++----- shared/src/ledger/protocol/mod.rs | 2 +- shared/src/vm/wasm/run.rs | 30 ++-- tests/src/vm_host_env/mod.rs | 34 ++-- 11 files changed, 321 insertions(+), 202 deletions(-) diff --git a/apps/src/lib/node/ledger/shell/finalize_block.rs b/apps/src/lib/node/ledger/shell/finalize_block.rs index 9e743d3b298..ce0d296b56f 100644 --- a/apps/src/lib/node/ledger/shell/finalize_block.rs +++ b/apps/src/lib/node/ledger/shell/finalize_block.rs @@ -1598,9 +1598,11 @@ mod test_finalize_block { // won't receive votes from TM since we receive votes at a 1-block // delay, so votes will be empty here next_block_for_inflation(&mut shell, pkh1.clone(), vec![]); - assert!(rewards_accumulator_handle() - .is_empty(&shell.wl_storage) - .unwrap()); + assert!( + rewards_accumulator_handle() + .is_empty(&shell.wl_storage) + .unwrap() + ); // FINALIZE BLOCK 2. Tell Namada that val1 is the block proposer. // Include votes that correspond to block 1. Make val2 the next block's @@ -1610,9 +1612,11 @@ mod test_finalize_block { assert!(rewards_prod_2.is_empty(&shell.wl_storage).unwrap()); assert!(rewards_prod_3.is_empty(&shell.wl_storage).unwrap()); assert!(rewards_prod_4.is_empty(&shell.wl_storage).unwrap()); - assert!(!rewards_accumulator_handle() - .is_empty(&shell.wl_storage) - .unwrap()); + assert!( + !rewards_accumulator_handle() + .is_empty(&shell.wl_storage) + .unwrap() + ); // Val1 was the proposer, so its reward should be larger than all // others, which should themselves all be equal let acc_sum = get_rewards_sum(&shell.wl_storage); @@ -1713,9 +1717,11 @@ mod test_finalize_block { ); next_block_for_inflation(&mut shell, pkh1.clone(), votes.clone()); } - assert!(rewards_accumulator_handle() - .is_empty(&shell.wl_storage) - .unwrap()); + assert!( + rewards_accumulator_handle() + .is_empty(&shell.wl_storage) + .unwrap() + ); let rp1 = rewards_prod_1 .get(&shell.wl_storage, &Epoch::default()) .unwrap() @@ -1841,10 +1847,12 @@ mod test_finalize_block { let code = event.attributes.get("code").expect("Testfailed").as_str(); assert_eq!(code, String::from(ErrorCodes::WasmRuntimeError).as_str()); - assert!(!shell - .wl_storage - .has_key(&inner_hash_key) - .expect("Test failed")) + assert!( + !shell + .wl_storage + .has_key(&inner_hash_key) + .expect("Test failed") + ) } /// Test that a wrapper transaction rejected by [`process_proposal`] because diff --git a/apps/src/lib/node/ledger/shell/process_proposal.rs b/apps/src/lib/node/ledger/shell/process_proposal.rs index 12ef115843f..692f94eacd7 100644 --- a/apps/src/lib/node/ledger/shell/process_proposal.rs +++ b/apps/src/lib/node/ledger/shell/process_proposal.rs @@ -363,19 +363,24 @@ where } // Tx gas (partial check) - let tx_hash = if tx.code_or_hash.len() - == HASH_LENGTH - { - match Hash::try_from(tx.code_or_hash.as_slice()) { + let tx_hash = + if tx.code_or_hash.len() == HASH_LENGTH { + match Hash::try_from( + tx.code_or_hash.as_slice(), + ) { Ok(hash) => hash, Err(_) => return TxResult { - code: ErrorCodes::DecryptedTxGasLimit.into(), - info: format!("Failed conversion of transaction's hash") - } + code: + ErrorCodes::DecryptedTxGasLimit + .into(), + info: "Failed conversion of \ + transaction's hash" + .to_string(), + }, } - } else { - Hash(tx.code_hash()) - }; + } else { + Hash(tx.code_hash()) + }; let tx_gas = match gas_table.get( &tx_hash.to_string().to_ascii_lowercase(), ) { @@ -383,7 +388,8 @@ where #[cfg(test)] None => 1_000, #[cfg(not(test))] - None => 0, // VPs will rejected the non-whitelisted tx + None => 0, /* VPs will rejected the + * non-whitelisted tx */ }; let inner_tx_gas_limit = temp_wl_storage .storage @@ -394,9 +400,14 @@ where TxGasMeter::new(inner_tx_gas_limit); if let Err(e) = tx_gas_meter.add(tx_gas) { return TxResult { - code: ErrorCodes::DecryptedTxGasLimit.into(), - info: format!("Decrypted transaction gas error: {}", e) - }; + code: ErrorCodes::DecryptedTxGasLimit + .into(), + info: format!( + "Decrypted transaction gas error: \ + {}", + e + ), + }; } } diff --git a/apps/src/lib/wasm_loader/mod.rs b/apps/src/lib/wasm_loader/mod.rs index 8c6dedc7c61..743e9d7b4e8 100644 --- a/apps/src/lib/wasm_loader/mod.rs +++ b/apps/src/lib/wasm_loader/mod.rs @@ -135,7 +135,7 @@ pub async fn pre_fetch_wasm(wasm_directory: impl AsRef) { join_all(checksums.0.into_iter().map(|(name, map)| { let wasm_directory = wasm_directory.as_ref().to_owned(); let full_name = - name.replace(".", &format!(".{}.", map.get("hash").unwrap())); + name.replace('.', &format!(".{}.", map.get("hash").unwrap())); // Async check and download (if needed) each file tokio::spawn(async move { @@ -270,7 +270,7 @@ pub fn read_wasm( if let Some(name) = os_name.to_str() { let wasm_path = match checksums.0.get(name) { Some(map) => wasm_directory.as_ref().join(name.replace( - ".", + '.', &format!( ".{}.", map.get("hash").ok_or_else(|| eyre!( diff --git a/benches/mod.rs b/benches/mod.rs index 7444c2b958f..6c43b403d48 100644 --- a/benches/mod.rs +++ b/benches/mod.rs @@ -16,6 +16,7 @@ use std::collections::BTreeMap; use std::ops::{Deref, DerefMut}; +use std::str::FromStr; use borsh::BorshSerialize; use ibc_proto::google::protobuf::Any; @@ -88,7 +89,6 @@ use namada_apps::wallet::defaults; use namada_apps::{config, wasm_loader}; use namada_test_utils::tx_data::TxWriteData; use rand_core::OsRng; -use std::str::FromStr; use tempfile::TempDir; pub const WASM_DIR: &str = "../wasm"; diff --git a/benches/native_vps.rs b/benches/native_vps.rs index 92a3799f6ae..dea8585d13d 100644 --- a/benches/native_vps.rs +++ b/benches/native_vps.rs @@ -189,13 +189,15 @@ fn governance(c: &mut Criterion) { group.bench_function(bench_name, |b| { b.iter(|| { - assert!(governance - .validate_tx( - signed_tx.data.as_ref().unwrap(), - governance.ctx.keys_changed, - governance.ctx.verifiers, - ) - .unwrap()) + assert!( + governance + .validate_tx( + signed_tx.data.as_ref().unwrap(), + governance.ctx.keys_changed, + governance.ctx.verifiers, + ) + .unwrap() + ) }) }); } @@ -254,13 +256,15 @@ fn slash_fund(c: &mut Criterion) { group.bench_function(bench_name, |b| { b.iter(|| { - assert!(slash_fund - .validate_tx( - tx.data.as_ref().unwrap(), - slash_fund.ctx.keys_changed, - slash_fund.ctx.verifiers, - ) - .unwrap()) + assert!( + slash_fund + .validate_tx( + tx.data.as_ref().unwrap(), + slash_fund.ctx.keys_changed, + slash_fund.ctx.verifiers, + ) + .unwrap() + ) }) }); } @@ -279,7 +283,7 @@ fn ibc(c: &mut Criterion) { ) .unwrap(), counterparty: Counterparty::new( - ClientId::from_str(&"01-tendermint-1").unwrap(), + ClientId::from_str("01-tendermint-1").unwrap(), Some(ConnectionId::new(1)), CommitmentPrefix::try_from(b"ibc".to_vec()).unwrap(), ), @@ -360,13 +364,14 @@ fn ibc(c: &mut Criterion) { group.bench_function(bench_name, |b| { b.iter(|| { - assert!(ibc - .validate_tx( + assert!( + ibc.validate_tx( signed_tx.data.as_ref().unwrap(), ibc.ctx.keys_changed, ibc.ctx.verifiers, ) - .unwrap()) + .unwrap() + ) }) }); } @@ -419,13 +424,14 @@ fn ibc_token(c: &mut Criterion) { group.bench_function(bench_name, |b| { b.iter(|| { - assert!(ibc - .validate_tx( + assert!( + ibc.validate_tx( signed_tx.data.as_ref().unwrap(), ibc.ctx.keys_changed, ibc.ctx.verifiers, ) - .unwrap()) + .unwrap() + ) }) }); } diff --git a/benches/process_wrapper.rs b/benches/process_wrapper.rs index 0cc38957252..ee64f992ec5 100644 --- a/benches/process_wrapper.rs +++ b/benches/process_wrapper.rs @@ -15,7 +15,8 @@ use namada_benches::{generate_tx, BenchShell, TX_TRANSFER_WASM}; fn process_tx(c: &mut Criterion) { let mut shell = BenchShell::default(); - // Advance chain height to allow the inclusion of wrapper txs by the block space allocator + // Advance chain height to allow the inclusion of wrapper txs by the block + // space allocator shell.wl_storage.storage.last_height = BlockHeight(2); let tx = generate_tx( TX_TRANSFER_WASM, diff --git a/benches/vps.rs b/benches/vps.rs index 57f69494f02..e11d8ebc69a 100644 --- a/benches/vps.rs +++ b/benches/vps.rs @@ -132,21 +132,23 @@ fn vp_user(c: &mut Criterion) { group.bench_function(bench_name, |b| { b.iter(|| { - assert!(run::vp( - &vp_code_hash, - signed_tx, - &TxIndex(0), - &defaults::albert_address(), - &shell.wl_storage.storage, - &shell.wl_storage.write_log, - &mut VpGasMeter::new(u64::MAX, 0), - &BTreeMap::default(), - &keys_changed, - &verifiers, - shell.vp_wasm_cache.clone(), - false, - ) - .unwrap()); + assert!( + run::vp( + &vp_code_hash, + signed_tx, + &TxIndex(0), + &defaults::albert_address(), + &shell.wl_storage.storage, + &shell.wl_storage.write_log, + &mut VpGasMeter::new(u64::MAX, 0), + &BTreeMap::default(), + &keys_changed, + &verifiers, + shell.vp_wasm_cache.clone(), + false, + ) + .unwrap() + ); }) }); } @@ -268,21 +270,23 @@ fn vp_implicit(c: &mut Criterion) { group.bench_function(bench_name, |b| { b.iter(|| { - assert!(run::vp( - &vp_code_hash, - tx, - &TxIndex(0), - &Address::from(&implicit_account.to_public()), - &shell.wl_storage.storage, - &shell.wl_storage.write_log, - &mut VpGasMeter::new(u64::MAX, 0), - &BTreeMap::default(), - &keys_changed, - &verifiers, - shell.vp_wasm_cache.clone(), - false, + assert!( + run::vp( + &vp_code_hash, + tx, + &TxIndex(0), + &Address::from(&implicit_account.to_public()), + &shell.wl_storage.storage, + &shell.wl_storage.write_log, + &mut VpGasMeter::new(u64::MAX, 0), + &BTreeMap::default(), + &keys_changed, + &verifiers, + shell.vp_wasm_cache.clone(), + false, + ) + .unwrap() ) - .unwrap()) }) }); } @@ -396,21 +400,23 @@ fn vp_validator(c: &mut Criterion) { group.bench_function(bench_name, |b| { b.iter(|| { - assert!(run::vp( - &vp_code_hash, - signed_tx, - &TxIndex(0), - &defaults::validator_address(), - &shell.wl_storage.storage, - &shell.wl_storage.write_log, - &mut VpGasMeter::new(u64::MAX, 0), - &BTreeMap::default(), - &keys_changed, - &verifiers, - shell.vp_wasm_cache.clone(), - false, - ) - .unwrap()); + assert!( + run::vp( + &vp_code_hash, + signed_tx, + &TxIndex(0), + &defaults::validator_address(), + &shell.wl_storage.storage, + &shell.wl_storage.write_log, + &mut VpGasMeter::new(u64::MAX, 0), + &BTreeMap::default(), + &keys_changed, + &verifiers, + shell.vp_wasm_cache.clone(), + false, + ) + .unwrap() + ); }) }); } @@ -454,21 +460,23 @@ fn vp_token(c: &mut Criterion) { group.bench_function(bench_name, |b| { b.iter(|| { - assert!(run::vp( - &vp_code_hash, - signed_tx, - &TxIndex(0), - &defaults::albert_address(), - &shell.wl_storage.storage, - &shell.wl_storage.write_log, - &mut VpGasMeter::new(u64::MAX, 0), - &BTreeMap::default(), - &keys_changed, - &verifiers, - shell.vp_wasm_cache.clone(), - false, - ) - .unwrap()); + assert!( + run::vp( + &vp_code_hash, + signed_tx, + &TxIndex(0), + &defaults::albert_address(), + &shell.wl_storage.storage, + &shell.wl_storage.write_log, + &mut VpGasMeter::new(u64::MAX, 0), + &BTreeMap::default(), + &keys_changed, + &verifiers, + shell.vp_wasm_cache.clone(), + false, + ) + .unwrap() + ); }) }); } @@ -542,21 +550,23 @@ fn vp_masp(c: &mut Criterion) { .verifiers_and_changed_keys(&BTreeSet::default()); b.iter(|| { - assert!(run::vp( - &vp_code_hash, - &signed_tx, - &TxIndex(0), - &defaults::validator_address(), - &shielded_ctx.shell.wl_storage.storage, - &shielded_ctx.shell.wl_storage.write_log, - &mut VpGasMeter::new(u64::MAX, 0), - &BTreeMap::default(), - &keys_changed, - &verifiers, - shielded_ctx.shell.vp_wasm_cache.clone(), - false, - ) - .unwrap()); + assert!( + run::vp( + &vp_code_hash, + &signed_tx, + &TxIndex(0), + &defaults::validator_address(), + &shielded_ctx.shell.wl_storage.storage, + &shielded_ctx.shell.wl_storage.write_log, + &mut VpGasMeter::new(u64::MAX, 0), + &BTreeMap::default(), + &keys_changed, + &verifiers, + shielded_ctx.shell.vp_wasm_cache.clone(), + false, + ) + .unwrap() + ); }) }); } diff --git a/shared/src/ledger/ibc/vp/mod.rs b/shared/src/ledger/ibc/vp/mod.rs index a0c2595dd70..9f11914b21f 100644 --- a/shared/src/ledger/ibc/vp/mod.rs +++ b/shared/src/ledger/ibc/vp/mod.rs @@ -224,8 +224,8 @@ pub fn get_dummy_header() -> crate::types::storage::Header { /// A dummy validator used for testing #[cfg(any(feature = "test", feature = "testing"))] -pub fn get_dummy_genesis_validator( -) -> namada_proof_of_stake::types::GenesisValidator { +pub fn get_dummy_genesis_validator() +-> namada_proof_of_stake::types::GenesisValidator { use rust_decimal::prelude::Decimal; use crate::core::types::address::testing::established_address_1; @@ -737,9 +737,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] @@ -949,9 +954,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] @@ -1054,9 +1064,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] @@ -1274,9 +1289,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] @@ -1379,9 +1399,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] @@ -1462,9 +1487,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] @@ -1581,9 +1611,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] @@ -1701,9 +1736,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] @@ -1805,9 +1845,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] @@ -1907,9 +1952,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") + ); } // skip test_close_init_channel() and test_close_confirm_channel() since it @@ -2042,9 +2092,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] @@ -2215,9 +2270,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] @@ -2357,9 +2417,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] @@ -2504,9 +2569,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] @@ -2651,8 +2721,13 @@ 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") + ); } } diff --git a/shared/src/ledger/protocol/mod.rs b/shared/src/ledger/protocol/mod.rs index 157ced4bdfd..a52f1ce9c6e 100644 --- a/shared/src/ledger/protocol/mod.rs +++ b/shared/src/ledger/protocol/mod.rs @@ -288,7 +288,7 @@ where storage, write_log, &mut gas_meter, - &gas_table, + gas_table, &keys_changed, &verifiers, vp_wasm_cache.clone(), diff --git a/shared/src/vm/wasm/run.rs b/shared/src/vm/wasm/run.rs index 740b4996ffe..fa22e3295ec 100644 --- a/shared/src/vm/wasm/run.rs +++ b/shared/src/vm/wasm/run.rs @@ -280,6 +280,7 @@ where ) } +#[allow(clippy::too_many_arguments)] fn run_vp( module: wasmer::Module, vp_imports: wasmer::ImportObject, @@ -431,13 +432,13 @@ where ctx, }; let gas_table_key = &namada_core::ledger::parameters::storage::get_gas_table_storage_key(); - let gas_table = match write_log.read(&gas_table_key).0 { + let gas_table = match write_log.read(gas_table_key).0 { Some(StorageModification::Write { value }) => { BTreeMap::try_from_slice(value) .map_err(|e| Error::ConversionError(e.to_string())) } _ => match storage - .read(&gas_table_key) + .read(gas_table_key) .map_err(|e| { Error::LoadWasmCode(format!( "Read gas table from storage failed: {}", @@ -505,7 +506,8 @@ pub fn prepare_wasm_code>(code: T) -> Result> { elements::serialize(module).map_err(Error::SerializationError) } -// Fetch or compile a WASM code from the cache or storage. Account for the loading and code compilation gas costs. +// Fetch or compile a WASM code from the cache or storage. Account for the +// loading and code compilation gas costs. fn fetch_or_compile( wasm_cache: &mut Cache, code_or_hash: WasmPayload, @@ -524,7 +526,7 @@ where let (module, store, tx_len) = match wasm_cache.fetch(code_hash)? { Some((module, store)) => { // Gas accounting even if the compiled module is in cache - let key = Key::wasm_code_len(&code_hash); + let key = Key::wasm_code_len(code_hash); let tx_len = match write_log.read(&key).0 { Some(StorageModification::Write { value }) => { u64::try_from_slice(value).map_err(|e| { @@ -535,10 +537,10 @@ where .read(&key) .map_err(|e| { Error::LoadWasmCode(format!( - "Read wasm code length failed from storage: key {}, \ - error {}", - key, e - )) + "Read wasm code length failed from \ + storage: key {}, error {}", + key, e + )) })? .0 { @@ -564,10 +566,10 @@ where .read(&key) .map_err(|e| { Error::LoadWasmCode(format!( - "Read wasm code failed from storage: key {}, \ - error {}", - key, e - )) + "Read wasm code failed from storage: key \ + {}, error {}", + key, e + )) })? .0 { @@ -599,7 +601,7 @@ where u64::try_from(code.as_ref().len()) .map_err(|e| Error::ConversionError(e.to_string()))?, )?; - validate_untrusted_wasm(&code).map_err(Error::ValidationError)?; + validate_untrusted_wasm(code).map_err(Error::ValidationError)?; match wasm_cache.compile_or_fetch(code)? { Some((module, store)) => Ok((module, store)), None => Err(Error::NoCompiledWasmCode), @@ -765,7 +767,7 @@ mod tests { storage.write(&len_key, code_len).unwrap(); let gas_table_key = &namada_core::ledger::parameters::storage::get_gas_table_storage_key(); storage - .write(&gas_table_key, gas_table.try_to_vec().unwrap()) + .write(gas_table_key, gas_table.try_to_vec().unwrap()) .unwrap(); // Assuming 200 pages, 12.8 MiB limit diff --git a/tests/src/vm_host_env/mod.rs b/tests/src/vm_host_env/mod.rs index 5acc692d2d1..6ba6ab2f397 100644 --- a/tests/src/vm_host_env/mod.rs +++ b/tests/src/vm_host_env/mod.rs @@ -134,11 +134,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] @@ -469,17 +471,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() + ); } }