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

Generate block headers properly in tests #4823

Merged
merged 1 commit into from
Aug 20, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
6 changes: 6 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ async fn app_tracks_uptime_for_genesis_validator_missing_blocks() -> anyhow::Res
let height = 4;
for i in 1..=height {
node.block()
.with_signatures(vec![])
.without_signatures()
.execute()
.tap(|_| trace!(%i, "executing block with no signatures"))
.instrument(error_span!("executing block with no signatures", %i))
Expand Down
16 changes: 13 additions & 3 deletions crates/core/app/tests/common/test_node_builder_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,21 @@ pub trait BuilderExt: Sized {

impl BuilderExt for Builder {
type Error = anyhow::Error;
fn with_penumbra_auto_app_state(self, app_state: AppState) -> Result<Self, Self::Error> {
fn with_penumbra_auto_app_state(mut self, app_state: AppState) -> Result<Self, Self::Error> {
let Self { keyring, .. } = &self;
let mut content = match app_state {
AppState::Content(c) => c,
AppState::Checkpoint(_) => anyhow::bail!("checkpointed state is not supported"),
};

for (consensus_vk, _) in keyring {
// Let the seed for the penumbra validator be derived from the verification key,
// that way tests can operate with no rng.
let seed = Some(SpendKeyBytes(consensus_vk.to_bytes()));

// Generate a penumbra validator with this consensus key, and a corresponding
// allocation of delegation tokens.
let (validator, allocation) = generate_penumbra_validator(consensus_vk);
let (validator, allocation) = generate_penumbra_validator(consensus_vk, seed);

// Add the validator to the staking component's genesis content.
trace!(?validator, "adding validator to staking genesis content");
Expand All @@ -50,6 +54,11 @@ impl BuilderExt for Builder {
content.shielded_pool_content.allocations.push(allocation);
}

// Set the chain ID from the content
if !content.chain_id.is_empty() {
self.chain_id = Some(content.chain_id.clone());
}

// Serialize the app state into bytes, and add it to the builder.
let app_state = AppState::Content(content);
serde_json::to_vec(&app_state)
Expand All @@ -61,8 +70,9 @@ impl BuilderExt for Builder {
/// Generates a [`Validator`][PenumbraValidator] given a consensus verification key.
fn generate_penumbra_validator(
consensus_key: &ed25519_consensus::VerificationKey,
seed: Option<SpendKeyBytes>,
) -> (PenumbraValidator, Allocation) {
let seed = SpendKeyBytes(OsRng.gen());
let seed = seed.unwrap_or(SpendKeyBytes(OsRng.gen()));
let spend_key = SpendKey::from(seed.clone());
let validator_id_sk = spend_key.spend_auth_key();
let validator_id_vk = VerificationKey::from(validator_id_sk);
Expand Down
Loading
Loading