mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-31 16:51:02 +00:00
Run cargo fmt on the whole code base (#9394)
* Run cargo fmt on the whole code base * Second run * Add CI check * Fix compilation * More unnecessary braces * Handle weights * Use --all * Use correct attributes... * Fix UI tests * AHHHHHHHHH * 🤦 * Docs * Fix compilation * 🤷 * Please stop * 🤦 x 2 * More * make rustfmt.toml consistent with polkadot Co-authored-by: André Silva <andrerfosilva@gmail.com>
This commit is contained in:
@@ -19,17 +19,21 @@
|
||||
|
||||
#![cfg(feature = "runtime-benchmarks")]
|
||||
|
||||
use sp_std::prelude::*;
|
||||
use super::*;
|
||||
use sp_runtime::traits::{Zero, Bounded};
|
||||
use sp_arithmetic::Perquintill;
|
||||
use frame_benchmarking::{benchmarks, impl_benchmark_test_suite, whitelisted_caller};
|
||||
use frame_support::{
|
||||
dispatch::UnfilteredDispatchable,
|
||||
traits::{Currency, EnsureOrigin, Get},
|
||||
};
|
||||
use frame_system::RawOrigin;
|
||||
use frame_benchmarking::{benchmarks, whitelisted_caller, impl_benchmark_test_suite};
|
||||
use frame_support::{traits::{Currency, Get, EnsureOrigin}, dispatch::UnfilteredDispatchable};
|
||||
use sp_arithmetic::Perquintill;
|
||||
use sp_runtime::traits::{Bounded, Zero};
|
||||
use sp_std::prelude::*;
|
||||
|
||||
use crate::Pallet as Gilt;
|
||||
|
||||
type BalanceOf<T> = <<T as Config>::Currency as Currency<<T as frame_system::Config>::AccountId>>::Balance;
|
||||
type BalanceOf<T> =
|
||||
<<T as Config>::Currency as Currency<<T as frame_system::Config>::AccountId>>::Balance;
|
||||
|
||||
benchmarks! {
|
||||
place_bid {
|
||||
@@ -129,8 +133,4 @@ benchmarks! {
|
||||
}: { Gilt::<T>::pursue_target(q) }
|
||||
}
|
||||
|
||||
impl_benchmark_test_suite!(
|
||||
Gilt,
|
||||
crate::mock::new_test_ext(),
|
||||
crate::mock::Test,
|
||||
);
|
||||
impl_benchmark_test_suite!(Gilt, crate::mock::new_test_ext(), crate::mock::Test,);
|
||||
|
||||
@@ -67,28 +67,33 @@
|
||||
|
||||
pub use pallet::*;
|
||||
|
||||
mod benchmarking;
|
||||
#[cfg(test)]
|
||||
mod mock;
|
||||
#[cfg(test)]
|
||||
mod tests;
|
||||
mod benchmarking;
|
||||
pub mod weights;
|
||||
|
||||
#[frame_support::pallet]
|
||||
pub mod pallet {
|
||||
use sp_std::prelude::*;
|
||||
use sp_arithmetic::{Perquintill, PerThing};
|
||||
use sp_runtime::traits::{Zero, Saturating};
|
||||
use frame_support::traits::{Currency, OnUnbalanced, ReservableCurrency};
|
||||
use frame_support::pallet_prelude::*;
|
||||
use frame_system::pallet_prelude::*;
|
||||
pub use crate::weights::WeightInfo;
|
||||
use frame_support::{
|
||||
pallet_prelude::*,
|
||||
traits::{Currency, OnUnbalanced, ReservableCurrency},
|
||||
};
|
||||
use frame_system::pallet_prelude::*;
|
||||
use sp_arithmetic::{PerThing, Perquintill};
|
||||
use sp_runtime::traits::{Saturating, Zero};
|
||||
use sp_std::prelude::*;
|
||||
|
||||
type BalanceOf<T> = <<T as Config>::Currency as Currency<<T as frame_system::Config>::AccountId>>::Balance;
|
||||
type PositiveImbalanceOf<T> =
|
||||
<<T as Config>::Currency as Currency<<T as frame_system::Config>::AccountId>>::PositiveImbalance;
|
||||
type NegativeImbalanceOf<T> =
|
||||
<<T as Config>::Currency as Currency<<T as frame_system::Config>::AccountId>>::NegativeImbalance;
|
||||
type BalanceOf<T> =
|
||||
<<T as Config>::Currency as Currency<<T as frame_system::Config>::AccountId>>::Balance;
|
||||
type PositiveImbalanceOf<T> = <<T as Config>::Currency as Currency<
|
||||
<T as frame_system::Config>::AccountId,
|
||||
>>::PositiveImbalance;
|
||||
type NegativeImbalanceOf<T> = <<T as Config>::Currency as Currency<
|
||||
<T as frame_system::Config>::AccountId,
|
||||
>>::NegativeImbalance;
|
||||
|
||||
#[pallet::config]
|
||||
pub trait Config: frame_system::Config {
|
||||
@@ -96,13 +101,17 @@ pub mod pallet {
|
||||
type Event: From<Event<Self>> + IsType<<Self as frame_system::Config>::Event>;
|
||||
|
||||
/// Currency type that this works on.
|
||||
type Currency: ReservableCurrency<Self::AccountId, Balance=Self::CurrencyBalance>;
|
||||
type Currency: ReservableCurrency<Self::AccountId, Balance = Self::CurrencyBalance>;
|
||||
|
||||
/// Just the `Currency::Balance` type; we have this item to allow us to constrain it to
|
||||
/// `From<u64>`.
|
||||
type CurrencyBalance:
|
||||
sp_runtime::traits::AtLeast32BitUnsigned + codec::FullCodec + Copy
|
||||
+ MaybeSerializeDeserialize + sp_std::fmt::Debug + Default + From<u64>;
|
||||
type CurrencyBalance: sp_runtime::traits::AtLeast32BitUnsigned
|
||||
+ codec::FullCodec
|
||||
+ Copy
|
||||
+ MaybeSerializeDeserialize
|
||||
+ sp_std::fmt::Debug
|
||||
+ Default
|
||||
+ From<u64>;
|
||||
|
||||
/// Origin required for setting the target proportion to be under gilt.
|
||||
type AdminOrigin: EnsureOrigin<Self::Origin>;
|
||||
@@ -227,13 +236,8 @@ pub mod pallet {
|
||||
|
||||
/// The queues of bids ready to become gilts. Indexed by duration (in `Period`s).
|
||||
#[pallet::storage]
|
||||
pub type Queues<T: Config> = StorageMap<
|
||||
_,
|
||||
Blake2_128Concat,
|
||||
u32,
|
||||
Vec<GiltBid<BalanceOf<T>, T::AccountId>>,
|
||||
ValueQuery,
|
||||
>;
|
||||
pub type Queues<T: Config> =
|
||||
StorageMap<_, Blake2_128Concat, u32, Vec<GiltBid<BalanceOf<T>, T::AccountId>>, ValueQuery>;
|
||||
|
||||
/// Information relating to the gilts currently active.
|
||||
#[pallet::storage]
|
||||
@@ -245,7 +249,11 @@ pub mod pallet {
|
||||
_,
|
||||
Blake2_128Concat,
|
||||
ActiveIndex,
|
||||
ActiveGilt<BalanceOf<T>, <T as frame_system::Config>::AccountId, <T as frame_system::Config>::BlockNumber>,
|
||||
ActiveGilt<
|
||||
BalanceOf<T>,
|
||||
<T as frame_system::Config>::AccountId,
|
||||
<T as frame_system::Config>::BlockNumber,
|
||||
>,
|
||||
OptionQuery,
|
||||
>;
|
||||
|
||||
@@ -255,7 +263,7 @@ pub mod pallet {
|
||||
|
||||
#[pallet::genesis_build]
|
||||
impl<T: Config> GenesisBuild<T> for GenesisConfig {
|
||||
fn build(&self) {
|
||||
fn build(&self) {
|
||||
QueueTotals::<T>::put(vec![(0, BalanceOf::<T>::zero()); T::QueueCount::get() as usize]);
|
||||
}
|
||||
}
|
||||
@@ -311,7 +319,7 @@ pub mod pallet {
|
||||
}
|
||||
|
||||
#[pallet::call]
|
||||
impl<T:Config> Pallet<T> {
|
||||
impl<T: Config> Pallet<T> {
|
||||
/// Place a bid for a gilt to be issued.
|
||||
///
|
||||
/// Origin must be Signed, and account must have at least `amount` in free balance.
|
||||
@@ -335,35 +343,35 @@ pub mod pallet {
|
||||
|
||||
ensure!(amount >= T::MinFreeze::get(), Error::<T>::AmountTooSmall);
|
||||
let queue_count = T::QueueCount::get() as usize;
|
||||
let queue_index = duration.checked_sub(1)
|
||||
.ok_or(Error::<T>::DurationTooSmall)? as usize;
|
||||
let queue_index = duration.checked_sub(1).ok_or(Error::<T>::DurationTooSmall)? as usize;
|
||||
ensure!(queue_index < queue_count, Error::<T>::DurationTooBig);
|
||||
|
||||
let net = Queues::<T>::try_mutate(duration, |q|
|
||||
-> Result<(u32, BalanceOf::<T>), DispatchError>
|
||||
{
|
||||
let queue_full = q.len() == T::MaxQueueLen::get() as usize;
|
||||
ensure!(!queue_full || q[0].amount < amount, Error::<T>::BidTooLow);
|
||||
T::Currency::reserve(&who, amount)?;
|
||||
let net = Queues::<T>::try_mutate(
|
||||
duration,
|
||||
|q| -> Result<(u32, BalanceOf<T>), DispatchError> {
|
||||
let queue_full = q.len() == T::MaxQueueLen::get() as usize;
|
||||
ensure!(!queue_full || q[0].amount < amount, Error::<T>::BidTooLow);
|
||||
T::Currency::reserve(&who, amount)?;
|
||||
|
||||
// queue is <Ordered: Lowest ... Highest><Fifo: Last ... First>
|
||||
let mut bid = GiltBid { amount, who: who.clone() };
|
||||
let net = if queue_full {
|
||||
sp_std::mem::swap(&mut q[0], &mut bid);
|
||||
T::Currency::unreserve(&bid.who, bid.amount);
|
||||
(0, amount - bid.amount)
|
||||
} else {
|
||||
q.insert(0, bid);
|
||||
(1, amount)
|
||||
};
|
||||
// queue is <Ordered: Lowest ... Highest><Fifo: Last ... First>
|
||||
let mut bid = GiltBid { amount, who: who.clone() };
|
||||
let net = if queue_full {
|
||||
sp_std::mem::swap(&mut q[0], &mut bid);
|
||||
T::Currency::unreserve(&bid.who, bid.amount);
|
||||
(0, amount - bid.amount)
|
||||
} else {
|
||||
q.insert(0, bid);
|
||||
(1, amount)
|
||||
};
|
||||
|
||||
let sorted_item_count = q.len().saturating_sub(T::FifoQueueLen::get() as usize);
|
||||
if sorted_item_count > 1 {
|
||||
q[0..sorted_item_count].sort_by_key(|x| x.amount);
|
||||
}
|
||||
let sorted_item_count = q.len().saturating_sub(T::FifoQueueLen::get() as usize);
|
||||
if sorted_item_count > 1 {
|
||||
q[0..sorted_item_count].sort_by_key(|x| x.amount);
|
||||
}
|
||||
|
||||
Ok(net)
|
||||
})?;
|
||||
Ok(net)
|
||||
},
|
||||
)?;
|
||||
QueueTotals::<T>::mutate(|qs| {
|
||||
qs.resize(queue_count, (0, Zero::zero()));
|
||||
qs[queue_index].0 += net.0;
|
||||
@@ -390,8 +398,7 @@ pub mod pallet {
|
||||
let who = ensure_signed(origin)?;
|
||||
|
||||
let queue_count = T::QueueCount::get() as usize;
|
||||
let queue_index = duration.checked_sub(1)
|
||||
.ok_or(Error::<T>::DurationTooSmall)? as usize;
|
||||
let queue_index = duration.checked_sub(1).ok_or(Error::<T>::DurationTooSmall)? as usize;
|
||||
ensure!(queue_index < queue_count, Error::<T>::DurationTooBig);
|
||||
|
||||
let bid = GiltBid { amount, who };
|
||||
@@ -453,11 +460,12 @@ pub mod pallet {
|
||||
Active::<T>::remove(index);
|
||||
|
||||
// Multiply the proportion it is by the total issued.
|
||||
let total_issuance = T::Currency::total_issuance().saturating_sub(T::IgnoredIssuance::get());
|
||||
let total_issuance =
|
||||
T::Currency::total_issuance().saturating_sub(T::IgnoredIssuance::get());
|
||||
ActiveTotal::<T>::mutate(|totals| {
|
||||
let nongilt_issuance = total_issuance.saturating_sub(totals.frozen);
|
||||
let effective_issuance = totals.proportion.left_from_one()
|
||||
.saturating_reciprocal_mul(nongilt_issuance);
|
||||
let effective_issuance =
|
||||
totals.proportion.left_from_one().saturating_reciprocal_mul(nongilt_issuance);
|
||||
let gilt_value = gilt.proportion * effective_issuance;
|
||||
|
||||
totals.frozen = totals.frozen.saturating_sub(gilt.amount);
|
||||
@@ -518,14 +526,9 @@ pub mod pallet {
|
||||
|
||||
let total_issuance = T::Currency::total_issuance();
|
||||
let non_gilt = total_issuance.saturating_sub(totals.frozen);
|
||||
let effective = totals.proportion.left_from_one()
|
||||
.saturating_reciprocal_mul(non_gilt);
|
||||
let effective = totals.proportion.left_from_one().saturating_reciprocal_mul(non_gilt);
|
||||
|
||||
IssuanceInfo {
|
||||
reserved: totals.frozen,
|
||||
non_gilt,
|
||||
effective,
|
||||
}
|
||||
IssuanceInfo { reserved: totals.frozen, non_gilt, effective }
|
||||
}
|
||||
|
||||
/// Attempt to enlarge our gilt-set from bids in order to satisfy our desired target amount
|
||||
@@ -535,16 +538,17 @@ pub mod pallet {
|
||||
if totals.proportion < totals.target {
|
||||
let missing = totals.target.saturating_sub(totals.proportion);
|
||||
|
||||
let total_issuance = T::Currency::total_issuance().saturating_sub(T::IgnoredIssuance::get());
|
||||
let total_issuance =
|
||||
T::Currency::total_issuance().saturating_sub(T::IgnoredIssuance::get());
|
||||
let nongilt_issuance = total_issuance.saturating_sub(totals.frozen);
|
||||
let effective_issuance = totals.proportion.left_from_one()
|
||||
.saturating_reciprocal_mul(nongilt_issuance);
|
||||
let effective_issuance =
|
||||
totals.proportion.left_from_one().saturating_reciprocal_mul(nongilt_issuance);
|
||||
let intake = missing * effective_issuance;
|
||||
|
||||
let (bids_taken, queues_hit) = Self::enlarge(intake, max_bids);
|
||||
let first_from_each_queue = T::WeightInfo::pursue_target_per_queue(queues_hit);
|
||||
let rest_from_each_queue = T::WeightInfo::pursue_target_per_item(bids_taken)
|
||||
.saturating_sub(T::WeightInfo::pursue_target_per_item(queues_hit));
|
||||
.saturating_sub(T::WeightInfo::pursue_target_per_item(queues_hit));
|
||||
first_from_each_queue + rest_from_each_queue
|
||||
} else {
|
||||
T::WeightInfo::pursue_target_noop()
|
||||
@@ -555,11 +559,9 @@ pub mod pallet {
|
||||
/// from the queue.
|
||||
///
|
||||
/// Return the number of bids taken and the number of distinct queues taken from.
|
||||
pub fn enlarge(
|
||||
amount: BalanceOf<T>,
|
||||
max_bids: u32,
|
||||
) -> (u32, u32) {
|
||||
let total_issuance = T::Currency::total_issuance().saturating_sub(T::IgnoredIssuance::get());
|
||||
pub fn enlarge(amount: BalanceOf<T>, max_bids: u32) -> (u32, u32) {
|
||||
let total_issuance =
|
||||
T::Currency::total_issuance().saturating_sub(T::IgnoredIssuance::get());
|
||||
let mut remaining = amount;
|
||||
let mut bids_taken = 0;
|
||||
let mut queues_hit = 0;
|
||||
@@ -572,7 +574,8 @@ pub mod pallet {
|
||||
continue
|
||||
}
|
||||
let queue_index = duration as usize - 1;
|
||||
let expiry = now.saturating_add(T::Period::get().saturating_mul(duration.into()));
|
||||
let expiry =
|
||||
now.saturating_add(T::Period::get().saturating_mul(duration.into()));
|
||||
Queues::<T>::mutate(duration, |q| {
|
||||
while let Some(mut bid) = q.pop() {
|
||||
if remaining < bid.amount {
|
||||
@@ -589,7 +592,9 @@ pub mod pallet {
|
||||
|
||||
// Now to activate the bid...
|
||||
let nongilt_issuance = total_issuance.saturating_sub(totals.frozen);
|
||||
let effective_issuance = totals.proportion.left_from_one()
|
||||
let effective_issuance = totals
|
||||
.proportion
|
||||
.left_from_one()
|
||||
.saturating_reciprocal_mul(nongilt_issuance);
|
||||
let n = amount;
|
||||
let d = effective_issuance;
|
||||
@@ -607,7 +612,7 @@ pub mod pallet {
|
||||
bids_taken += 1;
|
||||
|
||||
if remaining.is_zero() || bids_taken == max_bids {
|
||||
break;
|
||||
break
|
||||
}
|
||||
}
|
||||
queues_hit += 1;
|
||||
|
||||
@@ -20,11 +20,14 @@
|
||||
use crate as pallet_gilt;
|
||||
|
||||
use frame_support::{
|
||||
parameter_types, ord_parameter_types,
|
||||
traits::{OnInitialize, OnFinalize, GenesisBuild, Currency},
|
||||
ord_parameter_types, parameter_types,
|
||||
traits::{Currency, GenesisBuild, OnFinalize, OnInitialize},
|
||||
};
|
||||
use sp_core::H256;
|
||||
use sp_runtime::{traits::{BlakeTwo256, IdentityLookup}, testing::Header};
|
||||
use sp_runtime::{
|
||||
testing::Header,
|
||||
traits::{BlakeTwo256, IdentityLookup},
|
||||
};
|
||||
|
||||
type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;
|
||||
type Block = frame_system::mocking::MockBlock<Test>;
|
||||
@@ -125,9 +128,11 @@ impl pallet_gilt::Config for Test {
|
||||
// our desired mockup.
|
||||
pub fn new_test_ext() -> sp_io::TestExternalities {
|
||||
let mut t = frame_system::GenesisConfig::default().build_storage::<Test>().unwrap();
|
||||
pallet_balances::GenesisConfig::<Test>{
|
||||
pallet_balances::GenesisConfig::<Test> {
|
||||
balances: vec![(1, 100), (2, 100), (3, 100), (4, 100)],
|
||||
}.assimilate_storage(&mut t).unwrap();
|
||||
}
|
||||
.assimilate_storage(&mut t)
|
||||
.unwrap();
|
||||
GenesisBuild::<Test>::assimilate_storage(&crate::GenesisConfig, &mut t).unwrap();
|
||||
t.into()
|
||||
}
|
||||
|
||||
+209
-165
@@ -18,10 +18,10 @@
|
||||
//! Tests for Gilt pallet.
|
||||
|
||||
use super::*;
|
||||
use crate::{Error, mock::*};
|
||||
use frame_support::{assert_ok, assert_noop, dispatch::DispatchError, traits::Currency};
|
||||
use sp_arithmetic::Perquintill;
|
||||
use crate::{mock::*, Error};
|
||||
use frame_support::{assert_noop, assert_ok, dispatch::DispatchError, traits::Currency};
|
||||
use pallet_balances::Error as BalancesError;
|
||||
use sp_arithmetic::Perquintill;
|
||||
|
||||
#[test]
|
||||
fn basic_setup_works() {
|
||||
@@ -31,12 +31,15 @@ fn basic_setup_works() {
|
||||
for q in 0..3 {
|
||||
assert!(Queues::<Test>::get(q).is_empty());
|
||||
}
|
||||
assert_eq!(ActiveTotal::<Test>::get(), ActiveGiltsTotal {
|
||||
frozen: 0,
|
||||
proportion: Perquintill::zero(),
|
||||
index: 0,
|
||||
target: Perquintill::zero(),
|
||||
});
|
||||
assert_eq!(
|
||||
ActiveTotal::<Test>::get(),
|
||||
ActiveGiltsTotal {
|
||||
frozen: 0,
|
||||
proportion: Perquintill::zero(),
|
||||
index: 0,
|
||||
target: Perquintill::zero(),
|
||||
}
|
||||
);
|
||||
assert_eq!(QueueTotals::<Test>::get(), vec![(0, 0); 3]);
|
||||
});
|
||||
}
|
||||
@@ -49,12 +52,15 @@ fn set_target_works() {
|
||||
assert_noop!(Gilt::set_target(Origin::signed(2), Perquintill::from_percent(50)), e);
|
||||
assert_ok!(Gilt::set_target(Origin::signed(1), Perquintill::from_percent(50)));
|
||||
|
||||
assert_eq!(ActiveTotal::<Test>::get(), ActiveGiltsTotal {
|
||||
frozen: 0,
|
||||
proportion: Perquintill::zero(),
|
||||
index: 0,
|
||||
target: Perquintill::from_percent(50),
|
||||
});
|
||||
assert_eq!(
|
||||
ActiveTotal::<Test>::get(),
|
||||
ActiveGiltsTotal {
|
||||
frozen: 0,
|
||||
proportion: Perquintill::zero(),
|
||||
index: 0,
|
||||
target: Perquintill::from_percent(50),
|
||||
}
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -63,7 +69,10 @@ fn place_bid_works() {
|
||||
new_test_ext().execute_with(|| {
|
||||
run_to_block(1);
|
||||
assert_noop!(Gilt::place_bid(Origin::signed(1), 1, 2), Error::<Test>::AmountTooSmall);
|
||||
assert_noop!(Gilt::place_bid(Origin::signed(1), 101, 2), BalancesError::<Test>::InsufficientBalance);
|
||||
assert_noop!(
|
||||
Gilt::place_bid(Origin::signed(1), 101, 2),
|
||||
BalancesError::<Test>::InsufficientBalance
|
||||
);
|
||||
assert_noop!(Gilt::place_bid(Origin::signed(1), 10, 4), Error::<Test>::DurationTooBig);
|
||||
assert_ok!(Gilt::place_bid(Origin::signed(1), 10, 2));
|
||||
assert_eq!(Balances::reserved_balance(1), 10);
|
||||
@@ -86,11 +95,14 @@ fn place_bid_queuing_works() {
|
||||
assert_ok!(Gilt::place_bid(Origin::signed(1), 25, 2));
|
||||
assert_eq!(Balances::reserved_balance(1), 60);
|
||||
assert_noop!(Gilt::place_bid(Origin::signed(1), 10, 2), Error::<Test>::BidTooLow);
|
||||
assert_eq!(Queues::<Test>::get(2), vec![
|
||||
GiltBid { amount: 15, who: 1 },
|
||||
GiltBid { amount: 25, who: 1 },
|
||||
GiltBid { amount: 20, who: 1 },
|
||||
]);
|
||||
assert_eq!(
|
||||
Queues::<Test>::get(2),
|
||||
vec![
|
||||
GiltBid { amount: 15, who: 1 },
|
||||
GiltBid { amount: 25, who: 1 },
|
||||
GiltBid { amount: 20, who: 1 },
|
||||
]
|
||||
);
|
||||
assert_eq!(QueueTotals::<Test>::get(), vec![(0, 0), (3, 60), (0, 0)]);
|
||||
});
|
||||
}
|
||||
@@ -119,17 +131,16 @@ fn multiple_place_bids_works() {
|
||||
|
||||
assert_eq!(Balances::reserved_balance(1), 40);
|
||||
assert_eq!(Balances::reserved_balance(2), 10);
|
||||
assert_eq!(Queues::<Test>::get(1), vec![
|
||||
GiltBid { amount: 10, who: 1 },
|
||||
]);
|
||||
assert_eq!(Queues::<Test>::get(2), vec![
|
||||
GiltBid { amount: 10, who: 2 },
|
||||
GiltBid { amount: 10, who: 1 },
|
||||
GiltBid { amount: 10, who: 1 },
|
||||
]);
|
||||
assert_eq!(Queues::<Test>::get(3), vec![
|
||||
GiltBid { amount: 10, who: 1 },
|
||||
]);
|
||||
assert_eq!(Queues::<Test>::get(1), vec![GiltBid { amount: 10, who: 1 },]);
|
||||
assert_eq!(
|
||||
Queues::<Test>::get(2),
|
||||
vec![
|
||||
GiltBid { amount: 10, who: 2 },
|
||||
GiltBid { amount: 10, who: 1 },
|
||||
GiltBid { amount: 10, who: 1 },
|
||||
]
|
||||
);
|
||||
assert_eq!(Queues::<Test>::get(3), vec![GiltBid { amount: 10, who: 1 },]);
|
||||
assert_eq!(QueueTotals::<Test>::get(), vec![(1, 10), (3, 30), (1, 10)]);
|
||||
});
|
||||
}
|
||||
@@ -144,7 +155,7 @@ fn retract_single_item_queue_works() {
|
||||
|
||||
assert_eq!(Balances::reserved_balance(1), 10);
|
||||
assert_eq!(Queues::<Test>::get(1), vec![]);
|
||||
assert_eq!(Queues::<Test>::get(2), vec![ GiltBid { amount: 10, who: 1 } ]);
|
||||
assert_eq!(Queues::<Test>::get(2), vec![GiltBid { amount: 10, who: 1 }]);
|
||||
assert_eq!(QueueTotals::<Test>::get(), vec![(0, 0), (1, 10), (0, 0)]);
|
||||
});
|
||||
}
|
||||
@@ -161,13 +172,11 @@ fn retract_with_other_and_duplicate_works() {
|
||||
assert_ok!(Gilt::retract_bid(Origin::signed(1), 10, 2));
|
||||
assert_eq!(Balances::reserved_balance(1), 20);
|
||||
assert_eq!(Balances::reserved_balance(2), 10);
|
||||
assert_eq!(Queues::<Test>::get(1), vec![
|
||||
GiltBid { amount: 10, who: 1 },
|
||||
]);
|
||||
assert_eq!(Queues::<Test>::get(2), vec![
|
||||
GiltBid { amount: 10, who: 2 },
|
||||
GiltBid { amount: 10, who: 1 },
|
||||
]);
|
||||
assert_eq!(Queues::<Test>::get(1), vec![GiltBid { amount: 10, who: 1 },]);
|
||||
assert_eq!(
|
||||
Queues::<Test>::get(2),
|
||||
vec![GiltBid { amount: 10, who: 2 }, GiltBid { amount: 10, who: 1 },]
|
||||
);
|
||||
assert_eq!(QueueTotals::<Test>::get(), vec![(1, 10), (2, 20), (0, 0)]);
|
||||
});
|
||||
}
|
||||
@@ -195,22 +204,23 @@ fn basic_enlarge_works() {
|
||||
// Takes 2/2, then stopped because it reaches its max amount
|
||||
assert_eq!(Balances::reserved_balance(1), 40);
|
||||
assert_eq!(Balances::reserved_balance(2), 40);
|
||||
assert_eq!(Queues::<Test>::get(1), vec![ GiltBid { amount: 40, who: 1 } ]);
|
||||
assert_eq!(Queues::<Test>::get(1), vec![GiltBid { amount: 40, who: 1 }]);
|
||||
assert_eq!(Queues::<Test>::get(2), vec![]);
|
||||
assert_eq!(QueueTotals::<Test>::get(), vec![(1, 40), (0, 0), (0, 0)]);
|
||||
|
||||
assert_eq!(ActiveTotal::<Test>::get(), ActiveGiltsTotal {
|
||||
frozen: 40,
|
||||
proportion: Perquintill::from_percent(10),
|
||||
index: 1,
|
||||
target: Perquintill::zero(),
|
||||
});
|
||||
assert_eq!(Active::<Test>::get(0).unwrap(), ActiveGilt {
|
||||
proportion: Perquintill::from_percent(10),
|
||||
amount: 40,
|
||||
who: 2,
|
||||
expiry: 7,
|
||||
});
|
||||
assert_eq!(
|
||||
ActiveTotal::<Test>::get(),
|
||||
ActiveGiltsTotal {
|
||||
frozen: 40,
|
||||
proportion: Perquintill::from_percent(10),
|
||||
index: 1,
|
||||
target: Perquintill::zero(),
|
||||
}
|
||||
);
|
||||
assert_eq!(
|
||||
Active::<Test>::get(0).unwrap(),
|
||||
ActiveGilt { proportion: Perquintill::from_percent(10), amount: 40, who: 2, expiry: 7 }
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -225,29 +235,33 @@ fn enlarge_respects_bids_limit() {
|
||||
Gilt::enlarge(100, 2);
|
||||
|
||||
// Should have taken 4/3 and 2/2, then stopped because it's only allowed 2.
|
||||
assert_eq!(Queues::<Test>::get(1), vec![ GiltBid { amount: 40, who: 1 } ]);
|
||||
assert_eq!(Queues::<Test>::get(2), vec![ GiltBid { amount: 40, who: 3 } ]);
|
||||
assert_eq!(Queues::<Test>::get(1), vec![GiltBid { amount: 40, who: 1 }]);
|
||||
assert_eq!(Queues::<Test>::get(2), vec![GiltBid { amount: 40, who: 3 }]);
|
||||
assert_eq!(Queues::<Test>::get(3), vec![]);
|
||||
assert_eq!(QueueTotals::<Test>::get(), vec![(1, 40), (1, 40), (0, 0)]);
|
||||
|
||||
assert_eq!(Active::<Test>::get(0).unwrap(), ActiveGilt {
|
||||
proportion: Perquintill::from_percent(10),
|
||||
amount: 40,
|
||||
who: 4,
|
||||
expiry: 10,
|
||||
});
|
||||
assert_eq!(Active::<Test>::get(1).unwrap(), ActiveGilt {
|
||||
proportion: Perquintill::from_percent(10),
|
||||
amount: 40,
|
||||
who: 2,
|
||||
expiry: 7,
|
||||
});
|
||||
assert_eq!(ActiveTotal::<Test>::get(), ActiveGiltsTotal {
|
||||
frozen: 80,
|
||||
proportion: Perquintill::from_percent(20),
|
||||
index: 2,
|
||||
target: Perquintill::zero(),
|
||||
});
|
||||
assert_eq!(
|
||||
Active::<Test>::get(0).unwrap(),
|
||||
ActiveGilt {
|
||||
proportion: Perquintill::from_percent(10),
|
||||
amount: 40,
|
||||
who: 4,
|
||||
expiry: 10,
|
||||
}
|
||||
);
|
||||
assert_eq!(
|
||||
Active::<Test>::get(1).unwrap(),
|
||||
ActiveGilt { proportion: Perquintill::from_percent(10), amount: 40, who: 2, expiry: 7 }
|
||||
);
|
||||
assert_eq!(
|
||||
ActiveTotal::<Test>::get(),
|
||||
ActiveGiltsTotal {
|
||||
frozen: 80,
|
||||
proportion: Perquintill::from_percent(20),
|
||||
index: 2,
|
||||
target: Perquintill::zero(),
|
||||
}
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -259,21 +273,22 @@ fn enlarge_respects_amount_limit_and_will_split() {
|
||||
Gilt::enlarge(40, 2);
|
||||
|
||||
// Takes 2/2, then stopped because it reaches its max amount
|
||||
assert_eq!(Queues::<Test>::get(1), vec![ GiltBid { amount: 40, who: 1 } ]);
|
||||
assert_eq!(Queues::<Test>::get(1), vec![GiltBid { amount: 40, who: 1 }]);
|
||||
assert_eq!(QueueTotals::<Test>::get(), vec![(1, 40), (0, 0), (0, 0)]);
|
||||
|
||||
assert_eq!(Active::<Test>::get(0).unwrap(), ActiveGilt {
|
||||
proportion: Perquintill::from_percent(10),
|
||||
amount: 40,
|
||||
who: 1,
|
||||
expiry: 4,
|
||||
});
|
||||
assert_eq!(ActiveTotal::<Test>::get(), ActiveGiltsTotal {
|
||||
frozen: 40,
|
||||
proportion: Perquintill::from_percent(10),
|
||||
index: 1,
|
||||
target: Perquintill::zero(),
|
||||
});
|
||||
assert_eq!(
|
||||
Active::<Test>::get(0).unwrap(),
|
||||
ActiveGilt { proportion: Perquintill::from_percent(10), amount: 40, who: 1, expiry: 4 }
|
||||
);
|
||||
assert_eq!(
|
||||
ActiveTotal::<Test>::get(),
|
||||
ActiveGiltsTotal {
|
||||
frozen: 40,
|
||||
proportion: Perquintill::from_percent(10),
|
||||
index: 1,
|
||||
target: Perquintill::zero(),
|
||||
}
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -290,12 +305,15 @@ fn basic_thaw_works() {
|
||||
assert_noop!(Gilt::thaw(Origin::signed(2), 0), Error::<Test>::NotOwner);
|
||||
assert_ok!(Gilt::thaw(Origin::signed(1), 0));
|
||||
|
||||
assert_eq!(ActiveTotal::<Test>::get(), ActiveGiltsTotal {
|
||||
frozen: 0,
|
||||
proportion: Perquintill::zero(),
|
||||
index: 1,
|
||||
target: Perquintill::zero(),
|
||||
});
|
||||
assert_eq!(
|
||||
ActiveTotal::<Test>::get(),
|
||||
ActiveGiltsTotal {
|
||||
frozen: 0,
|
||||
proportion: Perquintill::zero(),
|
||||
index: 1,
|
||||
target: Perquintill::zero(),
|
||||
}
|
||||
);
|
||||
assert_eq!(Active::<Test>::get(0), None);
|
||||
assert_eq!(Balances::free_balance(1), 100);
|
||||
assert_eq!(Balances::reserved_balance(1), 0);
|
||||
@@ -426,98 +444,124 @@ fn enlargement_to_target_works() {
|
||||
assert_ok!(Gilt::set_target(Origin::signed(1), Perquintill::from_percent(40)));
|
||||
|
||||
run_to_block(3);
|
||||
assert_eq!(Queues::<Test>::get(1), vec![
|
||||
GiltBid { amount: 40, who: 1 },
|
||||
]);
|
||||
assert_eq!(Queues::<Test>::get(2), vec![
|
||||
GiltBid { amount: 40, who: 2 },
|
||||
GiltBid { amount: 40, who: 1 },
|
||||
]);
|
||||
assert_eq!(Queues::<Test>::get(3), vec![
|
||||
GiltBid { amount: 40, who: 3 },
|
||||
GiltBid { amount: 40, who: 2 },
|
||||
]);
|
||||
assert_eq!(Queues::<Test>::get(1), vec![GiltBid { amount: 40, who: 1 },]);
|
||||
assert_eq!(
|
||||
Queues::<Test>::get(2),
|
||||
vec![GiltBid { amount: 40, who: 2 }, GiltBid { amount: 40, who: 1 },]
|
||||
);
|
||||
assert_eq!(
|
||||
Queues::<Test>::get(3),
|
||||
vec![GiltBid { amount: 40, who: 3 }, GiltBid { amount: 40, who: 2 },]
|
||||
);
|
||||
assert_eq!(QueueTotals::<Test>::get(), vec![(1, 40), (2, 80), (2, 80)]);
|
||||
|
||||
run_to_block(4);
|
||||
// Two new gilts should have been issued to 2 & 3 for 40 each & duration of 3.
|
||||
assert_eq!(Active::<Test>::get(0).unwrap(), ActiveGilt {
|
||||
proportion: Perquintill::from_percent(10),
|
||||
amount: 40,
|
||||
who: 2,
|
||||
expiry: 13,
|
||||
});
|
||||
assert_eq!(Active::<Test>::get(1).unwrap(), ActiveGilt {
|
||||
proportion: Perquintill::from_percent(10),
|
||||
amount: 40,
|
||||
who: 3,
|
||||
expiry: 13,
|
||||
|
||||
});
|
||||
assert_eq!(ActiveTotal::<Test>::get(), ActiveGiltsTotal {
|
||||
frozen: 80,
|
||||
proportion: Perquintill::from_percent(20),
|
||||
index: 2,
|
||||
target: Perquintill::from_percent(40),
|
||||
});
|
||||
assert_eq!(
|
||||
Active::<Test>::get(0).unwrap(),
|
||||
ActiveGilt {
|
||||
proportion: Perquintill::from_percent(10),
|
||||
amount: 40,
|
||||
who: 2,
|
||||
expiry: 13,
|
||||
}
|
||||
);
|
||||
assert_eq!(
|
||||
Active::<Test>::get(1).unwrap(),
|
||||
ActiveGilt {
|
||||
proportion: Perquintill::from_percent(10),
|
||||
amount: 40,
|
||||
who: 3,
|
||||
expiry: 13,
|
||||
}
|
||||
);
|
||||
assert_eq!(
|
||||
ActiveTotal::<Test>::get(),
|
||||
ActiveGiltsTotal {
|
||||
frozen: 80,
|
||||
proportion: Perquintill::from_percent(20),
|
||||
index: 2,
|
||||
target: Perquintill::from_percent(40),
|
||||
}
|
||||
);
|
||||
|
||||
run_to_block(5);
|
||||
// No change
|
||||
assert_eq!(ActiveTotal::<Test>::get(), ActiveGiltsTotal {
|
||||
frozen: 80,
|
||||
proportion: Perquintill::from_percent(20),
|
||||
index: 2,
|
||||
target: Perquintill::from_percent(40),
|
||||
});
|
||||
assert_eq!(
|
||||
ActiveTotal::<Test>::get(),
|
||||
ActiveGiltsTotal {
|
||||
frozen: 80,
|
||||
proportion: Perquintill::from_percent(20),
|
||||
index: 2,
|
||||
target: Perquintill::from_percent(40),
|
||||
}
|
||||
);
|
||||
|
||||
run_to_block(6);
|
||||
// Two new gilts should have been issued to 1 & 2 for 40 each & duration of 2.
|
||||
assert_eq!(Active::<Test>::get(2).unwrap(), ActiveGilt {
|
||||
proportion: Perquintill::from_percent(10),
|
||||
amount: 40,
|
||||
who: 1,
|
||||
expiry: 12,
|
||||
});
|
||||
assert_eq!(Active::<Test>::get(3).unwrap(), ActiveGilt {
|
||||
proportion: Perquintill::from_percent(10),
|
||||
amount: 40,
|
||||
who: 2,
|
||||
expiry: 12,
|
||||
|
||||
});
|
||||
assert_eq!(ActiveTotal::<Test>::get(), ActiveGiltsTotal {
|
||||
frozen: 160,
|
||||
proportion: Perquintill::from_percent(40),
|
||||
index: 4,
|
||||
target: Perquintill::from_percent(40),
|
||||
});
|
||||
assert_eq!(
|
||||
Active::<Test>::get(2).unwrap(),
|
||||
ActiveGilt {
|
||||
proportion: Perquintill::from_percent(10),
|
||||
amount: 40,
|
||||
who: 1,
|
||||
expiry: 12,
|
||||
}
|
||||
);
|
||||
assert_eq!(
|
||||
Active::<Test>::get(3).unwrap(),
|
||||
ActiveGilt {
|
||||
proportion: Perquintill::from_percent(10),
|
||||
amount: 40,
|
||||
who: 2,
|
||||
expiry: 12,
|
||||
}
|
||||
);
|
||||
assert_eq!(
|
||||
ActiveTotal::<Test>::get(),
|
||||
ActiveGiltsTotal {
|
||||
frozen: 160,
|
||||
proportion: Perquintill::from_percent(40),
|
||||
index: 4,
|
||||
target: Perquintill::from_percent(40),
|
||||
}
|
||||
);
|
||||
|
||||
run_to_block(8);
|
||||
// No change now.
|
||||
assert_eq!(ActiveTotal::<Test>::get(), ActiveGiltsTotal {
|
||||
frozen: 160,
|
||||
proportion: Perquintill::from_percent(40),
|
||||
index: 4,
|
||||
target: Perquintill::from_percent(40),
|
||||
});
|
||||
assert_eq!(
|
||||
ActiveTotal::<Test>::get(),
|
||||
ActiveGiltsTotal {
|
||||
frozen: 160,
|
||||
proportion: Perquintill::from_percent(40),
|
||||
index: 4,
|
||||
target: Perquintill::from_percent(40),
|
||||
}
|
||||
);
|
||||
|
||||
// Set target a bit higher to use up the remaining bid.
|
||||
assert_ok!(Gilt::set_target(Origin::signed(1), Perquintill::from_percent(60)));
|
||||
run_to_block(10);
|
||||
|
||||
// Two new gilts should have been issued to 1 & 2 for 40 each & duration of 2.
|
||||
assert_eq!(Active::<Test>::get(4).unwrap(), ActiveGilt {
|
||||
proportion: Perquintill::from_percent(10),
|
||||
amount: 40,
|
||||
who: 1,
|
||||
expiry: 13,
|
||||
});
|
||||
assert_eq!(
|
||||
Active::<Test>::get(4).unwrap(),
|
||||
ActiveGilt {
|
||||
proportion: Perquintill::from_percent(10),
|
||||
amount: 40,
|
||||
who: 1,
|
||||
expiry: 13,
|
||||
}
|
||||
);
|
||||
|
||||
assert_eq!(ActiveTotal::<Test>::get(), ActiveGiltsTotal {
|
||||
frozen: 200,
|
||||
proportion: Perquintill::from_percent(50),
|
||||
index: 5,
|
||||
target: Perquintill::from_percent(60),
|
||||
});
|
||||
assert_eq!(
|
||||
ActiveTotal::<Test>::get(),
|
||||
ActiveGiltsTotal {
|
||||
frozen: 200,
|
||||
proportion: Perquintill::from_percent(50),
|
||||
index: 5,
|
||||
target: Perquintill::from_percent(60),
|
||||
}
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -36,6 +36,7 @@
|
||||
// --template=./.maintain/frame-weight-template.hbs
|
||||
|
||||
|
||||
#![cfg_attr(rustfmt, rustfmt_skip)]
|
||||
#![allow(unused_parens)]
|
||||
#![allow(unused_imports)]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user