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

Remove usage of "unwrap" in the chain component #2990

Merged
merged 1 commit into from
Sep 8, 2023
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
3 changes: 2 additions & 1 deletion crates/core/component/chain/src/component/view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ pub trait StateReadExt: StateRead {
.await?
.ok_or_else(|| anyhow!("Missing block_timestamp"))?;

Ok(Time::from_str(&timestamp_string).unwrap())
Ok(Time::from_str(&timestamp_string)
.context("block_timestamp was an invalid RFC3339 time string")?)
}

/// Checks a provided chain_id against the chain state.
Expand Down
38 changes: 29 additions & 9 deletions crates/core/component/chain/src/genesis/app_state.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use anyhow::Context;
use penumbra_proto::{
core::chain::v1alpha1 as pb, core::stake::v1alpha1 as pb_stake, DomainType, TypeUrl,
};
Expand Down Expand Up @@ -27,23 +28,39 @@ impl Default for AppState {
allocations: vec![
Allocation {
amount: 1000u128.into(),
denom: "penumbra".parse().unwrap(),
address: crate::test_keys::ADDRESS_0_STR.parse().unwrap(),
denom: "penumbra"
.parse()
.expect("hardcoded \"penumbra\" denom should be parseable"),
address: crate::test_keys::ADDRESS_0_STR
.parse()
.expect("hardcoded test address should be valid"),
},
Allocation {
amount: 100u128.into(),
denom: "test_usd".parse().unwrap(),
address: crate::test_keys::ADDRESS_0_STR.parse().unwrap(),
denom: "test_usd"
.parse()
.expect("hardcoded \"test_usd\" denom should be parseable"),
address: crate::test_keys::ADDRESS_0_STR
.parse()
.expect("hardcoded test address should be valid"),
},
Allocation {
amount: 100u128.into(),
denom: "gm".parse().unwrap(),
address: crate::test_keys::ADDRESS_1_STR.parse().unwrap(),
denom: "gm"
.parse()
.expect("hardcoded \"gm\" denom should be parseable"),
address: crate::test_keys::ADDRESS_1_STR
.parse()
.expect("hardcoded test address should be valid"),
},
Allocation {
amount: 100u128.into(),
denom: "gn".parse().unwrap(),
address: crate::test_keys::ADDRESS_1_STR.parse().unwrap(),
denom: "gn"
.parse()
.expect("hardcoded \"gn\" denom should be parseable"),
address: crate::test_keys::ADDRESS_1_STR
.parse()
.expect("hardcoded test address should be valid"),
},
],
}
Expand All @@ -65,7 +82,10 @@ impl TryFrom<pb::GenesisAppState> for AppState {

fn try_from(msg: pb::GenesisAppState) -> Result<Self, Self::Error> {
Ok(AppState {
chain_params: msg.chain_params.unwrap().try_into()?,
chain_params: msg
.chain_params
.context("chain params not present in protobuf message")?
.try_into()?,
validators: msg
.validators
.into_iter()
Expand Down
23 changes: 19 additions & 4 deletions crates/core/component/chain/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![deny(clippy::unwrap_used)]
#![cfg_attr(docsrs, feature(doc_cfg))]

mod epoch;
Expand Down Expand Up @@ -33,11 +34,25 @@ pub mod test_keys {
/// These addresses both correspond to the test wallet above.
pub const ADDRESS_1_STR: &str = "penumbrav2t1gl609fq6xzjcqn3hz3crysw2s0nkt330lyhaq403ztmrm3yygsgdklt9uxfs0gedwp6sypp5k5ln9t62lvs9t0a990q832wnxak8r939g5u6uz5aessd8saxvv7ewlz4hhqnws";

pub static ADDRESS_0: Lazy<Address> = Lazy::new(|| ADDRESS_0_STR.parse().unwrap());
pub static ADDRESS_1: Lazy<Address> = Lazy::new(|| ADDRESS_1_STR.parse().unwrap());
pub static ADDRESS_0: Lazy<Address> = Lazy::new(|| {
ADDRESS_0_STR
.parse()
.expect("hardcoded test addresses should be valid")
});
pub static ADDRESS_1: Lazy<Address> = Lazy::new(|| {
ADDRESS_1_STR
.parse()
.expect("hardcoded test addresses should be valid")
});

pub static SPEND_KEY: Lazy<SpendKey> =
Lazy::new(|| SpendKey::from_seed_phrase(SEED_PHRASE.parse().unwrap(), 0));
pub static SPEND_KEY: Lazy<SpendKey> = Lazy::new(|| {
SpendKey::from_seed_phrase(
SEED_PHRASE
.parse()
.expect("hardcoded test seed phrase should be valid"),
0,
)
});

pub static FULL_VIEWING_KEY: Lazy<FullViewingKey> =
Lazy::new(|| SPEND_KEY.full_viewing_key().clone());
Expand Down