From 8d09a752a7044ebf9433088b3ba4f59654f72395 Mon Sep 17 00:00:00 2001 From: katelyn martin Date: Wed, 20 Mar 2024 12:56:23 -0400 Subject: [PATCH] =?UTF-8?q?tests(app):=20=F0=9F=8D=96=20compare=20new=20an?= =?UTF-8?q?d=20existing=20validator=20rates=20(#4059)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit addresses ยง7.b in #3995. this introduces new assertions so that the `mock_consensus_can_define_and_delegate_to_a_validator` test exercises that the staking component is calculating different rates for validators that were created at different times. --- .../core/app/tests/mock_consensus_staking.rs | 27 ++++++++++++++++--- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/crates/core/app/tests/mock_consensus_staking.rs b/crates/core/app/tests/mock_consensus_staking.rs index 823deeae9f..3aa6cda6cb 100644 --- a/crates/core/app/tests/mock_consensus_staking.rs +++ b/crates/core/app/tests/mock_consensus_staking.rs @@ -2,7 +2,7 @@ mod common; use { self::common::BuilderExt, - anyhow::Context, + anyhow::{anyhow, Context}, cnidarium::TempStorage, decaf377_rdsa::{SigningKey, SpendAuth}, penumbra_app::server::consensus::Consensus, @@ -185,7 +185,7 @@ async fn mock_consensus_can_define_and_delegate_to_a_validator() -> anyhow::Resu // Show that the set of validators looks correct. { use penumbra_stake::{component::ConsensusIndexRead, validator::State}; - let snapshot = post_tx_snapshot; + let snapshot = post_tx_snapshot.clone(); info!("checking consensus set in block after validator definition"); // The original validator should still be active. assert_eq!( @@ -208,6 +208,25 @@ async fn mock_consensus_can_define_and_delegate_to_a_validator() -> anyhow::Resu ); } + // Show that the validators have different rates. The second validator was created later, and + // should thus have a different rate than a validator that has existed since genesis. + { + use penumbra_stake::component::validator_handler::validator_store::ValidatorDataRead; + let snapshot = post_tx_snapshot; + let existing = snapshot + .get_validator_rate(&existing_validator_id) + .await? + .ok_or(anyhow!("existing validator has a rate"))?; + let new = snapshot + .get_validator_rate(&new_validator_id) + .await? + .ok_or(anyhow!("new validator has a rate"))?; + assert_ne!( + existing, new, + "validators created at different times should have different rates" + ); + } + // Now, create a transaction that delegates to the new validator. let plan = { use { @@ -223,7 +242,7 @@ async fn mock_consensus_can_define_and_delegate_to_a_validator() -> anyhow::Resu let rate = snapshot .get_validator_rate(&new_validator_id) .await? - .ok_or(anyhow::anyhow!("new validator has a rate"))? + .ok_or(anyhow!("new validator has a rate"))? .tap(|rate| tracing::info!(?rate, "got new validator rate")); let note = client .notes @@ -347,7 +366,7 @@ async fn mock_consensus_can_define_and_delegate_to_a_validator() -> anyhow::Resu let rate = snapshot .get_validator_rate(&new_validator_id) .await? - .ok_or(anyhow::anyhow!("new validator has a rate"))? + .ok_or(anyhow!("new validator has a rate"))? .tap(|rate| tracing::info!(?rate, "got new validator rate")); let undelegation_id = DelegationToken::new(new_validator_id).id();