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

IceFrog alpha version #161

Merged
merged 21 commits into from
Dec 12, 2019
Merged
Prev Previous commit
update: format
  • Loading branch information
aurexav committed Dec 12, 2019
commit 341ae3837ea051da37e2ecd2b961198864e6efb6
57 changes: 30 additions & 27 deletions srml/balances/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use std::cell::RefCell;
use primitives::H256;
use sr_primitives::{
testing::Header,
traits::{ConvertInto, IdentityLookup},
traits::{BlakeTwo256, ConvertInto, IdentityLookup},
weights::{DispatchInfo, Weight},
Perbill,
};
Expand Down Expand Up @@ -61,21 +61,21 @@ impl Get<u64> for CreationFee {

// Workaround for https://github.com/rust-lang/rust/issues/26925 . Remove when sorted.
#[derive(Clone, PartialEq, Eq, Debug)]
pub struct Runtime;
pub struct Test;
parameter_types! {
pub const BlockHashCount: u64 = 250;
pub const MaximumBlockWeight: u32 = 1024;
pub const MaximumBlockLength: u32 = 2 * 1024;
pub const AvailableBlockRatio: Perbill = Perbill::one();
}
impl system::Trait for Runtime {
impl system::Trait for Test {
type Origin = Origin;
type Index = u64;
type BlockNumber = u64;
type Call = ();
type Index = u64;
type BlockNumber = BlockNumber;
type Hash = H256;
type Hashing = ::sr_primitives::traits::BlakeTwo256;
type AccountId = u64;
type Hashing = BlakeTwo256;
type AccountId = AccountId;
type Lookup = IdentityLookup<Self::AccountId>;
type Header = Header;
type Event = ();
Expand All @@ -85,40 +85,42 @@ impl system::Trait for Runtime {
type AvailableBlockRatio = AvailableBlockRatio;
type Version = ();
}

parameter_types! {
pub const TransactionBaseFee: u64 = 0;
pub const TransactionByteFee: u64 = 1;
}
impl transaction_payment::Trait for Runtime {
type Currency = Module<Runtime>;
impl transaction_payment::Trait for Test {
type Currency = Module<Test>;
type OnTransactionPayment = ();
type TransactionBaseFee = TransactionBaseFee;
type TransactionByteFee = TransactionByteFee;
type WeightToFee = ConvertInto;
type FeeMultiplierUpdate = ();
}
impl Trait for Runtime {
type Balance = u64;
type OnFreeBalanceZero = ();
type OnNewAccount = ();
type Event = ();
type DustRemoval = ();
type TransferPayment = ();
type ExistentialDeposit = ExistentialDeposit;
type TransferFee = TransferFee;
type CreationFee = CreationFee;
}

parameter_types! {
pub const MinimumPeriod: u64 = 5;
}

impl timestamp::Trait for Runtime {
impl timestamp::Trait for Test {
type Moment = u64;
type OnTimestampSet = ();
type MinimumPeriod = MinimumPeriod;
}

impl Trait for Test {
type Balance = Balance;
type OnFreeBalanceZero = ();
type OnNewAccount = ();
type TransferPayment = ();
type DustRemoval = ();
type Event = ();
type ExistentialDeposit = ExistentialDeposit;
type TransferFee = TransferFee;
type CreationFee = CreationFee;
}

pub struct ExtBuilder {
existential_deposit: u64,
transfer_fee: u64,
Expand Down Expand Up @@ -169,8 +171,8 @@ impl ExtBuilder {
}
pub fn build(self) -> runtime_io::TestExternalities {
self.set_associated_consts();
let mut t = system::GenesisConfig::default().build_storage::<Runtime>().unwrap();
GenesisConfig::<Runtime> {
let mut t = system::GenesisConfig::default().build_storage::<Test>().unwrap();
GenesisConfig::<Test> {
balances: if self.monied {
vec![
(1, 10 * self.existential_deposit),
Expand Down Expand Up @@ -198,11 +200,12 @@ impl ExtBuilder {
}
}

pub type System = system::Module<Runtime>;
pub type Timestamp = timestamp::Module<Runtime>;
pub type Balances = Module<Runtime>;
pub type System = system::Module<Test>;
pub type Timestamp = timestamp::Module<Test>;

pub type Balances = Module<Test>;

pub const CALL: &<Runtime as system::Trait>::Call = &();
pub const CALL: &<Test as system::Trait>::Call = &();

/// create a transaction info struct from weight. Handy to avoid building the whole struct.
pub fn info_from_weight(w: Weight) -> DispatchInfo {
Expand Down
32 changes: 16 additions & 16 deletions srml/balances/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ fn lock_reasons_should_work() {
);
assert_ok!(<Balances as ReservableCurrency<_>>::reserve(&1, 1));
// NOTE: this causes a fee payment.
assert!(<ChargeTransactionPayment<Runtime> as SignedExtension>::pre_dispatch(
assert!(<ChargeTransactionPayment<Test> as SignedExtension>::pre_dispatch(
ChargeTransactionPayment::from(1),
&1,
CALL,
Expand All @@ -257,7 +257,7 @@ fn lock_reasons_should_work() {
<Balances as ReservableCurrency<_>>::reserve(&1, 1),
"account liquidity restrictions prevent withdrawal"
);
assert!(<ChargeTransactionPayment<Runtime> as SignedExtension>::pre_dispatch(
assert!(<ChargeTransactionPayment<Test> as SignedExtension>::pre_dispatch(
ChargeTransactionPayment::from(1),
&1,
CALL,
Expand All @@ -277,7 +277,7 @@ fn lock_reasons_should_work() {
);
assert_ok!(<Balances as Currency<_>>::transfer(&1, &2, 1, AllowDeath));
assert_ok!(<Balances as ReservableCurrency<_>>::reserve(&1, 1));
assert!(<ChargeTransactionPayment<Runtime> as SignedExtension>::pre_dispatch(
assert!(<ChargeTransactionPayment<Test> as SignedExtension>::pre_dispatch(
ChargeTransactionPayment::from(1),
&1,
CALL,
Expand Down Expand Up @@ -396,7 +396,7 @@ fn reward_should_work() {
assert_eq!(Balances::total_balance(&1), 10);
assert_ok!(Balances::deposit_into_existing(&1, 10).map(drop));
assert_eq!(Balances::total_balance(&1), 20);
assert_eq!(<TotalIssuance<Runtime>>::get(), 120);
assert_eq!(<TotalIssuance<Test>>::get(), 120);
});
}

Expand Down Expand Up @@ -528,7 +528,7 @@ fn slashing_balance_should_work() {
assert!(Balances::slash(&1, 69).1.is_zero());
assert_eq!(Balances::free_balance(&1), 0);
assert_eq!(Balances::reserved_balance(&1), 42);
assert_eq!(<TotalIssuance<Runtime>>::get(), 42);
assert_eq!(<TotalIssuance<Test>>::get(), 42);
});
}

Expand All @@ -540,7 +540,7 @@ fn slashing_incomplete_balance_should_work() {
assert_eq!(Balances::slash(&1, 69).1, 27);
assert_eq!(Balances::free_balance(&1), 0);
assert_eq!(Balances::reserved_balance(&1), 0);
assert_eq!(<TotalIssuance<Runtime>>::get(), 0);
assert_eq!(<TotalIssuance<Test>>::get(), 0);
});
}

Expand All @@ -563,7 +563,7 @@ fn slashing_reserved_balance_should_work() {
assert_eq!(Balances::slash_reserved(&1, 42).1, 0);
assert_eq!(Balances::reserved_balance(&1), 69);
assert_eq!(Balances::free_balance(&1), 0);
assert_eq!(<TotalIssuance<Runtime>>::get(), 69);
assert_eq!(<TotalIssuance<Test>>::get(), 69);
});
}

Expand All @@ -575,7 +575,7 @@ fn slashing_incomplete_reserved_balance_should_work() {
assert_eq!(Balances::slash_reserved(&1, 69).1, 27);
assert_eq!(Balances::free_balance(&1), 69);
assert_eq!(Balances::reserved_balance(&1), 0);
assert_eq!(<TotalIssuance<Runtime>>::get(), 69);
assert_eq!(<TotalIssuance<Test>>::get(), 69);
});
}

Expand Down Expand Up @@ -622,8 +622,8 @@ fn transferring_incomplete_reserved_balance_should_work() {
#[test]
fn transferring_too_high_value_should_not_panic() {
ExtBuilder::default().build().execute_with(|| {
<FreeBalance<Runtime>>::insert(1, u64::max_value());
<FreeBalance<Runtime>>::insert(2, 1);
<FreeBalance<Test>>::insert(1, u64::max_value());
<FreeBalance<Test>>::insert(2, 1);

assert_err!(
Balances::transfer(Some(1).into(), 2, u64::max_value()),
Expand All @@ -639,12 +639,12 @@ fn transferring_too_high_value_should_not_panic() {
fn account_create_on_free_too_low_with_other() {
ExtBuilder::default().existential_deposit(100).build().execute_with(|| {
let _ = Balances::deposit_creating(&1, 100);
assert_eq!(<TotalIssuance<Runtime>>::get(), 100);
assert_eq!(<TotalIssuance<Test>>::get(), 100);

// No-op.
let _ = Balances::deposit_creating(&2, 50);
assert_eq!(Balances::free_balance(&2), 0);
assert_eq!(<TotalIssuance<Runtime>>::get(), 100);
assert_eq!(<TotalIssuance<Test>>::get(), 100);
})
}

Expand All @@ -654,22 +654,22 @@ fn account_create_on_free_too_low() {
// No-op.
let _ = Balances::deposit_creating(&2, 50);
assert_eq!(Balances::free_balance(&2), 0);
assert_eq!(<TotalIssuance<Runtime>>::get(), 0);
assert_eq!(<TotalIssuance<Test>>::get(), 0);
})
}

#[test]
fn account_removal_on_free_too_low() {
ExtBuilder::default().existential_deposit(100).build().execute_with(|| {
assert_eq!(<TotalIssuance<Runtime>>::get(), 0);
assert_eq!(<TotalIssuance<Test>>::get(), 0);

// Setup two accounts with free balance above the existential threshold.
let _ = Balances::deposit_creating(&1, 110);
let _ = Balances::deposit_creating(&2, 110);

assert_eq!(Balances::free_balance(&1), 110);
assert_eq!(Balances::free_balance(&2), 110);
assert_eq!(<TotalIssuance<Runtime>>::get(), 220);
assert_eq!(<TotalIssuance<Test>>::get(), 220);

// Transfer funds from account 1 of such amount that after this transfer
// the balance of account 1 will be below the existential threshold.
Expand All @@ -681,7 +681,7 @@ fn account_removal_on_free_too_low() {
assert_eq!(Balances::free_balance(&2), 130);

// Verify that TotalIssuance tracks balance removal when free balance is too low.
assert_eq!(<TotalIssuance<Runtime>>::get(), 130);
assert_eq!(<TotalIssuance<Test>>::get(), 130);
});
}

Expand Down
6 changes: 4 additions & 2 deletions srml/staking/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,13 @@ pub type AccountId = u64;
pub type BlockNumber = u64;

/// Module alias
pub type Session = session::Module<Test>;
pub type System = system::Module<Test>;
pub type Timestamp = timestamp::Module<Test>;

pub type Ring = balances::Module<Test>;
pub type Kton = kton::Module<Test>;
pub type Session = session::Module<Test>;
pub type Timestamp = timestamp::Module<Test>;

pub type Staking = Module<Test>;

pub const NANO: Balance = 1;
Expand Down