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

chore(sequencer): add snapshots for storage values to enforce non-state-breaking changes #1985

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
source: crates/astria-sequencer/src/accounts/storage/values.rs
expression: "format!(\"{:?}\",\ndiscriminant(&StoredValue::Accounts(Value(ValueImpl::Balance(Balance(0))))))"
---
Discriminant(3)
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
source: crates/astria-sequencer/src/accounts/storage/values.rs
expression: "format!(\"{:?}\", discriminant(&ValueImpl::Balance(Balance(0))))"
---
Discriminant(0)
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
source: crates/astria-sequencer/src/accounts/storage/values.rs
expression: "format!(\"{:?}\", discriminant(&ValueImpl::Nonce(Nonce(0))))"
---
Discriminant(1)
41 changes: 41 additions & 0 deletions crates/astria-sequencer/src/accounts/storage/values.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,44 @@ impl<'a> TryFrom<crate::storage::StoredValue<'a>> for Nonce {
Ok(nonce)
}
}

#[cfg(test)]
mod tests {
use std::mem::discriminant;

use insta::assert_snapshot;

use super::*;

#[test]
fn value_impl_balance_discriminant_unchanged() {
assert_snapshot!(
"value_impl_balance_discriminant",
format!("{:?}", discriminant(&ValueImpl::Balance(Balance(0))))
);
}

#[test]
fn value_impl_nonce_discriminant_unchanged() {
assert_snapshot!(
"value_impl_nonce_discriminant",
format!("{:?}", discriminant(&ValueImpl::Nonce(Nonce(0))))
);
}

// Note: This test must be here instead of in `crate::storage` since `ValueImpl` is not
// re-exported.
#[test]
fn stored_value_account_discriminant_unchanged() {
use crate::storage::StoredValue;
assert_snapshot!(
"stored_value_account_discriminant",
format!(
"{:?}",
discriminant(&StoredValue::Accounts(Value(ValueImpl::Balance(Balance(
0
)))))
)
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
source: crates/astria-sequencer/src/address/storage/values.rs
expression: "format!(\"{:?}\",\ndiscriminant(&StoredValue::Address(Value(ValueImpl::AddressPrefix(\"test_prefix\".into())))))"
---
Discriminant(1)
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
source: crates/astria-sequencer/src/address/storage/values.rs
expression: "format!(\"{:?}\", discriminant(&ValueImpl::AddressPrefix(\"test_prefix\".into())))"
---
Discriminant(0)
36 changes: 36 additions & 0 deletions crates/astria-sequencer/src/address/storage/values.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,39 @@ impl<'a> TryFrom<crate::storage::StoredValue<'a>> for AddressPrefix<'a> {
Ok(prefix)
}
}

#[cfg(test)]
mod tests {
use std::mem::discriminant;

use insta::assert_snapshot;

use super::*;

#[test]
fn value_impl_address_prefix_discriminant_unchanged() {
assert_snapshot!(
"value_impl_address_prefix_discriminant",
format!(
"{:?}",
discriminant(&ValueImpl::AddressPrefix("test_prefix".into()))
)
);
}

// Note: This test must be here instead of in `crate::storage` since `ValueImpl` is not
// re-exported.
#[test]
fn stored_value_address_discriminant_unchanged() {
use crate::storage::StoredValue;
assert_snapshot!(
"stored_value_address_discriminant",
format!(
"{:?}",
discriminant(&StoredValue::Address(Value(ValueImpl::AddressPrefix(
"test_prefix".into()
))))
)
);
}
}
69 changes: 69 additions & 0 deletions crates/astria-sequencer/src/app/storage/values/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,72 @@ enum ValueImpl<'a> {
BlockTimestamp(BlockTimestamp),
StorageVersion(StorageVersion),
}

