Skip to content

Commit

Permalink
Fixes whitelisted gas for tests
Browse files Browse the repository at this point in the history
  • Loading branch information
grarco committed Mar 28, 2023
1 parent 77ae72c commit 07a5b63
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 29 deletions.
29 changes: 8 additions & 21 deletions apps/src/lib/node/ledger/shell/process_proposal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 6 additions & 8 deletions shared/src/ledger/protocol/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)?;

Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 07a5b63

Please sign in to comment.