Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor testing addresses #2507

Merged
merged 19 commits into from
Feb 27, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Hid addresses used for testing from public API.
([\#2507](https://github.com/anoma/namada/pull/2507))
6 changes: 3 additions & 3 deletions crates/apps/src/lib/bench_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@

pub fn generate_ibc_transfer_tx(&self) -> Tx {
let token = PrefixedCoin {
denom: address::nam().to_string().parse().unwrap(),
denom: address::testing::nam().to_string().parse().unwrap(),

Check warning on line 353 in crates/apps/src/lib/bench_utils.rs

View check run for this annotation

Codecov / codecov/patch

crates/apps/src/lib/bench_utils.rs#L353

Added line #L353 was not covered by tests
amount: Amount::native_whole(1000)
.to_string_native()
.split('.')
Expand Down Expand Up @@ -414,11 +414,11 @@
current_epoch + params.pipeline_len,
)
.unwrap();

namada::token::conversion::update_allowed_conversions(
&mut self.wl_storage,
)
.unwrap();

Check warning on line 421 in crates/apps/src/lib/bench_utils.rs

View check run for this annotation

Codecov / codecov/patch

crates/apps/src/lib/bench_utils.rs#L417-L421

Added lines #L417 - L421 were not covered by tests
}

pub fn init_ibc_client_state(&mut self, addr_key: Key) -> ClientId {
Expand Down Expand Up @@ -892,7 +892,7 @@

impl Default for BenchShieldedCtx {
fn default() -> Self {
let shell = BenchShell::default();

Check warning on line 895 in crates/apps/src/lib/bench_utils.rs

View check run for this annotation

Codecov / codecov/patch

crates/apps/src/lib/bench_utils.rs#L895

Added line #L895 was not covered by tests
let base_dir = shell.tempdir.as_ref().canonicalize().unwrap();

// Create a global config and an empty wallet in the chain dir - this is
Expand Down Expand Up @@ -1005,7 +1005,7 @@
&namada,
&source,
&target,
&address::nam(),
&address::testing::nam(),

Check warning on line 1008 in crates/apps/src/lib/bench_utils.rs

View check run for this annotation

Codecov / codecov/patch

crates/apps/src/lib/bench_utils.rs#L1008

Added line #L1008 was not covered by tests
denominated_amount,
),
)
Expand All @@ -1021,7 +1021,7 @@

let mut hasher = Sha256::new();
let shielded_section_hash = shielded.clone().map(|transaction| {
namada::core::hash::Hash(

Check warning on line 1024 in crates/apps/src/lib/bench_utils.rs

View check run for this annotation

Codecov / codecov/patch

crates/apps/src/lib/bench_utils.rs#L1024

Added line #L1024 was not covered by tests
Section::MaspTx(transaction)
.hash(&mut hasher)
.finalize_reset()
Expand All @@ -1034,7 +1034,7 @@
Transfer {
source: source.effective_address(),
target: target.effective_address(),
token: address::nam(),
token: address::testing::nam(),

Check warning on line 1037 in crates/apps/src/lib/bench_utils.rs

View check run for this annotation

Codecov / codecov/patch

crates/apps/src/lib/bench_utils.rs#L1037

Added line #L1037 was not covered by tests
amount: DenominatedAmount::native(amount),
key: None,
shielded: shielded_section_hash,
Expand Down
2 changes: 1 addition & 1 deletion crates/apps/src/lib/config/genesis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ pub fn make_dev_genesis(
use std::net::{IpAddr, Ipv4Addr, SocketAddr};
use std::time::Duration;

use namada::core::address::wnam;
use namada::core::address::testing::wnam;
use namada::core::chain::ChainIdPrefix;
use namada::core::ethereum_events::EthAddress;
use namada::core::key::*;
Expand Down
23 changes: 14 additions & 9 deletions crates/apps/src/lib/config/genesis/transactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
use ledger_transport_hid::hidapi::HidApi;
use ledger_transport_hid::TransportNativeHID;
use namada::account::AccountPublicKeysMap;
use namada::core::address::{nam, Address, EstablishedAddress};
use namada::core::address::{Address, EstablishedAddress};
use namada::core::chain::ChainId;
use namada::core::dec::Dec;
use namada::core::key::{
Expand Down Expand Up @@ -81,7 +81,7 @@
wallet_alias_force: false,
fee_amount: None,
wrapper_fee_payer: None,
fee_token: nam(),
fee_token: genesis_fee_token_address(),

Check warning on line 84 in crates/apps/src/lib/config/genesis/transactions.rs

View check run for this annotation

Codecov / codecov/patch

crates/apps/src/lib/config/genesis/transactions.rs#L84

Added line #L84 was not covered by tests
fee_unshield: None,
gas_limit: Default::default(),
expiration: None,
Expand Down Expand Up @@ -120,26 +120,31 @@
salt: [0; 8],
data: data.serialize_to_vec(),
});
let pk = get_sentinel_pubkey();
let fee_payer = genesis_fee_payer_pk();
tx.add_wrapper(
Fee {
amount_per_gas_unit: DenominatedAmount::native(0.into()),
token: Address::from(&pk),
token: genesis_fee_token_address(),
},
pk,
fee_payer,
Default::default(),
Default::default(),
None,
);
tx
}

/// Get a dummy public key.
/// Get a dummy public key for a fee payer - there are no fees for genesis tx
#[inline]
fn get_sentinel_pubkey() -> common::PublicKey {
fn genesis_fee_payer_pk() -> common::PublicKey {
common::SecretKey::Ed25519(ed25519::SigScheme::from_bytes([0; 32])).ref_to()
}

/// Dummy genesis fee token address - there are no fees for genesis tx
fn genesis_fee_token_address() -> Address {
Address::from(&genesis_fee_payer_pk())
}

pub struct GenesisValidatorData {
pub address: EstablishedAddress,
pub commission_rate: Dec,
Expand Down Expand Up @@ -741,7 +746,7 @@
account_public_keys_map: Some(pks.iter().cloned().collect()),
public_keys: pks.clone(),
threshold,
fee_payer: get_sentinel_pubkey(),
fee_payer: genesis_fee_payer_pk(),

Check warning on line 749 in crates/apps/src/lib/config/genesis/transactions.rs

View check run for this annotation

Codecov / codecov/patch

crates/apps/src/lib/config/genesis/transactions.rs#L749

Added line #L749 was not covered by tests
};

let mut tx = self.data.tx_to_sign();
Expand Down Expand Up @@ -769,7 +774,7 @@
_parts: HashSet<namada_sdk::signing::Signable>,
_user: (),
) -> Result<Tx, namada_sdk::error::Error> {
if pubkey == get_sentinel_pubkey() {
if pubkey == genesis_fee_payer_pk() {

Check warning on line 777 in crates/apps/src/lib/config/genesis/transactions.rs

View check run for this annotation

Codecov / codecov/patch

crates/apps/src/lib/config/genesis/transactions.rs#L777

Added line #L777 was not covered by tests
Ok(tx)
} else {
Err(namada_sdk::error::Error::Other(format!(
Expand Down
29 changes: 19 additions & 10 deletions crates/apps/src/lib/node/ledger/shell/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -410,16 +410,24 @@ where
std::fs::create_dir(&base_dir)
.expect("Creating directory for Namada should not fail");
}
let native_token = if cfg!(feature = "integration")
|| (!cfg!(test) && !cfg!(feature = "benches"))
{

// For all tests except integration use hard-coded native token addr ...
#[cfg(all(
any(test, feature = "testing", feature = "benches"),
not(feature = "integration"),
))]
let native_token = address::testing::nam();
// ... Otherwise, look it up from the genesis file
#[cfg(not(all(
any(test, feature = "testing", feature = "benches"),
not(feature = "integration"),
)))]
let native_token = {
let chain_dir = base_dir.join(chain_id.as_str());
let genesis =
genesis::chain::Finalized::read_toml_files(&chain_dir)
.expect("Missing genesis files");
genesis.get_native_token().clone()
} else {
address::nam()
};

// load last state from storage
Expand Down Expand Up @@ -1935,7 +1943,7 @@ mod test_utils {
);
let vp_wasm_compilation_cache = 50 * 1024 * 1024; // 50 kiB
let tx_wasm_compilation_cache = 50 * 1024 * 1024; // 50 kiB
let native_token = address::nam();
let native_token = address::testing::nam();
let mut shell = Shell::<PersistentDB, PersistentStorageHasher>::new(
config::Ledger::new(
base_dir.clone(),
Expand Down Expand Up @@ -2742,9 +2750,10 @@ mod shell_tests {
#[test]
fn test_fee_non_whitelisted_token() {
let (shell, _recv, _, _) = test_utils::setup();
let apfel_denom = read_denom(&shell.wl_storage, &address::apfel())
.expect("unable to read denomination from storage")
.expect("unable to find denomination of apfels");
let apfel_denom =
read_denom(&shell.wl_storage, &address::testing::apfel())
.expect("unable to read denomination from storage")
.expect("unable to find denomination of apfels");

let mut wrapper =
Tx::from_type(TxType::Wrapper(Box::new(WrapperTx::new(
Expand All @@ -2753,7 +2762,7 @@ mod shell_tests {
100.into(),
apfel_denom,
),
token: address::apfel(),
token: address::testing::apfel(),
},
crate::wallet::defaults::albert_keypair().ref_to(),
Epoch(0),
Expand Down
17 changes: 9 additions & 8 deletions crates/apps/src/lib/node/ledger/shell/prepare_proposal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1183,13 +1183,13 @@ mod test_prepare_proposal {
// Remove the allowed btc
*local_config = Some(ValidatorLocalConfig {
accepted_gas_tokens: std::collections::HashMap::from([(
namada::core::address::nam(),
namada::core::address::testing::nam(),
Amount::from(1),
)]),
});
}

let btc_denom = read_denom(&shell.wl_storage, &address::btc())
let btc_denom = read_denom(&shell.wl_storage, &address::testing::btc())
.expect("unable to read denomination from storage")
.expect("unable to find denomination of btcs");

Expand All @@ -1199,7 +1199,7 @@ mod test_prepare_proposal {
100.into(),
btc_denom,
),
token: address::btc(),
token: address::testing::btc(),
},
crate::wallet::defaults::albert_keypair().ref_to(),
Epoch(0),
Expand Down Expand Up @@ -1237,17 +1237,18 @@ mod test_prepare_proposal {
fn test_fee_non_whitelisted_token() {
let (shell, _recv, _, _) = test_utils::setup();

let apfel_denom = read_denom(&shell.wl_storage, &address::apfel())
.expect("unable to read denomination from storage")
.expect("unable to find denomination of apfels");
let apfel_denom =
read_denom(&shell.wl_storage, &address::testing::apfel())
.expect("unable to read denomination from storage")
.expect("unable to find denomination of apfels");

let wrapper = WrapperTx::new(
Fee {
amount_per_gas_unit: DenominatedAmount::new(
100.into(),
apfel_denom,
),
token: address::apfel(),
token: address::testing::apfel(),
},
crate::wallet::defaults::albert_keypair().ref_to(),
Epoch(0),
Expand Down Expand Up @@ -1289,7 +1290,7 @@ mod test_prepare_proposal {
// Remove btc and increase minimum for nam
*local_config = Some(ValidatorLocalConfig {
accepted_gas_tokens: std::collections::HashMap::from([(
namada::core::address::nam(),
namada::core::address::testing::nam(),
Amount::from(100),
)]),
});
Expand Down
9 changes: 5 additions & 4 deletions crates/apps/src/lib/node/ledger/shell/process_proposal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1868,9 +1868,10 @@ mod test_process_proposal {
fn test_fee_non_whitelisted_token() {
let (shell, _recv, _, _) = test_utils::setup();

let apfel_denom = read_denom(&shell.wl_storage, &address::apfel())
.expect("unable to read denomination from storage")
.expect("unable to find denomination of apfels");
let apfel_denom =
read_denom(&shell.wl_storage, &address::testing::apfel())
.expect("unable to read denomination from storage")
.expect("unable to find denomination of apfels");

let mut wrapper =
Tx::from_type(TxType::Wrapper(Box::new(WrapperTx::new(
Expand All @@ -1879,7 +1880,7 @@ mod test_process_proposal {
100.into(),
apfel_denom,
),
token: address::apfel(),
token: address::testing::apfel(),
},
crate::wallet::defaults::albert_keypair().ref_to(),
Epoch(0),
Expand Down
20 changes: 10 additions & 10 deletions crates/apps/src/lib/node/ledger/storage/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
let mut storage = PersistentStorage::open(
db_path.path(),
ChainId::default(),
address::nam(),
address::testing::nam(),
None,
None,
is_merklized_storage_key,
Expand Down Expand Up @@ -139,7 +139,7 @@
let mut storage = PersistentStorage::open(
db_path.path(),
ChainId::default(),
address::nam(),
address::testing::nam(),
None,
None,
is_merklized_storage_key,
Expand Down Expand Up @@ -201,7 +201,7 @@
let mut storage = PersistentStorage::open(
db_path.path(),
ChainId::default(),
address::nam(),
address::testing::nam(),
None,
None,
is_merklized_storage_key,
Expand All @@ -226,7 +226,7 @@
let mut storage = PersistentStorage::open(
db_path.path(),
ChainId::default(),
address::nam(),
address::testing::nam(),
None,
None,
is_merklized_storage_key,
Expand Down Expand Up @@ -273,7 +273,7 @@
let mut storage = PersistentStorage::open(
db_path.path(),
ChainId::default(),
address::nam(),
address::testing::nam(),
None,
None,
is_merklized_storage_key,
Expand Down Expand Up @@ -341,7 +341,7 @@
let mut storage = PersistentStorage::open(
db_path.path(),
ChainId::default(),
address::nam(),
address::testing::nam(),
None,
None,
is_merklized_storage_key,
Expand Down Expand Up @@ -393,7 +393,7 @@
let value: BlockHeight = decode(value_bytes).unwrap();
assert_eq!(value, height);
} else if value_bytes.is_some() {
let value: BlockHeight = decode(value_bytes.unwrap()).unwrap();

Check warning on line 396 in crates/apps/src/lib/node/ledger/storage/mod.rs

View check run for this annotation

Codecov / codecov/patch

crates/apps/src/lib/node/ledger/storage/mod.rs#L396

Added line #L396 was not covered by tests
panic!("Expected no value at height {height}, got {}", value,);
}
}
Expand All @@ -416,7 +416,7 @@
let value: BlockHeight = decode(value_bytes).unwrap();
assert_eq!(value, storage.get_last_block_height());
} else if value_bytes.is_some() {
let value: BlockHeight = decode(value_bytes.unwrap()).unwrap();

Check warning on line 419 in crates/apps/src/lib/node/ledger/storage/mod.rs

View check run for this annotation

Codecov / codecov/patch

crates/apps/src/lib/node/ledger/storage/mod.rs#L419

Added line #L419 was not covered by tests
panic!("Expected no value at height {height}, got {}", value,);
}
}
Expand All @@ -433,7 +433,7 @@
let mut storage = PersistentStorage::open(
db_path.path(),
ChainId::default(),
address::nam(),
address::testing::nam(),
None,
None,
is_merklized_storage_key,
Expand Down Expand Up @@ -552,7 +552,7 @@
let mut storage = PersistentStorage::open(
db_path.path(),
ChainId::default(),
address::nam(),
address::testing::nam(),
None,
Some(5),
is_merklized_storage_key,
Expand Down Expand Up @@ -654,7 +654,7 @@
let storage = PersistentStorage::open(
db_path.path(),
ChainId::default(),
address::nam(),
address::testing::nam(),
None,
None,
is_merklized_storage_key,
Expand Down Expand Up @@ -769,7 +769,7 @@
let storage = PersistentStorage::open(
db_path.path(),
ChainId::default(),
address::nam(),
address::testing::nam(),
None,
None,
merkle_tree_key_filter,
Expand Down
5 changes: 3 additions & 2 deletions crates/apps/src/lib/wallet/defaults.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ mod dev {
use std::collections::HashMap;

use lazy_static::lazy_static;
use namada::core::address::{
apfel, btc, dot, eth, kartoffel, nam, schnitzel, Address,
use namada::core::address::testing::{
apfel, btc, dot, eth, kartoffel, nam, schnitzel,
};
use namada::core::address::Address;
use namada::core::key::*;
use namada::ledger::{governance, pgf, pos};
use namada_sdk::wallet::alias::Alias;
Expand Down
2 changes: 1 addition & 1 deletion crates/benches/host_env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ fn tx_section_signature_validation(c: &mut Criterion) {
let transfer_data = Transfer {
source: defaults::albert_address(),
target: defaults::bertha_address(),
token: address::nam(),
token: address::testing::nam(),
amount: Amount::native_whole(500).native_denominated(),
key: None,
shielded: None,
Expand Down
2 changes: 1 addition & 1 deletion crates/benches/native_vps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ fn vp_multitoken(c: &mut Criterion) {
Transfer {
source: defaults::albert_address(),
target: defaults::bertha_address(),
token: address::nam(),
token: address::testing::nam(),
amount: Amount::native_whole(1000).native_denominated(),
key: None,
shielded: None,
Expand Down
4 changes: 2 additions & 2 deletions crates/benches/process_wrapper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ fn process_tx(c: &mut Criterion) {
Transfer {
source: defaults::albert_address(),
target: defaults::bertha_address(),
token: address::nam(),
token: address::testing::nam(),
amount: Amount::native_whole(1).native_denominated(),
key: None,
shielded: None,
Expand All @@ -36,7 +36,7 @@ fn process_tx(c: &mut Criterion) {
tx.update_header(namada::tx::data::TxType::Wrapper(Box::new(
WrapperTx::new(
Fee {
token: address::nam(),
token: address::testing::nam(),
amount_per_gas_unit: DenominatedAmount::native(1.into()),
},
defaults::albert_keypair().ref_to(),
Expand Down
Loading
Loading