Skip to content

Commit

Permalink
tests(app): 🍖 compare new and existing validator rates (#4059)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
cratelyn authored Mar 20, 2024
1 parent cd15210 commit 8d09a75
Showing 1 changed file with 23 additions and 4 deletions.
27 changes: 23 additions & 4 deletions crates/core/app/tests/mock_consensus_staking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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!(
Expand All @@ -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 {
Expand All @@ -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
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 8d09a75

Please sign in to comment.