-
Notifications
You must be signed in to change notification settings - Fork 316
/
Copy pathmod.rs
81 lines (68 loc) · 2.81 KB
/
mod.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
//! Shared integration testing facilities.
// NB: Allow dead code, these are in fact shared by files in `tests/`.
#![allow(dead_code)]
use async_trait::async_trait;
use cnidarium::TempStorage;
use penumbra_app::app::App;
use penumbra_genesis::AppState;
use std::ops::Deref;
// Installs a tracing subscriber to log events until the returned guard is dropped.
pub fn set_tracing_subscriber() -> tracing::subscriber::DefaultGuard {
use tracing_subscriber::filter::EnvFilter;
let filter = "debug,penumbra_app=trace,penumbra_mock_consensus=trace";
let filter = EnvFilter::try_from_default_env()
.or_else(|_| EnvFilter::try_new(filter))
.expect("should have a valid filter directive")
// Without explicitly disabling the `r1cs` target, the ZK proof implementations
// will spend an enormous amount of CPU and memory building useless tracing output.
.add_directive(
"r1cs=off"
.parse()
.expect("rics=off is a valid filter directive"),
);
let subscriber = tracing_subscriber::fmt()
.with_env_filter(filter)
.pretty()
.with_test_writer()
.finish();
tracing::subscriber::set_default(subscriber)
}
#[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_trait]
impl TempStorageExt for TempStorage {
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 {
anyhow::bail!("database already initialized");
}
// Apply the genesis state to the storage
let mut app = App::new(self.latest_snapshot()).await?;
app.init_chain(&genesis).await;
app.commit(self.deref().clone()).await;
Ok(self)
}
async fn apply_default_genesis(self) -> anyhow::Result<Self> {
self.apply_genesis(Default::default()).await
}
}
/// Penumbra-specific extensions to the mock consensus builder.
pub trait BuilderExt: Sized {
type Error;
fn with_penumbra_auto_app_state(self, app_state: AppState) -> Result<Self, Self::Error>;
}
impl BuilderExt for penumbra_mock_consensus::builder::Builder {
type Error = anyhow::Error;
fn with_penumbra_auto_app_state(self, app_state: AppState) -> Result<Self, Self::Error> {
// what to do here?
// - read out list of abci/comet validators from the builder,
// - define a penumbra validator for each one
// - inject that into the penumbra app state
// - serialize to json and then call `with_app_state_bytes`
let app_state = serde_json::to_vec(&app_state)?;
Ok(self.app_state(app_state))
}
}