Skip to content

Commit

Permalink
Vtoken voting test (#1031)
Browse files Browse the repository at this point in the history
* More tests

* More tests

* Rename `DelegatorTokenUnlockNotified` to `DelegatorVoteRemovedNotified`

* Fix

* More tests

* More tests
  • Loading branch information
ark930 authored Sep 6, 2023
1 parent 6721059 commit 73af1b5
Show file tree
Hide file tree
Showing 3 changed files with 404 additions and 14 deletions.
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

0 comments on commit 73af1b5

Please sign in to comment.