Remove Purchase Pallet from Polkadot + Westend (#1636)

* Remove purchase pallet

* Update runtime/common/src/purchase.rs

Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>

* Actually check and fix compile

* Add events to dummy

* Fix kusama too

* remove events where it did not exist historically

Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>
This commit is contained in:
Shawn Tabrizi
2020-09-08 15:10:28 +02:00
committed by GitHub
parent d1b1c17285
commit 4d31f8159d
5 changed files with 101 additions and 204 deletions
+12 -2
View File
@@ -16,9 +16,11 @@
//! A dummy module for holding place of modules in a runtime.
use frame_support::{decl_module, decl_storage};
use frame_support::{decl_module, decl_storage, decl_event};
pub trait Trait<I: Instance = DefaultInstance>: frame_system::Trait { }
pub trait Trait<I: Instance = DefaultInstance>: frame_system::Trait {
type Event: Into<<Self as frame_system::Trait>::Event>;
}
decl_module! {
pub struct Module<T: Trait<I>, I: Instance = DefaultInstance> for enum Call where origin: T::Origin {
@@ -28,3 +30,11 @@ decl_module! {
decl_storage! {
trait Store for Module<T: Trait<I>, I: Instance = DefaultInstance> as Dummy { }
}
decl_event!{
pub enum Event<T, I: Instance = DefaultInstance> where
<T as frame_system::Trait>::AccountId
{
Dummy(AccountId),
}
}
+50
View File
@@ -371,6 +371,20 @@ fn account_to_bytes<AccountId>(account: &AccountId) -> Result<[u8; 32], Dispatch
Ok(bytes)
}
/// WARNING: Executing this function will clear all storage used by this pallet.
/// Be sure this is what you want...
pub fn remove_pallet<T>() -> frame_support::weights::Weight
where T: frame_system::Trait
{
use frame_support::migration::remove_storage_prefix;
remove_storage_prefix(b"Purchase", b"Accounts", b"");
remove_storage_prefix(b"Purchase", b"PaymentAccount", b"");
remove_storage_prefix(b"Purchase", b"Statement", b"");
remove_storage_prefix(b"Purchase", b"UnlockBlock", b"");
T::MaximumBlockWeight::get()
}
#[cfg(test)]
mod tests {
use super::*;
@@ -1011,4 +1025,40 @@ mod tests {
), BalancesError::<Test, _>::InsufficientBalance);
});
}
#[test]
fn remove_pallet_works() {
new_test_ext().execute_with(|| {
let account_status = AccountStatus {
validity: AccountValidity::Completed,
free_balance: 1234,
locked_balance: 4321,
signature: b"my signature".to_vec(),
vat: Permill::from_percent(50),
};
// Add some storage.
Accounts::<Test>::insert(alice(), account_status.clone());
Accounts::<Test>::insert(bob(), account_status);
PaymentAccount::<Test>::put(alice());
Statement::put(b"hello, world!".to_vec());
UnlockBlock::<Test>::put(4);
// Verify storage exists.
assert_eq!(Accounts::<Test>::iter().count(), 2);
assert!(PaymentAccount::<Test>::exists());
assert!(Statement::exists());
assert!(UnlockBlock::<Test>::exists());
// Remove storage.
remove_pallet::<Test>();
// Verify storage is gone.
assert_eq!(Accounts::<Test>::iter().count(), 0);
assert!(!PaymentAccount::<Test>::exists());
assert!(!Statement::exists());
assert!(!UnlockBlock::<Test>::exists());
});
}
}