fn compute_maturities(
    stakes_e8s: Vec<u64>,
    proposals: Vec<impl Into<ProposalNeuronBehavior>>,
) -> Vec<u64> {
    let proposals: Vec<ProposalNeuronBehavior> = proposals.into_iter().map(|x| x.into()).collect();

    let mut fake_driver = FakeDriver::default()
        // To make assertion easy to sanity-check, the total supply of ICPs is chosen
        // so that the reward supply for the first day is 100 (365_250 * 10% / 365.25 = 100).
        .with_supply(ICPTs::from_e8s(365_250));

    let fixture = GovernanceProto {
        neurons: stakes_e8s
            .iter()
            .enumerate()
            .map(|(i, stake_e8s)| {
                (
                    i as u64,
                    Neuron {
                        id: Some(NeuronId { id: i as u64 }),
                        controller: Some(principal(i as u64)),
                        cached_neuron_stake_e8s: *stake_e8s,
                        dissolve_state: NOTDISSOLVING_MIN_DISSOLVE_DELAY_TO_VOTE,
                        account: fake_driver.get_fake_env().random_byte_array().to_vec(),
                        ..Default::default()
                    },
                )
            })
            .collect(),
        wait_for_quiet_threshold_seconds: 1,
        economics: Some(NetworkEconomics::default()),
        ..Default::default()
    };

    let mut gov = Governance::new(
        fixture,
        fake_driver.get_fake_env(),
        fake_driver.get_fake_ledger(),
    );

    let expected_initial_event = RewardEvent {
        day_after_genesis: 0,
        actual_timestamp_seconds: DEFAULT_TEST_START_TIMESTAMP_SECONDS,
        settled_proposals: vec![],
        distributed_e8s_equivalent: 0,
    };

    assert_eq!(*gov.latest_reward_event(), expected_initial_event);

    for (i, behavior) in (1_u64..).zip(proposals.iter()) {
        behavior.propose_and_vote(&mut gov, format!("proposal {}", i));
    }

    // Let's advance time by one reward periods. All proposals should be considered
    // for reward.
    fake_driver.advance_time_by(REWARD_DISTRIBUTION_PERIOD_SECONDS);
    gov.run_periodic_tasks().now_or_never();
    let actual_reward_event = gov.latest_reward_event();
    assert_eq!(
        *actual_reward_event,
        RewardEvent {
            day_after_genesis: 1,
            actual_timestamp_seconds: DEFAULT_TEST_START_TIMESTAMP_SECONDS
                + REWARD_DISTRIBUTION_PERIOD_SECONDS,
            settled_proposals: (1_u64..1 + proposals.len() as u64)
                .map(|id| ProposalId { id })
                .collect(),
            // Don't assert on distributed_e8s_equivalent here -- the assertions
            // is the job of the caller
            distributed_e8s_equivalent: actual_reward_event.distributed_e8s_equivalent,
        }
    );

    (0_u64..stakes_e8s.len() as u64)
        .map(|id| {
            gov.get_neuron(&NeuronId { id })
                .unwrap()
                .maturity_e8s_equivalent
        })
        .collect()
}
/// Test helper where several proposals are created and voted on by various
/// neurons. The final maturities are returned.
///
/// In this test, all proposals last 1 second, which is smaller than the reward
/// period. This allows to have tests where everything interesting happens in
/// the first reward period.
Test helper where several proposals are created and voted on by various
neurons. The final maturities are returned.

