Skip to content

Commit

Permalink
wasm: fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tzemanovic committed Jan 8, 2024
1 parent 9c68c1c commit 6785bd1
Show file tree
Hide file tree
Showing 9 changed files with 53 additions and 48 deletions.
14 changes: 14 additions & 0 deletions wasm/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions wasm/wasm_source/src/tx_bond.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,11 @@ mod tests {
arb_established_address, arb_non_internal_address,
};
use namada_tx_prelude::address::InternalAddress;
use namada_tx_prelude::borsh_ext::BorshSerializeExt;
use namada_tx_prelude::chain::ChainId;
use namada_tx_prelude::key::testing::arb_common_keypair;
use namada_tx_prelude::key::RefTo;
use namada_tx_prelude::proof_of_stake::parameters::testing::arb_pos_params;
use namada_tx_prelude::token;
use namada_tx_prelude::{token, BorshSerializeExt};
use proptest::prelude::*;

use super::*;
Expand Down Expand Up @@ -124,7 +123,7 @@ mod tests {

// Ensure that the initial stake of the sole validator is equal to the
// PoS account balance
let pos_balance_key = token::balance_key(
let pos_balance_key = token::storage_key::balance_key(
&native_token,
&Address::Internal(InternalAddress::PoS),
);
Expand Down
3 changes: 1 addition & 2 deletions wasm/wasm_source/src/tx_change_validator_commission.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,11 @@ mod tests {
use namada_tests::native_vp::TestNativeVpEnv;
use namada_tests::tx::*;
use namada_tx_prelude::address::testing::arb_established_address;
use namada_tx_prelude::borsh_ext::BorshSerializeExt;
use namada_tx_prelude::chain::ChainId;
use namada_tx_prelude::key::testing::arb_common_keypair;
use namada_tx_prelude::key::RefTo;
use namada_tx_prelude::proof_of_stake::parameters::testing::arb_pos_params;
use namada_tx_prelude::token;
use namada_tx_prelude::{token, BorshSerializeExt};
use proptest::prelude::*;

use super::*;
Expand Down
5 changes: 2 additions & 3 deletions wasm/wasm_source/src/tx_redelegate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,11 @@ mod tests {
use namada_tests::native_vp::TestNativeVpEnv;
use namada_tests::tx::*;
use namada_tx_prelude::address::InternalAddress;
use namada_tx_prelude::borsh_ext::BorshSerializeExt;
use namada_tx_prelude::chain::ChainId;
use namada_tx_prelude::key::testing::arb_common_keypair;
use namada_tx_prelude::key::RefTo;
use namada_tx_prelude::proof_of_stake::parameters::testing::arb_pos_params;
use namada_tx_prelude::token;
use namada_tx_prelude::{token, BorshSerializeExt};
use proptest::prelude::*;

use super::*;
Expand Down Expand Up @@ -144,7 +143,7 @@ mod tests {
let signed_tx = tx;

// Check that PoS balance is the same as the initial validator stake
let pos_balance_key = token::balance_key(
let pos_balance_key = token::storage_key::balance_key(
&native_token,
&Address::Internal(InternalAddress::PoS),
);
Expand Down
5 changes: 2 additions & 3 deletions wasm/wasm_source/src/tx_unbond.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,11 @@ mod tests {
use namada_tests::native_vp::TestNativeVpEnv;
use namada_tests::tx::*;
use namada_tx_prelude::address::InternalAddress;
use namada_tx_prelude::borsh_ext::BorshSerializeExt;
use namada_tx_prelude::chain::ChainId;
use namada_tx_prelude::key::testing::arb_common_keypair;
use namada_tx_prelude::key::RefTo;
use namada_tx_prelude::proof_of_stake::parameters::testing::arb_pos_params;
use namada_tx_prelude::token;
use namada_tx_prelude::{token, BorshSerializeExt};
use proptest::prelude::*;

use super::*;
Expand Down Expand Up @@ -155,7 +154,7 @@ mod tests {
.unwrap_or_else(|| unbond.validator.clone());

// Check that PoS balance is the same as the initial validator stake
let pos_balance_key = token::balance_key(
let pos_balance_key = token::storage_key::balance_key(
&native_token,
&Address::Internal(InternalAddress::PoS),
);
Expand Down
4 changes: 2 additions & 2 deletions wasm/wasm_source/src/tx_withdraw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ mod tests {
arb_established_address, arb_non_internal_address,
};
use namada_tx_prelude::address::InternalAddress;
use namada_tx_prelude::borsh_ext::BorshSerializeExt;
use namada_tx_prelude::chain::ChainId;
use namada_tx_prelude::key::testing::arb_common_keypair;
use namada_tx_prelude::key::RefTo;
use namada_tx_prelude::proof_of_stake::parameters::testing::arb_pos_params;
use namada_tx_prelude::BorshSerializeExt;
use proptest::prelude::*;

use super::*;
Expand Down Expand Up @@ -187,7 +187,7 @@ mod tests {
let signed_tx = tx;

// Read data before we apply tx:
let pos_balance_key = token::balance_key(
let pos_balance_key = token::storage_key::balance_key(
&native_token,
&Address::Internal(InternalAddress::PoS),
);
Expand Down
22 changes: 11 additions & 11 deletions wasm/wasm_source/src/vp_implicit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -291,17 +291,17 @@ fn validate_pos_changes(
mod tests {
// Use this as `#[test]` annotation to enable logging
use namada::ledger::pos::{GenesisValidator, PosParams};
use namada::proto::{Code, Data, Signature};
use namada::tx::data::TxType;
use namada::tx::{Code, Data, Signature};
use namada::types::dec::Dec;
use namada::types::storage::Epoch;
use namada::types::transaction::TxType;
use namada_test_utils::TestWasms;
use namada_tests::log::test;
use namada_tests::native_vp::pos::init_pos;
use namada_tests::tx::{self, tx_host_env, TestTxEnv};
use namada_tests::vp::vp_host_env::storage::Key;
use namada_tests::vp::*;
use namada_tx_prelude::{storage_api, StorageWrite, TxEnv};
use namada_tx_prelude::{StorageWrite, TxEnv};
use namada_vp_prelude::account::AccountPublicKeysMap;
use namada_vp_prelude::key::RefTo;
use proptest::prelude::*;
Expand Down Expand Up @@ -405,7 +405,7 @@ mod tests {
// Initialize VP environment from a transaction
vp_host_env::init_from_tx(addr.clone(), tx_env, |_address| {
// Do the same as reveal_pk, but with the wrong key
let _ = storage_api::account::set_public_key_at(
let _ = account::set_public_key_at(
tx_host_env::ctx(),
&addr,
&mismatched_pk,
Expand Down Expand Up @@ -442,7 +442,7 @@ mod tests {
// Spawn the accounts to be able to modify their storage
tx_env.spawn_accounts([&vp_owner, &source, &token]);
// write the denomination of NAM into storage
storage_api::token::write_denom(
token::write_denom(
&mut tx_env.wl_storage,
&token,
token::NATIVE_MAX_DECIMAL_PLACES.into(),
Expand Down Expand Up @@ -534,7 +534,7 @@ mod tests {
// be able to transfer from it
tx_env.credit_tokens(&vp_owner, &token, amount);
// write the denomination of NAM into storage
storage_api::token::write_denom(
token::write_denom(
&mut tx_env.wl_storage,
&token,
token::NATIVE_MAX_DECIMAL_PLACES.into(),
Expand Down Expand Up @@ -618,7 +618,7 @@ mod tests {
// be able to transfer from it
tx_env.credit_tokens(&vp_owner, &token, amount);
// write the denomination of NAM into storage
storage_api::token::write_denom(
token::write_denom(
&mut tx_env.wl_storage,
&token,
token::NATIVE_MAX_DECIMAL_PLACES.into(),
Expand Down Expand Up @@ -681,7 +681,7 @@ mod tests {
// be able to transfer from it
tx_env.credit_tokens(&vp_owner, &token, amount);
// write the denomination of NAM into storage
storage_api::token::write_denom(
token::write_denom(
&mut tx_env.wl_storage,
&token,
token::NATIVE_MAX_DECIMAL_PLACES.into(),
Expand Down Expand Up @@ -742,7 +742,7 @@ mod tests {
// be able to transfer from it
tx_env.credit_tokens(&vp_owner, &token, amount);
// write the denomination of NAM into storage
storage_api::token::write_denom(
token::write_denom(
&mut tx_env.wl_storage,
&token,
token::NATIVE_MAX_DECIMAL_PLACES.into(),
Expand Down Expand Up @@ -813,7 +813,7 @@ mod tests {
// be able to transfer from it
tx_env.credit_tokens(&source, &token, amount);
// write the denomination of NAM into storage
storage_api::token::write_denom(
token::write_denom(
&mut tx_env.wl_storage,
&token,
token::NATIVE_MAX_DECIMAL_PLACES.into(),
Expand Down Expand Up @@ -919,7 +919,7 @@ mod tests {
tx_env.spawn_accounts(storage_key_addresses);

let public_key = secret_key.ref_to();
let _ = storage_api::account::set_public_key_at(tx_host_env::ctx(), &vp_owner, &public_key, 0);
let _ = account::set_public_key_at(tx_host_env::ctx(), &vp_owner, &public_key, 0);

// Initialize VP environment from a transaction
vp_host_env::init_from_tx(vp_owner.clone(), tx_env, |_address| {
Expand Down
21 changes: 8 additions & 13 deletions wasm/wasm_source/src/vp_testnet_faucet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ fn validate_tx(
let post: token::Amount =
ctx.read_post(key)?.unwrap_or_default();
let change = post.change() - pre.change();
let maybe_denom =
storage_api::token::read_denom(&ctx.pre(), token)?;
let maybe_denom = token::read_denom(&ctx.pre(), token)?;
if maybe_denom.is_none() {
debug_log!(
"A denomination for token address {} does not exist \
Expand Down Expand Up @@ -108,7 +107,7 @@ fn validate_tx(
#[cfg(test)]
mod tests {
use address::testing::arb_non_internal_address;
use namada::proto::{Code, Data, Signature};
use namada::tx::{Code, Data, Signature};
use namada::types::transaction::TxType;
use namada_test_utils::TestWasms;
// Use this as `#[test]` annotation to enable logging
Expand All @@ -118,8 +117,8 @@ mod tests {
use namada_tests::vp::*;
use namada_tx_prelude::{StorageWrite, TxEnv};
use namada_vp_prelude::account::AccountPublicKeysMap;
use namada_vp_prelude::borsh_ext::BorshSerializeExt;
use namada_vp_prelude::key::RefTo;
use namada_vp_prelude::BorshSerializeExt;
use proptest::prelude::*;
use storage::testing::arb_account_storage_key_no_vp;

Expand Down Expand Up @@ -275,14 +274,10 @@ mod tests {
vp_env.all_touched_storage_keys();
let verifiers: BTreeSet<Address> = BTreeSet::default();
vp_host_env::set(vp_env);
assert!(validate_tx(
&CTX,
signed_tx,
vp_owner,
keys_changed,
verifiers
)
.unwrap());
assert!(
validate_tx(&CTX, signed_tx, vp_owner, keys_changed, verifiers)
.unwrap()
);
}

prop_compose! {
Expand Down Expand Up @@ -372,7 +367,7 @@ mod tests {
// be able to transfer from it
tx_env.credit_tokens(&vp_owner, &token, amount);
// write the denomination of NAM into storage
storage_api::token::write_denom(&mut tx_env.wl_storage, &token, token::NATIVE_MAX_DECIMAL_PLACES.into()).unwrap();
token::write_denom(&mut tx_env.wl_storage, &token, token::NATIVE_MAX_DECIMAL_PLACES.into()).unwrap();
tx_env.commit_genesis();

// Construct a PoW solution like a client would
Expand Down
22 changes: 11 additions & 11 deletions wasm/wasm_source/src/vp_user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -344,10 +344,10 @@ fn validate_pos_changes(
mod tests {
use address::testing::arb_non_internal_address;
use namada::ledger::pos::{GenesisValidator, PosParams};
use namada::proto::{Code, Data, Signature};
use namada::tx::data::{self, TxType};
use namada::tx::{Code, Data, Signature};
use namada::types::dec::Dec;
use namada::types::storage::Epoch;
use namada::types::transaction::{self, TxType};
use namada_test_utils::TestWasms;
// Use this as `#[test]` annotation to enable logging
use namada_tests::log::test;
Expand Down Expand Up @@ -398,7 +398,7 @@ mod tests {
// able to transfer from it
tx_env.credit_tokens(&source, &token, amount);
// write the denomination of NAM into storage
storage_api::token::write_denom(
token::write_denom(
&mut tx_env.wl_storage,
&token,
token::NATIVE_MAX_DECIMAL_PLACES.into(),
Expand Down Expand Up @@ -449,7 +449,7 @@ mod tests {
// Spawn the accounts to be able to modify their storage
tx_env.spawn_accounts([&vp_owner, &target, &token]);
// write the denomination of NAM into storage
storage_api::token::write_denom(
token::write_denom(
&mut tx_env.wl_storage,
&token,
token::NATIVE_MAX_DECIMAL_PLACES.into(),
Expand Down Expand Up @@ -511,7 +511,7 @@ mod tests {
// be able to transfer from it
tx_env.credit_tokens(&vp_owner, &token, amount);
// write the denomination of NAM into storage
storage_api::token::write_denom(
token::write_denom(
&mut tx_env.wl_storage,
&token,
token::NATIVE_MAX_DECIMAL_PLACES.into(),
Expand Down Expand Up @@ -604,7 +604,7 @@ mod tests {
tx_env.spawn_accounts([&target, &token]);
tx_env.init_account_storage(&vp_owner, vec![public_key], 1);
// write the denomination of NAM into storage
storage_api::token::write_denom(
token::write_denom(
&mut tx_env.wl_storage,
&token,
token::NATIVE_MAX_DECIMAL_PLACES.into(),
Expand Down Expand Up @@ -694,7 +694,7 @@ mod tests {
.ref_to();
let commission_rate = Dec::new(5, 2).unwrap();
let max_commission_rate_change = Dec::new(1, 2).unwrap();
let args = transaction::pos::BecomeValidator {
let args = data::pos::BecomeValidator {
address: address.clone(),
consensus_key,
eth_cold_key,
Expand Down Expand Up @@ -767,7 +767,7 @@ mod tests {
tx_env.spawn_accounts([&target, &token]);
tx_env.init_account_storage(&validator, vec![public_key], 1);
// write the denomination of NAM into storage
storage_api::token::write_denom(
token::write_denom(
&mut tx_env.wl_storage,
&token,
token::NATIVE_MAX_DECIMAL_PLACES.into(),
Expand Down Expand Up @@ -863,7 +863,7 @@ mod tests {
tx_env.init_account_storage(&vp_owner, vec![public_key.clone()], 1);

// write the denomination of NAM into storage
storage_api::token::write_denom(
token::write_denom(
&mut tx_env.wl_storage,
&token,
token::NATIVE_MAX_DECIMAL_PLACES.into(),
Expand Down Expand Up @@ -963,7 +963,7 @@ mod tests {
.ref_to();
let commission_rate = Dec::new(5, 2).unwrap();
let max_commission_rate_change = Dec::new(1, 2).unwrap();
let args = transaction::pos::BecomeValidator {
let args = data::pos::BecomeValidator {
address: address.clone(),
consensus_key,
eth_cold_key,
Expand Down Expand Up @@ -1051,7 +1051,7 @@ mod tests {
tx_env.init_account_storage(&validator, vec![public_key.clone()], 1);

// write the denomination of NAM into storage
storage_api::token::write_denom(
token::write_denom(
&mut tx_env.wl_storage,
&token,
token::NATIVE_MAX_DECIMAL_PLACES.into(),
Expand Down

0 comments on commit 6785bd1

Please sign in to comment.