Identity pallet improvements (#2048)

This PR is a follow up to #1661 

- [x] rename the `simple` module to `legacy`
- [x] fix benchmarks to disregard the number of additional fields
- [x] change the storage deposits to charge per encoded byte of the
identity information instance, removing the need for `fn
additional(&self) -> usize` in `IdentityInformationProvider`
- [x] ~add an extrinsic to rejig deposits to account for the change
above~
- [ ] ~ensure through proper configuration that the new byte-based
deposit is always lower than whatever is reserved now~
- [x] remove `IdentityFields` from the `set_fields` extrinsic signature,
as per [this
discussion](https://github.com/paritytech/polkadot-sdk/pull/1661#discussion_r1371703403)

> ensure through proper configuration that the new byte-based deposit is
always lower than whatever is reserved now

Not sure this is needed anymore. If the new deposits are higher than
what is currently on chain and users don't have enough funds to reserve
what is needed, the extrinisc fails and they're basically grandfathered
and frozen until they add more funds and/or make a change to their
identity. This behavior seems fine to me. Original idea
[here](https://github.com/paritytech/polkadot-sdk/pull/1661#issuecomment-1779606319).

> add an extrinsic to rejig deposits to account for the change above

This was initially implemented but now removed from this PR in favor of
the implementation detailed
[here](https://github.com/paritytech/polkadot-sdk/pull/2088).

---------

Signed-off-by: georgepisaltu <george.pisaltu@parity.io>
Co-authored-by: joepetrowski <joe@parity.io>
This commit is contained in:
georgepisaltu
2023-11-03 21:38:26 +02:00
committed by GitHub
parent ca5f10567a
commit 21fbc00d04
15 changed files with 353 additions and 459 deletions
+156 -107
View File
@@ -20,13 +20,13 @@
use super::*;
use crate::{
self as pallet_identity,
simple::{IdentityField as SimpleIdentityField, IdentityInfo},
legacy::{IdentityField, IdentityInfo},
};
use codec::{Decode, Encode};
use frame_support::{
assert_noop, assert_ok, ord_parameter_types, parameter_types,
traits::{ConstU32, ConstU64, EitherOfDiverse},
traits::{ConstU32, ConstU64, EitherOfDiverse, Get},
BoundedVec,
};
use frame_system::{EnsureRoot, EnsureSignedBy};
@@ -105,11 +105,10 @@ impl pallet_identity::Config for Test {
type RuntimeEvent = RuntimeEvent;
type Currency = Balances;
type Slashed = ();
type BasicDeposit = ConstU64<10>;
type FieldDeposit = ConstU64<10>;
type SubAccountDeposit = ConstU64<10>;
type BasicDeposit = ConstU64<100>;
type ByteDeposit = ConstU64<10>;
type SubAccountDeposit = ConstU64<100>;
type MaxSubAccounts = ConstU32<2>;
type MaxAdditionalFields = MaxAdditionalFields;
type IdentityInformation = IdentityInfo<MaxAdditionalFields>;
type MaxRegistrars = MaxRegistrars;
type RegistrarOrigin = EnsureOneOrRoot;
@@ -120,7 +119,7 @@ impl pallet_identity::Config for Test {
pub fn new_test_ext() -> sp_io::TestExternalities {
let mut t = frame_system::GenesisConfig::<Test>::default().build_storage().unwrap();
pallet_balances::GenesisConfig::<Test> {
balances: vec![(1, 10), (2, 10), (3, 10), (10, 100), (20, 100), (30, 100)],
balances: vec![(1, 100), (2, 100), (3, 100), (10, 1000), (20, 1000), (30, 1000)],
}
.assimilate_storage(&mut t)
.unwrap();
@@ -143,39 +142,43 @@ fn twenty() -> IdentityInfo<MaxAdditionalFields> {
}
}
fn id_deposit(id: &IdentityInfo<MaxAdditionalFields>) -> u64 {
let base_deposit: u64 = <<Test as Config>::BasicDeposit as Get<u64>>::get();
let byte_deposit: u64 = <<Test as Config>::ByteDeposit as Get<u64>>::get() *
TryInto::<u64>::try_into(id.encoded_size()).unwrap();
base_deposit + byte_deposit
}
#[test]
fn identity_fields_repr_works() {
// `SimpleIdentityField` sanity checks.
assert_eq!(SimpleIdentityField::Display as u64, 1 << 0);
assert_eq!(SimpleIdentityField::Legal as u64, 1 << 1);
assert_eq!(SimpleIdentityField::Web as u64, 1 << 2);
assert_eq!(SimpleIdentityField::Riot as u64, 1 << 3);
assert_eq!(SimpleIdentityField::Email as u64, 1 << 4);
assert_eq!(SimpleIdentityField::PgpFingerprint as u64, 1 << 5);
assert_eq!(SimpleIdentityField::Image as u64, 1 << 6);
assert_eq!(SimpleIdentityField::Twitter as u64, 1 << 7);
// `IdentityField` sanity checks.
assert_eq!(IdentityField::Display as u64, 1 << 0);
assert_eq!(IdentityField::Legal as u64, 1 << 1);
assert_eq!(IdentityField::Web as u64, 1 << 2);
assert_eq!(IdentityField::Riot as u64, 1 << 3);
assert_eq!(IdentityField::Email as u64, 1 << 4);
assert_eq!(IdentityField::PgpFingerprint as u64, 1 << 5);
assert_eq!(IdentityField::Image as u64, 1 << 6);
assert_eq!(IdentityField::Twitter as u64, 1 << 7);
let fields = IdentityFields(
SimpleIdentityField::Legal |
SimpleIdentityField::Web |
SimpleIdentityField::Riot |
SimpleIdentityField::PgpFingerprint |
SimpleIdentityField::Twitter,
);
let fields = IdentityField::Legal |
IdentityField::Web |
IdentityField::Riot |
IdentityField::PgpFingerprint |
IdentityField::Twitter;
assert!(!fields.0.contains(SimpleIdentityField::Display));
assert!(fields.0.contains(SimpleIdentityField::Legal));
assert!(fields.0.contains(SimpleIdentityField::Web));
assert!(fields.0.contains(SimpleIdentityField::Riot));
assert!(!fields.0.contains(SimpleIdentityField::Email));
assert!(fields.0.contains(SimpleIdentityField::PgpFingerprint));
assert!(!fields.0.contains(SimpleIdentityField::Image));
assert!(fields.0.contains(SimpleIdentityField::Twitter));
assert!(!fields.contains(IdentityField::Display));
assert!(fields.contains(IdentityField::Legal));
assert!(fields.contains(IdentityField::Web));
assert!(fields.contains(IdentityField::Riot));
assert!(!fields.contains(IdentityField::Email));
assert!(fields.contains(IdentityField::PgpFingerprint));
assert!(!fields.contains(IdentityField::Image));
assert!(fields.contains(IdentityField::Twitter));
// The `IdentityFields` inner `BitFlags::bits` is used for `Encode`/`Decode`, so we ensure that
// the `u64` representation matches what we expect during encode/decode operations.
// Ensure that the `u64` representation matches what we expect.
assert_eq!(
fields.0.bits(),
fields.bits(),
0b00000000_00000000_00000000_00000000_00000000_00000000_00000000_10101110
);
}
@@ -190,18 +193,23 @@ fn editing_subaccounts_should_work() {
Error::<Test>::NoIdentity
);
assert_ok!(Identity::set_identity(RuntimeOrigin::signed(10), Box::new(ten())));
let ten = ten();
assert_ok!(Identity::set_identity(RuntimeOrigin::signed(10), Box::new(ten.clone())));
let id_deposit = id_deposit(&ten);
assert_eq!(Balances::free_balance(10), 1000 - id_deposit);
let sub_deposit: u64 = <<Test as Config>::SubAccountDeposit as Get<u64>>::get();
// first sub account
assert_ok!(Identity::add_sub(RuntimeOrigin::signed(10), 1, data(1)));
assert_eq!(SuperOf::<Test>::get(1), Some((10, data(1))));
assert_eq!(Balances::free_balance(10), 80);
assert_eq!(Balances::free_balance(10), 1000 - id_deposit - sub_deposit);
// second sub account
assert_ok!(Identity::add_sub(RuntimeOrigin::signed(10), 2, data(2)));
assert_eq!(SuperOf::<Test>::get(1), Some((10, data(1))));
assert_eq!(SuperOf::<Test>::get(2), Some((10, data(2))));
assert_eq!(Balances::free_balance(10), 70);
assert_eq!(Balances::free_balance(10), 1000 - id_deposit - 2 * sub_deposit);
// third sub account is too many
assert_noop!(
@@ -213,20 +221,20 @@ fn editing_subaccounts_should_work() {
assert_ok!(Identity::rename_sub(RuntimeOrigin::signed(10), 1, data(11)));
assert_eq!(SuperOf::<Test>::get(1), Some((10, data(11))));
assert_eq!(SuperOf::<Test>::get(2), Some((10, data(2))));
assert_eq!(Balances::free_balance(10), 70);
assert_eq!(Balances::free_balance(10), 1000 - id_deposit - 2 * sub_deposit);
// remove first sub account
assert_ok!(Identity::remove_sub(RuntimeOrigin::signed(10), 1));
assert_eq!(SuperOf::<Test>::get(1), None);
assert_eq!(SuperOf::<Test>::get(2), Some((10, data(2))));
assert_eq!(Balances::free_balance(10), 80);
assert_eq!(Balances::free_balance(10), 1000 - id_deposit - sub_deposit);
// add third sub account
assert_ok!(Identity::add_sub(RuntimeOrigin::signed(10), 3, data(3)));
assert_eq!(SuperOf::<Test>::get(1), None);
assert_eq!(SuperOf::<Test>::get(2), Some((10, data(2))));
assert_eq!(SuperOf::<Test>::get(3), Some((10, data(3))));
assert_eq!(Balances::free_balance(10), 70);
assert_eq!(Balances::free_balance(10), 1000 - id_deposit - 2 * sub_deposit);
});
}
@@ -234,15 +242,22 @@ fn editing_subaccounts_should_work() {
fn resolving_subaccount_ownership_works() {
new_test_ext().execute_with(|| {
let data = |x| Data::Raw(vec![x; 1].try_into().unwrap());
let sub_deposit: u64 = <<Test as Config>::SubAccountDeposit as Get<u64>>::get();
assert_ok!(Identity::set_identity(RuntimeOrigin::signed(10), Box::new(ten())));
assert_ok!(Identity::set_identity(RuntimeOrigin::signed(20), Box::new(twenty())));
let ten = ten();
let ten_deposit = id_deposit(&ten);
let twenty = twenty();
let twenty_deposit = id_deposit(&twenty);
assert_ok!(Identity::set_identity(RuntimeOrigin::signed(10), Box::new(ten)));
assert_eq!(Balances::free_balance(10), 1000 - ten_deposit);
assert_ok!(Identity::set_identity(RuntimeOrigin::signed(20), Box::new(twenty)));
assert_eq!(Balances::free_balance(20), 1000 - twenty_deposit);
// 10 claims 1 as a subaccount
assert_ok!(Identity::add_sub(RuntimeOrigin::signed(10), 1, data(1)));
assert_eq!(Balances::free_balance(1), 10);
assert_eq!(Balances::free_balance(10), 80);
assert_eq!(Balances::reserved_balance(10), 20);
assert_eq!(Balances::free_balance(1), 100);
assert_eq!(Balances::free_balance(10), 1000 - ten_deposit - sub_deposit);
assert_eq!(Balances::reserved_balance(10), ten_deposit + sub_deposit);
// 20 cannot claim 1 now
assert_noop!(
Identity::add_sub(RuntimeOrigin::signed(20), 1, data(1)),
@@ -251,9 +266,9 @@ fn resolving_subaccount_ownership_works() {
// 1 wants to be with 20 so it quits from 10
assert_ok!(Identity::quit_sub(RuntimeOrigin::signed(1)));
// 1 gets the 10 that 10 paid.
assert_eq!(Balances::free_balance(1), 20);
assert_eq!(Balances::free_balance(10), 80);
assert_eq!(Balances::reserved_balance(10), 10);
assert_eq!(Balances::free_balance(1), 100 + sub_deposit);
assert_eq!(Balances::free_balance(10), 1000 - ten_deposit - sub_deposit);
assert_eq!(Balances::reserved_balance(10), ten_deposit);
// 20 can claim 1 now
assert_ok!(Identity::add_sub(RuntimeOrigin::signed(20), 1, data(1)));
});
@@ -269,16 +284,29 @@ fn trailing_zeros_decodes_into_default_data() {
assert_eq!(b, Data::None);
}
#[test]
fn adding_registrar_invalid_index() {
new_test_ext().execute_with(|| {
assert_ok!(Identity::add_registrar(RuntimeOrigin::signed(1), 3));
assert_ok!(Identity::set_fee(RuntimeOrigin::signed(3), 0, 10));
let fields = IdentityField::Display | IdentityField::Legal;
assert_noop!(
Identity::set_fields(RuntimeOrigin::signed(3), 100, fields.bits()),
Error::<Test>::InvalidIndex
);
});
}
#[test]
fn adding_registrar_should_work() {
new_test_ext().execute_with(|| {
assert_ok!(Identity::add_registrar(RuntimeOrigin::signed(1), 3));
assert_ok!(Identity::set_fee(RuntimeOrigin::signed(3), 0, 10));
let fields = IdentityFields(SimpleIdentityField::Display | SimpleIdentityField::Legal);
assert_ok!(Identity::set_fields(RuntimeOrigin::signed(3), 0, fields));
let fields = IdentityField::Display | IdentityField::Legal;
assert_ok!(Identity::set_fields(RuntimeOrigin::signed(3), 0, fields.bits()));
assert_eq!(
Identity::registrars(),
vec![Some(RegistrarInfo { account: 3, fee: 10, fields })]
vec![Some(RegistrarInfo { account: 3, fee: 10, fields: fields.bits() })]
);
});
}
@@ -306,11 +334,13 @@ fn registration_should_work() {
three_fields.additional.try_push(Default::default()).unwrap();
three_fields.additional.try_push(Default::default()).unwrap();
assert!(three_fields.additional.try_push(Default::default()).is_err());
assert_ok!(Identity::set_identity(RuntimeOrigin::signed(10), Box::new(ten())));
assert_eq!(Identity::identity(10).unwrap().info, ten());
assert_eq!(Balances::free_balance(10), 90);
let ten = ten();
let id_deposit = id_deposit(&ten);
assert_ok!(Identity::set_identity(RuntimeOrigin::signed(10), Box::new(ten.clone())));
assert_eq!(Identity::identity(10).unwrap().info, ten);
assert_eq!(Balances::free_balance(10), 1000 - id_deposit);
assert_ok!(Identity::clear_identity(RuntimeOrigin::signed(10)));
assert_eq!(Balances::free_balance(10), 100);
assert_eq!(Balances::free_balance(10), 1000);
assert_noop!(Identity::clear_identity(RuntimeOrigin::signed(10)), Error::<Test>::NotNamed);
});
}
@@ -407,11 +437,13 @@ fn clearing_judgement_should_work() {
#[test]
fn killing_slashing_should_work() {
new_test_ext().execute_with(|| {
assert_ok!(Identity::set_identity(RuntimeOrigin::signed(10), Box::new(ten())));
let ten = ten();
let id_deposit = id_deposit(&ten);
assert_ok!(Identity::set_identity(RuntimeOrigin::signed(10), Box::new(ten)));
assert_noop!(Identity::kill_identity(RuntimeOrigin::signed(1), 10), BadOrigin);
assert_ok!(Identity::kill_identity(RuntimeOrigin::signed(2), 10));
assert_eq!(Identity::identity(10), None);
assert_eq!(Balances::free_balance(10), 90);
assert_eq!(Balances::free_balance(10), 1000 - id_deposit);
assert_noop!(
Identity::kill_identity(RuntimeOrigin::signed(2), 10),
Error::<Test>::NotNamed
@@ -422,38 +454,43 @@ fn killing_slashing_should_work() {
#[test]
fn setting_subaccounts_should_work() {
new_test_ext().execute_with(|| {
let ten = ten();
let id_deposit = id_deposit(&ten);
let sub_deposit: u64 = <<Test as Config>::SubAccountDeposit as Get<u64>>::get();
let mut subs = vec![(20, Data::Raw(vec![40; 1].try_into().unwrap()))];
assert_noop!(
Identity::set_subs(RuntimeOrigin::signed(10), subs.clone()),
Error::<Test>::NotFound
);
assert_ok!(Identity::set_identity(RuntimeOrigin::signed(10), Box::new(ten())));
assert_ok!(Identity::set_identity(RuntimeOrigin::signed(10), Box::new(ten)));
assert_eq!(Balances::free_balance(10), 1000 - id_deposit);
assert_ok!(Identity::set_subs(RuntimeOrigin::signed(10), subs.clone()));
assert_eq!(Balances::free_balance(10), 80);
assert_eq!(Identity::subs_of(10), (10, vec![20].try_into().unwrap()));
assert_eq!(Balances::free_balance(10), 1000 - id_deposit - sub_deposit);
assert_eq!(Identity::subs_of(10), (sub_deposit, vec![20].try_into().unwrap()));
assert_eq!(Identity::super_of(20), Some((10, Data::Raw(vec![40; 1].try_into().unwrap()))));
// push another item and re-set it.
subs.push((30, Data::Raw(vec![50; 1].try_into().unwrap())));
assert_ok!(Identity::set_subs(RuntimeOrigin::signed(10), subs.clone()));
assert_eq!(Balances::free_balance(10), 70);
assert_eq!(Identity::subs_of(10), (20, vec![20, 30].try_into().unwrap()));
assert_eq!(Balances::free_balance(10), 1000 - id_deposit - 2 * sub_deposit);
assert_eq!(Identity::subs_of(10), (2 * sub_deposit, vec![20, 30].try_into().unwrap()));
assert_eq!(Identity::super_of(20), Some((10, Data::Raw(vec![40; 1].try_into().unwrap()))));
assert_eq!(Identity::super_of(30), Some((10, Data::Raw(vec![50; 1].try_into().unwrap()))));
// switch out one of the items and re-set.
subs[0] = (40, Data::Raw(vec![60; 1].try_into().unwrap()));
assert_ok!(Identity::set_subs(RuntimeOrigin::signed(10), subs.clone()));
assert_eq!(Balances::free_balance(10), 70); // no change in the balance
assert_eq!(Identity::subs_of(10), (20, vec![40, 30].try_into().unwrap()));
// no change in the balance
assert_eq!(Balances::free_balance(10), 1000 - id_deposit - 2 * sub_deposit);
assert_eq!(Identity::subs_of(10), (2 * sub_deposit, vec![40, 30].try_into().unwrap()));
assert_eq!(Identity::super_of(20), None);
assert_eq!(Identity::super_of(30), Some((10, Data::Raw(vec![50; 1].try_into().unwrap()))));
assert_eq!(Identity::super_of(40), Some((10, Data::Raw(vec![60; 1].try_into().unwrap()))));
// clear
assert_ok!(Identity::set_subs(RuntimeOrigin::signed(10), vec![]));
assert_eq!(Balances::free_balance(10), 90);
assert_eq!(Balances::free_balance(10), 1000 - id_deposit);
assert_eq!(Identity::subs_of(10), (0, BoundedVec::default()));
assert_eq!(Identity::super_of(30), None);
assert_eq!(Identity::super_of(40), None);
@@ -469,13 +506,15 @@ fn setting_subaccounts_should_work() {
#[test]
fn clearing_account_should_remove_subaccounts_and_refund() {
new_test_ext().execute_with(|| {
assert_ok!(Identity::set_identity(RuntimeOrigin::signed(10), Box::new(ten())));
let ten = ten();
assert_ok!(Identity::set_identity(RuntimeOrigin::signed(10), Box::new(ten.clone())));
assert_eq!(Balances::free_balance(10), 1000 - id_deposit(&ten));
assert_ok!(Identity::set_subs(
RuntimeOrigin::signed(10),
vec![(20, Data::Raw(vec![40; 1].try_into().unwrap()))]
));
assert_ok!(Identity::clear_identity(RuntimeOrigin::signed(10)));
assert_eq!(Balances::free_balance(10), 100);
assert_eq!(Balances::free_balance(10), 1000);
assert!(Identity::super_of(20).is_none());
});
}
@@ -483,13 +522,18 @@ fn clearing_account_should_remove_subaccounts_and_refund() {
#[test]
fn killing_account_should_remove_subaccounts_and_not_refund() {
new_test_ext().execute_with(|| {
assert_ok!(Identity::set_identity(RuntimeOrigin::signed(10), Box::new(ten())));
let ten = ten();
let id_deposit = id_deposit(&ten);
let sub_deposit: u64 = <<Test as Config>::SubAccountDeposit as Get<u64>>::get();
assert_ok!(Identity::set_identity(RuntimeOrigin::signed(10), Box::new(ten)));
assert_eq!(Balances::free_balance(10), 1000 - id_deposit);
assert_ok!(Identity::set_subs(
RuntimeOrigin::signed(10),
vec![(20, Data::Raw(vec![40; 1].try_into().unwrap()))]
));
assert_eq!(Balances::free_balance(10), 1000 - id_deposit - sub_deposit);
assert_ok!(Identity::kill_identity(RuntimeOrigin::signed(2), 10));
assert_eq!(Balances::free_balance(10), 80);
assert_eq!(Balances::free_balance(10), 1000 - id_deposit - sub_deposit);
assert!(Identity::super_of(20).is_none());
});
}
@@ -503,10 +547,12 @@ fn cancelling_requested_judgement_should_work() {
Identity::cancel_request(RuntimeOrigin::signed(10), 0),
Error::<Test>::NoIdentity
);
assert_ok!(Identity::set_identity(RuntimeOrigin::signed(10), Box::new(ten())));
let ten = ten();
assert_ok!(Identity::set_identity(RuntimeOrigin::signed(10), Box::new(ten.clone())));
assert_eq!(Balances::free_balance(10), 1000 - id_deposit(&ten));
assert_ok!(Identity::request_judgement(RuntimeOrigin::signed(10), 0, 10));
assert_ok!(Identity::cancel_request(RuntimeOrigin::signed(10), 0));
assert_eq!(Balances::free_balance(10), 90);
assert_eq!(Balances::free_balance(10), 1000 - id_deposit(&ten));
assert_noop!(
Identity::cancel_request(RuntimeOrigin::signed(10), 0),
Error::<Test>::NotFound
@@ -517,7 +563,7 @@ fn cancelling_requested_judgement_should_work() {
0,
10,
Judgement::Reasonable,
BlakeTwo256::hash_of(&ten())
BlakeTwo256::hash_of(&ten)
));
assert_noop!(
Identity::cancel_request(RuntimeOrigin::signed(10), 0),
@@ -531,14 +577,17 @@ fn requesting_judgement_should_work() {
new_test_ext().execute_with(|| {
assert_ok!(Identity::add_registrar(RuntimeOrigin::signed(1), 3));
assert_ok!(Identity::set_fee(RuntimeOrigin::signed(3), 0, 10));
assert_ok!(Identity::set_identity(RuntimeOrigin::signed(10), Box::new(ten())));
let ten = ten();
let id_deposit = id_deposit(&ten);
assert_ok!(Identity::set_identity(RuntimeOrigin::signed(10), Box::new(ten.clone())));
assert_eq!(Balances::free_balance(10), 1000 - id_deposit);
assert_noop!(
Identity::request_judgement(RuntimeOrigin::signed(10), 0, 9),
Error::<Test>::FeeChanged
);
assert_ok!(Identity::request_judgement(RuntimeOrigin::signed(10), 0, 10));
// 10 for the judgement request, 10 for the identity.
assert_eq!(Balances::free_balance(10), 80);
// 10 for the judgement request and the deposit for the identity.
assert_eq!(Balances::free_balance(10), 1000 - id_deposit - 10);
// Re-requesting won't work as we already paid.
assert_noop!(
@@ -550,10 +599,11 @@ fn requesting_judgement_should_work() {
0,
10,
Judgement::Erroneous,
BlakeTwo256::hash_of(&ten())
BlakeTwo256::hash_of(&ten)
));
// Registrar got their payment now.
assert_eq!(Balances::free_balance(3), 20);
// 100 initial balance and 10 for the judgement.
assert_eq!(Balances::free_balance(3), 100 + 10);
// Re-requesting still won't work as it's erroneous.
assert_noop!(
@@ -571,7 +621,7 @@ fn requesting_judgement_should_work() {
0,
10,
Judgement::OutOfDate,
BlakeTwo256::hash_of(&ten())
BlakeTwo256::hash_of(&ten)
));
assert_ok!(Identity::request_judgement(RuntimeOrigin::signed(10), 0, 10));
});
@@ -580,12 +630,14 @@ fn requesting_judgement_should_work() {
#[test]
fn provide_judgement_should_return_judgement_payment_failed_error() {
new_test_ext().execute_with(|| {
let ten = ten();
let id_deposit = id_deposit(&ten);
assert_ok!(Identity::add_registrar(RuntimeOrigin::signed(1), 3));
assert_ok!(Identity::set_fee(RuntimeOrigin::signed(3), 0, 10));
assert_ok!(Identity::set_identity(RuntimeOrigin::signed(10), Box::new(ten())));
assert_ok!(Identity::set_identity(RuntimeOrigin::signed(10), Box::new(ten.clone())));
assert_ok!(Identity::request_judgement(RuntimeOrigin::signed(10), 0, 10));
// 10 for the judgement request, 10 for the identity.
assert_eq!(Balances::free_balance(10), 80);
// 10 for the judgement request and the deposit for the identity.
assert_eq!(Balances::free_balance(10), 1000 - id_deposit - 10);
// This forces judgement payment failed error
Balances::make_free_balance_be(&3, 0);
@@ -595,7 +647,7 @@ fn provide_judgement_should_return_judgement_payment_failed_error() {
0,
10,
Judgement::Erroneous,
BlakeTwo256::hash_of(&ten())
BlakeTwo256::hash_of(&ten)
),
Error::<Test>::JudgementPaymentFailed
);
@@ -607,25 +659,24 @@ fn field_deposit_should_work() {
new_test_ext().execute_with(|| {
assert_ok!(Identity::add_registrar(RuntimeOrigin::signed(1), 3));
assert_ok!(Identity::set_fee(RuntimeOrigin::signed(3), 0, 10));
assert_ok!(Identity::set_identity(
RuntimeOrigin::signed(10),
Box::new(IdentityInfo {
additional: vec![
(
Data::Raw(b"number".to_vec().try_into().unwrap()),
Data::Raw(10u32.encode().try_into().unwrap())
),
(
Data::Raw(b"text".to_vec().try_into().unwrap()),
Data::Raw(b"10".to_vec().try_into().unwrap())
),
]
.try_into()
.unwrap(),
..Default::default()
})
));
assert_eq!(Balances::free_balance(10), 70);
let id = IdentityInfo {
additional: vec![
(
Data::Raw(b"number".to_vec().try_into().unwrap()),
Data::Raw(10u32.encode().try_into().unwrap()),
),
(
Data::Raw(b"text".to_vec().try_into().unwrap()),
Data::Raw(b"10".to_vec().try_into().unwrap()),
),
]
.try_into()
.unwrap(),
..Default::default()
};
let id_deposit = id_deposit(&id);
assert_ok!(Identity::set_identity(RuntimeOrigin::signed(10), Box::new(id)));
assert_eq!(Balances::free_balance(10), 1000 - id_deposit);
});
}
@@ -649,17 +700,15 @@ fn setting_account_id_should_work() {
fn test_has_identity() {
new_test_ext().execute_with(|| {
assert_ok!(Identity::set_identity(RuntimeOrigin::signed(10), Box::new(ten())));
assert!(Identity::has_identity(&10, SimpleIdentityField::Display as u64));
assert!(Identity::has_identity(&10, SimpleIdentityField::Legal as u64));
assert!(Identity::has_identity(&10, IdentityField::Display as u64));
assert!(Identity::has_identity(&10, IdentityField::Legal as u64));
assert!(Identity::has_identity(
&10,
SimpleIdentityField::Display as u64 | SimpleIdentityField::Legal as u64
IdentityField::Display as u64 | IdentityField::Legal as u64
));
assert!(!Identity::has_identity(
&10,
SimpleIdentityField::Display as u64 |
SimpleIdentityField::Legal as u64 |
SimpleIdentityField::Web as u64
IdentityField::Display as u64 | IdentityField::Legal as u64 | IdentityField::Web as u64
));
});
}