Skip to content

Commit 6e08b0b

Browse files
Self describing action for CreateServiceNervousSystem
1 parent 221cc5a commit 6e08b0b

File tree

5 files changed

+220
-3
lines changed

5 files changed

+220
-3
lines changed

rs/nns/governance/protobuf_generator/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ pub fn generate_prost_files(proto: ProtoPaths<'_>, out: &Path) {
151151
"NeuronsFundEconomics",
152152
"NeuronsFundMatchedFundingCurveCoefficients",
153153
"VotingPowerEconomics",
154+
"CreateServiceNervousSystem",
154155
];
155156
for type_name in self_describing_types {
156157
config.type_attribute(

rs/nns/governance/src/gen/ic_nns_governance.pb.v1.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2238,6 +2238,7 @@ pub struct OpenSnsTokenSwap {
22382238
candid::Deserialize,
22392239
serde::Serialize,
22402240
comparable::Comparable,
2241+
ic_nns_governance_derive_self_describing::SelfDescribing,
22412242
Clone,
22422243
PartialEq,
22432244
::prost::Message,
@@ -2273,6 +2274,7 @@ pub mod create_service_nervous_system {
22732274
candid::Deserialize,
22742275
serde::Serialize,
22752276
comparable::Comparable,
2277+
ic_nns_governance_derive_self_describing::SelfDescribing,
22762278
Clone,
22772279
PartialEq,
22782280
::prost::Message,
@@ -2294,6 +2296,7 @@ pub mod create_service_nervous_system {
22942296
candid::Deserialize,
22952297
serde::Serialize,
22962298
comparable::Comparable,
2299+
ic_nns_governance_derive_self_describing::SelfDescribing,
22972300
Clone,
22982301
PartialEq,
22992302
::prost::Message,
@@ -2310,6 +2313,7 @@ pub mod create_service_nervous_system {
23102313
candid::Deserialize,
23112314
serde::Serialize,
23122315
comparable::Comparable,
2316+
ic_nns_governance_derive_self_describing::SelfDescribing,
23132317
Clone,
23142318
PartialEq,
23152319
::prost::Message,
@@ -2334,6 +2338,7 @@ pub mod create_service_nervous_system {
23342338
candid::Deserialize,
23352339
serde::Serialize,
23362340
comparable::Comparable,
2341+
ic_nns_governance_derive_self_describing::SelfDescribing,
23372342
Clone,
23382343
Copy,
23392344
PartialEq,
@@ -2348,6 +2353,7 @@ pub mod create_service_nervous_system {
23482353
candid::Deserialize,
23492354
serde::Serialize,
23502355
comparable::Comparable,
2356+
ic_nns_governance_derive_self_describing::SelfDescribing,
23512357
Clone,
23522358
Copy,
23532359
PartialEq,
@@ -2363,6 +2369,7 @@ pub mod create_service_nervous_system {
23632369
candid::Deserialize,
23642370
serde::Serialize,
23652371
comparable::Comparable,
2372+
ic_nns_governance_derive_self_describing::SelfDescribing,
23662373
Clone,
23672374
PartialEq,
23682375
::prost::Message,
@@ -2418,6 +2425,7 @@ pub mod create_service_nervous_system {
24182425
candid::Deserialize,
24192426
serde::Serialize,
24202427
comparable::Comparable,
2428+
ic_nns_governance_derive_self_describing::SelfDescribing,
24212429
Clone,
24222430
Copy,
24232431
PartialEq,
@@ -2436,6 +2444,7 @@ pub mod create_service_nervous_system {
24362444
candid::Deserialize,
24372445
serde::Serialize,
24382446
comparable::Comparable,
2447+
ic_nns_governance_derive_self_describing::SelfDescribing,
24392448
Clone,
24402449
PartialEq,
24412450
::prost::Message,
@@ -2457,6 +2466,7 @@ pub mod create_service_nervous_system {
24572466
candid::Deserialize,
24582467
serde::Serialize,
24592468
comparable::Comparable,
2469+
ic_nns_governance_derive_self_describing::SelfDescribing,
24602470
Clone,
24612471
Copy,
24622472
PartialEq,
@@ -2500,6 +2510,7 @@ pub mod create_service_nervous_system {
25002510
candid::Deserialize,
25012511
serde::Serialize,
25022512
comparable::Comparable,
2513+
ic_nns_governance_derive_self_describing::SelfDescribing,
25032514
Clone,
25042515
Copy,
25052516
PartialEq,

rs/nns/governance/src/proposals/create_service_nervous_system.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
use crate::pb::v1::CreateServiceNervousSystem;
1+
use crate::{
2+
pb::v1::{CreateServiceNervousSystem, SelfDescribingValue},
3+
proposals::self_describing::LocallyDescribableProposalAction,
4+
};
5+
26
use ic_nervous_system_proto::pb::v1::{Duration, GlobalTimeOfDay};
37

48
impl CreateServiceNervousSystem {
@@ -24,3 +28,12 @@ impl CreateServiceNervousSystem {
2428
)
2529
}
2630
}
31+
32+
impl LocallyDescribableProposalAction for CreateServiceNervousSystem {
33+
const TYPE_NAME: &'static str = "Create Service Nervous System (SNS)";
34+
const TYPE_DESCRIPTION: &'static str = "Create a new Service Nervous System (SNS).";
35+
36+
fn to_self_describing_value(&self) -> SelfDescribingValue {
37+
SelfDescribingValue::from(self.clone())
38+
}
39+
}

rs/nns/governance/src/proposals/self_describing.rs

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ use crate::pb::v1::{
66

77
use ic_base_types::PrincipalId;
88
use ic_cdk::println;
9-
use ic_nervous_system_proto::pb::v1::{Decimal, Percentage};
9+
use ic_nervous_system_proto::pb::v1::{
10+
Canister, Countries, Decimal, Duration, GlobalTimeOfDay, Image, Percentage, Tokens,
11+
};
1012
use ic_nns_common::pb::v1::{NeuronId, ProposalId};
1113
use icp_ledger::protobuf::AccountIdentifier;
1214
use std::{collections::HashMap, marker::PhantomData};
@@ -321,6 +323,56 @@ where
321323
Value::Int(bytes)
322324
}
323325

326+
impl From<Duration> for SelfDescribingValue {
327+
fn from(value: Duration) -> Self {
328+
let Duration { seconds } = value;
329+
ValueBuilder::new().add_field("seconds", seconds).build()
330+
}
331+
}
332+
333+
impl From<Tokens> for SelfDescribingValue {
334+
fn from(value: Tokens) -> Self {
335+
let Tokens { e8s } = value;
336+
ValueBuilder::new().add_field("e8s", e8s).build()
337+
}
338+
}
339+
340+
impl From<Image> for SelfDescribingValue {
341+
fn from(value: Image) -> Self {
342+
let Image { base64_encoding } = value;
343+
ValueBuilder::new()
344+
.add_field("base64_encoding", base64_encoding)
345+
.build()
346+
}
347+
}
348+
349+
impl From<Countries> for SelfDescribingValue {
350+
fn from(value: Countries) -> Self {
351+
let Countries { iso_codes } = value;
352+
ValueBuilder::new()
353+
.add_field("iso_codes", iso_codes)
354+
.build()
355+
}
356+
}
357+
358+
impl From<GlobalTimeOfDay> for SelfDescribingValue {
359+
fn from(value: GlobalTimeOfDay) -> Self {
360+
let GlobalTimeOfDay {
361+
seconds_after_utc_midnight,
362+
} = value;
363+
ValueBuilder::new()
364+
.add_field("seconds_after_utc_midnight", seconds_after_utc_midnight)
365+
.build()
366+
}
367+
}
368+
369+
impl From<Canister> for SelfDescribingValue {
370+
fn from(value: Canister) -> Self {
371+
let Canister { id } = value;
372+
Self::from(id)
373+
}
374+
}
375+
324376
#[path = "self_describing_tests.rs"]
325377
#[cfg(test)]
326378
pub mod tests;

rs/nns/governance/src/proposals/self_describing_tests.rs

Lines changed: 141 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
use super::*;
22

3-
use crate::pb::v1::{NetworkEconomics, SelfDescribingValue as SelfDescribingValuePb, Topic};
3+
use crate::{
4+
governance::test_data::{CREATE_SERVICE_NERVOUS_SYSTEM, IMAGE_1, IMAGE_2},
5+
pb::v1::{NetworkEconomics, SelfDescribingValue as SelfDescribingValuePb, Topic},
6+
};
47

58
use ic_base_types::PrincipalId;
69
use ic_nns_governance_api::SelfDescribingValue;
@@ -168,6 +171,143 @@ fn test_network_economics_to_self_describing_minimal() {
168171
);
169172
}
170173

174+
#[test]
175+
fn test_create_service_nervous_system_to_self_describing() {
176+
use SelfDescribingValue::*;
177+
178+
assert_proposal_action_self_describing_value_is(
179+
CREATE_SERVICE_NERVOUS_SYSTEM.clone(),
180+
Map(hashmap! {
181+
"name".to_string() => Text("Hello, world!".to_string()),
182+
"description".to_string() => Text("Best app that you ever did saw.".to_string()),
183+
"url".to_string() => Text("https://best.app".to_string()),
184+
"logo".to_string() => Map(hashmap! {
185+
"base64_encoding".to_string() => Text(IMAGE_1.to_string()),
186+
}),
187+
"fallback_controller_principal_ids".to_string() => Array(vec![
188+
Text("iakpb-r4pky-cqaaa-aaaap-4ai".to_string()),
189+
]),
190+
"dapp_canisters".to_string() => Array(vec![
191+
Text("uc7f6-kaaaa-aaaaq-qaaaa-cai".to_string()),
192+
]),
193+
"initial_token_distribution".to_string() => Map(hashmap! {
194+
"developer_distribution".to_string() => Map(hashmap! {
195+
"developer_neurons".to_string() => Array(vec![
196+
Map(hashmap! {
197+
"controller".to_string() => Text("qarve-vpdvu-gaaaa-aaaap-4ai".to_string()),
198+
"dissolve_delay".to_string() => Map(hashmap! {
199+
"seconds".to_string() => Nat(candid::Nat::from(15_778_800_u64)),
200+
}),
201+
"memo".to_string() => Nat(candid::Nat::from(763535_u64)),
202+
"stake".to_string() => Map(hashmap! {
203+
"e8s".to_string() => Nat(candid::Nat::from(756575_u64)),
204+
}),
205+
"vesting_period".to_string() => Map(hashmap! {
206+
"seconds".to_string() => Nat(candid::Nat::from(0_u64)),
207+
}),
208+
}),
209+
]),
210+
}),
211+
"treasury_distribution".to_string() => Map(hashmap! {
212+
"total".to_string() => Map(hashmap! {
213+
"e8s".to_string() => Nat(candid::Nat::from(307064_u64)),
214+
}),
215+
}),
216+
"swap_distribution".to_string() => Map(hashmap! {
217+
"total".to_string() => Map(hashmap! {
218+
"e8s".to_string() => Nat(candid::Nat::from(1_840_880_000_u64)),
219+
}),
220+
}),
221+
}),
222+
"ledger_parameters".to_string() => Map(hashmap! {
223+
"transaction_fee".to_string() => Map(hashmap! {
224+
"e8s".to_string() => Nat(candid::Nat::from(11143_u64)),
225+
}),
226+
"token_name".to_string() => Text("Most valuable SNS of all time.".to_string()),
227+
"token_symbol".to_string() => Text("Kanye".to_string()),
228+
"token_logo".to_string() => Map(hashmap! {
229+
"base64_encoding".to_string() => Text(IMAGE_2.to_string()),
230+
}),
231+
}),
232+
"governance_parameters".to_string() => Map(hashmap! {
233+
"proposal_rejection_fee".to_string() => Map(hashmap! {
234+
"e8s".to_string() => Nat(candid::Nat::from(372250_u64)),
235+
}),
236+
"proposal_initial_voting_period".to_string() => Map(hashmap! {
237+
"seconds".to_string() => Nat(candid::Nat::from(709_499_u64)),
238+
}),
239+
"proposal_wait_for_quiet_deadline_increase".to_string() => Map(hashmap! {
240+
"seconds".to_string() => Nat(candid::Nat::from(75_891_u64)),
241+
}),
242+
"neuron_minimum_stake".to_string() => Map(hashmap! {
243+
"e8s".to_string() => Nat(candid::Nat::from(250_000_u64)),
244+
}),
245+
"neuron_minimum_dissolve_delay_to_vote".to_string() => Map(hashmap! {
246+
"seconds".to_string() => Nat(candid::Nat::from(482538_u64)),
247+
}),
248+
"neuron_maximum_dissolve_delay".to_string() => Map(hashmap! {
249+
"seconds".to_string() => Nat(candid::Nat::from(31_557_600_u64)),
250+
}),
251+
"neuron_maximum_dissolve_delay_bonus".to_string() => Map(hashmap! {
252+
"basis_points".to_string() => Nat(candid::Nat::from(1800_u64)),
253+
}),
254+
"neuron_maximum_age_for_age_bonus".to_string() => Map(hashmap! {
255+
"seconds".to_string() => Nat(candid::Nat::from(740908_u64)),
256+
}),
257+
"neuron_maximum_age_bonus".to_string() => Map(hashmap! {
258+
"basis_points".to_string() => Nat(candid::Nat::from(5400_u64)),
259+
}),
260+
"voting_reward_parameters".to_string() => Map(hashmap! {
261+
"initial_reward_rate".to_string() => Map(hashmap! {
262+
"basis_points".to_string() => Nat(candid::Nat::from(2592_u64)),
263+
}),
264+
"final_reward_rate".to_string() => Map(hashmap! {
265+
"basis_points".to_string() => Nat(candid::Nat::from(740_u64)),
266+
}),
267+
"reward_rate_transition_duration".to_string() => Map(hashmap! {
268+
"seconds".to_string() => Nat(candid::Nat::from(378025_u64)),
269+
}),
270+
}),
271+
}),
272+
"swap_parameters".to_string() => Map(hashmap! {
273+
"minimum_participants".to_string() => Nat(candid::Nat::from(50_u64)),
274+
"minimum_icp".to_string() => Null,
275+
"maximum_icp".to_string() => Null,
276+
"minimum_direct_participation_icp".to_string() => Map(hashmap! {
277+
"e8s".to_string() => Nat(candid::Nat::from(6_200_000_000_u64)),
278+
}),
279+
"maximum_direct_participation_icp".to_string() => Map(hashmap! {
280+
"e8s".to_string() => Nat(candid::Nat::from(18_900_000_000_u64)),
281+
}),
282+
"minimum_participant_icp".to_string() => Map(hashmap! {
283+
"e8s".to_string() => Nat(candid::Nat::from(100_000_000_u64)),
284+
}),
285+
"maximum_participant_icp".to_string() => Map(hashmap! {
286+
"e8s".to_string() => Nat(candid::Nat::from(10_000_000_000_u64)),
287+
}),
288+
"neuron_basket_construction_parameters".to_string() => Map(hashmap! {
289+
"count".to_string() => Nat(candid::Nat::from(2_u64)),
290+
"dissolve_delay_interval".to_string() => Map(hashmap! {
291+
"seconds".to_string() => Nat(candid::Nat::from(10_001_u64)),
292+
}),
293+
}),
294+
"confirmation_text".to_string() => Text("Confirm you are a human".to_string()),
295+
"restricted_countries".to_string() => Map(hashmap! {
296+
"iso_codes".to_string() => Array(vec![Text("CH".to_string())]),
297+
}),
298+
"start_time".to_string() => Map(hashmap! {
299+
"seconds_after_utc_midnight".to_string() => Nat(candid::Nat::from(0_u64)),
300+
}),
301+
"duration".to_string() => Map(hashmap! {
302+
"seconds".to_string() => Nat(candid::Nat::from(604_800_u64)),
303+
}),
304+
"neurons_fund_investment_icp".to_string() => Null,
305+
"neurons_fund_participation".to_string() => Nat(candid::Nat::from(0_u8)),
306+
}),
307+
}),
308+
);
309+
}
310+
171311
// Tests for the SelfDescribing derive macro
172312

173313
/// Test struct with named fields.

0 commit comments

Comments
 (0)