Newer
Older
// Copyright 2021 Axiom-Team
//
// This file is part of Substrate-Libre-Currency.
//
// Substrate-Libre-Currency is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, version 3 of the License.
//
// Substrate-Libre-Currency is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with Substrate-Libre-Currency. If not, see <https://www.gnu.org/licenses/>.
use crate::mock::IdtyRight as Right;
use crate::mock::*;
use frame_support::assert_err;
use frame_support::assert_ok;
use frame_system::{EventRecord, Phase};
#[test]
fn test_no_identity() {
let identities = Vec::with_capacity(0);
new_test_ext(IdentityConfig { identities }).execute_with(|| {
assert_eq!(Identity::identities_count(), 0);
});
}
#[test]
fn test_two_identities() {
let identities = vec![
rights: vec![(Right::Right2, Some(10))],
status: crate::IdtyStatus::Validated,
rights: vec![(Right::Right1, Some(20))],
status: crate::IdtyStatus::Validated,
new_test_ext(IdentityConfig { identities }).execute_with(|| {
// Should have two identities
assert_eq!(Identity::identities_count(), 2);
// We need to initialize at least one block before any call
run_to_block(1);
let events = System::events();
assert_eq!(events.len(), 1);
assert_eq!(
events[0],
EventRecord {
phase: Phase::Initialization,
event: Event::Identity(crate::Event::IdtyAcquireRight(
IdtyName(vec![0]),
Right::Right1
)),
// Add right Right2 for IdtyName(vec![0])
// Should fail because IdtyName(vec![0]) already have this right
Error::<Test>::RightAlreadyAdded
);
run_to_block(3);
let events = System::events();
assert_eq!(events.len(), 2);
assert_eq!(
events[1],
EventRecord {
phase: Phase::Initialization,
event: Event::Identity(crate::Event::IdtyLostRight(
IdtyName(vec![1]),
Right::Right1
)),
// The IdtyName(vec![1]) identity has no more rights, the inactivity period must start to run
let idty2 = Identity::identity(2).expect("idty not found");