Skip to content

Commit fe879a5

Browse files
Omit logos for CreateServiceNervousSystem proposals
1 parent 6e08b0b commit fe879a5

File tree

3 files changed

+380
-221
lines changed

3 files changed

+380
-221
lines changed

rs/nns/governance/src/pb/conversions/mod.rs

Lines changed: 0 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
use crate::pb::proposal_conversions::{ProposalDisplayOptions, convert_proposal};
22
use crate::pb::v1 as pb;
33

4-
use candid::{Int, Nat};
54
use ic_crypto_sha2::Sha256;
65
use ic_nns_governance_api as pb_api;
76
use ic_protobuf::registry::replica_version::v1::{
87
GuestLaunchMeasurement as PbGuestLaunchMeasurement,
98
GuestLaunchMeasurementMetadata as PbGuestLaunchMeasurementMetadata,
109
GuestLaunchMeasurements as PbGuestLaunchMeasurements,
1110
};
12-
use std::collections::HashMap;
1311

1412
#[cfg(test)]
1513
mod tests;
@@ -4176,76 +4174,3 @@ impl From<pb::MaturityDisbursement> for pb_api::MaturityDisbursement {
41764174
}
41774175
}
41784176
}
4179-
4180-
impl From<pb::SelfDescribingValue> for pb_api::SelfDescribingValue {
4181-
fn from(item: pb::SelfDescribingValue) -> Self {
4182-
let Some(value) = item.value else {
4183-
return Self::Map(HashMap::new());
4184-
};
4185-
match value {
4186-
pb::self_describing_value::Value::Blob(v) => Self::Blob(v),
4187-
pb::self_describing_value::Value::Text(v) => Self::Text(v),
4188-
pb::self_describing_value::Value::Nat(v) => {
4189-
let nat = Nat::decode(&mut v.as_slice()).unwrap();
4190-
Self::Nat(nat)
4191-
}
4192-
pb::self_describing_value::Value::Int(v) => {
4193-
let int = Int::decode(&mut v.as_slice()).unwrap();
4194-
Self::Int(int)
4195-
}
4196-
pb::self_describing_value::Value::Array(v) => {
4197-
Self::Array(v.values.into_iter().map(Self::from).collect())
4198-
}
4199-
pb::self_describing_value::Value::Map(v) => Self::Map(
4200-
v.values
4201-
.into_iter()
4202-
.map(|(k, v)| (k, Self::from(v)))
4203-
.collect(),
4204-
),
4205-
pb::self_describing_value::Value::Null(_) => Self::Null,
4206-
}
4207-
}
4208-
}
4209-
4210-
impl From<pb_api::SelfDescribingValue> for pb::SelfDescribingValue {
4211-
fn from(item: pb_api::SelfDescribingValue) -> Self {
4212-
let value = match item {
4213-
pb_api::SelfDescribingValue::Blob(v) => pb::self_describing_value::Value::Blob(v),
4214-
pb_api::SelfDescribingValue::Text(v) => pb::self_describing_value::Value::Text(v),
4215-
pb_api::SelfDescribingValue::Nat(v) => {
4216-
let mut bytes = Vec::new();
4217-
v.encode(&mut bytes).unwrap();
4218-
pb::self_describing_value::Value::Nat(bytes)
4219-
}
4220-
pb_api::SelfDescribingValue::Int(v) => {
4221-
let mut bytes = Vec::new();
4222-
v.encode(&mut bytes).unwrap();
4223-
pb::self_describing_value::Value::Int(bytes)
4224-
}
4225-
pb_api::SelfDescribingValue::Array(v) => {
4226-
pb::self_describing_value::Value::Array(pb::SelfDescribingValueArray {
4227-
values: v.into_iter().map(Self::from).collect(),
4228-
})
4229-
}
4230-
pb_api::SelfDescribingValue::Map(v) => {
4231-
pb::self_describing_value::Value::Map(pb::SelfDescribingValueMap {
4232-
values: v.into_iter().map(|(k, v)| (k, Self::from(v))).collect(),
4233-
})
4234-
}
4235-
pb_api::SelfDescribingValue::Null => {
4236-
pb::self_describing_value::Value::Null(pb::Empty {})
4237-
}
4238-
};
4239-
Self { value: Some(value) }
4240-
}
4241-
}
4242-
4243-
impl From<pb::SelfDescribingProposalAction> for pb_api::SelfDescribingProposalAction {
4244-
fn from(item: pb::SelfDescribingProposalAction) -> Self {
4245-
Self {
4246-
type_name: Some(item.type_name),
4247-
type_description: Some(item.type_description),
4248-
value: item.value.map(pb_api::SelfDescribingValue::from),
4249-
}
4250-
}
4251-
}
Lines changed: 1 addition & 143 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
use super::*;
2-
use candid::{Int, Nat};
2+
33
use ic_base_types::PrincipalId;
44
use icp_ledger::protobuf::AccountIdentifier;
5-
use maplit::hashmap;
65