In this test, all proposals last 1 second, which is smaller than the reward
period. This allows to have tests where everything interesting happens in
the first reward period.
Test helper where several proposals are created and voted on by various neurons . The final maturities are returned . In this test all proposals last 1 second which is smaller than the reward period . This allows to have tests where everything interesting happens in the first reward period .
fn compute_maturities(
    stakes_e8s: Vec<u64>,
    proposals: Vec<impl Into<ProposalNeuronBehavior>>,
) -> Vec<u64> {
    let proposals: Vec<ProposalNeuronBehavior> = proposals.into_iter().map(|x| x.into()).collect();
    let mut fake_driver = FakeDriver::default()
        // To make assertion easy to sanity-check, the total supply of ICPs is chosen
        // so that the reward supply for the first day is 100 (365_250 * 10% / 365.25 = 100).
        .with_supply(ICPTs::from_e8s(365_250));
    let fixture = GovernanceProto {
        neurons: stakes_e8s
            .iter()
            .enumerate()
            .map(|(i, stake_e8s)| {
                (
                    i as u64,
                    Neuron {
                        id: Some(NeuronId { id: i as u64 }),
                        controller: Some(principal(i as u64)),
                        cached_neuron_stake_e8s: *stake_e8s,
                        dissolve_state: NOTDISSOLVING_MIN_DISSOLVE_DELAY_TO_VOTE,
                        account: fake_driver.get_fake_env().random_byte_array().to_vec(),
                        ..Default::default()
                    },
                )
            })
            .collect(),
        wait_for_quiet_threshold_seconds: 1,
        economics: Some(NetworkEconomics::default()),
        ..Default::default()
    };
    let mut gov = Governance::new(
        fixture,
        fake_driver.get_fake_env(),
        fake_driver.get_fake_ledger(),
    );
    let expected_initial_event = RewardEvent {
        day_after_genesis: 0,
        actual_timestamp_seconds: DEFAULT_TEST_START_TIMESTAMP_SECONDS,
        settled_proposals: vec![],
        distributed_e8s_equivalent: 0,
    };
    assert_eq!(*gov.latest_reward_event(), expected_initial_event);
    for (i, behavior) in (1_u64..).zip(proposals.iter()) {
        behavior.propose_and_vote(&mut gov, format!("proposal {}", i));
    }
    // Let's advance time by one reward periods. All proposals should be considered
    // for reward.
    fake_driver.advance_time_by(REWARD_DISTRIBUTION_PERIOD_SECONDS);
    gov.run_periodic_tasks().now_or_never();
    let actual_reward_event = gov.latest_reward_event();
    assert_eq!(
        *actual_reward_event,
        RewardEvent {
            day_after_genesis: 1,
            actual_timestamp_seconds: DEFAULT_TEST_START_TIMESTAMP_SECONDS
                + REWARD_DISTRIBUTION_PERIOD_SECONDS,
            settled_proposals: (1_u64..1 + proposals.len() as u64)
                .map(|id| ProposalId { id })
                .collect(),
            // Don't assert on distributed_e8s_equivalent here -- the assertions
            // is the job of the caller
            distributed_e8s_equivalent: actual_reward_event.distributed_e8s_equivalent,
        }
    );
    (0_u64..stakes_e8s.len() as u64)
        .map(|id| {
            gov.get_neuron(&NeuronId { id })
                .unwrap()
                .maturity_e8s_equivalent
        })
        .collect()
}
fn compute_maturities ( stakes_e8s : Vec < u64 > , proposals : Vec < impl Into < ProposalNeuronBehavior > > , ) -> Vec < u64 > { let proposals : Vec < ProposalNeuronBehavior > = proposals . into_iter ( ) . map ( | x | x . into ( ) ) . collect ( ) ; let mut fake_driver = FakeDriver :: default ( ) // To make assertion easy to sanity-check, the total supply of ICPs is chosen // so that the reward supply for the first day is 100 (365_250 * 10% / 365.25 = 100). . with_supply ( ICPTs :: from_e8s ( 365_250 ) ) ; let fixture = GovernanceProto { neurons : stakes_e8s . iter ( ) . enumerate ( ) . map ( | ( i , stake_e8s ) | { ( i as u64 , Neuron { id : Some ( NeuronId { id : i as u64 } ) , controller : Some ( principal ( i as u64 ) ) , cached_neuron_stake_e8s : * stake_e8s , dissolve_state : NOTDISSOLVING_MIN_DISSOLVE_DELAY_TO_VOTE , account : fake_driver . get_fake_env ( ) . random_byte_array ( ) . to_vec ( ) , .. Default :: default ( ) } , ) } ) . collect ( ) , wait_for_quiet_threshold_seconds : 1 , economics : Some ( NetworkEconomics :: default ( ) ) , .. Default :: default ( ) } ; let mut gov = Governance :: new ( fixture , fake_driver . get_fake_env ( ) , fake_driver . get_fake_ledger ( ) , ) ; let expected_initial_event = RewardEvent { day_after_genesis : 0 , actual_timestamp_seconds : DEFAULT_TEST_START_TIMESTAMP_SECONDS , settled_proposals : vec ! [ ] , distributed_e8s_equivalent : 0 , } ; assert_eq ! ( gov latest_reward_event ( ) expected_initial_event ) ; for ( i , behavior ) in ( 1_u64 .. ) . zip ( proposals . iter ( ) ) { behavior . propose_and_vote ( & mut gov , format ! ( " " i ) ) ; } // Let's advance time by one reward periods. All proposals should be considered // for reward. fake_driver . advance_time_by ( REWARD_DISTRIBUTION_PERIOD_SECONDS ) ; gov . run_periodic_tasks ( ) . now_or_never ( ) ; let actual_reward_event = gov . latest_reward_event ( ) ; assert_eq ! ( actual_reward_event RewardEvent { day_after_genesis 1 actual_timestamp_seconds DEFAULT_TEST_START_TIMESTAMP_SECONDS REWARD_DISTRIBUTION_PERIOD_SECONDS settled_proposals ( 1_u64 1 proposals len ( ) as u64 ) map ( id ProposalId { id } ) collect ( ) // Don't assert on distributed_e8s_equivalent here -- the assertions // is the job of the caller distributed_e8s_equivalent actual_reward_event distributed_e8s_equivalent } ) ; ( 0_u64 .. stakes_e8s . len ( ) as u64 ) . map ( | id | { gov . get_neuron ( & NeuronId { id } ) . unwrap ( ) . maturity_e8s_equivalent } ) . collect ( ) }
Test helper where several proposals are created and voted on by various
neurons.
Test helper where several proposals are created and voted on by various neurons .
stakes_e8s
Vec<u64>
proposals
Vec<impl Into<ProposalNeuronBehavior>>
stakes_e8s
Vec<u64>
proposals
Vec<impl Into<ProposalNeuronBehavior>>