purchase.rs 34.8 KB
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(
				&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());
		});
	}