Skip to content

Commit

Permalink
app(tests): build chain state with test chain id
Browse files Browse the repository at this point in the history
  • Loading branch information
erwanor committed May 4, 2024
1 parent 68f7627 commit 816a6ee
Show file tree
Hide file tree
Showing 13 changed files with 66 additions and 18 deletions.
4 changes: 4 additions & 0 deletions crates/core/app/src/genesis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,10 @@ impl DomainType for AppState {
}

impl Content {
pub fn with_chain_id(self, chain_id: String) -> Self {
Self { chain_id, ..self }
}

pub fn with_epoch_duration(self, epoch_duration: u64) -> Self {
Self {
sct_content: penumbra_sct::genesis::Content {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,11 @@ async fn app_can_define_and_delegate_to_a_validator() -> anyhow::Result<()> {
let storage = TempStorage::new().await?;

// Configure an AppState with slightly shorter epochs than usual.
let app_state =
AppState::Content(genesis::Content::default().with_epoch_duration(EPOCH_DURATION));
let app_state = AppState::Content(
genesis::Content::default()
.with_epoch_duration(EPOCH_DURATION)
.with_chain_id(TestNode::<()>::CHAIN_ID.to_string()),
);

// Start the test node.
let mut node = {
Expand Down
9 changes: 7 additions & 2 deletions crates/core/app/tests/app_can_deposit_into_community_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ use {
self::common::BuilderExt,
anyhow::anyhow,
cnidarium::TempStorage,
penumbra_app::{genesis::AppState, server::consensus::Consensus},
penumbra_app::{
genesis::{self, AppState},
server::consensus::Consensus,
},
penumbra_asset::asset,
penumbra_community_pool::{CommunityPoolDeposit, StateReadExt},
penumbra_keys::test_keys,
Expand All @@ -29,7 +32,9 @@ async fn app_can_deposit_into_community_pool() -> anyhow::Result<()> {

// Define our application state, and start the test node.
let mut test_node = {
let app_state = AppState::default();
let app_state = AppState::Content(
genesis::Content::default().with_chain_id(TestNode::<()>::CHAIN_ID.to_string()),
);
let consensus = Consensus::new(storage.as_ref().clone());
TestNode::builder()
.single_validator()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ async fn app_can_disable_community_pool_spends() -> anyhow::Result<()> {
// Define our application state, and start the test node.
let mut test_node = {
let mut content = Content {
chain_id: TestNode::<()>::CHAIN_ID.to_string(),
governance_content: penumbra_governance::genesis::Content {
governance_params: penumbra_governance::params::GovernanceParameters {
proposal_deposit_amount: 0_u32.into(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ async fn app_can_propose_community_pool_spends() -> anyhow::Result<()> {
// Define our application state, and start the test node.
let mut test_node = {
let mut content = Content {
chain_id: TestNode::<()>::CHAIN_ID.to_string(),
governance_content: penumbra_governance::genesis::Content {
governance_params: penumbra_governance::params::GovernanceParameters {
proposal_deposit_amount: 0_u32.into(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ use {
self::common::BuilderExt,
anyhow::anyhow,
cnidarium::TempStorage,
penumbra_app::{genesis::AppState, server::consensus::Consensus},
penumbra_app::{
genesis::{self, AppState},
server::consensus::Consensus,
},
penumbra_keys::test_keys,
penumbra_mock_client::MockClient,
penumbra_mock_consensus::TestNode,
Expand All @@ -26,7 +29,9 @@ async fn app_can_spend_notes_and_detect_outputs() -> anyhow::Result<()> {
let guard = common::set_tracing_subscriber();
let storage = TempStorage::new().await?;
let mut test_node = {
let app_state = AppState::default();
let app_state = AppState::Content(
genesis::Content::default().with_chain_id(TestNode::<()>::CHAIN_ID.to_string()),
);
let consensus = Consensus::new(storage.as_ref().clone());
TestNode::builder()
.single_validator()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ async fn app_can_undelegate_from_a_validator() -> anyhow::Result<()> {
// Configure an AppState with slightly shorter epochs than usual.
let app_state = AppState::Content(
genesis::Content::default()
.with_chain_id(TestNode::<()>::CHAIN_ID.to_string())
.with_epoch_duration(EPOCH_DURATION)
.with_unbonding_delay(UNBONDING_DELAY),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ use {
self::common::{BuilderExt, ValidatorDataReadExt},
cnidarium::TempStorage,
decaf377_rdsa::{SigningKey, SpendAuth, VerificationKey},
penumbra_app::{genesis::AppState, server::consensus::Consensus},
penumbra_app::{
genesis::{self, AppState},
server::consensus::Consensus,
},
penumbra_keys::test_keys,
penumbra_mock_client::MockClient,
penumbra_mock_consensus::TestNode,
Expand All @@ -25,7 +28,9 @@ async fn app_rejects_validator_definitions_with_invalid_auth_sigs() -> anyhow::R
// Start the test node.
let mut node = {
let consensus = Consensus::new(storage.as_ref().clone());
let app_state = AppState::default();
let app_state = AppState::Content(
genesis::Content::default().with_chain_id(TestNode::<()>::CHAIN_ID.to_string()),
);
TestNode::builder()
.single_validator()
.with_penumbra_auto_app_state(app_state)?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ use {
self::common::{BuilderExt, ValidatorDataReadExt},
anyhow::Context,
cnidarium::TempStorage,
penumbra_app::{genesis::AppState, server::consensus::Consensus},
penumbra_app::{
genesis::{self, AppState},
server::consensus::Consensus,
},
penumbra_mock_consensus::TestNode,
penumbra_stake::component::validator_handler::validator_store::ValidatorDataRead,
tap::Tap,
Expand All @@ -19,7 +22,9 @@ async fn app_tracks_uptime_for_genesis_validator_missing_blocks() -> anyhow::Res

// Start the test node.
let mut node = {
let app_state = AppState::default();
let app_state = AppState::Content(
genesis::Content::default().with_chain_id(TestNode::<()>::CHAIN_ID.to_string()),
);
let consensus = Consensus::new(storage.as_ref().clone());
TestNode::builder()
.single_validator()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ use {
self::common::{BuilderExt, ValidatorDataReadExt},
anyhow::Context,
cnidarium::TempStorage,
penumbra_app::{genesis::AppState, server::consensus::Consensus},
penumbra_app::{
genesis::{self, AppState},
server::consensus::Consensus,
},
penumbra_mock_consensus::TestNode,
penumbra_stake::component::validator_handler::validator_store::ValidatorDataRead,
tap::Tap,
Expand All @@ -19,7 +22,9 @@ async fn app_tracks_uptime_for_genesis_validator_missing_blocks() -> anyhow::Res

// Start the test node.
let mut node = {
let app_state = AppState::default();
let app_state = AppState::Content(
genesis::Content::default().with_chain_id(TestNode::<()>::CHAIN_ID.to_string()),
);
let consensus = Consensus::new(storage.as_ref().clone());
TestNode::builder()
.single_validator()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,11 @@ async fn app_tracks_uptime_for_validators_only_once_active() -> anyhow::Result<(
let storage = TempStorage::new().await?;

// Configure an AppState with slightly shorter epochs than usual.
let app_state =
AppState::Content(genesis::Content::default().with_epoch_duration(EPOCH_DURATION));
let app_state = AppState::Content(
genesis::Content::default()
.with_epoch_duration(EPOCH_DURATION)
.with_chain_id(TestNode::<()>::CHAIN_ID.to_string()),
);

// Start the test node.
let mut node = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ use {
self::common::{BuilderExt, ValidatorDataReadExt},
anyhow::anyhow,
cnidarium::TempStorage,
penumbra_app::{genesis::AppState, server::consensus::Consensus},
penumbra_app::{
genesis::{self, AppState},
server::consensus::Consensus,
},
penumbra_mock_consensus::TestNode,
penumbra_stake::component::validator_handler::ValidatorDataRead as _,
tap::{Tap, TapFallible},
Expand All @@ -18,7 +21,9 @@ async fn mock_consensus_can_define_a_genesis_validator() -> anyhow::Result<()> {
let guard = common::set_tracing_subscriber();
let storage = TempStorage::new().await?;
let test_node = {
let app_state = AppState::default();
let app_state = AppState::Content(
genesis::Content::default().with_chain_id(TestNode::<()>::CHAIN_ID.to_string()),
);
let consensus = Consensus::new(storage.as_ref().clone());
TestNode::builder()
.single_validator()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
use {
self::common::BuilderExt,
cnidarium::TempStorage,
penumbra_app::{genesis::AppState, server::consensus::Consensus},
penumbra_app::{
genesis::{self, AppState},
server::consensus::Consensus,
},
penumbra_mock_consensus::TestNode,
penumbra_sct::component::clock::EpochRead as _,
tap::TapFallible,
Expand All @@ -17,7 +20,9 @@ async fn mock_consensus_can_send_a_sequence_of_empty_blocks() -> anyhow::Result<
let guard = common::set_tracing_subscriber();
let storage = TempStorage::new().await?;
let mut test_node = {
let app_state = AppState::default();
let app_state = AppState::Content(
genesis::Content::default().with_chain_id(TestNode::<()>::CHAIN_ID.to_string()),
);
let consensus = Consensus::new(storage.as_ref().clone());
TestNode::builder()
.single_validator()
Expand Down

0 comments on commit 816a6ee

Please sign in to comment.