@@ -21,7 +21,7 @@ use std::collections::BTreeMap;
21
21
22
22
use frame_support:: {
23
23
assert_noop, assert_ok, parameter_types,
24
- traits:: { ConstU32 , ConstU64 , Contains , Polling } ,
24
+ traits:: { ConstU32 , ConstU64 , Contains , Polling , VoteTally } ,
25
25
} ;
26
26
use sp_core:: H256 ;
27
27
use sp_runtime:: {
@@ -166,7 +166,7 @@ impl Polling<TallyOf<Test>> for TestPolls {
166
166
fn create_ongoing ( class : Self :: Class ) -> Result < Self :: Index , ( ) > {
167
167
let mut polls = Polls :: get ( ) ;
168
168
let i = polls. keys ( ) . rev ( ) . next ( ) . map_or ( 0 , |x| x + 1 ) ;
169
- polls. insert ( i, Ongoing ( Tally :: default ( ) , class) ) ;
169
+ polls. insert ( i, Ongoing ( Tally :: new ( 0 ) , class) ) ;
170
170
Polls :: set ( polls) ;
171
171
Ok ( i)
172
172
}
@@ -271,19 +271,19 @@ fn basic_voting_works() {
271
271
assert_ok ! ( Voting :: vote( Origin :: signed( 1 ) , 3 , aye( 2 , 5 ) ) ) ;
272
272
assert_eq ! ( tally( 3 ) , Tally :: from_parts( 10 , 0 , 2 ) ) ;
273
273
assert_ok ! ( Voting :: vote( Origin :: signed( 1 ) , 3 , nay( 2 , 5 ) ) ) ;
274
- assert_eq ! ( tally( 3 ) , Tally :: from_parts( 0 , 10 , 2 ) ) ;
274
+ assert_eq ! ( tally( 3 ) , Tally :: from_parts( 0 , 10 , 0 ) ) ;
275
275
assert_eq ! ( Balances :: usable_balance( 1 ) , 8 ) ;
276
276
277
277
assert_ok ! ( Voting :: vote( Origin :: signed( 1 ) , 3 , aye( 5 , 1 ) ) ) ;
278
278
assert_eq ! ( tally( 3 ) , Tally :: from_parts( 5 , 0 , 5 ) ) ;
279
279
assert_ok ! ( Voting :: vote( Origin :: signed( 1 ) , 3 , nay( 5 , 1 ) ) ) ;
280
- assert_eq ! ( tally( 3 ) , Tally :: from_parts( 0 , 5 , 5 ) ) ;
280
+ assert_eq ! ( tally( 3 ) , Tally :: from_parts( 0 , 5 , 0 ) ) ;
281
281
assert_eq ! ( Balances :: usable_balance( 1 ) , 5 ) ;
282
282
283
283
assert_ok ! ( Voting :: vote( Origin :: signed( 1 ) , 3 , aye( 10 , 0 ) ) ) ;
284
284
assert_eq ! ( tally( 3 ) , Tally :: from_parts( 1 , 0 , 10 ) ) ;
285
285
assert_ok ! ( Voting :: vote( Origin :: signed( 1 ) , 3 , nay( 10 , 0 ) ) ) ;
286
- assert_eq ! ( tally( 3 ) , Tally :: from_parts( 0 , 1 , 10 ) ) ;
286
+ assert_eq ! ( tally( 3 ) , Tally :: from_parts( 0 , 1 , 0 ) ) ;
287
287
assert_eq ! ( Balances :: usable_balance( 1 ) , 0 ) ;
288
288
289
289
assert_ok ! ( Voting :: remove_vote( Origin :: signed( 1 ) , None , 3 ) ) ;
@@ -300,19 +300,19 @@ fn voting_balance_gets_locked() {
300
300
assert_ok ! ( Voting :: vote( Origin :: signed( 1 ) , 3 , aye( 2 , 5 ) ) ) ;
301
301
assert_eq ! ( tally( 3 ) , Tally :: from_parts( 10 , 0 , 2 ) ) ;
302
302
assert_ok ! ( Voting :: vote( Origin :: signed( 1 ) , 3 , nay( 2 , 5 ) ) ) ;
303
- assert_eq ! ( tally( 3 ) , Tally :: from_parts( 0 , 10 , 2 ) ) ;
303
+ assert_eq ! ( tally( 3 ) , Tally :: from_parts( 0 , 10 , 0 ) ) ;
304
304
assert_eq ! ( Balances :: usable_balance( 1 ) , 8 ) ;
305
305
306
306
assert_ok ! ( Voting :: vote( Origin :: signed( 1 ) , 3 , aye( 5 , 1 ) ) ) ;
307
307
assert_eq ! ( tally( 3 ) , Tally :: from_parts( 5 , 0 , 5 ) ) ;
308
308
assert_ok ! ( Voting :: vote( Origin :: signed( 1 ) , 3 , nay( 5 , 1 ) ) ) ;
309
- assert_eq ! ( tally( 3 ) , Tally :: from_parts( 0 , 5 , 5 ) ) ;
309
+ assert_eq ! ( tally( 3 ) , Tally :: from_parts( 0 , 5 , 0 ) ) ;
310
310
assert_eq ! ( Balances :: usable_balance( 1 ) , 5 ) ;
311
311
312
312
assert_ok ! ( Voting :: vote( Origin :: signed( 1 ) , 3 , aye( 10 , 0 ) ) ) ;
313
313
assert_eq ! ( tally( 3 ) , Tally :: from_parts( 1 , 0 , 10 ) ) ;
314
314
assert_ok ! ( Voting :: vote( Origin :: signed( 1 ) , 3 , nay( 10 , 0 ) ) ) ;
315
- assert_eq ! ( tally( 3 ) , Tally :: from_parts( 0 , 1 , 10 ) ) ;
315
+ assert_eq ! ( tally( 3 ) , Tally :: from_parts( 0 , 1 , 0 ) ) ;
316
316
assert_eq ! ( Balances :: usable_balance( 1 ) , 0 ) ;
317
317
318
318
assert_ok ! ( Voting :: remove_vote( Origin :: signed( 1 ) , None , 3 ) ) ;
@@ -376,10 +376,10 @@ fn classwise_delegation_works() {
376
376
new_test_ext ( ) . execute_with ( || {
377
377
Polls :: set (
378
378
vec ! [
379
- ( 0 , Ongoing ( Tally :: default ( ) , 0 ) ) ,
380
- ( 1 , Ongoing ( Tally :: default ( ) , 1 ) ) ,
381
- ( 2 , Ongoing ( Tally :: default ( ) , 2 ) ) ,
382
- ( 3 , Ongoing ( Tally :: default ( ) , 2 ) ) ,
379
+ ( 0 , Ongoing ( Tally :: new ( 0 ) , 0 ) ) ,
380
+ ( 1 , Ongoing ( Tally :: new ( 0 ) , 1 ) ) ,
381
+ ( 2 , Ongoing ( Tally :: new ( 0 ) , 2 ) ) ,
382
+ ( 3 , Ongoing ( Tally :: new ( 0 ) , 2 ) ) ,
383
383
]
384
384
. into_iter ( )
385
385
. collect ( ) ,
@@ -403,9 +403,9 @@ fn classwise_delegation_works() {
403
403
assert_eq ! (
404
404
Polls :: get( ) ,
405
405
vec![
406
- ( 0 , Ongoing ( Tally :: from_parts( 6 , 2 , 35 ) , 0 ) ) ,
407
- ( 1 , Ongoing ( Tally :: from_parts( 6 , 2 , 35 ) , 1 ) ) ,
408
- ( 2 , Ongoing ( Tally :: from_parts( 6 , 2 , 35 ) , 2 ) ) ,
406
+ ( 0 , Ongoing ( Tally :: from_parts( 6 , 2 , 15 ) , 0 ) ) ,
407
+ ( 1 , Ongoing ( Tally :: from_parts( 6 , 2 , 15 ) , 1 ) ) ,
408
+ ( 2 , Ongoing ( Tally :: from_parts( 6 , 2 , 15 ) , 2 ) ) ,
409
409
( 3 , Ongoing ( Tally :: from_parts( 0 , 0 , 0 ) , 2 ) ) ,
410
410
]
411
411
. into_iter( )
@@ -417,10 +417,10 @@ fn classwise_delegation_works() {
417
417
assert_eq ! (
418
418
Polls :: get( ) ,
419
419
vec![
420
- ( 0 , Ongoing ( Tally :: from_parts( 6 , 2 , 35 ) , 0 ) ) ,
421
- ( 1 , Ongoing ( Tally :: from_parts( 6 , 2 , 35 ) , 1 ) ) ,
422
- ( 2 , Ongoing ( Tally :: from_parts( 6 , 2 , 35 ) , 2 ) ) ,
423
- ( 3 , Ongoing ( Tally :: from_parts( 0 , 6 , 15 ) , 2 ) ) ,
420
+ ( 0 , Ongoing ( Tally :: from_parts( 6 , 2 , 15 ) , 0 ) ) ,
421
+ ( 1 , Ongoing ( Tally :: from_parts( 6 , 2 , 15 ) , 1 ) ) ,
422
+ ( 2 , Ongoing ( Tally :: from_parts( 6 , 2 , 15 ) , 2 ) ) ,
423
+ ( 3 , Ongoing ( Tally :: from_parts( 0 , 6 , 0 ) , 2 ) ) ,
424
424
]
425
425
. into_iter( )
426
426
. collect( )
@@ -432,10 +432,10 @@ fn classwise_delegation_works() {
432
432
assert_eq ! (
433
433
Polls :: get( ) ,
434
434
vec![
435
- ( 0 , Ongoing ( Tally :: from_parts( 6 , 2 , 35 ) , 0 ) ) ,
436
- ( 1 , Ongoing ( Tally :: from_parts( 6 , 2 , 35 ) , 1 ) ) ,
437
- ( 2 , Ongoing ( Tally :: from_parts( 1 , 7 , 35 ) , 2 ) ) ,
438
- ( 3 , Ongoing ( Tally :: from_parts( 0 , 1 , 10 ) , 2 ) ) ,
435
+ ( 0 , Ongoing ( Tally :: from_parts( 6 , 2 , 15 ) , 0 ) ) ,
436
+ ( 1 , Ongoing ( Tally :: from_parts( 6 , 2 , 15 ) , 1 ) ) ,
437
+ ( 2 , Ongoing ( Tally :: from_parts( 1 , 7 , 10 ) , 2 ) ) ,
438
+ ( 3 , Ongoing ( Tally :: from_parts( 0 , 1 , 0 ) , 2 ) ) ,
439
439
]
440
440
. into_iter( )
441
441
. collect( )
@@ -451,10 +451,10 @@ fn classwise_delegation_works() {
451
451
assert_eq ! (
452
452
Polls :: get( ) ,
453
453
vec![
454
- ( 0 , Ongoing ( Tally :: from_parts( 4 , 2 , 33 ) , 0 ) ) ,
455
- ( 1 , Ongoing ( Tally :: from_parts( 4 , 2 , 33 ) , 1 ) ) ,
456
- ( 2 , Ongoing ( Tally :: from_parts( 4 , 2 , 33 ) , 2 ) ) ,
457
- ( 3 , Ongoing ( Tally :: from_parts( 0 , 4 , 13 ) , 2 ) ) ,
454
+ ( 0 , Ongoing ( Tally :: from_parts( 4 , 2 , 13 ) , 0 ) ) ,
455
+ ( 1 , Ongoing ( Tally :: from_parts( 4 , 2 , 13 ) , 1 ) ) ,
456
+ ( 2 , Ongoing ( Tally :: from_parts( 4 , 2 , 13 ) , 2 ) ) ,
457
+ ( 3 , Ongoing ( Tally :: from_parts( 0 , 4 , 0 ) , 2 ) ) ,
458
458
]
459
459
. into_iter( )
460
460
. collect( )
@@ -483,10 +483,10 @@ fn classwise_delegation_works() {
483
483
assert_eq ! (
484
484
Polls :: get( ) ,
485
485
vec![
486
- ( 0 , Ongoing ( Tally :: from_parts( 7 , 2 , 36 ) , 0 ) ) ,
487
- ( 1 , Ongoing ( Tally :: from_parts( 8 , 2 , 37 ) , 1 ) ) ,
488
- ( 2 , Ongoing ( Tally :: from_parts( 9 , 2 , 38 ) , 2 ) ) ,
489
- ( 3 , Ongoing ( Tally :: from_parts( 0 , 9 , 18 ) , 2 ) ) ,
486
+ ( 0 , Ongoing ( Tally :: from_parts( 7 , 2 , 16 ) , 0 ) ) ,
487
+ ( 1 , Ongoing ( Tally :: from_parts( 8 , 2 , 17 ) , 1 ) ) ,
488
+ ( 2 , Ongoing ( Tally :: from_parts( 9 , 2 , 18 ) , 2 ) ) ,
489
+ ( 3 , Ongoing ( Tally :: from_parts( 0 , 9 , 0 ) , 2 ) ) ,
490
490
]
491
491
. into_iter( )
492
492
. collect( )
@@ -497,7 +497,7 @@ fn classwise_delegation_works() {
497
497
#[ test]
498
498
fn redelegation_after_vote_ending_should_keep_lock ( ) {
499
499
new_test_ext ( ) . execute_with ( || {
500
- Polls :: set ( vec ! [ ( 0 , Ongoing ( Tally :: default ( ) , 0 ) ) ] . into_iter ( ) . collect ( ) ) ;
500
+ Polls :: set ( vec ! [ ( 0 , Ongoing ( Tally :: new ( 0 ) , 0 ) ) ] . into_iter ( ) . collect ( ) ) ;
501
501
assert_ok ! ( Voting :: delegate( Origin :: signed( 1 ) , 0 , 2 , Conviction :: Locked1x , 5 ) ) ;
502
502
assert_ok ! ( Voting :: vote( Origin :: signed( 2 ) , 0 , aye( 10 , 1 ) ) ) ;
503
503
Polls :: set ( vec ! [ ( 0 , Completed ( 1 , true ) ) ] . into_iter ( ) . collect ( ) ) ;
@@ -515,9 +515,9 @@ fn lock_amalgamation_valid_with_multiple_removed_votes() {
515
515
new_test_ext ( ) . execute_with ( || {
516
516
Polls :: set (
517
517
vec ! [
518
- ( 0 , Ongoing ( Tally :: default ( ) , 0 ) ) ,
519
- ( 1 , Ongoing ( Tally :: default ( ) , 0 ) ) ,
520
- ( 2 , Ongoing ( Tally :: default ( ) , 0 ) ) ,
518
+ ( 0 , Ongoing ( Tally :: new ( 0 ) , 0 ) ) ,
519
+ ( 1 , Ongoing ( Tally :: new ( 0 ) , 0 ) ) ,
520
+ ( 2 , Ongoing ( Tally :: new ( 0 ) , 0 ) ) ,
521
521
]
522
522
. into_iter ( )
523
523
. collect ( ) ,
@@ -587,7 +587,7 @@ fn lock_amalgamation_valid_with_multiple_delegations() {
587
587
#[ test]
588
588
fn lock_amalgamation_valid_with_move_roundtrip_to_delegation ( ) {
589
589
new_test_ext ( ) . execute_with ( || {
590
- Polls :: set ( vec ! [ ( 0 , Ongoing ( Tally :: default ( ) , 0 ) ) ] . into_iter ( ) . collect ( ) ) ;
590
+ Polls :: set ( vec ! [ ( 0 , Ongoing ( Tally :: new ( 0 ) , 0 ) ) ] . into_iter ( ) . collect ( ) ) ;
591
591
assert_ok ! ( Voting :: vote( Origin :: signed( 1 ) , 0 , aye( 5 , 1 ) ) ) ;
592
592
Polls :: set ( vec ! [ ( 0 , Completed ( 1 , true ) ) ] . into_iter ( ) . collect ( ) ) ;
593
593
assert_ok ! ( Voting :: remove_vote( Origin :: signed( 1 ) , Some ( 0 ) , 0 ) ) ;
@@ -599,7 +599,7 @@ fn lock_amalgamation_valid_with_move_roundtrip_to_delegation() {
599
599
assert_ok ! ( Voting :: unlock( Origin :: signed( 1 ) , 0 , 1 ) ) ;
600
600
assert_eq ! ( Balances :: usable_balance( 1 ) , 0 ) ;
601
601
602
- Polls :: set ( vec ! [ ( 1 , Ongoing ( Tally :: default ( ) , 0 ) ) ] . into_iter ( ) . collect ( ) ) ;
602
+ Polls :: set ( vec ! [ ( 1 , Ongoing ( Tally :: new ( 0 ) , 0 ) ) ] . into_iter ( ) . collect ( ) ) ;
603
603
assert_ok ! ( Voting :: vote( Origin :: signed( 1 ) , 1 , aye( 5 , 2 ) ) ) ;
604
604
Polls :: set ( vec ! [ ( 1 , Completed ( 1 , true ) ) ] . into_iter ( ) . collect ( ) ) ;
605
605
assert_ok ! ( Voting :: remove_vote( Origin :: signed( 1 ) , Some ( 0 ) , 1 ) ) ;
@@ -627,7 +627,7 @@ fn lock_amalgamation_valid_with_move_roundtrip_to_casting() {
627
627
assert_ok ! ( Voting :: unlock( Origin :: signed( 1 ) , 0 , 1 ) ) ;
628
628
assert_eq ! ( Balances :: usable_balance( 1 ) , 5 ) ;
629
629
630
- Polls :: set ( vec ! [ ( 0 , Ongoing ( Tally :: default ( ) , 0 ) ) ] . into_iter ( ) . collect ( ) ) ;
630
+ Polls :: set ( vec ! [ ( 0 , Ongoing ( Tally :: new ( 0 ) , 0 ) ) ] . into_iter ( ) . collect ( ) ) ;
631
631
assert_ok ! ( Voting :: vote( Origin :: signed( 1 ) , 0 , aye( 10 , 1 ) ) ) ;
632
632
Polls :: set ( vec ! [ ( 0 , Completed ( 1 , true ) ) ] . into_iter ( ) . collect ( ) ) ;
633
633
assert_ok ! ( Voting :: remove_vote( Origin :: signed( 1 ) , Some ( 0 ) , 0 ) ) ;
@@ -688,9 +688,9 @@ fn lock_aggregation_over_different_classes_with_casting_works() {
688
688
new_test_ext ( ) . execute_with ( || {
689
689
Polls :: set (
690
690
vec ! [
691
- ( 0 , Ongoing ( Tally :: default ( ) , 0 ) ) ,
692
- ( 1 , Ongoing ( Tally :: default ( ) , 1 ) ) ,
693
- ( 2 , Ongoing ( Tally :: default ( ) , 2 ) ) ,
691
+ ( 0 , Ongoing ( Tally :: new ( 0 ) , 0 ) ) ,
692
+ ( 1 , Ongoing ( Tally :: new ( 0 ) , 1 ) ) ,
693
+ ( 2 , Ongoing ( Tally :: new ( 0 ) , 2 ) ) ,
694
694
]
695
695
. into_iter ( )
696
696
. collect ( ) ,
@@ -747,10 +747,10 @@ fn errors_with_vote_work() {
747
747
assert_ok ! ( Voting :: undelegate( Origin :: signed( 1 ) , 0 ) ) ;
748
748
Polls :: set (
749
749
vec ! [
750
- ( 0 , Ongoing ( Tally :: default ( ) , 0 ) ) ,
751
- ( 1 , Ongoing ( Tally :: default ( ) , 0 ) ) ,
752
- ( 2 , Ongoing ( Tally :: default ( ) , 0 ) ) ,
753
- ( 3 , Ongoing ( Tally :: default ( ) , 0 ) ) ,
750
+ ( 0 , Ongoing ( Tally :: new ( 0 ) , 0 ) ) ,
751
+ ( 1 , Ongoing ( Tally :: new ( 0 ) , 0 ) ) ,
752
+ ( 2 , Ongoing ( Tally :: new ( 0 ) , 0 ) ) ,
753
+ ( 3 , Ongoing ( Tally :: new ( 0 ) , 0 ) ) ,
754
754
]
755
755
. into_iter ( )
756
756
. collect ( ) ,
0 commit comments