From 07a5b631848d0116d8b2a2467e8bab5ebc5b0bb9 Mon Sep 17 00:00:00 2001 From: Marco Granelli Date: Tue, 28 Mar 2023 15:31:50 +0200 Subject: [PATCH] Fixes whitelisted gas for tests --- .../lib/node/ledger/shell/process_proposal.rs | 29 +++++-------------- shared/src/ledger/protocol/mod.rs | 14 ++++----- 2 files changed, 14 insertions(+), 29 deletions(-) diff --git a/apps/src/lib/node/ledger/shell/process_proposal.rs b/apps/src/lib/node/ledger/shell/process_proposal.rs index 6d22d25c96f..7003bf3a5d6 100644 --- a/apps/src/lib/node/ledger/shell/process_proposal.rs +++ b/apps/src/lib/node/ledger/shell/process_proposal.rs @@ -244,27 +244,14 @@ where let tx_hash = Hash::sha256(tx.code) .to_string() .to_ascii_lowercase(); - let tx_gas = match gas_table - .get(tx_hash.as_str()) - { - Some(gas) => gas.to_owned(), - #[cfg(any(test, feature = "testing"))] - None => 1_000, - #[cfg(not(any( - test, - feature = "testing" - )))] - None => { - return TxResult { - // Tx is not whitelisted - code: - ErrorCodes::DecryptedTxGasLimit - .into(), - info: "Tx is not whitelisted" - .to_string(), - }; - } - }; + let tx_gas = + match gas_table.get(tx_hash.as_str()) { + Some(gas) => gas.to_owned(), + #[cfg(test)] + None => 1_000, + #[cfg(not(test))] + None => 0, // VPs will rejected the non-whitelisted tx + }; let inner_tx_gas_limit = temp_wl_storage .storage .tx_queue diff --git a/shared/src/ledger/protocol/mod.rs b/shared/src/ledger/protocol/mod.rs index c430a9ee9e8..131872c1d3b 100644 --- a/shared/src/ledger/protocol/mod.rs +++ b/shared/src/ledger/protocol/mod.rs @@ -67,8 +67,6 @@ pub enum Error { ), #[error("Access to an internal address {0} is forbidden")] AccessForbidden(InternalAddress), - #[error("The gas cost for the tx/vp {0} was not found in storage")] - MissingGasCost(String), } /// Result of applying a transaction @@ -168,10 +166,10 @@ where let tx_hash = Hash::sha256(&tx.code).to_string().to_ascii_lowercase(); let tx_gas_required = match gas_table.get(tx_hash.as_str()) { Some(gas) => gas.to_owned(), - #[cfg(any(test, feature = "testing"))] + #[cfg(test)] None => 1_000, - #[cfg(not(any(test, feature = "testing")))] - None => return Err(Error::MissingGasCost(tx_hash)), + #[cfg(not(test))] + None => 0, // VPs will reject the non-whitelisted tx }; tx_gas_meter.add(tx_gas_required).map_err(Error::GasError)?; @@ -501,10 +499,10 @@ fn add_precomputed_gas( ) -> Result<()> { let vp_gas_required = match gas_table.get(vp) { Some(gas) => gas.to_owned(), - #[cfg(any(test, feature = "testing"))] + #[cfg(test)] None => 1_000, - #[cfg(not(any(test, feature = "testing")))] - None => return Err(Error::MissingGasCost(vp.to_owned())), + #[cfg(not(test))] + None => 0, }; gas_meter.add(vp_gas_required).map_err(Error::GasError)