From 3b241d603bb4379b39053cb8a5c3ed3cc4b80431 Mon Sep 17 00:00:00 2001 From: brentstone Date: Mon, 23 Sep 2024 16:07:32 -0700 Subject: [PATCH] WIP testing --- crates/node/src/shell/init_chain.rs | 4 +- crates/tests/src/e2e/ledger_tests.rs | 27 ++++ crates/tests/src/integration/ledger_tests.rs | 125 +++++++++++++++++++ 3 files changed, 155 insertions(+), 1 deletion(-) diff --git a/crates/node/src/shell/init_chain.rs b/crates/node/src/shell/init_chain.rs index 6a5bcb5cbc..96ee1a0c44 100644 --- a/crates/node/src/shell/init_chain.rs +++ b/crates/node/src/shell/init_chain.rs @@ -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, @@ -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: @@ -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}" ); diff --git a/crates/tests/src/e2e/ledger_tests.rs b/crates/tests/src/e2e/ledger_tests.rs index dceed2b2ac..af8334511a 100644 --- a/crates/tests/src/e2e/ledger_tests.rs +++ b/crates/tests/src/e2e/ledger_tests.rs @@ -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::*; @@ -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( @@ -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![ diff --git a/crates/tests/src/integration/ledger_tests.rs b/crates/tests/src/integration/ledger_tests.rs index 7d6322d448..cf1146df9e 100644 --- a/crates/tests/src/integration/ledger_tests.rs +++ b/crates/tests/src/integration/ledger_tests.rs @@ -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: theokayestvalidator@namada.net")); + 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", + "theokayestvalidator@namada.net", + "--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: theokayestvalidator@namada.net")); + 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));