Skip to content

Commit

Permalink
Tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Dinonard committed Jan 3, 2024
1 parent bd01d5d commit 95fa9ce
Showing 1 changed file with 58 additions and 0 deletions.
58 changes: 58 additions & 0 deletions pallets/dapp-staking-v3/src/test/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,18 @@ fn maintenace_mode_call_filtering_works() {
DappStaking::force(RuntimeOrigin::root(), ForcingType::Era),
Error::<Test>::Disabled
);
assert_noop!(
DappStaking::unbond_and_unstake(
RuntimeOrigin::signed(1),
MockSmartContract::wasm(1 as AccountId),
100
),
Error::<Test>::Disabled
);
assert_noop!(
DappStaking::withdraw_unbonded(RuntimeOrigin::signed(1),),
Error::<Test>::Disabled
);
})
}

Expand Down Expand Up @@ -503,6 +515,29 @@ fn lock_with_incorrect_amount_fails() {
})
}

#[test]
fn unbond_and_unstake_is_ok() {
ExtBuilder::build().execute_with(|| {
// Lock some amount
let account = 2;
let lock_amount = 101;
assert_lock(account, lock_amount);

// 'unbond_and_unstake' some amount, assert expected event is emitted
let unlock_amount = 19;
let dummy_smart_contract = MockSmartContract::Wasm(1);
assert_ok!(DappStaking::unbond_and_unstake(
RuntimeOrigin::signed(account),
dummy_smart_contract,
unlock_amount
));
System::assert_last_event(RuntimeEvent::DappStaking(Event::Unlocking {
account,
amount: unlock_amount,
}));
})
}

#[test]
fn unlock_basic_example_is_ok() {
ExtBuilder::build().execute_with(|| {
Expand Down Expand Up @@ -682,6 +717,29 @@ fn unlock_with_exceeding_unlocking_chunks_storage_limits_fails() {
})
}

#[test]
fn withdraw_unbonded_is_ok() {
ExtBuilder::build().execute_with(|| {
// Lock & immediatelly unlock some amount
let account = 2;
let lock_amount = 97;
let unlock_amount = 11;
assert_lock(account, lock_amount);
assert_unlock(account, unlock_amount);

// Run for enough blocks so the chunk becomes claimable
let unlocking_blocks = DappStaking::unlocking_period();
run_for_blocks(unlocking_blocks);
assert_ok!(DappStaking::withdraw_unbonded(RuntimeOrigin::signed(
account
)));
System::assert_last_event(RuntimeEvent::DappStaking(Event::ClaimedUnlocked {
account,
amount: unlock_amount,
}));
})
}

#[test]
fn claim_unlocked_is_ok() {
ExtBuilder::build().execute_with(|| {
Expand Down

0 comments on commit 95fa9ce

Please sign in to comment.