Skip to content
Snippets Groups Projects
Commit 33060a55 authored by Pascal Engélibert's avatar Pascal Engélibert :bicyclist:
Browse files

Disable UD for non-members at genesis (!304)

* use FirstEligibleUd::min

* Fix UD eligibility at genesis

* end2end: non-member idty has UD at genesis
parent b5630b24
No related branches found
No related tags found
1 merge request!304Disable UD for non-members at genesis
Pipeline #39524 passed
@genesis.wot
Feature: Universal Dividend
Scenario: Eligibility at genesis
When 2 blocks later
# Members
Then alice should be eligible to UD
Then bob should be eligible to UD
Then charlie should be eligible to UD
# Not members
Then eve should not be eligible to UD
Then ferdie should not be eligible to UD
......@@ -59,6 +59,31 @@
"membership_revokes_on": 2700000001,
"revoked": false,
"next_cert_issuable_on": 0
},
"Eve": {
"index": 5,
"balance": 1000,
"certs_received": {
"Alice": 2700000000,
"Bob": 2700000000
},
"owner_address": "5HGjWAeFDfFCWPsjFQdVV2Msvz2XtMktvgocEZcCj68kUMaw",
"membership_expire_on": 2700000000,
"membership_revokes_on": 2700000001,
"revoked": true,
"next_cert_issuable_on": 0
},
"Ferdie": {
"index": 6,
"balance": 1000,
"certs_received": {
"Alice": 2700000000
},
"owner_address": "5CiPPseXPECbkjWCa6MnjNokrgYjMqmKndv2rSnekmSK2DjL",
"membership_expire_on": 2700000000,
"membership_revokes_on": 2700000001,
"revoked": false,
"next_cert_issuable_on": 0
}
},
"parameters": {
......@@ -99,7 +124,7 @@
],
"treasury_funder_pubkey": "FHNpKmJrUtusuvKPGomAygQqeiks98bdV6yD61Stb6vg",
"ud": 1000,
"initial_monetary_mass": 4000,
"initial_monetary_mass": 6000,
"current_block": {
"number": 0,
"medianTime": 1700000000
......
......@@ -526,6 +526,26 @@ async fn should_be_certified_by(
}
}
#[then(regex = r"([a-zA-Z]+) should (not )?be eligible to UD")]
async fn should_be_eligible_to_ud(
world: &mut DuniterWorld,
identity: String,
not: String,
) -> Result<()> {
let eligible = not.is_empty();
assert_eq!(
identity::get_identity_value(world, identity)
.await
.expect("Identity not found")
.data
.first_eligible_ud
!= 0,
eligible
);
Ok(())
}
use gdev::runtime_types::pallet_identity::types::IdtyStatus;
// status from string
......
......@@ -198,7 +198,14 @@ fn genesis_data_to_g1_genesis_conf(
index: idty_index,
name: common_runtime::IdtyName::from(name.as_str()),
value: common_runtime::IdtyValue {
data: IdtyData::new(),
data: IdtyData {
first_eligible_ud: match status {
// Only members are eligible to UD.
// The first claimable UD has the minimum index (1).
common_runtime::IdtyStatus::Member => g1_runtime::pallet_universal_dividend::FirstEligibleUd::min(),
_ => g1_runtime::pallet_universal_dividend::FirstEligibleUd(None),
}
},
next_creatable_identity_on: 0,
old_owner_key: None,
owner_key,
......
......@@ -286,7 +286,14 @@ fn genesis_data_to_gdev_genesis_conf(
index: idty_index,
name: common_runtime::IdtyName::from(name.as_str()),
value: common_runtime::IdtyValue {
data: IdtyData::new(),
data: IdtyData {
first_eligible_ud: match status {
// Only members are eligible to UD.
// The first claimable UD has the minimum index (1).
common_runtime::IdtyStatus::Member => gdev_runtime::pallet_universal_dividend::FirstEligibleUd::min(),
_ => gdev_runtime::pallet_universal_dividend::FirstEligibleUd(None),
}
},
next_creatable_identity_on: 0,
old_owner_key: None,
owner_key,
......
......@@ -291,7 +291,14 @@ fn genesis_data_to_gtest_genesis_conf(
index: idty_index,
name: common_runtime::IdtyName::from(name.as_str()),
value: common_runtime::IdtyValue {
data: IdtyData::new(),
data: IdtyData {
first_eligible_ud: match status {
// Only members are eligible to UD.
// The first claimable UD has the minimum index (1).
common_runtime::IdtyStatus::Member => gtest_runtime::pallet_universal_dividend::FirstEligibleUd::min(),
_ => gtest_runtime::pallet_universal_dividend::FirstEligibleUd(None),
}
},
next_creatable_identity_on: 0,
old_owner_key: None,
owner_key,
......
......@@ -22,10 +22,18 @@ use sp_runtime::RuntimeDebug;
pub type UdIndex = u16;
/// Represents the first eligible Universal Dividend.
#[derive(Clone, Default, Eq, PartialEq, RuntimeDebug, serde::Deserialize, serde::Serialize)]
#[derive(Clone, Eq, PartialEq, RuntimeDebug, serde::Deserialize, serde::Serialize)]
pub struct FirstEligibleUd(pub Option<NonZeroU16>);
/// Default is not eligible
impl Default for FirstEligibleUd {
fn default() -> Self {
FirstEligibleUd(None)
}
}
impl FirstEligibleUd {
/// Eligible at the first UD index
pub fn min() -> Self {
Self(Some(NonZeroU16::new(1).expect("unreachable")))
}
......
......@@ -53,15 +53,6 @@ pub struct IdtyData {
pub first_eligible_ud: pallet_universal_dividend::FirstEligibleUd,
}
#[cfg(feature = "std")]
impl IdtyData {
pub fn new() -> Self {
Self {
first_eligible_ud: pallet_universal_dividend::FirstEligibleUd::min(),
}
}
}
impl From<IdtyData> for pallet_universal_dividend::FirstEligibleUd {
fn from(idty_data: IdtyData) -> Self {
idty_data.first_eligible_ud
......
......@@ -223,7 +223,9 @@ impl ExtBuilder {
index: i as u32 + 1,
name: name.clone(),
value: IdtyValue {
data: IdtyData::new(),
data: IdtyData {
first_eligible_ud: pallet_universal_dividend::FirstEligibleUd::min(),
},
next_creatable_identity_on: Default::default(),
owner_key: owner_key.clone(),
old_owner_key: None,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment