diff --git a/end2end-tests/cucumber-features/universal_dividend.feature b/end2end-tests/cucumber-features/universal_dividend.feature new file mode 100644 index 0000000000000000000000000000000000000000..c858c5e1936a4e5a9dff666ceb84d3475ecbfa68 --- /dev/null +++ b/end2end-tests/cucumber-features/universal_dividend.feature @@ -0,0 +1,15 @@ +@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 diff --git a/end2end-tests/cucumber-genesis/wot.json b/end2end-tests/cucumber-genesis/wot.json index 26042cf39ac533154c31b76d3608bc7e0253652a..0bc2d54571b77d96583fcfc0f231576ea5ce33bd 100644 --- a/end2end-tests/cucumber-genesis/wot.json +++ b/end2end-tests/cucumber-genesis/wot.json @@ -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 diff --git a/end2end-tests/tests/cucumber_tests.rs b/end2end-tests/tests/cucumber_tests.rs index 642779ec85b58b5f02da11126586dda095156499..58a532b2d6b1f8bbfe2e59a06123e90528061785 100644 --- a/end2end-tests/tests/cucumber_tests.rs +++ b/end2end-tests/tests/cucumber_tests.rs @@ -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 diff --git a/node/src/chain_spec/g1.rs b/node/src/chain_spec/g1.rs index 8ad20d230ab6f271536fae861681bcc21ab576b4..78f879a8c8e75c9c6775634e93b75560c2477c9e 100644 --- a/node/src/chain_spec/g1.rs +++ b/node/src/chain_spec/g1.rs @@ -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, diff --git a/node/src/chain_spec/gdev.rs b/node/src/chain_spec/gdev.rs index c78154891055aa953851add1c16ab0b668137624..d6ff6806f28d596fb4ef9ce6755dbbc0749668af 100644 --- a/node/src/chain_spec/gdev.rs +++ b/node/src/chain_spec/gdev.rs @@ -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, diff --git a/node/src/chain_spec/gtest.rs b/node/src/chain_spec/gtest.rs index 2b4020664fa5d8cfcc4af95891538a9ac420866d..b80ad714fd552c675bc9bebe9ef9cd0316b07a41 100644 --- a/node/src/chain_spec/gtest.rs +++ b/node/src/chain_spec/gtest.rs @@ -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, diff --git a/pallets/universal-dividend/src/types.rs b/pallets/universal-dividend/src/types.rs index 12fb017cf82de668be51873aa25fe2a1a38e9b0b..b5b5907e6d2663407d07adb933d5f350bf306b44 100644 --- a/pallets/universal-dividend/src/types.rs +++ b/pallets/universal-dividend/src/types.rs @@ -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"))) } diff --git a/runtime/common/src/entities.rs b/runtime/common/src/entities.rs index 4f21fa71b02d2d026b5752f3b3c2fc5d070d412e..8884f399ff9c9867f5619286a8288fad155901e7 100644 --- a/runtime/common/src/entities.rs +++ b/runtime/common/src/entities.rs @@ -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 diff --git a/runtime/gdev/tests/common/mod.rs b/runtime/gdev/tests/common/mod.rs index ae5c557d7b761427cb6455464ba79c151eb6bab4..82b5ade8d586dfb587c83b5ebd850b5d6b303500 100644 --- a/runtime/gdev/tests/common/mod.rs +++ b/runtime/gdev/tests/common/mod.rs @@ -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,