Skip to content

Commit

Permalink
Update tests with auto withdraw feature
Browse files Browse the repository at this point in the history
  • Loading branch information
yanganto committed Jan 20, 2020
1 parent b0aef5b commit 1c6674f
Showing 1 changed file with 21 additions and 79 deletions.
100 changes: 21 additions & 79 deletions srml/staking/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2532,30 +2532,7 @@ fn time_deposit_ring_unbond_and_withdraw_automatically_should_work() {
reasons: WithdrawReasons::all(),
}],
);
assert_eq!(
Staking::ledger(controller).unwrap(),
StakingLedger {
stash,
active_ring: 0,
active_deposit_ring: 0,
active_kton: 0,
deposit_items: vec![],
ring_staking_lock: StakingLock {
staking_amount: 0,
unbondings: vec![
NormalLock {
amount: unbond_value,
until: BondingDuration::get(),
},
NormalLock {
amount: 1000 - unbond_value,
until: unbond_start + BondingDuration::get(),
},
],
},
kton_staking_lock: Default::default(),
},
);
assert_eq!(Staking::ledger(controller), None);

assert_err!(
Ring::transfer(Origin::signed(stash), controller, 1),
Expand Down Expand Up @@ -3979,7 +3956,8 @@ fn xavier_q2() {
}

#[test]
fn xavier_q3() {
fn bond_values_then_unbond_all_then_bond_again() {
// The Kton part
ExtBuilder::default().build().execute_with(|| {
let stash = 123;
let controller = 456;
Expand All @@ -3993,6 +3971,7 @@ fn xavier_q3() {
RewardDestination::Stash,
0,
));

assert_eq!(Timestamp::get(), 1);
assert_eq!(
Staking::ledger(controller).unwrap(),
Expand All @@ -4009,38 +3988,22 @@ fn xavier_q3() {
},
}
);
// println!("Locks: {:#?}", Kton::locks(stash));
// println!("StakingLedger: {:#?}", Staking::ledger(controller));
// println!();

// all values are unbond
assert_ok!(Staking::unbond(
Origin::signed(controller),
StakingBalances::KtonBalance(5)
));
assert_eq!(
Staking::ledger(controller).unwrap(),
StakingLedger {
stash: 123,
active_ring: 0,
active_deposit_ring: 0,
active_kton: 0,
deposit_items: vec![],
ring_staking_lock: Default::default(),
kton_staking_lock: StakingLock {
staking_amount: 0,
unbondings: vec![NormalLock { amount: 5, until: 61 }],
},
}
);
// println!("Locks: {:#?}", Kton::locks(stash));
// println!("StakingLedger: {:#?}", Staking::ledger(controller));
// println!();
assert_eq!(Staking::ledger(controller), None);

// bond again
Timestamp::set_timestamp(61);
assert_ok!(Staking::bond_extra(
assert_ok!(Staking::bond(
Origin::signed(stash),
controller,
StakingBalances::KtonBalance(1),
0
RewardDestination::Stash,
0,
));
assert_eq!(Timestamp::get(), 61);
assert_eq!(
Expand All @@ -4054,15 +4017,13 @@ fn xavier_q3() {
ring_staking_lock: Default::default(),
kton_staking_lock: StakingLock {
staking_amount: 1,
unbondings: vec![NormalLock { amount: 5, until: 61 }],
unbondings: vec![],
},
}
);
// println!("Locks: {:#?}", Kton::locks(stash));
// println!("StakingLedger: {:#?}", Staking::ledger(controller));
// println!();
});

// The Ring part
ExtBuilder::default().build().execute_with(|| {
let stash = 123;
let controller = 456;
Expand Down Expand Up @@ -4092,38 +4053,22 @@ fn xavier_q3() {
kton_staking_lock: Default::default(),
}
);
// println!("Locks: {:#?}", Ring::locks(stash));
// println!("StakingLedger: {:#?}", Staking::ledger(controller));
// println!();

// all values are unbond
assert_ok!(Staking::unbond(
Origin::signed(controller),
StakingBalances::RingBalance(5),
));
assert_eq!(
Staking::ledger(controller).unwrap(),
StakingLedger {
stash: 123,
active_ring: 0,
active_deposit_ring: 0,
active_kton: 0,
deposit_items: vec![],
ring_staking_lock: StakingLock {
staking_amount: 0,
unbondings: vec![NormalLock { amount: 5, until: 61 }],
},
kton_staking_lock: Default::default(),
}
);
// println!("Locks: {:#?}", Ring::locks(stash));
// println!("StakingLedger: {:#?}", Staking::ledger(controller));
// println!();
assert_eq!(Staking::ledger(controller), None);

// bond again
Timestamp::set_timestamp(61);
assert_ok!(Staking::bond_extra(
assert_ok!(Staking::bond(
Origin::signed(stash),
controller,
StakingBalances::RingBalance(1),
0
RewardDestination::Stash,
0,
));
assert_eq!(Timestamp::get(), 61);
assert_eq!(
Expand All @@ -4136,14 +4081,11 @@ fn xavier_q3() {
deposit_items: vec![],
ring_staking_lock: StakingLock {
staking_amount: 1,
unbondings: vec![NormalLock { amount: 5, until: 61 }],
unbondings: vec![],
},
kton_staking_lock: Default::default(),
}
);
// println!("Locks: {:#?}", Ring::locks(stash));
// println!("StakingLedger: {:#?}", Staking::ledger(controller));
// println!();
});
}

Expand Down

0 comments on commit 1c6674f

Please sign in to comment.