#[cfg(test)]
mod tests {
use std::mem::discriminant;

use insta::assert_snapshot;

use super::*;

#[test]
fn value_impl_chain_id_discriminant_unchanged() {
assert_snapshot!(
"value_impl_chain_id_discriminant",
format!(
"{:?}",
discriminant(&ValueImpl::ChainId(
(&tendermint::chain::Id::try_from("test_prefix".to_string()).unwrap()).into()
))
)
);
}

#[test]
fn value_impl_revision_number_discriminant_unchanged() {
assert_snapshot!(
"value_impl_revision_number_discriminant",
format!("{:?}", discriminant(&ValueImpl::RevisionNumber(1.into())))
);
}

#[test]
fn value_impl_block_height_discriminant_unchanged() {
assert_snapshot!(
"value_impl_block_height_discriminant",
format!("{:?}", discriminant(&ValueImpl::BlockHeight(1.into())))
);
}

#[test]
fn value_impl_block_timestamp_discriminant_unchanged() {
assert_snapshot!(
"value_impl_block_timestamp_discriminant",
format!(
"{:?}",
discriminant(&ValueImpl::BlockTimestamp(tendermint::Time::now().into()))
)
);
}

#[test]
fn value_impl_storage_version_discriminant_unchanged() {
assert_snapshot!(
"value_impl_storage_version_discriminant",
format!("{:?}", discriminant(&ValueImpl::StorageVersion(1.into())))
);
}

#[test]
fn stored_value_app_discriminant_unchanged() {
use crate::storage::StoredValue;
assert_snapshot!(
"stored_value_app_discriminant",
format!(
"{:?}",
discriminant(&StoredValue::App(Value(ValueImpl::BlockHeight(1.into()))))
)
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
source: crates/astria-sequencer/src/app/storage/values/mod.rs
expression: "format!(\"{:?}\",\ndiscriminant(&StoredValue::App(Value(ValueImpl::BlockHeight(1.into())))))"
---
Discriminant(8)
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
source: crates/astria-sequencer/src/app/storage/values/mod.rs
expression: "format!(\"{:?}\", discriminant(&ValueImpl::BlockHeight(1.into())))"
---
Discriminant(2)
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
source: crates/astria-sequencer/src/app/storage/values/mod.rs
expression: "format!(\"{:?}\",\ndiscriminant(&ValueImpl::BlockTimestamp(tendermint::Time::now().into())))"
---
Discriminant(3)
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
source: crates/astria-sequencer/src/app/storage/values/mod.rs
expression: "format!(\"{:?}\",\ndiscriminant(&ValueImpl::ChainId((&tendermint::chain::Id::try_from(\"test_prefix\".to_string()).unwrap()).into())))"
---
Discriminant(0)
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
source: crates/astria-sequencer/src/app/storage/values/mod.rs
expression: "format!(\"{:?}\", discriminant(&ValueImpl::RevisionNumber(1.into())))"
---
Discriminant(1)
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
source: crates/astria-sequencer/src/app/storage/values/mod.rs
expression: "format!(\"{:?}\", discriminant(&ValueImpl::StorageVersion(1.into())))"
---
Discriminant(4)
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
source: crates/astria-sequencer/src/assets/storage/values.rs
expression: "format!(\"{:?}\",\ndiscriminant(&StoredValue::Assets(Value(ValueImpl::TracePrefixedDenom((&\"test_denom\".to_string().parse::<DomainTracePrefixed>().unwrap()).into())))))"
---
Discriminant(2)
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
source: crates/astria-sequencer/src/assets/storage/values.rs
expression: "format!(\"{:?}\",\ndiscriminant(&ValueImpl::TracePrefixedDenom((&\"test_denom\".to_string().parse::<DomainTracePrefixed>().unwrap()).into())))"
---
Discriminant(0)
46 changes: 46 additions & 0 deletions crates/astria-sequencer/src/assets/storage/values.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,49 @@ impl<'a> TryFrom<crate::storage::StoredValue<'a>> for TracePrefixedDenom<'a> {
Ok(denom)
}
}

#[cfg(test)]
mod tests {
use std::mem::discriminant;

use insta::assert_snapshot;

use super::*;

#[test]
fn value_impl_trace_prefixed_denom_discriminant_unchanged() {
assert_snapshot!(
"value_impl_trace_prefixed_denom_discriminant",
format!(
"{:?}",
discriminant(&ValueImpl::TracePrefixedDenom(
(&"test_denom"
.to_string()
.parse::<DomainTracePrefixed>()
.unwrap())
.into()
))
)
);
}

// Note: This test must be here instead of in `crate::storage` since `ValueImpl` is not
// re-exported.
#[test]
fn stored_value_assets_discriminant_unchanged() {
use crate::storage::StoredValue;
assert_snapshot!(
"stored_value_assets_discriminant",
format!(
"{:?}",
discriminant(&StoredValue::Assets(Value(ValueImpl::TracePrefixedDenom(
(&"test_denom"
.to_string()
.parse::<DomainTracePrefixed>()
.unwrap())
.into()
))))
)
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
source: crates/astria-sequencer/src/authority/storage/values.rs
expression: "format!(\"{:?}\",\ndiscriminant(&StoredValue::Authority(Value(ValueImpl::ValidatorSet(ValidatorSet(vec![]))))))"
---
Discriminant(4)
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
source: crates/astria-sequencer/src/authority/storage/values.rs
expression: "format!(\"{:?}\",\ndiscriminant(&ValueImpl::AddressBytes((&[0; ADDRESS_LEN]).into())))"
---
Discriminant(0)
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
source: crates/astria-sequencer/src/authority/storage/values.rs
expression: "format!(\"{:?}\", discriminant(&ValueImpl::ValidatorSet(ValidatorSet(vec![]))))"
---
Discriminant(1)
47 changes: 47 additions & 0 deletions crates/astria-sequencer/src/authority/storage/values.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,3 +153,50 @@ impl<'a> TryFrom<crate::storage::StoredValue<'a>> for ValidatorSet<'a> {
Ok(validator_set)
}
}

#[cfg(test)]
mod tests {
use std::mem::discriminant;

use insta::assert_snapshot;

use super::*;

#[test]
fn value_impl_address_bytes_discriminant_unchanged() {
assert_snapshot!(
"value_impl_address_bytes_discriminant",
format!(
"{:?}",
discriminant(&ValueImpl::AddressBytes((&[0; ADDRESS_LEN]).into()))
)
);
}

#[test]
fn value_impl_validator_set_discriminant_unchanged() {
assert_snapshot!(
"value_impl_validator_set_discriminant",
format!(
"{:?}",
discriminant(&ValueImpl::ValidatorSet(ValidatorSet(vec![])))
)
);
}

// Note: This test must be here instead of in `crate::storage` since `ValueImpl` is not
// re-exported.
#[test]
fn stored_value_authority_discriminant_unchanged() {
use crate::storage::StoredValue;
assert_snapshot!(
"stored_value_authority_discriminant",
format!(
"{:?}",
discriminant(&StoredValue::Authority(Value(ValueImpl::ValidatorSet(
ValidatorSet(vec![])
))))
)
);
}
}
Loading
Loading