Skip to content

Commit

Permalink
Fixes gas in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
grarco committed Nov 5, 2023
1 parent c090c82 commit be607d4
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 15 deletions.
2 changes: 1 addition & 1 deletion apps/src/lib/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2771,7 +2771,7 @@ pub mod args {
pub const FEE_PAYER_OPT: ArgOpt<WalletKeypair> = arg_opt("gas-payer");
pub const FORCE: ArgFlag = flag("force");
pub const GAS_LIMIT: ArgDefault<GasLimit> =
arg_default("gas-limit", DefaultFn(|| GasLimit::from(20_000)));
arg_default("gas-limit", DefaultFn(|| GasLimit::from(25_000)));
pub const FEE_TOKEN: ArgDefaultFromCtx<WalletAddress> =
arg_default_from_ctx("gas-token", DefaultFn(|| "NAM".parse().unwrap()));
pub const FEE_PAYER: Arg<WalletAddress> = arg("fee-payer");
Expand Down
2 changes: 1 addition & 1 deletion apps/src/lib/node/ledger/shell/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2808,7 +2808,7 @@ mod shell_tests {
Tx::from_type(TxType::Wrapper(Box::new(WrapperTx::new(
Fee {
amount_per_gas_unit: 100.into(),
token: address::btc(),
token: address::apfel(),
},
crate::wallet::defaults::albert_keypair().ref_to(),
Epoch(0),
Expand Down
2 changes: 1 addition & 1 deletion apps/src/lib/node/ledger/shell/process_proposal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2532,7 +2532,7 @@ mod test_process_proposal {
Tx::from_type(TxType::Wrapper(Box::new(WrapperTx::new(
Fee {
amount_per_gas_unit: 100.into(),
token: address::btc(),
token: address::apfel(),
},
crate::wallet::defaults::albert_keypair().ref_to(),
Epoch(0),
Expand Down
22 changes: 15 additions & 7 deletions apps/src/lib/node/ledger/storage/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ mod tests {
use std::collections::HashMap;

use itertools::Itertools;
use namada::ledger::gas::STORAGE_ACCESS_GAS_PER_BYTE;
use namada::ledger::parameters::{EpochDuration, Parameters};
use namada::ledger::storage::write_log::WriteLog;
use namada::ledger::storage::{
Expand Down Expand Up @@ -91,24 +92,28 @@ mod tests {
// before insertion
let (result, gas) = storage.has_key(&key).expect("has_key failed");
assert!(!result);
assert_eq!(gas, key.len() as u64);
assert_eq!(gas, key.len() as u64 * STORAGE_ACCESS_GAS_PER_BYTE);
let (result, gas) = storage.read(&key).expect("read failed");
assert_eq!(result, None);
assert_eq!(gas, key.len() as u64);
assert_eq!(gas, key.len() as u64 * STORAGE_ACCESS_GAS_PER_BYTE);

// insert
storage.write(&key, value_bytes).expect("write failed");

// read
let (result, gas) = storage.has_key(&key).expect("has_key failed");
assert!(result);
assert_eq!(gas, key.len() as u64);
assert_eq!(gas, key.len() as u64 * STORAGE_ACCESS_GAS_PER_BYTE);
let (result, gas) = storage.read(&key).expect("read failed");
let read_value: u64 =
types::decode(result.expect("value doesn't exist"))
.expect("decoding failed");
assert_eq!(read_value, value);
assert_eq!(gas, key.len() as u64 + value_bytes_len as u64);
assert_eq!(
gas,
(key.len() as u64 + value_bytes_len as u64)
* STORAGE_ACCESS_GAS_PER_BYTE
);

// delete
storage.delete(&key).expect("delete failed");
Expand Down Expand Up @@ -276,7 +281,7 @@ mod tests {
storage.commit_block(batch).expect("commit failed");

let (iter, gas) = storage.iter_prefix(&prefix);
assert_eq!(gas, prefix.len() as u64);
assert_eq!(gas, (prefix.len() as u64) * STORAGE_ACCESS_GAS_PER_BYTE);
for (k, v, gas) in iter {
match expected.pop() {
Some((expected_key, expected_val)) => {
Expand Down Expand Up @@ -312,7 +317,7 @@ mod tests {
let (vp, gas) =
storage.validity_predicate(&addr).expect("VP load failed");
assert_eq!(vp, None);
assert_eq!(gas, key.len() as u64);
assert_eq!(gas, (key.len() as u64) * STORAGE_ACCESS_GAS_PER_BYTE);

// insert
let vp1 = Hash::sha256("vp1".as_bytes());
Expand All @@ -322,7 +327,10 @@ mod tests {
let (vp_code_hash, gas) =
storage.validity_predicate(&addr).expect("VP load failed");
assert_eq!(vp_code_hash.expect("no VP"), vp1);
assert_eq!(gas, (key.len() + vp1.len()) as u64);
assert_eq!(
gas,
((key.len() + vp1.len()) as u64) * STORAGE_ACCESS_GAS_PER_BYTE
);
}

proptest! {
Expand Down
2 changes: 1 addition & 1 deletion core/src/ledger/gas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ pub const IBC_ACTION_EXECUTE_GAS: u64 = 47_452;
pub type Result<T> = std::result::Result<T, Error>;

/// Decimal scale of Gas units
const SCALE: u64 = 1_000;
const SCALE: u64 = 10_000;

/// Helper function to retrieve the `max_block_gas` protocol parameter from
/// storage
Expand Down
7 changes: 5 additions & 2 deletions core/src/ledger/storage/write_log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -750,7 +750,7 @@ mod tests {
// read a non-existing key
let (value, gas) = write_log.read(&key);
assert!(value.is_none());
assert_eq!(gas, key.len() as u64);
assert_eq!(gas, (key.len() as u64) * MEMORY_ACCESS_GAS_PER_BYTE);

// delete a non-existing key
let (gas, diff) = write_log.delete(&key).unwrap();
Expand All @@ -774,7 +774,10 @@ mod tests {
}
_ => panic!("unexpected read result"),
}
assert_eq!(gas, (key.len() + inserted.len()) as u64);
assert_eq!(
gas,
((key.len() + inserted.len()) as u64) * MEMORY_ACCESS_GAS_PER_BYTE
);

// update the value
let updated = "updated".as_bytes().to_vec();
Expand Down
2 changes: 1 addition & 1 deletion shared/src/vm/wasm/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,7 @@ mod tests {
use crate::types::validity_predicate::EvalVp;
use crate::vm::wasm;

const TX_GAS_LIMIT: u64 = 100_000_000;
const TX_GAS_LIMIT: u64 = 10_000_000_000;

/// Test that when a transaction wasm goes over the stack-height limit, the
/// execution is aborted.
Expand Down
2 changes: 1 addition & 1 deletion tests/src/vm_host_env/vp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ impl Default for TestVpEnv {
wl_storage,
iterators: PrefixIterators::default(),
gas_meter: VpGasMeter::new_from_tx_meter(
&TxGasMeter::new_from_sub_limit(10_000_000.into()),
&TxGasMeter::new_from_sub_limit(10_000_000_000.into()),
),
tx,
tx_index: TxIndex::default(),
Expand Down

0 comments on commit be607d4

Please sign in to comment.