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 @@ -66,6 +66,7 @@ type RcChecks = (
pallet_rc_migrator::staking::bags_list::BagsListMigrator<Polkadot>,
pallet_rc_migrator::staking::fast_unstake::FastUnstakeMigrator<Polkadot>,
pallet_rc_migrator::conviction_voting::ConvictionVotingMigrator<Polkadot>,
pallet_rc_migrator::treasury::TreasuryMigrator<Polkadot>,
pallet_rc_migrator::asset_rate::AssetRateMigrator<Polkadot>,
// other pallets go here
ProxiesStillWork,
Expand All @@ -82,6 +83,7 @@ type AhChecks = (
pallet_rc_migrator::staking::bags_list::BagsListMigrator<AssetHub>,
pallet_rc_migrator::staking::fast_unstake::FastUnstakeMigrator<AssetHub>,
pallet_rc_migrator::conviction_voting::ConvictionVotingMigrator<AssetHub>,
pallet_rc_migrator::treasury::TreasuryMigrator<AssetHub>,
pallet_rc_migrator::asset_rate::AssetRateMigrator<AssetHub>,
// other pallets go here
ProxiesStillWork,
Expand Down
109 changes: 108 additions & 1 deletion pallets/ah-migrator/src/treasury.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@
// limitations under the License.

use crate::*;
use pallet_rc_migrator::treasury::alias as treasury_alias;
use pallet_rc_migrator::treasury::{
alias as treasury_alias, RcSpendStatus, RcSpendStatusOf, TreasuryMigrator,
};
use pallet_treasury::{ProposalIndex, SpendIndex};

impl<T: Config> Pallet<T> {
pub fn do_receive_treasury_messages(messages: Vec<RcTreasuryMessageOf<T>>) -> DispatchResult {
Expand Down Expand Up @@ -181,3 +184,107 @@ impl<T: Config> Pallet<T> {
};
}
}

#[cfg(feature = "std")]
impl<T: Config> crate::types::AhMigrationCheck for TreasuryMigrator<T> {
// (proposals ids, historical proposals count, approvals ids, spends, historical spends count)
type RcPrePayload =
(Vec<ProposalIndex>, u32, Vec<ProposalIndex>, Vec<(SpendIndex, RcSpendStatusOf<T>)>, u32);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doc comment please on what this is

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added comment in bcdbd7b

type AhPrePayload = ();

fn pre_check(_: Self::RcPrePayload) -> Self::AhPrePayload {
// Assert storage 'Treasury::ProposalCount::ah_pre::empty'
assert_eq!(
pallet_treasury::ProposalCount::<T>::get(),
0,
"ProposalCount should be 0 on Asset Hub before migration"
);

// Assert storage 'Treasury::Approvals::ah_pre::empty'
assert!(
pallet_treasury::Approvals::<T>::get().is_empty(),
"Approvals should be empty on Asset Hub before migration"
);

// Assert storage 'Treasury::Proposals::ah_pre::empty'
assert!(
pallet_treasury::Proposals::<T>::iter().next().is_none(),
"Proposals should be empty on Asset Hub before migration"
);

// Assert storage 'Treasury::SpendCount::ah_pre::empty'
assert_eq!(
treasury_alias::SpendCount::<T>::get(),
0,
"SpendCount should be 0 on Asset Hub before migration"
);

// Assert storage 'Treasury::Spends::ah_pre::empty'
assert!(
treasury_alias::Spends::<T>::iter().next().is_none(),
"Spends should be empty on Asset Hub before migration"
);
}

fn post_check(
(proposals, proposals_count, approvals, spends, spends_count): Self::RcPrePayload,
_: Self::AhPrePayload,
) {
// Assert storage 'Treasury::ProposalCount::ah_post::correct'
assert_eq!(
pallet_treasury::ProposalCount::<T>::get(),
proposals_count,
"ProposalCount on Asset Hub should match RC value"
);

// Assert storage 'Treasury::SpendCount::ah_post::correct'
assert_eq!(
treasury_alias::SpendCount::<T>::get(),
spends_count,
"SpendCount on Asset Hub should match RC value"
);

// Assert storage 'Treasury::ProposalCount::ah_post::consistent'
assert_eq!(
pallet_treasury::Proposals::<T>::iter_keys().count() as u32,
proposals.len() as u32,
"ProposalCount on Asset Hub should match RC value"
);

// Assert storage 'Treasury::Proposals::ah_post::consistent'
assert_eq!(
proposals,
pallet_treasury::Proposals::<T>::iter_keys().collect::<Vec<_>>(),
"Proposals on Asset Hub should match RC proposals"
);

// Assert storage 'Treasury::Approvals::ah_post::correct'
assert_eq!(
pallet_treasury::Approvals::<T>::get().into_inner(),
approvals,
"Approvals on Asset Hub should match RC value"
);

// Assert storage 'Treasury::SpendCount::ah_post::consistent'
assert_eq!(
treasury_alias::Spends::<T>::iter_keys().count() as u32,
spends.len() as u32,
"SpendCount on Asset Hub should match RC value"
);

// Assert storage 'Treasury::Spends::ah_post::consistent'
let mut ah_spends = Vec::new();
for (spend_id, spend) in treasury_alias::Spends::<T>::iter() {
ah_spends.push((
spend_id,
RcSpendStatus {
amount: spend.amount,
valid_from: spend.valid_from,
expire_at: spend.expire_at,
status: spend.status,
},
));
}
assert_eq!(ah_spends.len(), spends.len(), "Spends on Asset Hub should match RC values");
}
}
79 changes: 78 additions & 1 deletion pallets/rc-migrator/src/treasury.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ pub type RcTreasuryMessageOf<T> = RcTreasuryMessage<
<<T as pallet_treasury::Config>::Paymaster as Pay>::Id,
>;

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

Expand Down Expand Up @@ -230,3 +230,80 @@ pub mod alias {
pub status: pallet_treasury::PaymentState<PaymentId>,
}
}

#[derive(Clone, PartialEq, Eq, Debug)]
pub struct RcSpendStatus<AssetBalance, BlockNumber, PaymentId> {
pub amount: AssetBalance,
pub valid_from: BlockNumber,
pub expire_at: BlockNumber,
pub status: PaymentId,
}

pub type RcSpendStatusOf<T> = RcSpendStatus<
pallet_treasury::AssetBalanceOf<T, ()>,
BlockNumberFor<T>,
pallet_treasury::PaymentState<<<T as pallet_treasury::Config>::Paymaster as Pay>::Id>,
>;

#[cfg(feature = "std")]
impl<T: Config> crate::types::RcMigrationCheck for TreasuryMigrator<T> {
// (proposals ids, historicalproposals count, approvals ids, spends, historical spends count)
type RcPrePayload =
(Vec<ProposalIndex>, u32, Vec<ProposalIndex>, Vec<(SpendIndex, RcSpendStatusOf<T>)>, u32);

fn pre_check() -> Self::RcPrePayload {
// Store the counts and approvals before migration
let proposals = pallet_treasury::Proposals::<T>::iter_keys().collect::<Vec<_>>();
let proposals_count = pallet_treasury::ProposalCount::<T>::get();
let approvals = pallet_treasury::Approvals::<T>::get().into_inner();
let spends = alias::Spends::<T>::iter()
.map(|(spend_id, spend_status)| {
(
spend_id,
RcSpendStatus {
amount: spend_status.amount,
valid_from: spend_status.valid_from,
expire_at: spend_status.expire_at,
status: spend_status.status,
},
)
})
.collect::<Vec<_>>();
let spends_count = alias::SpendCount::<T>::get();
(proposals, proposals_count, approvals, spends, spends_count)
}

fn post_check(_rc_payload: Self::RcPrePayload) {
// Assert storage 'Treasury::ProposalCount::rc_post::empty'
assert_eq!(
pallet_treasury::ProposalCount::<T>::get(),
0,
"ProposalCount should be 0 on relay chain after migration"
);

// Assert storage 'Treasury::Approvals::rc_post::empty'
assert!(
pallet_treasury::Approvals::<T>::get().is_empty(),
"Approvals should be empty on relay chain after migration"
);

// Assert storage 'Treasury::Proposals::rc_post::empty'
assert!(
pallet_treasury::Proposals::<T>::iter().next().is_none(),
"Proposals should be empty on relay chain after migration"
);

// Assert storage 'Treasury::SpendCount::rc_post::empty'
assert_eq!(
alias::SpendCount::<T>::get(),
0,
"SpendCount should be 0 on relay chain after migration"
);

// Assert storage 'Treasury::Spends::rc_post::empty'
assert!(
alias::Spends::<T>::iter().next().is_none(),
"Spends should be empty on relay chain after migration"
);
}
}
Loading