Newer
Older
#[test]
fn payout_handles_basic_errors() {
new_test_ext().execute_with(|| {
// Wrong Origin
assert_noop!(Purchase::payout(
Origin::signed(alice()),
alice(),
), BadOrigin);
// Account with Existing Vesting Schedule
assert_ok!(<Test as Config>::VestingSchedule::add_vesting_schedule(
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
&bob(), 100, 1, 50,
));
assert_noop!(Purchase::payout(
Origin::signed(payment_account()),
bob(),
), Error::<Test>::VestingScheduleExists);
// Invalid Account (never created)
assert_noop!(Purchase::payout(
Origin::signed(payment_account()),
alice(),
), Error::<Test>::InvalidAccount);
// Invalid Account (created, but not valid)
assert_ok!(Purchase::create_account(
Origin::signed(validity_origin()),
alice(),
alice_signature().to_vec())
);
assert_noop!(Purchase::payout(
Origin::signed(payment_account()),
alice(),
), Error::<Test>::InvalidAccount);
// Not enough funds in payment account
assert_ok!(Purchase::update_validity_status(
Origin::signed(validity_origin()),
alice(),
AccountValidity::ValidHigh,
));
assert_ok!(Purchase::update_balance(
Origin::signed(validity_origin()),
alice(),
100_000,
100_000,
Permill::zero(),
));
assert_noop!(Purchase::payout(
Origin::signed(payment_account()),
alice(),
), BalancesError::<Test, _>::InsufficientBalance);
});
}
#[test]
fn remove_pallet_works() {
new_test_ext().execute_with(|| {
let account_status = AccountStatus {
validity: AccountValidity::Completed,
free_balance: 1234,
locked_balance: 4321,
signature: b"my signature".to_vec(),
vat: Permill::from_percent(50),
};
// Add some storage.
Accounts::<Test>::insert(alice(), account_status.clone());
Accounts::<Test>::insert(bob(), account_status);
PaymentAccount::<Test>::put(alice());
Statement::<Test>::put(b"hello, world!".to_vec());
UnlockBlock::<Test>::put(4);
// Verify storage exists.
assert_eq!(Accounts::<Test>::iter().count(), 2);
assert!(PaymentAccount::<Test>::exists());
assert!(Statement::<Test>::exists());
assert!(UnlockBlock::<Test>::exists());
// Remove storage.
remove_pallet::<Test>();
// Verify storage is gone.
assert_eq!(Accounts::<Test>::iter().count(), 0);
assert!(!PaymentAccount::<Test>::exists());
assert!(!Statement::<Test>::exists());
assert!(!UnlockBlock::<Test>::exists());
});
}