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

Vtoken voting test #1031

Merged
merged 6 commits into from
Sep 6, 2023
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
11 changes: 8 additions & 3 deletions pallets/vtoken-voting/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ pub mod pallet {
poll_index: PollIndex,
success: bool,
},
DelegatorTokenUnlockNotified {
DelegatorVoteRemovedNotified {
vtoken: CurrencyIdOf<T>,
poll_index: PollIndex,
success: bool,
Expand Down Expand Up @@ -696,7 +696,7 @@ pub mod pallet {
},
)?;
}
Self::deposit_event(Event::<T>::DelegatorTokenUnlockNotified {
Self::deposit_event(Event::<T>::DelegatorVoteRemovedNotified {
vtoken,
poll_index,
success,
Expand Down Expand Up @@ -977,9 +977,14 @@ pub mod pallet {
Some(ReferendumInfo::Completed(moment)) => {
let locking_period =
VoteLockingPeriod::<T>::get(vtoken).ok_or(Error::<T>::NoData)?;
ensure!(
T::RelaychainBlockNumberProvider::current_block_number() >=
moment.saturating_add(locking_period),
Error::<T>::NotExpired
);
Ok(moment.saturating_add(locking_period))
},
_ => Err(Error::<T>::NotCompleted.into()),
_ => Err(Error::<T>::NotExpired.into()),
}
}

Expand Down
24 changes: 22 additions & 2 deletions pallets/vtoken-voting/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ use pallet_xcm::EnsureResponse;
use sp_core::H256;
use sp_runtime::{
testing::Header,
traits::{BlakeTwo256, ConstU32, IdentityLookup},
traits::{BlakeTwo256, BlockNumberProvider, ConstU32, IdentityLookup},
};
use xcm::{prelude::*, v3::Weight as XcmWeight};
use xcm_builder::FixedWeightBounds;
Expand Down Expand Up @@ -274,6 +274,26 @@ impl DerivativeAccountHandler<Runtime> for DerivativeAccount {
}
}

parameter_types! {
pub static RelaychainBlockNumber: BlockNumber = 1;
}

pub struct RelaychainDataProvider;

impl RelaychainDataProvider {
pub fn set_block_number(block: BlockNumber) {
RelaychainBlockNumber::set(block);
}
}

impl BlockNumberProvider for RelaychainDataProvider {
type BlockNumber = BlockNumber;

fn current_block_number() -> Self::BlockNumber {
RelaychainBlockNumber::get()
}
}

impl vtoken_voting::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type RuntimeOrigin = RuntimeOrigin;
Expand All @@ -283,7 +303,7 @@ impl vtoken_voting::Config for Runtime {
type ResponseOrigin = EnsureResponse<Everything>;
type XcmDestWeightAndFee = XcmDestWeightAndFee;
type DerivativeAccount = DerivativeAccount;
type RelaychainBlockNumberProvider = System;
type RelaychainBlockNumberProvider = RelaychainDataProvider;
type MaxVotes = ConstU32<3>;
type ParachainId = ParachainId;
type QueryTimeout = QueryTimeout;
Expand Down
Loading