Skip to content

Commit 2740201

Browse files
Merge branch 'begin-sns-config-v2-daniel-wong' into 'master'
feat: NNS1-1969: Begin SNS config v2. No humanization yet. Fields that require humanization are simply given type String + a comment about the type that's supposed to eventually be there. The overall structure is there, as well as most field names. See merge request dfinity-lab/public/ic!12507
2 parents 95c8415 + 7b06ec0 commit 2740201

File tree

7 files changed

+317
-3
lines changed

7 files changed

+317
-3
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rs/sns/cli/BUILD.bazel

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ DEPENDENCIES = [
2727
"@crate_index//:hex",
2828
"@crate_index//:json-patch",
2929
"@crate_index//:maplit",
30+
"@crate_index//:pretty_assertions",
3031
"@crate_index//:prost",
3132
"@crate_index//:rand_0_8_4",
3233
"@crate_index//:regex",
@@ -47,7 +48,13 @@ ALIASES = {}
4748

4849
rust_library(
4950
name = "cli",
50-
srcs = glob(["src/*.rs"]),
51+
srcs = glob(
52+
["src/**/*.rs"],
53+
exclude = [
54+
"src/**/*_tests.rs",
55+
"main.rs",
56+
],
57+
),
5158
aliases = ALIASES,
5259
crate_name = "ic_sns_cli",
5360
proc_macro_deps = MACRO_DEPENDENCIES,
@@ -57,7 +64,10 @@ rust_library(
5764

5865
rust_binary(
5966
name = "sns",
60-
srcs = glob(["src/*.rs"]),
67+
srcs = glob(
68+
["src/**/*.rs"],
69+
exclude = ["src/**/*_tests.rs"],
70+
),
6171
aliases = ALIASES,
6272
proc_macro_deps = MACRO_DEPENDENCIES,
6373
version = "1.0.0",
@@ -69,7 +79,10 @@ rust_test(
6979
srcs = glob(["src/**"]),
7080
aliases = ALIASES,
7181
crate_root = "src/main.rs",
72-
data = ["test.png"],
82+
data = [
83+
"example_sns_init_v2.yaml",
84+
"test.png",
85+
],
7386
env = {
7487
"CARGO_MANIFEST_DIR": "rs/sns/cli",
7588
},

rs/sns/cli/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ ic-sns-wasm = { path = "../../nns/sns-wasm" }
3434
icp-ledger = { path = "../../rosetta-api/icp_ledger" }
3535
maplit = "1.0.2"
3636
on_wire = { path = "../../rust_canisters/on_wire" }
37+
pretty_assertions = "0.6.1"
3738
prost = "0.11.0"
3839
rand = "0.8"
3940
regex = "1.5.6"

rs/sns/cli/example_sns_init_v2.yaml

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# This is used in a unit test, so if you make non-comment changes, you might
2+
# break the test.
3+
4+
name: Daniel
5+
description: >
6+
The best software engineer you ever did saw.
7+
8+
logo: batman.png
9+
url: https://www.example.com
10+
11+
Principals:
12+
- id: hello-world-big-opaque-blob-here-to-ruin-your-eyes
13+
name: Bruce Wayne
14+
15+
16+
fallback_controller_principals:
17+
- Bruce Wayne
18+
19+
Token:
20+
name: Batman
21+
symbol: BTM
22+
transaction_fee: 10_000 e8s
23+
24+
Proposals:
25+
rejection_fee: 1 token
26+
initial_voting_period: 4d
27+
maximum_wait_for_quiet_deadline_extension: 1 day
28+
29+
Neurons:
30+
minimum_creation_stake: 10 tokens
31+
32+
Voting:
33+
minimum_dissolve_delay: 26 weeks
34+
35+
MaximumVotingPowerBonuses:
36+
DissolveDelay:
37+
duration: 8 years
38+
boost: 100%
39+
40+
Age:
41+
duration: 4 years
42+
boost: 25%
43+
44+
RewardRate:
45+
initial: 10%
46+
final: 2.25%
47+
transition_duration: 12 years
48+
49+
Distribution:
50+
51+
Neurons:
52+
53+
- principal: Bruce Wayne
54+
stake: 15 tokens
55+
memo: 42
56+
dissolve_delay: 0.5 years
57+
58+
- principal: Bruce Wayne
59+
stake: 15 tokens
60+
dissolve_delay: 0.5 years
61+
62+
Balances:
63+
governance: 50 tokens
64+
swap: 30 tokens
65+
66+
# Optional, but highly recommended. This is a literal
67+
# checksum.
68+
total: 95 tokens

rs/sns/cli/src/init_config_file.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ use std::{
1919
str::FromStr,
2020
};
2121

22+
mod friendly;
23+
2224
const DEFAULT_INIT_CONFIG_PATH: &str = "sns_init.yaml";
2325

2426
#[derive(Debug, Parser)]
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
use std::path::PathBuf;
2+
3+
#[derive(serde::Deserialize, serde::Serialize, Debug, PartialEq, Eq)]
4+
#[serde(deny_unknown_fields)]
5+
struct SnsConfigurationFile {
6+
name: String,
7+
description: String,
8+
logo: PathBuf,
9+
url: String,
10+
11+
#[serde(rename = "Principals")]
12+
principals: Vec<PrincipalAlias>,
13+
14+
fallback_controller_principals: Vec<String>,
15+
16+
#[serde(rename = "Token")]
17+
token: Token,
18+
19+
#[serde(rename = "Proposals")]
20+
proposals: Proposals,
21+
22+
#[serde(rename = "Neurons")]
23+
neurons: Neurons,
24+
25+
#[serde(rename = "Voting")]
26+
voting: Voting,
27+
28+
#[serde(rename = "Distribution")]
29+
distribution: Distribution,
30+
}
31+
32+
#[derive(serde::Deserialize, serde::Serialize, Debug, PartialEq, Eq)]
33+
#[serde(deny_unknown_fields)]
34+
struct PrincipalAlias {
35+
id: String,
36+
name: Option<String>,
37+
email: Option<String>,
38+
}
39+
40+
#[derive(serde::Deserialize, serde::Serialize, Debug, PartialEq, Eq)]
41+
#[serde(deny_unknown_fields)]
42+
struct Token {
43+
name: String,
44+
symbol: String,
45+
transaction_fee: String, // Tokens
46+
}
47+
48+
#[derive(serde::Deserialize, serde::Serialize, Debug, PartialEq, Eq)]
49+
#[serde(deny_unknown_fields)]
50+
struct Proposals {
51+
rejection_fee: String, // Tokens
52+
initial_voting_period: String, // Duration
53+
maximum_wait_for_quiet_deadline_extension: String, // Duration
54+
}
55+
56+
#[derive(serde::Deserialize, serde::Serialize, Debug, PartialEq, Eq)]
57+
#[serde(deny_unknown_fields)]
58+
struct Neurons {
59+
minimum_creation_stake: String, // Tokens
60+
}
61+
62+
#[derive(serde::Deserialize, serde::Serialize, Debug, PartialEq, Eq)]
63+
#[serde(deny_unknown_fields)]
64+
struct Voting {
65+
minimum_dissolve_delay: String, // Duration
66+
67+
#[serde(rename = "MaximumVotingPowerBonuses")]
68+
maximum_voting_power_bonuses: MaximumVotingPowerBonuses,
69+
70+
#[serde(rename = "RewardRate")]
71+
reward_rate: RewardRate,
72+
}
73+
74+
#[derive(serde::Deserialize, serde::Serialize, Debug, PartialEq, Eq)]
75+
#[serde(deny_unknown_fields)]
76+
struct MaximumVotingPowerBonuses {
77+
#[serde(rename = "DissolveDelay")]
78+
dissolve_delay: Bonus,
79+
80+
#[serde(rename = "Age")]
81+
age: Bonus,
82+
}
83+
84+
#[derive(serde::Deserialize, serde::Serialize, Debug, PartialEq, Eq)]
85+
#[serde(deny_unknown_fields)]
86+
struct Bonus {
87+
duration: String, // Duration
88+
boost: String, // Percentage
89+
}
90+
91+
#[derive(serde::Deserialize, serde::Serialize, Debug, PartialEq, Eq)]
92+
#[serde(deny_unknown_fields)]
93+
struct RewardRate {
94+
initial: String, // Percentage
95+
r#final: String, // Percentage
96+
transition_duration: String, // Duration
97+
}
98+
99+
#[derive(serde::Deserialize, serde::Serialize, Debug, PartialEq, Eq)]
100+
#[serde(deny_unknown_fields)]
101+
struct Distribution {
102+
#[serde(rename = "Neurons")]
103+
neurons: Vec<Neuron>,
104+
105+
#[serde(rename = "Balances")]
106+
balances: Balances,
107+
108+
total: String, // Tokens
109+
}
110+
111+
#[derive(serde::Deserialize, serde::Serialize, Debug, PartialEq, Eq)]
112+
#[serde(deny_unknown_fields)]
113+
struct Neuron {
114+
principal: String, // Principal (alias)
115+
116+
stake: String, // Tokens
117+
118+
#[serde(default)]
119+
memo: u64,
120+
121+
dissolve_delay: String, // Duration
122+
}
123+
124+
#[derive(serde::Deserialize, serde::Serialize, Debug, PartialEq, Eq)]
125+
#[serde(deny_unknown_fields)]
126+
struct Balances {
127+
governance: String, // Tokens
128+
swap: String, // Tokens
129+
}
130+
131+
#[cfg(test)]
132+
mod friendly_tests;
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
use super::*;
2+
use pretty_assertions::assert_eq;
3+
4+
#[test]
5+
fn test_parse() {
6+
let configuration_file_path = {
7+
let mut result = std::path::PathBuf::from(&std::env::var("CARGO_MANIFEST_DIR").unwrap());
8+
result.push("example_sns_init_v2.yaml");
9+
result
10+
};
11+
let contents = std::fs::read_to_string(configuration_file_path).unwrap();
12+
13+
let observed_sns_configuration_file =
14+
serde_yaml::from_str::<SnsConfigurationFile>(&contents).unwrap();
15+
16+
let expected_sns_configuration_file = SnsConfigurationFile {
17+
name: "Daniel".to_string(),
18+
description: "The best software engineer you ever did saw.\n".to_string(),
19+
logo: PathBuf::from("batman.png"),
20+
url: "https://www.example.com".to_string(),
21+
22+
principals: vec![PrincipalAlias {
23+
id: "hello-world-big-opaque-blob-here-to-ruin-your-eyes".to_string(),
24+
name: Some("Bruce Wayne".to_string()),
25+
email: Some("[email protected]".to_string()),
26+
}],
27+
28+
fallback_controller_principals: vec!["Bruce Wayne".to_string()],
29+
30+
token: Token {
31+
name: "Batman".to_string(),
32+
symbol: "BTM".to_string(),
33+
transaction_fee: "10_000 e8s".to_string(),
34+
},
35+
36+
proposals: Proposals {
37+
rejection_fee: "1 token".to_string(),
38+
initial_voting_period: "4d".to_string(),
39+
maximum_wait_for_quiet_deadline_extension: "1 day".to_string(),
40+
},
41+
42+
neurons: Neurons {
43+
minimum_creation_stake: "10 tokens".to_string(),
44+
},
45+
46+
voting: Voting {
47+
minimum_dissolve_delay: "26 weeks".to_string(),
48+
49+
maximum_voting_power_bonuses: MaximumVotingPowerBonuses {
50+
dissolve_delay: Bonus {
51+
duration: "8 years".to_string(),
52+
boost: "100%".to_string(),
53+
},
54+
55+
age: Bonus {
56+
duration: "4 years".to_string(),
57+
boost: "25%".to_string(),
58+
},
59+
},
60+
61+
reward_rate: RewardRate {
62+
initial: "10%".to_string(),
63+
r#final: "2.25%".to_string(),
64+
transition_duration: "12 years".to_string(),
65+
},
66+
},
67+
68+
distribution: Distribution {
69+
neurons: vec![
70+
Neuron {
71+
principal: "Bruce Wayne".to_string(),
72+
stake: "15 tokens".to_string(),
73+
memo: 42,
74+
dissolve_delay: "0.5 years".to_string(),
75+
},
76+
Neuron {
77+
principal: "Bruce Wayne".to_string(),
78+
stake: "15 tokens".to_string(),
79+
memo: 0, // Not explicitly supplied -> 0 is taken as default.
80+
dissolve_delay: "0.5 years".to_string(),
81+
},
82+
],
83+
84+
balances: Balances {
85+
governance: "50 tokens".to_string(),
86+
swap: "30 tokens".to_string(),
87+
},
88+
89+
total: "95 tokens".to_string(),
90+
},
91+
};
92+
93+
assert_eq!(
94+
observed_sns_configuration_file,
95+
expected_sns_configuration_file,
96+
);
97+
}

0 commit comments

Comments
 (0)