Skip to content

Commit

Permalink
Merge branch 'jason/NNS1-2951-rosetta' into 'master'
Browse files Browse the repository at this point in the history
test: NNS1-2951 Change rosetta tests to set up NNS neurons in valid states

We want 3 invariants to hold for every NNS neuron:

1. Dissolve state always exists
2. For non-dissolving neurons, dissolve delay should be positive (no longer use delay = 0 to represent dissolved neurons)
3. For dissolving neurons, aging_since_timestamp_seconds is u64::MAX

Those are already ensured within the NNS Governance. In this MR we try to change the test setup rosetta_tests so that post_upgrade can fail with bad initial governance state without breaking those tests. 

See merge request dfinity-lab/public/ic!19668
  • Loading branch information
jasonz-dfinity committed Jun 6, 2024
2 parents 1a5b982 + 86360e1 commit dfbc93d
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 19 deletions.
4 changes: 2 additions & 2 deletions rs/tests/src/rosetta_tests/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -624,7 +624,7 @@ pub fn create_custom_neuron(
.to_vec(),
controller: Some(pid),
created_timestamp_seconds,
aging_since_timestamp_seconds: created_timestamp_seconds + 10,
aging_since_timestamp_seconds: u64::MAX,
dissolve_state: Some(DissolveState::WhenDissolvedTimestampSeconds(0)),
cached_neuron_stake_e8s: Tokens::new(10, 0).unwrap().get_e8s(),
kyc_verified: true,
Expand Down Expand Up @@ -673,7 +673,7 @@ pub fn create_neuron(
.to_vec(),
controller: Some(principal_id),
created_timestamp_seconds,
aging_since_timestamp_seconds: created_timestamp_seconds + 10,
aging_since_timestamp_seconds: u64::MAX,
dissolve_state: Some(DissolveState::WhenDissolvedTimestampSeconds(0)),
cached_neuron_stake_e8s: Tokens::new(10, 0).unwrap().get_e8s(),
kyc_verified: true,
Expand Down
18 changes: 10 additions & 8 deletions rs/tests/src/rosetta_tests/tests/neuron_dissolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,23 @@ pub fn test(env: TestEnv) {
let mut ledger_balances = HashMap::new();

// Create neurons.
let one_year_from_now = 60 * 60 * 24 * 365
+ std::time::SystemTime::now()
.duration_since(UNIX_EPOCH)
.unwrap()
.as_secs();
let now = std::time::SystemTime::now()
.duration_since(UNIX_EPOCH)
.unwrap()
.as_secs();
let one_year_from_now = 60 * 60 * 24 * 365 + now;

let mut neurons = TestNeurons::new(2000, &mut ledger_balances);

let neuron1 = neurons.create(|neuron| {
neuron.dissolve_state = Some(DissolveState::DissolveDelaySeconds(one_year_from_now))
neuron.dissolve_state = Some(DissolveState::DissolveDelaySeconds(one_year_from_now));
neuron.aging_since_timestamp_seconds = now;
});
let neuron2 = neurons.create(|neuron| {
neuron.dissolve_state = Some(DissolveState::DissolveDelaySeconds(one_year_from_now))
neuron.dissolve_state = Some(DissolveState::DissolveDelaySeconds(one_year_from_now));
neuron.aging_since_timestamp_seconds = now;
});
let neuron3 = neurons.create(|neuron| neuron.dissolve_state = None);
let neuron3 = neurons.create(|_| {});

// Create Rosetta and ledger clients.
let neurons = neurons.get_neurons();
Expand Down
7 changes: 7 additions & 0 deletions rs/tests/src/rosetta_tests/tests/neuron_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,14 @@ pub fn test(env: TestEnv) {

// Create neurons.
let mut neurons = TestNeurons::new(2000, &mut ledger_balances);
let now = std::time::SystemTime::now()
.duration_since(std::time::UNIX_EPOCH)
.unwrap()
.as_secs();

let neuron1 = neurons.create(|neuron| {
neuron.dissolve_state = Some(DissolveState::DissolveDelaySeconds(2 * 365 * 24 * 60 * 60));
neuron.aging_since_timestamp_seconds = now;
neuron.maturity_e8s_equivalent = 345_000_000;
neuron.kyc_verified = true;
neuron.followees = HashMap::from([
Expand Down Expand Up @@ -65,6 +70,7 @@ pub fn test(env: TestEnv) {
3 * 365 * 24 * 60 * 60,
),
);
neuron.aging_since_timestamp_seconds = now;
neuron.maturity_e8s_equivalent = 678_000_000;
neuron.kyc_verified = true;
neuron.followees = HashMap::from([
Expand Down Expand Up @@ -92,6 +98,7 @@ pub fn test(env: TestEnv) {
3 * 365 * 24 * 60 * 60,
),
);
neuron.aging_since_timestamp_seconds = now;
neuron.maturity_e8s_equivalent = 679_000_000;
neuron.kyc_verified = true;
neuron.followees = HashMap::from([
Expand Down
1 change: 0 additions & 1 deletion rs/tests/src/rosetta_tests/tests/neuron_maturity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ pub fn test(env: TestEnv) {
// Create neurons.
let mut neurons = TestNeurons::new(2000, &mut ledger_balances);
let neuron_setup = |neuron: &mut Neuron| {
neuron.dissolve_state = None;
neuron.maturity_e8s_equivalent = 420_000_000;
};
let neuron1 = neurons.create(neuron_setup);
Expand Down
3 changes: 0 additions & 3 deletions rs/tests/src/rosetta_tests/tests/neuron_spawn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,12 @@ pub fn test(env: TestEnv) {
let mut neurons = TestNeurons::new(2000, &mut ledger_balances);

let neuron1 = neurons.create(|neuron| {
neuron.dissolve_state = None;
neuron.maturity_e8s_equivalent = 500_000_000;
});
let neuron2 = neurons.create(|neuron| {
neuron.dissolve_state = None;
neuron.maturity_e8s_equivalent = 4_000;
});
let neuron3 = neurons.create(|neuron| {
neuron.dissolve_state = None;
neuron.maturity_e8s_equivalent = 500_000_000;
});

Expand Down
12 changes: 7 additions & 5 deletions rs/tests/src/rosetta_tests/tests/neuron_voting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ pub fn test(env: TestEnv) {
let _logger = env.logger();

let mut ledger_balances = HashMap::new();
let one_year_from_now = 60 * 60 * 24 * 365
+ std::time::SystemTime::now()
.duration_since(UNIX_EPOCH)
.unwrap()
.as_secs();
let now = std::time::SystemTime::now()
.duration_since(UNIX_EPOCH)
.unwrap()
.as_secs();
let one_year_from_now = 60 * 60 * 24 * 365 + now;

//We need to know the identity of the agent before we create the neurons.
//The controller of the neuron has to be the agent principal otherwise we cannot make proposals and vote on them.
Expand All @@ -44,6 +44,7 @@ pub fn test(env: TestEnv) {
let mut neurons = TestNeurons::new(2000, &mut ledger_balances);
let neuron_setup = |neuron: &mut Neuron| {
neuron.dissolve_state = Some(DissolveState::DissolveDelaySeconds(one_year_from_now));
neuron.aging_since_timestamp_seconds = now;
neuron.maturity_e8s_equivalent = 420_000_000;
neuron.controller = Some(agent_principal.into());
neuron.account =
Expand All @@ -56,6 +57,7 @@ pub fn test(env: TestEnv) {
//Setup for non proposal making entities
let neuron_setup = |neuron: &mut Neuron| {
neuron.dissolve_state = Some(DissolveState::DissolveDelaySeconds(one_year_from_now));
neuron.aging_since_timestamp_seconds = now;
neuron.maturity_e8s_equivalent = 420_000_000;
};
let neuron2 = neurons.create(neuron_setup);
Expand Down

0 comments on commit dfbc93d

Please sign in to comment.