Skip to content

Commit

Permalink
WIP testing
Browse files Browse the repository at this point in the history
  • Loading branch information
brentstone committed Sep 23, 2024
1 parent b8492b9 commit 3b241d6
Show file tree
Hide file tree
Showing 3 changed files with 155 additions and 1 deletion.
4 changes: 3 additions & 1 deletion crates/node/src/shell/init_chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,7 @@ where
self.init_token_accounts(&genesis);
self.init_token_balances(&genesis);
self.apply_genesis_txs_established_account(&genesis, &mut vp_cache);
println!("\nABOUT TO APPLY GENESIS TXS VALIDATOR ACCOUNT\n");
self.apply_genesis_txs_validator_account(
&genesis,
&mut vp_cache,
Expand Down Expand Up @@ -585,6 +586,7 @@ where
params: &PosParams,
current_epoch: namada_sdk::chain::Epoch,
) -> ControlFlow<()> {
tracing::info!("Applying genesis txs to init validator accounts");
if let Some(txs) = genesis.transactions.validator_account.as_ref() {
for FinalizedValidatorAccountTx {
tx:
Expand All @@ -610,7 +612,7 @@ where
{
let address = &Address::Established(address.raw.clone());

tracing::debug!(
tracing::info!(
"Applying genesis tx to init a validator account {address}"
);

Expand Down
27 changes: 27 additions & 0 deletions crates/tests/src/e2e/ledger_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,11 @@ use namada_core::chain::ChainId;
use namada_core::token::NATIVE_MAX_DECIMAL_PLACES;
use namada_sdk::address::Address;
use namada_sdk::chain::Epoch;
use namada_sdk::dec::Dec;
use namada_sdk::time::DateTimeUtc;
use namada_sdk::token;
use namada_test_utils::TestWasms;
use regex::Regex;
use serde::Serialize;
use serde_json::json;
use setup::constants::*;
Expand Down Expand Up @@ -503,10 +505,13 @@ fn stop_ledger_at_height() -> Result<()> {
fn pos_bonds() -> Result<()> {
let pipeline_len = 2;
let unbonding_len = 4;
let min_commission_rate = Dec::from_str("0.1").unwrap();
let test = setup::network(
|mut genesis, base_dir: &_| {
genesis.parameters.pos_params.pipeline_len = pipeline_len;
genesis.parameters.pos_params.unbonding_len = unbonding_len;
genesis.parameters.pos_params.min_commission_rate =
min_commission_rate;
genesis.parameters.parameters.min_num_of_blocks = 6;
genesis.parameters.parameters.epochs_per_year = 31_536_000;
let mut genesis = setup::set_validators(
Expand Down Expand Up @@ -577,6 +582,28 @@ fn pos_bonds() -> Result<()> {
wait_for_block_height(&test, &rpc, 2, 30)?;

let validator_0_rpc = get_actor_rpc(&test, Who::Validator(0));
let tx_args = vec![
"commission-rate",
"--validator",
"validator-0-validator",
"--node",
&validator_0_rpc,
];
let mut client =
run_as!(test, Who::Validator(0), Bin::Client, tx_args, Some(40))?;
// let expected = "Amount 1600.000000 withdrawable starting from epoch ";
// let val_str = client.exp_regex(&format!("{expected}.*\n"))?;

let a = client.exp_regex(r".* commission rate: [0-1]\.[0-9]*,.*")?.1;
dbg!(&a);
let b = Regex::new(r"commission rate: ([0-1]\.[0-9]+),")?
.captures(&a)
.unwrap()
.get(1)
.unwrap()
.as_str();
dbg!(&b);
client.assert_success();

// 2. Submit a self-bond for the first genesis validator
let tx_args = vec![
Expand Down
125 changes: 125 additions & 0 deletions crates/tests/src/integration/ledger_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1666,6 +1666,131 @@ fn change_validator_metadata() -> Result<()> {
assert_matches!(captured.result, Ok(_));
assert!(captured.contains(TX_APPLIED_SUCCESS));

// 6. Query the metadata to see that the validator website is removed
let captured =
CapturedOutput::of(|| run(&node, Bin::Client, metadata_query_args));
assert_matches!(captured.result, Ok(_));
assert!(captured.contains("Email: [email protected]"));
assert!(captured.contains(
"Description: We are just an okay validator node trying to get by"
));
assert!(captured.contains("No website"));
assert!(captured.contains("No discord handle"));
assert!(captured.contains("commission rate:"));
assert!(captured.contains("max change per epoch:"));

// 6. Try to change the validator commission below the minimum
let commission_change_args = apply_use_device(vec![
"change-commission-rate",
"--validator",
"validator-0-validator",
"--commission-rate",
"0.01",
"--node",
&validator_one_rpc,
]);
let captured =
CapturedOutput::of(|| run(&node, Bin::Client, commission_change_args));
assert_matches!(captured.result, Err(_));

// 7. Query to ensure it hasn't changed
let commission_change_args = apply_use_device(vec![
"commission-rate",
"--validator",
"validator-0-validator",
"--node",
&validator_one_rpc,
]);
let captured =
CapturedOutput::of(|| run(&node, Bin::Client, commission_change_args));
assert_matches!(captured.result, Ok(_));
assert!(
captured.contains("commission rate: 0.05, max change per epoch: 0.01")
);

Ok(())
}

/// Change validator metadata
#[test]
fn check_validator_commission() -> Result<()> {
// This address doesn't matter for tests. But an argument is required.
let validator_one_rpc = "http://127.0.0.1:26567";
// 1. start the ledger node
let (node, _services) = setup::setup()?;

// 2. Query the validator metadata loaded from genesis
let metadata_query_args = vec![
"validator-metadata",
"--validator",
"validator-0-validator",
"--node",
&validator_one_rpc,
];
let captured = CapturedOutput::of(|| {
run(&node, Bin::Client, metadata_query_args.clone())
});
assert_matches!(captured.result, Ok(_));
assert!(captured.contains("No validator name"));
assert!(captured.contains("Email:"));
assert!(captured.contains("No description"));
assert!(captured.contains("No website"));
assert!(captured.contains("No discord handle"));
assert!(captured.contains("commission rate:"));
assert!(captured.contains("max change per epoch:"));

// 3. Add some metadata to the validator
let metadata_change_args = apply_use_device(vec![
"change-metadata",
"--validator",
"validator-0-validator",
"--name",
"theokayestvalidator",
"--email",
"[email protected]",
"--description",
"We are just an okay validator node trying to get by",
"--website",
"theokayestvalidator.com",
"--node",
&validator_one_rpc,
]);

let captured =
CapturedOutput::of(|| run(&node, Bin::Client, metadata_change_args));
assert_matches!(captured.result, Ok(_));
assert!(captured.contains(TX_APPLIED_SUCCESS));

// 4. Query the metadata after the change
let captured = CapturedOutput::of(|| {
run(&node, Bin::Client, metadata_query_args.clone())
});
assert_matches!(captured.result, Ok(_));
assert!(captured.contains("Validator name: theokayestvalidator"));
assert!(captured.contains("Email: [email protected]"));
assert!(captured.contains(
"Description: We are just an okay validator node trying to get by"
));
assert!(captured.contains("Website: theokayestvalidator.com"));
assert!(captured.contains("No discord handle"));
assert!(captured.contains("commission rate:"));
assert!(captured.contains("max change per epoch:"));

// 5. Remove the validator website
let metadata_change_args = apply_use_device(vec![
"change-metadata",
"--validator",
"validator-0-validator",
"--website",
"",
"--node",
&validator_one_rpc,
]);
let captured =
CapturedOutput::of(|| run(&node, Bin::Client, metadata_change_args));
assert_matches!(captured.result, Ok(_));
assert!(captured.contains(TX_APPLIED_SUCCESS));

// 6. Query the metadata to see that the validator website is removed
let captured =
CapturedOutput::of(|| run(&node, Bin::Client, metadata_query_args));
Expand Down

0 comments on commit 3b241d6

Please sign in to comment.