Skip to content

Commit

Permalink
tests: update for native_token
Browse files Browse the repository at this point in the history
  • Loading branch information
tzemanovic committed Oct 25, 2022
1 parent 3880c61 commit e0c02c3
Show file tree
Hide file tree
Showing 11 changed files with 71 additions and 56 deletions.
1 change: 1 addition & 0 deletions apps/src/lib/config/genesis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -877,6 +877,7 @@ pub fn genesis() -> Genesis {
parameters,
pos_params: PosParams::default(),
gov_params: GovParams::default(),
native_token: address::nam(),
}
}

Expand Down
11 changes: 5 additions & 6 deletions apps/src/lib/node/ledger/shell/finalize_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,6 @@ where
/// are covered by the e2e tests.
#[cfg(test)]
mod test_finalize_block {
use namada::types::address::nam;
use namada::types::storage::Epoch;
use namada::types::transaction::{EncryptionKey, Fee};

Expand Down Expand Up @@ -349,7 +348,7 @@ mod test_finalize_block {
let wrapper = WrapperTx::new(
Fee {
amount: i.into(),
token: shell.native_token.clone(),
token: shell.storage.native_token.clone(),
},
&keypair,
Epoch(0),
Expand Down Expand Up @@ -420,7 +419,7 @@ mod test_finalize_block {
let wrapper = WrapperTx::new(
Fee {
amount: 0.into(),
token: shell.native_token.clone(),
token: shell.storage.native_token.clone(),
},
&keypair,
Epoch(0),
Expand Down Expand Up @@ -472,7 +471,7 @@ mod test_finalize_block {
let wrapper = WrapperTx {
fee: Fee {
amount: 0.into(),
token: shell.native_token.clone(),
token: shell.storage.native_token.clone(),
},
pk: keypair.ref_to(),
epoch: Epoch(0),
Expand Down Expand Up @@ -538,7 +537,7 @@ mod test_finalize_block {
let wrapper_tx = WrapperTx::new(
Fee {
amount: 0.into(),
token: shell.native_token.clone(),
token: shell.storage.native_token.clone(),
},
&keypair,
Epoch(0),
Expand Down Expand Up @@ -569,7 +568,7 @@ mod test_finalize_block {
let wrapper_tx = WrapperTx::new(
Fee {
amount: 0.into(),
token: shell.native_token.clone(),
token: shell.storage.native_token.clone(),
},
&keypair,
Epoch(0),
Expand Down
6 changes: 4 additions & 2 deletions apps/src/lib/node/ledger/shell/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -644,7 +644,7 @@ mod test_utils {

use namada::ledger::storage::mockdb::MockDB;
use namada::ledger::storage::{BlockStateWrite, MerkleTree, Sha256Hasher};
use namada::types::address::{nam, EstablishedAddressGen};
use namada::types::address::EstablishedAddressGen;
use namada::types::chain::ChainId;
use namada::types::hash::Hash;
use namada::types::key::*;
Expand Down Expand Up @@ -742,6 +742,7 @@ mod test_utils {
None,
vp_wasm_compilation_cache,
tx_wasm_compilation_cache,
address::nam(),
),
},
receiver,
Expand Down Expand Up @@ -866,7 +867,7 @@ mod test_utils {
let wrapper = WrapperTx::new(
Fee {
amount: 0.into(),
token: native_token.clone(),
token: native_token,
},
&keypair,
Epoch(0),
Expand Down Expand Up @@ -914,6 +915,7 @@ mod test_utils {
None,
vp_wasm_compilation_cache,
tx_wasm_compilation_cache,
address::nam(),
);
assert!(!shell.storage.tx_queue.is_empty());
}
Expand Down
5 changes: 2 additions & 3 deletions apps/src/lib/node/ledger/shell/prepare_proposal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,6 @@ pub(super) mod record {
#[cfg(test)]
mod test_prepare_proposal {
use borsh::BorshSerialize;
use namada::types::address::nam;
use namada::types::storage::Epoch;
use namada::types::transaction::{Fee, WrapperTx};

Expand Down Expand Up @@ -189,7 +188,7 @@ mod test_prepare_proposal {
WrapperTx::new(
Fee {
amount: 0.into(),
token: shell.native_token.clone(),
token: shell.storage.native_token.clone(),
},
&keypair,
Epoch(0),
Expand Down Expand Up @@ -244,7 +243,7 @@ mod test_prepare_proposal {
let wrapper_tx = WrapperTx::new(
Fee {
amount: 0.into(),
token: shell.native_token.clone(),
token: shell.storage.native_token.clone(),
},
&keypair,
Epoch(0),
Expand Down
17 changes: 8 additions & 9 deletions apps/src/lib/node/ledger/shell/process_proposal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,6 @@ where
mod test_process_proposal {
use borsh::BorshDeserialize;
use namada::proto::SignedTxData;
use namada::types::address::nam;
use namada::types::hash::Hash;
use namada::types::key::*;
use namada::types::storage::Epoch;
Expand Down Expand Up @@ -217,7 +216,7 @@ mod test_process_proposal {
let wrapper = WrapperTx::new(
Fee {
amount: 0.into(),
token: shell.native_token.clone(),
token: shell.storage.native_token.clone(),
},
&keypair,
Epoch(0),
Expand Down Expand Up @@ -264,7 +263,7 @@ mod test_process_proposal {
let mut wrapper = WrapperTx::new(
Fee {
amount: 100.into(),
token: shell.native_token.clone(),
token: shell.storage.native_token.clone(),
},
&keypair,
Epoch(0),
Expand Down Expand Up @@ -346,7 +345,7 @@ mod test_process_proposal {
let wrapper = WrapperTx::new(
Fee {
amount: 1.into(),
token: shell.native_token.clone(),
token: shell.storage.native_token.clone(),
},
&keypair,
Epoch(0),
Expand Down Expand Up @@ -399,7 +398,7 @@ mod test_process_proposal {
let wrapper = WrapperTx::new(
Fee {
amount: Amount::whole(1_000_100),
token: shell.native_token.clone(),
token: shell.storage.native_token.clone(),
},
&keypair,
Epoch(0),
Expand Down Expand Up @@ -447,7 +446,7 @@ mod test_process_proposal {
let wrapper = WrapperTx::new(
Fee {
amount: i.into(),
token: shell.native_token.clone(),
token: shell.storage.native_token.clone(),
},
&keypair,
Epoch(0),
Expand Down Expand Up @@ -511,7 +510,7 @@ mod test_process_proposal {
let wrapper = WrapperTx::new(
Fee {
amount: 0.into(),
token: shell.native_token.clone(),
token: shell.storage.native_token.clone(),
},
&keypair,
Epoch(0),
Expand Down Expand Up @@ -570,7 +569,7 @@ mod test_process_proposal {
let mut wrapper = WrapperTx::new(
Fee {
amount: 0.into(),
token: shell.native_token.clone(),
token: shell.storage.native_token.clone(),
},
&keypair,
Epoch(0),
Expand Down Expand Up @@ -623,7 +622,7 @@ mod test_process_proposal {
let wrapper = WrapperTx {
fee: Fee {
amount: 0.into(),
token: shell.native_token.clone(),
token: shell.storage.native_token.clone(),
},
pk: keypair.ref_to(),
epoch: Epoch(0),
Expand Down
41 changes: 31 additions & 10 deletions apps/src/lib/node/ledger/storage/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ fn new_blake2b() -> Blake2b {
#[cfg(test)]
mod tests {
use namada::ledger::storage::types;
use namada::types::address;
use namada::types::chain::ChainId;
use namada::types::storage::{BlockHash, BlockHeight, Key};
use tempfile::TempDir;
Expand All @@ -61,8 +62,12 @@ mod tests {
fn test_crud_value() {
let db_path =
TempDir::new().expect("Unable to create a temporary DB directory");
let mut storage =
PersistentStorage::open(db_path.path(), ChainId::default(), None);
let mut storage = PersistentStorage::open(
db_path.path(),
ChainId::default(),
address::nam(),
None,
);
let key = Key::parse("key").expect("cannot parse the key string");
let value: u64 = 1;
let value_bytes = types::encode(&value);
Expand Down Expand Up @@ -104,8 +109,12 @@ mod tests {
fn test_commit_block() {
let db_path =
TempDir::new().expect("Unable to create a temporary DB directory");
let mut storage =
PersistentStorage::open(db_path.path(), ChainId::default(), None);
let mut storage = PersistentStorage::open(
db_path.path(),
ChainId::default(),
address::nam(),
None,
);
storage
.begin_block(BlockHash::default(), BlockHeight(100))
.expect("begin_block failed");
Expand All @@ -126,8 +135,12 @@ mod tests {
drop(storage);

// load the last state
let mut storage =
PersistentStorage::open(db_path.path(), ChainId::default(), None);
let mut storage = PersistentStorage::open(
db_path.path(),
ChainId::default(),
address::nam(),
None,
);
storage
.load_last_state()
.expect("loading the last state failed");
Expand All @@ -145,8 +158,12 @@ mod tests {
fn test_iter() {
let db_path =
TempDir::new().expect("Unable to create a temporary DB directory");
let mut storage =
PersistentStorage::open(db_path.path(), ChainId::default(), None);
let mut storage = PersistentStorage::open(
db_path.path(),
ChainId::default(),
address::nam(),
None,
);
storage
.begin_block(BlockHash::default(), BlockHeight(100))
.expect("begin_block failed");
Expand Down Expand Up @@ -185,8 +202,12 @@ mod tests {
fn test_validity_predicate() {
let db_path =
TempDir::new().expect("Unable to create a temporary DB directory");
let mut storage =
PersistentStorage::open(db_path.path(), ChainId::default(), None);
let mut storage = PersistentStorage::open(
db_path.path(),
ChainId::default(),
address::nam(),
None,
);
storage
.begin_block(BlockHash::default(), BlockHeight(100))
.expect("begin_block failed");
Expand Down
1 change: 1 addition & 0 deletions tests/src/vm_host_env/tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -380,5 +380,6 @@ mod native_tx_host_env {
native_host_fn!(tx_get_block_time() -> i64);
native_host_fn!(tx_get_block_hash(result_ptr: u64));
native_host_fn!(tx_get_block_epoch() -> u64);
native_host_fn!(tx_get_native_token(result_ptr: u64));
native_host_fn!(tx_log_string(str_ptr: u64, str_len: u64));
}
1 change: 1 addition & 0 deletions tests/src/vm_host_env/vp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,7 @@ mod native_vp_host_env {
native_host_fn!(vp_get_block_hash(result_ptr: u64));
native_host_fn!(vp_get_tx_code_hash(result_ptr: u64));
native_host_fn!(vp_get_block_epoch() -> u64);
native_host_fn!(vp_get_native_token(result_ptr: u64));
native_host_fn!(vp_verify_tx_signature(
pk_ptr: u64,
pk_len: u64,
Expand Down
12 changes: 6 additions & 6 deletions wasm/wasm_source/src/tx_bond.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,7 @@ mod tests {
use namada_vp_prelude::proof_of_stake::types::{
Bond, VotingPower, VotingPowerDelta,
};
use namada_vp_prelude::proof_of_stake::{
staking_token_address, BondId, GenesisValidator, PosVP,
};
use namada_vp_prelude::proof_of_stake::{BondId, GenesisValidator, PosVP};
use proptest::prelude::*;

use super::*;
Expand Down Expand Up @@ -82,14 +80,16 @@ mod tests {

init_pos(&genesis_validators[..], &pos_params, Epoch(0));

tx_host_env::with(|tx_env| {
let native_token = tx_host_env::with(|tx_env| {
if let Some(source) = &bond.source {
tx_env.spawn_accounts([source]);
}

// Ensure that the bond's source has enough tokens for the bond
let target = bond.source.as_ref().unwrap_or(&bond.validator);
tx_env.credit_tokens(target, &staking_token_address(), bond.amount);
let native_token = tx_env.storage.native_token.clone();
tx_env.credit_tokens(target, &native_token, bond.amount);
native_token
});

let tx_code = vec![];
Expand All @@ -100,7 +100,7 @@ mod tests {

// Read the data before the tx is executed
let pos_balance_key = token::balance_key(
&staking_token_address(),
&native_token,
&Address::Internal(InternalAddress::PoS),
);
let pos_balance_pre: token::Amount = ctx()
Expand Down
16 changes: 6 additions & 10 deletions wasm/wasm_source/src/tx_unbond.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,7 @@ mod tests {
use namada_vp_prelude::proof_of_stake::types::{
Bond, Unbond, VotingPower, VotingPowerDelta,
};
use namada_vp_prelude::proof_of_stake::{
staking_token_address, BondId, GenesisValidator, PosVP,
};
use namada_vp_prelude::proof_of_stake::{BondId, GenesisValidator, PosVP};
use proptest::prelude::*;

use super::*;
Expand Down Expand Up @@ -87,7 +85,8 @@ mod tests {

init_pos(&genesis_validators[..], &pos_params, Epoch(0));

tx_host_env::with(|tx_env| {
let native_token = tx_host_env::with(|tx_env| {
let native_token = tx_env.storage.native_token.clone();
if is_delegation {
let source = unbond.source.as_ref().unwrap();
tx_env.spawn_accounts([source]);
Expand All @@ -96,12 +95,9 @@ mod tests {
// bond first.
// First, credit the bond's source with the initial stake,
// before we initialize the bond below
tx_env.credit_tokens(
source,
&staking_token_address(),
initial_stake,
);
tx_env.credit_tokens(source, &native_token, initial_stake);
}
native_token
});

if is_delegation {
Expand Down Expand Up @@ -131,7 +127,7 @@ mod tests {
};

let pos_balance_key = token::balance_key(
&staking_token_address(),
&native_token,
&Address::Internal(InternalAddress::PoS),
);
let pos_balance_pre: token::Amount = ctx()
Expand Down
Loading

0 comments on commit e0c02c3

Please sign in to comment.