From 6785bd180c27c9e71aec34f1629ddc3c8c918c97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Zemanovi=C4=8D?= Date: Mon, 8 Jan 2024 17:16:33 +0000 Subject: [PATCH] wasm: fix tests --- wasm/Cargo.lock | 14 ++++++++++++ wasm/wasm_source/src/tx_bond.rs | 5 ++--- .../src/tx_change_validator_commission.rs | 3 +-- wasm/wasm_source/src/tx_redelegate.rs | 5 ++--- wasm/wasm_source/src/tx_unbond.rs | 5 ++--- wasm/wasm_source/src/tx_withdraw.rs | 4 ++-- wasm/wasm_source/src/vp_implicit.rs | 22 +++++++++---------- wasm/wasm_source/src/vp_testnet_faucet.rs | 21 +++++++----------- wasm/wasm_source/src/vp_user.rs | 22 +++++++++---------- 9 files changed, 53 insertions(+), 48 deletions(-) diff --git a/wasm/Cargo.lock b/wasm/Cargo.lock index 12b7a875f8..e9c7cb62ba 100644 --- a/wasm/Cargo.lock +++ b/wasm/Cargo.lock @@ -1783,6 +1783,17 @@ version = "2.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "25cbce373ec4653f1a01a31e8a5e5ec0c622dc27ff9c4e6606eefef5cbbed4a5" +[[package]] +name = "fd-lock" +version = "3.0.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ef033ed5e9bad94e55838ca0ca906db0e043f517adda0c8b79c7a8c66c93c1b5" +dependencies = [ + "cfg-if 1.0.0", + "rustix", + "windows-sys 0.48.0", +] + [[package]] name = "ff" version = "0.13.0" @@ -3575,6 +3586,7 @@ dependencies = [ "derivation-path", "ethbridge-bridge-contract", "ethers", + "fd-lock", "futures", "itertools 0.10.5", "lazy_static", @@ -3599,6 +3611,8 @@ dependencies = [ "paste", "proptest", "prost 0.12.3", + "rand 0.8.5", + "rand_core 0.6.4", "ripemd", "serde", "serde_json", diff --git a/wasm/wasm_source/src/tx_bond.rs b/wasm/wasm_source/src/tx_bond.rs index 733e021c59..94c2339d49 100644 --- a/wasm/wasm_source/src/tx_bond.rs +++ b/wasm/wasm_source/src/tx_bond.rs @@ -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::*; @@ -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), ); diff --git a/wasm/wasm_source/src/tx_change_validator_commission.rs b/wasm/wasm_source/src/tx_change_validator_commission.rs index 4569c4d603..ce95c6d780 100644 --- a/wasm/wasm_source/src/tx_change_validator_commission.rs +++ b/wasm/wasm_source/src/tx_change_validator_commission.rs @@ -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::*; diff --git a/wasm/wasm_source/src/tx_redelegate.rs b/wasm/wasm_source/src/tx_redelegate.rs index a02970a0c1..b3bce78c24 100644 --- a/wasm/wasm_source/src/tx_redelegate.rs +++ b/wasm/wasm_source/src/tx_redelegate.rs @@ -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::*; @@ -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), ); diff --git a/wasm/wasm_source/src/tx_unbond.rs b/wasm/wasm_source/src/tx_unbond.rs index f7f11b14bc..5d982c11bb 100644 --- a/wasm/wasm_source/src/tx_unbond.rs +++ b/wasm/wasm_source/src/tx_unbond.rs @@ -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::*; @@ -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), ); diff --git a/wasm/wasm_source/src/tx_withdraw.rs b/wasm/wasm_source/src/tx_withdraw.rs index f8984b1bef..260da26c11 100644 --- a/wasm/wasm_source/src/tx_withdraw.rs +++ b/wasm/wasm_source/src/tx_withdraw.rs @@ -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::*; @@ -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), ); diff --git a/wasm/wasm_source/src/vp_implicit.rs b/wasm/wasm_source/src/vp_implicit.rs index 493cf0f672..4f8f6b1125 100644 --- a/wasm/wasm_source/src/vp_implicit.rs +++ b/wasm/wasm_source/src/vp_implicit.rs @@ -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::*; @@ -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, @@ -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(), @@ -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(), @@ -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(), @@ -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(), @@ -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(), @@ -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(), @@ -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| { diff --git a/wasm/wasm_source/src/vp_testnet_faucet.rs b/wasm/wasm_source/src/vp_testnet_faucet.rs index b5c8b3456e..2719e68b67 100644 --- a/wasm/wasm_source/src/vp_testnet_faucet.rs +++ b/wasm/wasm_source/src/vp_testnet_faucet.rs @@ -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 \ @@ -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 @@ -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; @@ -275,14 +274,10 @@ mod tests { vp_env.all_touched_storage_keys(); let verifiers: BTreeSet
= 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! { @@ -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 diff --git a/wasm/wasm_source/src/vp_user.rs b/wasm/wasm_source/src/vp_user.rs index 2aa503c76c..b72d9f5e3e 100644 --- a/wasm/wasm_source/src/vp_user.rs +++ b/wasm/wasm_source/src/vp_user.rs @@ -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; @@ -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(), @@ -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(), @@ -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(), @@ -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(), @@ -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, @@ -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(), @@ -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(), @@ -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, @@ -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(),