Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
weichweich committed Oct 27, 2021
1 parent d246ab6 commit 0c07692
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 7 deletions.
8 changes: 4 additions & 4 deletions pallets/crowdloan/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,15 +82,14 @@ benchmarks! {
let reserve_free: AccountIdOf<T> = account("reserve_free", 0, SEED_1);
let reserve_vested: AccountIdOf<T> = account("reserve_vested", 0, SEED_1);
RegistrarAccount::<T>::set(registrar.clone());

}: _(
RawOrigin::Signed(registrar),
T::Lookup::unlookup(reserve_vested.clone()),
T::Lookup::unlookup(reserve_free.clone())
)
verify {
assert_eq!(
crate::Reserve::<T>::get(),
Reserve::<T>::get(),
ReserveAccounts {
vested: reserve_vested,
free: reserve_free,
Expand Down Expand Up @@ -130,11 +129,12 @@ benchmarks! {
}: {
let call = <Call<T> as Decode>::decode(&mut &*call_enc)
.expect("call is encoded above, encoding must be correct");
crate::Pallet::<T>::validate_unsigned(source, &call).map_err(|e| -> &'static str { e.into() })?;
Pallet::<T>::validate_unsigned(source, &call).map_err(|e| -> &'static str { e.into() })?;
call.dispatch_bypass_filter(RawOrigin::None.into())?;
}
verify {
assert!(crate::Contributions::<T>::get(contributor).is_none());
assert!(Contributions::<T>::get(contributor.clone()).is_none());
assert_eq!(CurrencyOf::<T>::free_balance(&contributor), contribution);
}

remove_contribution {
Expand Down
2 changes: 1 addition & 1 deletion pallets/crowdloan/src/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pub struct ReserveAccounts<A: Default> {
/// The configuration of the gratitude.
#[derive(Clone, Debug, Default, Decode, Encode, PartialEq, TypeInfo)]
pub struct GratitudeConfig<BlockNumber: Default> {
/// The perquintill of vested tokens that are given.
/// The permill of vested tokens that are given.
pub vested_share: Permill,
/// The start block of the vesting.
pub start_block: BlockNumber,
Expand Down
34 changes: 32 additions & 2 deletions pallets/crowdloan/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -456,8 +456,28 @@ fn validate_unsigned_works() {
use sp_runtime::traits::ValidateUnsigned;
let source = sp_runtime::transaction_validity::TransactionSource::External;
let contributor = ACCOUNT_00;
let free_reserve = ACCOUNT_01;
let vested_reserve = ACCOUNT_02;
let contributor2 = ACCOUNT_03;

ExtBuilder::default()
.with_contributions(vec![(contributor.clone(), BALANCE_02)])
.with_contributions(vec![
(contributor.clone(), BALANCE_02),
(contributor2.clone(), BALANCE_02 + BALANCE_02),
])
.with_balances(vec![
(free_reserve.clone(), BALANCE_01),
(vested_reserve.clone(), BALANCE_01),
])
.with_reserve(ReserveAccounts {
vested: vested_reserve,
free: free_reserve,
})
.with_configuration(GratitudeConfig {
vested_share: Permill::from_percent(50),
start_block: 1,
vesting_length: 10,
})
.build()
.execute_with(|| {
assert_eq!(
Expand All @@ -483,7 +503,17 @@ fn validate_unsigned_works() {
receiver: ACCOUNT_02.clone()
}
),
Err(InvalidTransaction::BadProof.into())
Err(InvalidTransaction::Custom(crate::ValidityError::NoContributor as u8).into())
);

assert_eq!(
crate::Pallet::<Test>::validate_unsigned(
source,
&crate::Call::receive_gratitude {
receiver: contributor2
}
),
Err(InvalidTransaction::Custom(crate::ValidityError::CannotSendGratitude as u8).into())
);

assert_eq!(
Expand Down

0 comments on commit 0c07692

Please sign in to comment.