Skip to content

Commit

Permalink
added fields AnnouncementSigner and CommunityRules to CommunityMetada…
Browse files Browse the repository at this point in the history
…ta (#336)

* added filed AnnouncementSigner to CommunityMetadata

* fmt

* clippy

* add CommunityRules enum to CommunityMetadata

* move outdated types to migrations file and add skeleton for v2

* implemented migration to v2

* implemented explicit migration with cropping. not yet working

* migration test passes. still need to sort out things

* clippy

* cleanup

* test migration v1 to v2 as well

* clippy

* explicit migration naming

* fix v1->v2 typing

* use upstream truncate_from instead of own

* get rid of MultiSigner in AnnouncementSigner

* explicit migration naming

* fix tests

* bump crate versions
  • Loading branch information
brenzi authored Jul 29, 2023
1 parent 14f07b2 commit c0084c2
Show file tree
Hide file tree
Showing 9 changed files with 326 additions and 97 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions ceremonies/src/migrations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ mod v0 {
pub mod v1 {
use super::*;

pub struct Migration<T>(sp_std::marker::PhantomData<T>);
pub struct MigrateToV1<T>(sp_std::marker::PhantomData<T>);

impl<T: Config + frame_system::Config> OnRuntimeUpgrade for Migration<T> {
impl<T: Config + frame_system::Config> OnRuntimeUpgrade for MigrateToV1<T> {
#[cfg(feature = "try-runtime")]
fn pre_upgrade() -> Result<Vec<u8>, &'static str> {
assert_eq!(StorageVersion::get::<Pallet<T>>(), 0, "can only upgrade from version 0");
Expand Down Expand Up @@ -123,9 +123,9 @@ mod test {
v0::AttestationRegistry::<TestRuntime>::insert((cids[1], 2), 3, attestations_2.clone());

// Migrate.
let state = v1::Migration::<TestRuntime>::pre_upgrade().unwrap();
let _weight = v1::Migration::<TestRuntime>::on_runtime_upgrade();
v1::Migration::<TestRuntime>::post_upgrade(state).unwrap();
let state = v1::MigrateToV1::<TestRuntime>::pre_upgrade().unwrap();
let _weight = v1::MigrateToV1::<TestRuntime>::on_runtime_upgrade();
v1::MigrateToV1::<TestRuntime>::post_upgrade(state).unwrap();

// Check that all values got migrated.

Expand Down Expand Up @@ -201,7 +201,7 @@ mod test {
attestations,
);
// Migrate.
let state = v1::Migration::<TestRuntime>::pre_upgrade();
let state = v1::MigrateToV1::<TestRuntime>::pre_upgrade();
assert_err!(state, "too many attestations");
});
}
Expand Down
2 changes: 1 addition & 1 deletion communities/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "pallet-encointer-communities"
version = "1.2.0"
version = "1.3.0"
authors = ["encointer.org <[email protected]>"]
edition = "2021"

Expand Down
4 changes: 3 additions & 1 deletion communities/rpc/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
// along with Encointer. If not, see <http://www.gnu.org/licenses/>.

use super::*;
use encointer_primitives::common::{FromStr, PalletString};
use sp_core::offchain::storage::InMemOffchainStorage;

#[test]
Expand All @@ -24,7 +25,8 @@ fn caching_works() {
let communities: CommunitiesRpc<_, (), _> =
CommunitiesRpc::new(Arc::new(client), storage, true);

let cid_names = vec![CidName::new(Default::default(), "hello world".into())];
let cid_names =
vec![CidName::new(Default::default(), PalletString::from_str("hello world").unwrap())];

assert!(communities.cache_dirty());
communities.set_storage(CIDS_KEY, &cid_names);
Expand Down
2 changes: 1 addition & 1 deletion communities/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ pub mod pallet {
use frame_support::pallet_prelude::*;
use frame_system::pallet_prelude::*;

const STORAGE_VERSION: StorageVersion = StorageVersion::new(1);
const STORAGE_VERSION: StorageVersion = StorageVersion::new(2);
#[pallet::pallet]
#[pallet::storage_version(STORAGE_VERSION)]
pub struct Pallet<T>(PhantomData<T>);
Expand Down
Loading

0 comments on commit c0084c2

Please sign in to comment.