Skip to content

Commit

Permalink
Skeleton of IBC tests
Browse files Browse the repository at this point in the history
  • Loading branch information
zbuc committed Aug 10, 2024
1 parent dd369ae commit c7c2d85
Show file tree
Hide file tree
Showing 34 changed files with 1,036 additions and 41 deletions.
Binary file modified crates/cnidarium/src/gen/proto_descriptor.bin.no_lfs
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use {
self::common::{BuilderExt, TestNodeExt, ValidatorDataReadExt},
anyhow::anyhow,
cnidarium::TempStorage,
common::TempStorageExt as _,
decaf377_rdsa::{SigningKey, SpendAuth, VerificationKey},
penumbra_app::{
genesis::{self, AppState},
Expand Down Expand Up @@ -32,7 +33,7 @@ const EPOCH_DURATION: u64 = 8;
async fn app_can_define_and_delegate_to_a_validator() -> anyhow::Result<()> {
// Install a test logger, acquire some temporary storage, and start the test node.
let guard = common::set_tracing_subscriber();
let storage = TempStorage::new().await?;
let storage = TempStorage::new_with_penumbra_prefixes().await?;

// Configure an AppState with slightly shorter epochs than usual.
let app_state = AppState::Content(
Expand Down
3 changes: 2 additions & 1 deletion crates/core/app/tests/app_can_deposit_into_community_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use {
self::common::BuilderExt,
anyhow::anyhow,
cnidarium::TempStorage,
common::TempStorageExt as _,
penumbra_app::{
genesis::{self, AppState},
server::consensus::Consensus,
Expand All @@ -28,7 +29,7 @@ mod common;
async fn app_can_deposit_into_community_pool() -> anyhow::Result<()> {
// Install a test logger, and acquire some temporary storage.
let guard = common::set_tracing_subscriber();
let storage = TempStorage::new().await?;
let storage = TempStorage::new_with_penumbra_prefixes().await?;

// Define our application state, and start the test node.
let mut test_node = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use {
self::common::ValidatorDataReadExt,
anyhow::anyhow,
cnidarium::TempStorage,
common::TempStorageExt as _,
decaf377_rdsa::VerificationKey,
penumbra_app::{
genesis::{AppState, Content},
Expand Down Expand Up @@ -49,7 +50,7 @@ const PROPOSAL_VOTING_BLOCKS: u64 = 3;
async fn app_can_disable_community_pool_spends() -> anyhow::Result<()> {
// Install a test logger, and acquire some temporary storage.
let guard = common::set_tracing_subscriber();
let storage = TempStorage::new().await?;
let storage = TempStorage::new_with_penumbra_prefixes().await?;

// Define a helper to get the current community pool balance.
let pool_balance = || async { storage.latest_snapshot().community_pool_balance().await };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use {
self::common::ValidatorDataReadExt,
anyhow::anyhow,
cnidarium::TempStorage,
common::TempStorageExt as _,
decaf377_rdsa::VerificationKey,
penumbra_app::{
genesis::{AppState, Content},
Expand Down Expand Up @@ -49,7 +50,7 @@ const PROPOSAL_VOTING_BLOCKS: u64 = 3;
async fn app_can_propose_community_pool_spends() -> anyhow::Result<()> {
// Install a test logger, and acquire some temporary storage.
let guard = common::set_tracing_subscriber();
let storage = TempStorage::new().await?;
let storage = TempStorage::new_with_penumbra_prefixes().await?;

// Define a helper to get the current community pool balance.
let pool_balance = || async { storage.latest_snapshot().community_pool_balance().await };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use {
self::common::BuilderExt,
anyhow::anyhow,
cnidarium::TempStorage,
common::TempStorageExt as _,
penumbra_app::{
genesis::{self, AppState},
server::consensus::Consensus,
Expand All @@ -27,7 +28,7 @@ mod common;
async fn app_can_spend_notes_and_detect_outputs() -> anyhow::Result<()> {
// Install a test logger, acquire some temporary storage, and start the test node.
let guard = common::set_tracing_subscriber();
let storage = TempStorage::new().await?;
let storage = TempStorage::new_with_penumbra_prefixes().await?;
let mut test_node = {
let app_state = AppState::Content(
genesis::Content::default().with_chain_id(TestNode::<()>::CHAIN_ID.to_string()),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use {
anyhow::Context,
cnidarium::TempStorage,
common::TempStorageExt as _,
penumbra_app::{
genesis::{AppState, Content},
server::consensus::Consensus,
Expand Down Expand Up @@ -37,7 +38,7 @@ const COUNT: usize = SWEEP_COUNT + 1;
async fn app_can_sweep_a_collection_of_small_notes() -> anyhow::Result<()> {
// Install a test logger, and acquire some temporary storage.
let guard = common::set_tracing_subscriber_with_env_filter("info".into());
let storage = TempStorage::new().await?;
let storage = TempStorage::new_with_penumbra_prefixes().await?;

// Instantiate a mock tendermint proxy, which we will connect to the test node.
let proxy = penumbra_mock_tendermint_proxy::TestNodeProxy::new::<Consensus>();
Expand Down
3 changes: 2 additions & 1 deletion crates/core/app/tests/app_can_undelegate_from_a_validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use {
self::common::{BuilderExt, TestNodeExt, ValidatorDataReadExt},
anyhow::anyhow,
cnidarium::TempStorage,
common::TempStorageExt as _,
decaf377_fmd::Precision,
penumbra_app::{
genesis::{self, AppState},
Expand Down Expand Up @@ -37,7 +38,7 @@ const UNBONDING_DELAY: u64 = 4;
async fn app_can_undelegate_from_a_validator() -> anyhow::Result<()> {
// Install a test logger, acquire some temporary storage, and start the test node.
let guard = common::set_tracing_subscriber();
let storage = TempStorage::new().await?;
let storage = TempStorage::new_with_penumbra_prefixes().await?;

// Helper function to get the latest block height.
let get_latest_height = || async {
Expand Down
5 changes: 4 additions & 1 deletion crates/core/app/tests/app_check_dex_vcb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ use std::{ops::Deref, sync::Arc};
/// This bug was fixed in #4643.
async fn dex_vcb_tracks_multiswap() -> anyhow::Result<()> {
let mut rng = rand_chacha::ChaChaRng::seed_from_u64(1776);
let storage = TempStorage::new().await?.apply_default_genesis().await?;
let storage = TempStorage::new_with_penumbra_prefixes()
.await?
.apply_default_genesis()
.await?;
let mut state = Arc::new(StateDelta::new(storage.latest_snapshot()));

// Create the first swap:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use {
self::common::{BuilderExt, ValidatorDataReadExt},
cnidarium::TempStorage,
common::TempStorageExt as _,
decaf377_rdsa::{SigningKey, SpendAuth, VerificationKey},
penumbra_app::{
genesis::{self, AppState},
Expand All @@ -23,7 +24,7 @@ mod common;
async fn app_rejects_validator_definitions_with_invalid_auth_sigs() -> anyhow::Result<()> {
// Install a test logger, and acquire some temporary storage.
let guard = common::set_tracing_subscriber();
let storage = TempStorage::new().await?;
let storage = TempStorage::new_with_penumbra_prefixes().await?;

// Start the test node.
let mut node = {
Expand Down
5 changes: 3 additions & 2 deletions crates/core/app/tests/app_reproduce_testnet_75_vcb_close.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,19 @@ use {
self::common::BuilderExt,
anyhow::anyhow,
cnidarium::TempStorage,
common::TempStorageExt as _,
penumbra_app::{
genesis::{self, AppState},
server::consensus::Consensus,
},
penumbra_asset::{Value, STAKING_TOKEN_ASSET_ID},
penumbra_auction::StateReadExt as _,
penumbra_auction::{
auction::{
dutch::{ActionDutchAuctionEnd, ActionDutchAuctionSchedule, DutchAuctionDescription},
AuctionNft,
},
component::AuctionStoreRead,
StateReadExt as _,
},
penumbra_keys::test_keys,
penumbra_mock_client::MockClient,
Expand Down Expand Up @@ -65,7 +66,7 @@ async fn app_can_reproduce_tesnet_75_vcb_close() -> anyhow::Result<()> {

common::set_tracing_subscriber_with_env_filter(filter)
};
let storage = TempStorage::new().await?;
let storage = TempStorage::new_with_penumbra_prefixes().await?;
let app_state = AppState::Content(
genesis::Content::default().with_chain_id(TestNode::<()>::CHAIN_ID.to_string()),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use {
self::common::{BuilderExt, ValidatorDataReadExt},
anyhow::Context,
cnidarium::TempStorage,
common::TempStorageExt as _,
penumbra_app::{
genesis::{self, AppState},
server::consensus::Consensus,
Expand All @@ -18,7 +19,7 @@ mod common;
async fn app_tracks_uptime_for_genesis_validator_missing_blocks() -> anyhow::Result<()> {
// Install a test logger, acquire some temporary storage, and start the test node.
let guard = common::set_tracing_subscriber();
let storage = TempStorage::new().await?;
let storage = TempStorage::new_with_penumbra_prefixes().await?;

// Start the test node.
let mut node = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use {
self::common::{BuilderExt, ValidatorDataReadExt},
anyhow::Context,
cnidarium::TempStorage,
common::TempStorageExt as _,
penumbra_app::{
genesis::{self, AppState},
server::consensus::Consensus,
Expand All @@ -18,7 +19,7 @@ mod common;
async fn app_tracks_uptime_for_genesis_validator_missing_blocks() -> anyhow::Result<()> {
// Install a test logger, acquire some temporary storage, and start the test node.
let guard = common::set_tracing_subscriber();
let storage = TempStorage::new().await?;
let storage = TempStorage::new_with_penumbra_prefixes().await?;

// Start the test node.
let mut node = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use {
self::common::{BuilderExt, TestNodeExt, ValidatorDataReadExt},
cnidarium::TempStorage,
common::TempStorageExt as _,
decaf377_rdsa::{SigningKey, SpendAuth, VerificationKey},
penumbra_app::{
genesis::{self, AppState},
Expand Down Expand Up @@ -32,7 +33,7 @@ async fn app_tracks_uptime_for_validators_only_once_active() -> anyhow::Result<(

// Install a test logger, acquire some temporary storage, and start the test node.
let guard = common::set_tracing_subscriber();
let storage = TempStorage::new().await?;
let storage = TempStorage::new_with_penumbra_prefixes().await?;

// Configure an AppState with slightly shorter epochs than usual.
let app_state = AppState::Content(
Expand Down
7 changes: 6 additions & 1 deletion crates/core/app/tests/common/temp_storage_ext.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
use {
async_trait::async_trait,
cnidarium::TempStorage,
penumbra_app::{app::App, genesis::AppState},
penumbra_app::{app::App, genesis::AppState, SUBSTORE_PREFIXES},
std::ops::Deref,
};

#[async_trait]
pub trait TempStorageExt: Sized {
async fn apply_genesis(self, genesis: AppState) -> anyhow::Result<Self>;
async fn apply_default_genesis(self) -> anyhow::Result<Self>;
async fn new_with_penumbra_prefixes() -> anyhow::Result<TempStorage>;
}

#[async_trait]
impl TempStorageExt for TempStorage {
async fn new_with_penumbra_prefixes() -> anyhow::Result<TempStorage> {
TempStorage::new_with_prefixes(SUBSTORE_PREFIXES.to_vec()).await
}

async fn apply_genesis(self, genesis: AppState) -> anyhow::Result<Self> {
// Check that we haven't already applied a genesis state:
if self.latest_version() != u64::MAX {
Expand Down
Loading

0 comments on commit c7c2d85

Please sign in to comment.