Skip to content
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
2 changes: 2 additions & 0 deletions integration-tests/ahm/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ use xcm_emulator::{assert_ok, ConvertLocation, WeightMeter};

type RcChecks = (
pallet_rc_migrator::accounts::AccountsMigrator<Polkadot>,
pallet_rc_migrator::bounties::BountiesMigrator<Polkadot>,
pallet_rc_migrator::preimage::PreimageChunkMigrator<Polkadot>,
pallet_rc_migrator::preimage::PreimageRequestStatusMigrator<Polkadot>,
pallet_rc_migrator::preimage::PreimageLegacyRequestStatusMigrator<Polkadot>,
Expand All @@ -71,6 +72,7 @@ type RcChecks = (

type AhChecks = (
pallet_rc_migrator::accounts::AccountsMigrator<AssetHub>,
pallet_rc_migrator::bounties::BountiesMigrator<AssetHub>,
pallet_rc_migrator::preimage::PreimageChunkMigrator<AssetHub>,
pallet_rc_migrator::preimage::PreimageRequestStatusMigrator<AssetHub>,
pallet_rc_migrator::preimage::PreimageLegacyRequestStatusMigrator<AssetHub>,
Expand Down
85 changes: 84 additions & 1 deletion pallets/ah-migrator/src/bounties.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>.

use crate::*;
use pallet_rc_migrator::bounties::{RcBountiesMessage, RcBountiesMessageOf};
use pallet_rc_migrator::bounties::{
BountiesMigrator, RcBountiesMessage, RcBountiesMessageOf, RcPrePayload,
};

impl<T: Config> Pallet<T> {
pub fn do_receive_bounties_messages(
Expand Down Expand Up @@ -79,3 +81,84 @@ impl<T: Config> Pallet<T> {
Ok(())
}
}

#[cfg(feature = "std")]
impl<T: Config> crate::types::AhMigrationCheck for BountiesMigrator<T> {
type RcPrePayload = RcPrePayload<T>;
type AhPrePayload = ();

fn pre_check(_rc_pre_payload: Self::RcPrePayload) -> Self::AhPrePayload {
// "Assert storage 'Bounties::BountyCount::ah_pre::empty'"
assert_eq!(
pallet_bounties::BountyCount::<T>::get(),
0,
"Bounty count should be empty on asset hub before migration"
);

// "Assert storage 'Bounties::Bounties::ah_pre::empty'"
assert!(
pallet_bounties::Bounties::<T>::iter().next().is_none(),
"The Bounties map should be empty on asset hub before migration"
);

// "Assert storage 'Bounties::BountyDescriptions::ah_pre::empty'"
assert!(
pallet_bounties::BountyDescriptions::<T>::iter().next().is_none(),
"The Bounty Descriptions map should be empty on asset hub before migration"
);

// "Assert storage 'Bounties::BountyApprovals::ah_pre::empty'"
assert!(
pallet_bounties::BountyApprovals::<T>::get().is_empty(),
"The Bounty Approvals vec should be empty on asset hub before migration"
);
}

fn post_check(rc_pre_payload: Self::RcPrePayload, _ah_pre_payload: Self::AhPrePayload) {
let (rc_count, rc_bounties, rc_descriptions, rc_approvals) = rc_pre_payload;

// Assert storage 'Bounties::BountyCount::ah_post::correct'
assert_eq!(
pallet_bounties::BountyCount::<T>::get(),
rc_count,
"Bounty count on Asset Hub should match the RC value"
);

// Assert storage 'Bounties::Bounties::ah_post::length'
assert_eq!(
pallet_bounties::Bounties::<T>::iter_keys().count() as u32,
rc_bounties.len() as u32,
"Bounties map length on Asset Hub should match the RC value"
);

// Assert storage 'Bounties::Bounties::ah_post::correct'
assert_eq!(
pallet_bounties::Bounties::<T>::iter().collect::<Vec<_>>(),
rc_bounties,
"Bounties map value on Asset Hub should match the RC value"
);

// Assert storage 'Bounties::BountyDescriptions::ah_post::length'
assert_eq!(
pallet_bounties::BountyDescriptions::<T>::iter_keys().count() as u32,
rc_descriptions.len() as u32,
"Bounty description map length on Asset Hub should match RC value"
);

// Assert storage 'Bounties::BountyDescriptions::ah_post::correct'
assert_eq!(
pallet_bounties::BountyDescriptions::<T>::iter()
.map(|(key, bounded_vec)| { (key, bounded_vec.into_inner()) })
.collect::<Vec<_>>(),
rc_descriptions,
"Bounty descriptions map value on Asset Hub should match RC value"
);

// Assert storage 'Bounties::BountyApprovals::ah_post::correct'
assert_eq!(
pallet_bounties::BountyApprovals::<T>::get().into_inner(),
rc_approvals,
"Bounty approvals vec value on Asset Hub should match RC values"
);
}
}
55 changes: 54 additions & 1 deletion pallets/rc-migrator/src/bounties.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ pub enum RcBountiesMessage<AccountId, Balance, BlockNumber> {
pub type RcBountiesMessageOf<T> =
RcBountiesMessage<<T as frame_system::Config>::AccountId, BalanceOf<T>, BlockNumberFor<T>>;

pub struct BountiesMigrator<T: Config> {
pub struct BountiesMigrator<T> {
_phantom: PhantomData<T>,
}

Expand Down Expand Up @@ -157,3 +157,56 @@ impl<T: Config> PalletMigration for BountiesMigrator<T> {
}
}
}

// (BountyCount, Bounties, BountyDescriptions, BountyApprovals)
pub type RcPrePayload<T> = (
BountyIndex,
Vec<(
BountyIndex,
Bounty<<T as frame_system::Config>::AccountId, BalanceOf<T>, BlockNumberFor<T>>,
)>,
Vec<(BountyIndex, Vec<u8>)>,
Vec<BountyIndex>,
);

#[cfg(feature = "std")]
impl<T: Config> crate::types::RcMigrationCheck for BountiesMigrator<T> {
type RcPrePayload = RcPrePayload<T>;

fn pre_check() -> Self::RcPrePayload {
let count = pallet_bounties::BountyCount::<T>::get();
let bounties: Vec<_> = pallet_bounties::Bounties::<T>::iter().collect();
let descriptions: Vec<_> = pallet_bounties::BountyDescriptions::<T>::iter()
.map(|(key, bounded_vec)| (key, bounded_vec.into_inner()))
.collect();
let approvals = pallet_bounties::BountyApprovals::<T>::get().into_inner();
(count, bounties, descriptions, approvals)
}

fn post_check(_rc_pre_payload: Self::RcPrePayload) {
// Assert storage 'Bounties::BountyCount::rc_post::empty'
assert_eq!(
pallet_bounties::BountyCount::<T>::get(),
0,
"Bounty count should be 0 on RC after migration"
);

// Assert storage 'Bounties::Bounties::rc_post::empty'
assert!(
pallet_bounties::Bounties::<T>::iter().next().is_none(),
"Bounties map should be empty on RC after migration"
);

// Assert storage 'Bounties::BountyDescriptions::rc_post::empty'
assert!(
pallet_bounties::BountyDescriptions::<T>::iter().next().is_none(),
"Bount descriptions map should be empty on RC after migration"
);

// Assert storage 'Bounties::BountyApprovals::rc_post::empty'
assert!(
pallet_bounties::BountyApprovals::<T>::get().is_empty(),
"Bounty Approvals vec should be empty on RC after migration"
);
}
}
Loading