git.delta.rocks / unique-network / refs/commits / 33d3cd09a241

difftreelog

test(collator-selection) intermediate changes and fixes to tests + minor refactor

Fahrrader2022-12-21parent: #1e14fe8.patch.diff
in: master

6 files changed

modifiedpallets/collator-selection/src/lib.rsdiffbeforeafterboth

no syntactic changes

modifiedpallets/collator-selection/src/tests.rsdiffbeforeafterboth
50 });50 });
51}51}
52
53// todo:collator add more tests later
5254
53#[test]55#[test]
54fn it_should_set_invulnerables() {56fn it_should_add_invulnerables() {
55 new_test_ext().execute_with(|| {57 new_test_ext().execute_with(|| {
56 let new_set = vec![1, 2, 3, 4];58 assert_ok!(CollatorSelection::add_invulnerable(
59 RuntimeOrigin::signed(RootAccount::get()),
60 1
61 ));
57 assert_ok!(CollatorSelection::set_invulnerables(62 assert_ok!(CollatorSelection::add_invulnerable(
58 RuntimeOrigin::signed(RootAccount::get()),63 RuntimeOrigin::signed(RootAccount::get()),
59 new_set.clone()64 2
60 ));65 ));
61 assert_eq!(CollatorSelection::invulnerables(), new_set);66 assert_eq!(CollatorSelection::invulnerables(), vec![1, 2]);
6267
63 // cannot set with non-root.68 // cannot set with non-root.
64 assert_noop!(69 assert_noop!(
65 CollatorSelection::set_invulnerables(RuntimeOrigin::signed(1), new_set.clone()),70 CollatorSelection::add_invulnerable(RuntimeOrigin::signed(1), 3),
66 BadOrigin71 BadOrigin
67 );72 );
6873
69 // cannot set invulnerables without associated validator keys74 // cannot set invulnerables without associated validator keys
70 let invulnerables = vec![7];
71 assert_noop!(75 assert_noop!(
72 CollatorSelection::set_invulnerables(76 CollatorSelection::add_invulnerable(
73 RuntimeOrigin::signed(RootAccount::get()),77 RuntimeOrigin::signed(RootAccount::get()),
74 invulnerables.clone()78 7
75 ),79 ),
76 Error::<Test>::ValidatorNotRegistered80 Error::<Test>::ValidatorNotRegistered
77 );81 );
78 });82 });
79}83}
84
85#[test]
86fn it_should_remove_invulnerables() {
87 new_test_ext().execute_with(|| {
88 assert_ok!(CollatorSelection::add_invulnerable(
89 RuntimeOrigin::signed(RootAccount::get()),
90 1
91 ));
92 assert_ok!(CollatorSelection::add_invulnerable(
93 RuntimeOrigin::signed(RootAccount::get()),
94 2
95 ));
96
97 // cannot remove with non-root.
98 assert_noop!(
99 CollatorSelection::remove_invulnerable(RuntimeOrigin::signed(1), 3),
100 BadOrigin
101 );
102
103 assert_ok!(CollatorSelection::remove_invulnerable(
104 RuntimeOrigin::signed(RootAccount::get()),
105 2
106 ));
107 assert_eq!(CollatorSelection::invulnerables(), vec![1]);
108
109 // cannot remove an invulnerable if there would be 0 invulnerables.
110 assert_noop!(
111 CollatorSelection::add_invulnerable(
112 RuntimeOrigin::signed(RootAccount::get()),
113 1
114 ),
115 Error::<Test>::NotInvulnerable
116 );
117 });
118}
80119
81#[test]120#[test]
82fn set_desired_candidates_works() {121fn set_desired_candidates_works() {
404 deposit: 10,443 deposit: 10,
405 };444 };
406 assert_eq!(CollatorSelection::candidates(), vec![collator]);445 assert_eq!(CollatorSelection::candidates(), vec![collator]);
446 assert_eq!(CollatorSelection::kick_threshold(), 1);
407 assert_eq!(CollatorSelection::last_authored_block(4), 20);447 assert_eq!(CollatorSelection::last_authored_block(4), 20);
408 initialize_to_block(30);448 initialize_to_block(30);
409 // 3 gets kicked after 1 session delay449 // 3 gets kicked after 1 session delay
457 let collator_selection = collator_selection::GenesisConfig::<Test> {497 let collator_selection = collator_selection::GenesisConfig::<Test> {
458 desired_candidates: 2,498 desired_candidates: 2,
459 candidacy_bond: 10,499 candidacy_bond: 10,
500 kick_threshold: 1,
460 invulnerables,501 invulnerables,
461 };502 };
462 // collator selection must be initialized before session.503 // collator selection must be initialized before session.
modifiedprimitives/common/src/constants.rsdiffbeforeafterboth
47/// Amount of Balance reserved for candidate registration.47/// Amount of Balance reserved for candidate registration.
48pub const GENESIS_CANDIDACY_BOND: u128 = EXISTENTIAL_DEPOSIT;48pub const GENESIS_CANDIDACY_BOND: u128 = EXISTENTIAL_DEPOSIT;
49/// How long a periodic session lasts in blocks.49/// How long a periodic session lasts in blocks.
50pub const SESSION_LENGTH: BlockNumber = MINUTES;50pub const SESSION_LENGTH: BlockNumber = HOURS;
5151
52// Targeting 0.1 UNQ per transfer52// Targeting 0.1 UNQ per transfer
53pub const WEIGHT_TO_FEE_COEFF: u32 = /*<weight2fee>*/175_199_920/*</weight2fee>*/;53pub const WEIGHT_TO_FEE_COEFF: u32 = /*<weight2fee>*/175_199_920/*</weight2fee>*/;
modifiedtests/package.jsondiffbeforeafterboth
85 "testSchedulingEVM": "mocha --timeout 9999999 -r ts-node/register ./**/eth/scheduling.test.ts",85 "testSchedulingEVM": "mocha --timeout 9999999 -r ts-node/register ./**/eth/scheduling.test.ts",
86 "testPalletPresence": "mocha --timeout 9999999 -r ts-node/register ./**/pallet-presence.test.ts",86 "testPalletPresence": "mocha --timeout 9999999 -r ts-node/register ./**/pallet-presence.test.ts",
87 "testBlockProduction": "mocha --timeout 9999999 -r ts-node/register ./**/block-production.test.ts",87 "testBlockProduction": "mocha --timeout 9999999 -r ts-node/register ./**/block-production.test.ts",
88 "testCollatorSelection": "mocha --timeout 9999999 -r ts-node/register ./**/collatorSelection.test.ts",88 "testCollatorSelection": "mocha --timeout 9999999 -r ts-node/register ./**/collatorSelection.*test.ts",
89 "testEnableDisableTransfers": "mocha --timeout 9999999 -r ts-node/register ./**/enableDisableTransfer.test.ts",89 "testEnableDisableTransfers": "mocha --timeout 9999999 -r ts-node/register ./**/enableDisableTransfer.test.ts",
90 "testLimits": "mocha --timeout 9999999 -r ts-node/register ./**/limits.test.ts",90 "testLimits": "mocha --timeout 9999999 -r ts-node/register ./**/limits.test.ts",
91 "testEthCreateNFTCollection": "mocha --timeout 9999999 -r ts-node/register ./**/eth/createNFTCollection.test.ts",91 "testEthCreateNFTCollection": "mocha --timeout 9999999 -r ts-node/register ./**/eth/createNFTCollection.test.ts",
addedtests/src/collatorSelection.seqtest.tsdiffbeforeafterboth

no changes

deletedtests/src/collatorSelection.test.tsdiffbeforeafterboth

no changes