76
#[test]
87
fn test_node_provider_conversions_always_create_32_byte_account_identifier() {
@@ -130,144 +129,3 @@ fn test_reward_to_account_invalid_account_identifier_just_return_what_is_stored(
130129
icp_ledger::AccountIdentifier::try_from(&converted_reward_to_account.to_account.unwrap())
131130
.expect_err("Should fail!");
132131
}
133-
134-
#[test]
135-
fn test_value_conversions() {
136-
// Prepare test data for all value types
137-
let nat_value = Nat::from(12345u64);
138-
let int_value = Int::from(-9876i64);
139-
140-
// Encode Nat and Int to bytes
141-
let mut nat_bytes = Vec::new();
142-
nat_value.encode(&mut nat_bytes).unwrap();
143-
144-
let mut int_bytes = Vec::new();
145-
int_value.encode(&mut int_bytes).unwrap();
146-
147-
// Create a comprehensive map with all possible SelfDescribingValue types
148-
let value_pb = pb::SelfDescribingValue {
149-
value: Some(pb::self_describing_value::Value::Map(
150-
pb::SelfDescribingValueMap {
151-
values: hashmap! {
152-
// Test Text type
153-
"text_field".to_string() => pb::SelfDescribingValue {
154-
value: Some(pb::self_describing_value::Value::Text("some text".to_string())),
155-
},
156-
// Test Blob type
157-
"blob_field".to_string() => pb::SelfDescribingValue {
158-
value: Some(pb::self_describing_value::Value::Blob(vec![1, 2, 3, 4, 5])),
159-
},
160-
// Test Nat type
161-
"nat_field".to_string() => pb::SelfDescribingValue {
162-
value: Some(pb::self_describing_value::Value::Nat(nat_bytes.clone())),
163-
},
164-
// Test Int type
165-
"int_field".to_string() => pb::SelfDescribingValue {
166-
value: Some(pb::self_describing_value::Value::Int(int_bytes.clone())),
167-
},
168-
// Test Array type with various elements
169-
"array_field".to_string() => pb::SelfDescribingValue {
170-
value: Some(pb::self_describing_value::Value::Array(pb::SelfDescribingValueArray {
171-
values: vec![
172-
pb::SelfDescribingValue {
173-
value: Some(pb::self_describing_value::Value::Text("first".to_string())),
174-
},
175-
pb::SelfDescribingValue {
176-
value: Some(pb::self_describing_value::Value::Text("second".to_string())),
177-
},
178-
pb::SelfDescribingValue {
179-
value: Some(pb::self_describing_value::Value::Blob(vec![10, 20, 30])),
180-
},
181-
],
182-
})),
183-
},
184-
// Test nested Map type
185-
"nested_map_field".to_string() => pb::SelfDescribingValue {
186-
value: Some(pb::self_describing_value::Value::Map(pb::SelfDescribingValueMap {
187-
values: hashmap! {
188-
"nested_text".to_string() => pb::SelfDescribingValue {
189-
value: Some(pb::self_describing_value::Value::Text("nested value".to_string())),
190-
},
191-
"nested_blob".to_string() => pb::SelfDescribingValue {
192-
value: Some(pb::self_describing_value::Value::Blob(vec![255, 254, 253])),
193-
},
194-
"nested_nat".to_string() => pb::SelfDescribingValue {
195-
value: Some(pb::self_describing_value::Value::Nat(nat_bytes.clone())),
196-
},
197-
},
198-
})),
199-
},
200-
// Test empty Array
201-
"empty_array_field".to_string() => pb::SelfDescribingValue {
202-
value: Some(pb::self_describing_value::Value::Array(pb::SelfDescribingValueArray {
203-
values: vec![],
204-
})),
205-
},
206-
// Test empty Map
207-
"empty_map_field".to_string() => pb::SelfDescribingValue {
208-
value: Some(pb::self_describing_value::Value::Map(pb::SelfDescribingValueMap {
209-
values: hashmap! {},
210-
})),
211-
},
212-
// Test Array containing Maps
213-
"array_of_maps_field".to_string() => pb::SelfDescribingValue {
214-
value: Some(pb::self_describing_value::Value::Array(pb::SelfDescribingValueArray {
215-
values: vec![
216-
pb::SelfDescribingValue {
217-
value: Some(pb::self_describing_value::Value::Map(pb::SelfDescribingValueMap {
218-
values: hashmap! {
219-
"key1".to_string() => pb::SelfDescribingValue {
220-
value: Some(pb::self_describing_value::Value::Text("value1".to_string())),
221-
},
222-
},
223-
})),
224-
},
225-
pb::SelfDescribingValue {
226-
value: Some(pb::self_describing_value::Value::Map(pb::SelfDescribingValueMap {
227-
values: hashmap! {
228-
"key2".to_string() => pb::SelfDescribingValue {
229-
value: Some(pb::self_describing_value::Value::Text("value2".to_string())),
230-
},
231-
},
232-
})),
233-
},
234-
],
235-
})),
236-
},
237-
},
238-
},
239-
)),
240-
};
241-
242-
let value_pb_api = pb_api::SelfDescribingValue::from(value_pb);
243-
244-
assert_eq!(
245-
value_pb_api,
246-
pb_api::SelfDescribingValue::Map(hashmap! {
247-
"text_field".to_string() => pb_api::SelfDescribingValue::Text("some text".to_string()),
248-
"blob_field".to_string() => pb_api::SelfDescribingValue::Blob(vec![1, 2, 3, 4, 5]),
249-
"nat_field".to_string() => pb_api::SelfDescribingValue::Nat(nat_value.clone()),
250-
"int_field".to_string() => pb_api::SelfDescribingValue::Int(int_value.clone()),
251-
"array_field".to_string() => pb_api::SelfDescribingValue::Array(vec![
252-
pb_api::SelfDescribingValue::Text("first".to_string()),
253-
pb_api::SelfDescribingValue::Text("second".to_string()),
254-
pb_api::SelfDescribingValue::Blob(vec![10, 20, 30]),
255-
]),
256-
"nested_map_field".to_string() => pb_api::SelfDescribingValue::Map(hashmap! {
257-
"nested_text".to_string() => pb_api::SelfDescribingValue::Text("nested value".to_string()),
258-
"nested_blob".to_string() => pb_api::SelfDescribingValue::Blob(vec![255, 254, 253]),
259-
"nested_nat".to_string() => pb_api::SelfDescribingValue::Nat(nat_value.clone()),
260-
}),
261-
"empty_array_field".to_string() => pb_api::SelfDescribingValue::Array(vec![]),
262-
"empty_map_field".to_string() => pb_api::SelfDescribingValue::Map(hashmap! {}),
263-
"array_of_maps_field".to_string() => pb_api::SelfDescribingValue::Array(vec![
264-
pb_api::SelfDescribingValue::Map(hashmap! {
265-
"key1".to_string() => pb_api::SelfDescribingValue::Text("value1".to_string()),
266-
}),
267-
pb_api::SelfDescribingValue::Map(hashmap! {
268-
"key2".to_string() => pb_api::SelfDescribingValue::Text("value2".to_string()),
269-
}),
270-
]),
271-
})
272-
);
273-
}

0 commit comments

Comments
 (0)