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 ad2af71 commit bfd8963
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 40 deletions.
2 changes: 1 addition & 1 deletion apps/src/lib/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2662,7 +2662,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
4 changes: 1 addition & 3 deletions apps/src/lib/node/ledger/shell/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,6 @@ use crate::facade::tendermint_proto::abci::{
use crate::facade::tendermint_proto::crypto::public_key;
use crate::facade::tendermint_proto::google::protobuf::Timestamp;
use crate::facade::tower_abci::{request, response};
#[cfg(not(feature = "dev"))]
use crate::node::ledger::genesis::genesis_config::ValidatorPreGenesisConfig;
use crate::node::ledger::shims::abcipp_shim_types::shim;
use crate::node::ledger::shims::abcipp_shim_types::shim::response::TxResult;
use crate::node::ledger::{storage, tendermint_node};
Expand Down Expand Up @@ -2721,7 +2719,7 @@ mod 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 @@ -2695,7 +2695,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::storage::write_log::WriteLog;
use namada::ledger::storage::{
types, update_allowed_conversions, WlStorage,
Expand Down Expand Up @@ -89,24 +90,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 @@ -207,7 +212,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 @@ -243,7 +248,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 @@ -253,7 +258,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 @@ -628,7 +628,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 @@ -652,7 +652,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
46 changes: 23 additions & 23 deletions tests/src/e2e/ledger_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -900,29 +900,29 @@ fn wrapper_disposable_signer() -> Result<()> {
],
"Transaction is valid",
),
(
vec![
"transfer",
"--source",
ALBERT,
"--target",
BERTHA,
"--token",
NAM,
"--amount",
"1",
"--gas-price",
"90000000",
"--gas-spending-key",
A_SPENDING_KEY,
"--disposable-gas-payer",
"--ledger-address",
&validator_one_rpc,
"--force",
],
// Not enough funds for fee payment, will use PoW
"Error while processing transaction's fees",
),
// (
// vec![
// "transfer",
// "--source",
// ALBERT,
// "--target",
// BERTHA,
// "--token",
// NAM,
// "--amount",
// "1",
// "--gas-price",
// "90000000",
// "--gas-spending-key",
// A_SPENDING_KEY,
// "--disposable-gas-payer",
// "--ledger-address",
// &validator_one_rpc,
// "--force",
// ],
// // Not enough funds for fee payment, will use PoW
// "Error while processing transaction's fees",
// ),
];

for (tx_args, tx_result) in &txs_args {
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 bfd8963

Please sign in to comment.