Substrate: Why the equalize doesn't happen in staking tests?

Created on 16 Mar 2020  路  3Comments  路  Source: paritytech/substrate

Got 125 and 375, rather than 250 and 250.
https://github.com/paritytech/substrate/blob/master/frame/staking/src/tests.rs#L96
https://github.com/paritytech/substrate/blob/master/frame/staking/src/tests.rs#L104

And I write a test in phragmen:

#[test]
fn phragmen_poc_works() {
    let candidates = vec![11, 21];
    let voters = vec![
        (101, vec![11, 21]),
    ];

    let PhragmenResult { winners, assignments } = elect::<_, _, _, TestCurrencyToVote, Output>(
        2,
        2,
        candidates,
        voters,
        create_stake_of(&[(101, 500)]),
    ).unwrap();

    assert_eq_uvec!(winners, vec![(11, 500), (21, 500)]);
    assert_eq_uvec!(
        assignments,
        vec![
            (101, vec![(11, Perbill::from_percent(50), (21, Perbill::from_percent(50))]),
        ]
    );
}

The percent is (50%, 50%). But in the staking test it is (25%, 75%).

Z1-question

All 3 comments

CC @kianenigma

We removed the equalize from the code, hence all the tests also don't assume it anymore.

As for the test, you are not taking the self vote into account. Try

#[test]
fn xxx() {
    let candidates = vec![11, 21];
    let voters = vec![
        (11, vec![11]),
        (21, vec![21]),
        (101, vec![11, 21]),
    ];

    let PhragmenResult { winners, assignments } = elect::<_, _, _, TestCurrencyToVote, Output>(
        2,
        2,
        candidates,
        voters,
        create_stake_of(&[(101, 500), (11, 1000), (21, 1000)]),
    ).unwrap();

    assert_eq_uvec!(winners, vec![(11, 1500), (21, 1500)]);
    assert_eq_uvec!(
        assignments,
        vec![
            (
                101,
                vec![
                    (11, Perbill::from_percent(50)), // this will now fail. 
                    (21, Perbill::from_percent(50))
                ],
            ),
        ]
    );
}

Please re-open if you have further questions!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

expenses picture expenses  路  5Comments

gavofyork picture gavofyork  路  4Comments

Mischi picture Mischi  路  5Comments

gavofyork picture gavofyork  路  4Comments

JoshOrndorff picture JoshOrndorff  路  4Comments