Skip to content

Commit

Permalink
fix benchmark amounts (#339)
Browse files Browse the repository at this point in the history
* fix benchmakr amounts

* add missing benchmark
  • Loading branch information
brenzi authored Jul 31, 2023
1 parent 2955273 commit 8454f74
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 18 deletions.
5 changes: 5 additions & 0 deletions balances/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ benchmarks! {
let balance_bob: f64 = Pallet::<T>::balance(cid, &bob).lossy_into();
assert_abs_diff_eq!(balance_bob, 12f64, epsilon= 0.0001);
}

set_fee_conversion_factor {
let alice: T::AccountId = account("alice", 1, 1);
let f : FeeConversionFactorType = 1;
}: _(RawOrigin::Root, f)
}

impl_benchmark_test_suite!(Pallet, crate::mock::new_test_ext(), crate::mock::TestRuntime);
36 changes: 18 additions & 18 deletions faucet/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,10 @@ benchmarks! {
create_faucet {
let cid = create_community::<T>();
let zoran = account("zoran", 1, 1);
<T as pallet::Config>::Currency::make_free_balance_be(&zoran, 200_000_000u32.into());
<T as pallet::Config>::Currency::make_free_balance_be(&zoran, 200_000_000_000_000u64.saturated_into());
let faucet_name = FaucetNameType::from_str("SomeFaucetNameWith64Charsaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa").unwrap();
let amount: BalanceOf<T> = 100_000_000u32.into();
let drip_amount: BalanceOf<T> = 10_000u32.into();
let amount: BalanceOf<T> = 100_000_000_000_000u64.saturated_into();
let drip_amount: BalanceOf<T> = 10_000_000_000_000u64.saturated_into();
let whitelist = BoundedVec::try_from(vec![cid; 1024]).unwrap();
assert!(<Faucets<T>>::iter().next().is_none());
}: _(RawOrigin::Signed(zoran), faucet_name, amount, Some(whitelist), drip_amount)
Expand All @@ -79,18 +79,18 @@ benchmarks! {
let dripper = account::<T::AccountId>("dripper", 2, 2);

frame_support::storage::unhashed::put_raw(&participant_reputation((cid, cindex), &dripper), &Reputation::VerifiedUnlinked.encode());
<T as pallet::Config>::Currency::make_free_balance_be(&zoran, 200_000_000u32.into());
<T as pallet::Config>::Currency::make_free_balance_be(&zoran, 200_000_000_000_000u64.saturated_into());
let faucet_name = FaucetNameType::from_str("Some Faucet Name").unwrap();
let amount: BalanceOf<T> = 100_000_000u32.into();
let drip_amount: BalanceOf<T> = 10_000u32.into();
let amount: BalanceOf<T> = 100_000_000_000_000u64.saturated_into();
let drip_amount: BalanceOf<T> = 10_000_000_000_000u64.saturated_into();
let whitelist = BoundedVec::try_from(vec![cid; 10]).unwrap();
assert!(<Faucets<T>>::iter().next().is_none());
FaucetPallet::<T>::create_faucet(RawOrigin::Signed(zoran).into(), faucet_name, amount, Some(whitelist), drip_amount).ok();
let faucet_account = <Faucets<T>>::iter().next().unwrap().0;

}: _(RawOrigin::Signed(dripper.clone()), faucet_account, cid, cindex)
verify {
assert_eq!(<T as pallet::Config>::Currency::free_balance(&dripper), 10_000u32.into());
assert_eq!(<T as pallet::Config>::Currency::free_balance(&dripper), 10_000_000_000_000u64.saturated_into());
}

dissolve_faucet {
Expand All @@ -101,10 +101,10 @@ benchmarks! {
let beneficiary = account::<T::AccountId>("beneficiary", 3, 3);

frame_support::storage::unhashed::put_raw(&participant_reputation((cid, cindex), &dripper), &Reputation::VerifiedUnlinked.encode());
<T as pallet::Config>::Currency::make_free_balance_be(&zoran, 200_000_000u32.into());
<T as pallet::Config>::Currency::make_free_balance_be(&zoran, 200_000_000_000_000u64.saturated_into());
let faucet_name = FaucetNameType::from_str("Some Faucet Name").unwrap();
let amount: BalanceOf<T> = 100_000_000u32.into();
let drip_amount: BalanceOf<T> = 10_000u32.into();
let amount: BalanceOf<T> = 100_000_000_000_000u64.saturated_into();
let drip_amount: BalanceOf<T> = 10_000_000_000_000u64.saturated_into();
let whitelist = BoundedVec::try_from(vec![cid; 10]).unwrap();
assert!(<Faucets<T>>::iter().next().is_none());
FaucetPallet::<T>::create_faucet(RawOrigin::Signed(zoran).into(), faucet_name, amount, Some(whitelist), drip_amount).ok();
Expand All @@ -113,7 +113,7 @@ benchmarks! {

}: _(RawOrigin::Root, faucet_account, beneficiary.clone())
verify {
assert_eq!(<T as pallet::Config>::Currency::free_balance(&beneficiary), 99_990_000u32.into());
assert_eq!(<T as pallet::Config>::Currency::free_balance(&beneficiary), 90_000_000_000_000u64.saturated_into());
}


Expand All @@ -125,25 +125,25 @@ benchmarks! {
let beneficiary = account::<T::AccountId>("beneficiary", 3, 3);

frame_support::storage::unhashed::put_raw(&participant_reputation((cid, cindex), &dripper), &Reputation::VerifiedUnlinked.encode());
<T as pallet::Config>::Currency::make_free_balance_be(&zoran, 100_000_000u32.into());
<T as pallet::Config>::Currency::make_free_balance_be(&zoran, 100_000_000_000_000u64.saturated_into());
let faucet_name = FaucetNameType::from_str("Some Faucet Name").unwrap();
let amount: BalanceOf<T> = 25_000_000u32.into();
let drip_amount: BalanceOf<T> = 10_000_000u32.into();
let amount: BalanceOf<T> = 25_000_000_000_000u64.saturated_into();
let drip_amount: BalanceOf<T> = 10_000_000_000_000u64.saturated_into();
let whitelist = BoundedVec::try_from(vec![cid; 10]).unwrap();
assert!(<Faucets<T>>::iter().next().is_none());
FaucetPallet::<T>::create_faucet(RawOrigin::Signed(zoran.clone()).into(), faucet_name, amount, Some(whitelist), drip_amount).ok();
let faucet_account = <Faucets<T>>::iter().next().unwrap().0;
FaucetPallet::<T>::drip(RawOrigin::Signed(dripper.clone()).into(), faucet_account.clone(), cid, cindex).ok();
assert_eq!(<T as pallet::Config>::Currency::free_balance(&faucet_account), 15_000_000u32.into());
assert_eq!(<T as pallet::Config>::Currency::free_balance(&faucet_account), 15_000_000_000_000u64.saturated_into());
}: _(RawOrigin::Signed(zoran), faucet_account.clone())
verify {
assert_eq!(<T as pallet::Config>::Currency::free_balance(&faucet_account), 0u32.into());
assert_eq!(<T as pallet::Config>::Currency::free_balance(&faucet_account), 0u64.saturated_into());
}

set_reserve_amount {
}: _(RawOrigin::Root, 1337u32.into())
}: _(RawOrigin::Root, 1337u64.saturated_into())
verify {
assert_eq!(<ReserveAmount<T>>::get(), 1337u32.into());
assert_eq!(<ReserveAmount<T>>::get(), 1337u64.saturated_into());
}
}

Expand Down

0 comments on commit 8454f74

Please sign in to comment.