difftreelog
test(CollatorSelection) invulnerables shuffling
in: master
3 files changed
launch-config.jsondiffbeforeafterboth1{2 "relaychain": {3 "bin": "../polkadot/target/release/polkadot",4 "chain": "rococo-local",5 "nodes": [6 {7 "name": "alice",8 "wsPort": 9844,9 "rpcPort": 9843,10 "port": 30444,11 "flags": [12 "-lparachain::candidate_validation=debug",13 "-lxcm=trace",14 "--rpc-cors=all",15 "--unsafe-rpc-external",16 "--unsafe-ws-external"17 ]18 },19 {20 "name": "bob",21 "wsPort": 9855,22 "rpcPort": 9854,23 "port": 30555,24 "flags": [25 "-lparachain::candidate_validation=debug",26 "-lxcm=trace",27 "--rpc-cors=all",28 "--unsafe-rpc-external",29 "--unsafe-ws-external"30 ]31 },32 {33 "name": "charlie",34 "wsPort": 9866,35 "rpcPort": 9865,36 "port": 30666,37 "flags": [38 "-lparachain::candidate_validation=debug",39 "-lxcm=trace",40 "--rpc-cors=all",41 "--unsafe-rpc-external",42 "--unsafe-ws-external"43 ]44 },45 {46 "name": "dave",47 "wsPort": 9877,48 "rpcPort": 9876,49 "port": 30777,50 "flags": [51 "-lparachain::candidate_validation=debug",52 "-lxcm=trace",53 "--rpc-cors=all",54 "--unsafe-rpc-external",55 "--unsafe-ws-external"56 ]57 },58 {59 "name": "eve",60 "wsPort": 9888,61 "rpcPort": 9887,62 "port": 30888,63 "flags": [64 "-lparachain::candidate_validation=debug",65 "-lxcm=trace",66 "--rpc-cors=all",67 "--unsafe-rpc-external",68 "--unsafe-ws-external"69 ]70 }71 ],72 "genesis": {73 "runtime": {74 "runtime_genesis_config": {75 "parachainsConfiguration": {76 "config": {77 "validation_upgrade_frequency": 1,78 "validation_upgrade_delay": 179 }80 }81 }82 }83 }84 },85 "parachains": [86 {87 "bin": "../unique-chain/target/release/unique-collator",88 "id": "1000",89 "balance": "1000000000000000000000000",90 "nodes": [91 {92 "port": 31200,93 "wsPort": 9944,94 "rpcPort": 9933,95 "name": "alice",96 "flags": [97 "--rpc-cors=all",98 "--unsafe-rpc-external",99 "--unsafe-ws-external",100 "-lxcm=trace"101 ]102 },103 {104 "port": 31201,105 "wsPort": 9945,106 "rpcPort": 9934,107 "name": "bob",108 "flags": [109 "--rpc-cors=all",110 "--unsafe-rpc-external",111 "--unsafe-ws-external",112 "-lxcm=trace"113 ]114 }115 ]116 }117 ],118 "simpleParachains": [],119 "hrmpChannels": [],120 "finalization": false121}1{2 "relaychain": {3 "bin": "../polkadot/target/release/polkadot",4 "chain": "rococo-local",5 "nodes": [6 {7 "name": "alice",8 "wsPort": 9844,9 "rpcPort": 9843,10 "port": 30444,11 "flags": [12 "-lparachain::candidate_validation=debug",13 "-lxcm=trace",14 "--rpc-cors=all",15 "--unsafe-rpc-external",16 "--unsafe-ws-external"17 ]18 },19 {20 "name": "bob",21 "wsPort": 9855,22 "rpcPort": 9854,23 "port": 30555,24 "flags": [25 "-lparachain::candidate_validation=debug",26 "-lxcm=trace",27 "--rpc-cors=all",28 "--unsafe-rpc-external",29 "--unsafe-ws-external"30 ]31 },32 {33 "name": "charlie",34 "wsPort": 9866,35 "rpcPort": 9865,36 "port": 30666,37 "flags": [38 "-lparachain::candidate_validation=debug",39 "-lxcm=trace",40 "--rpc-cors=all",41 "--unsafe-rpc-external",42 "--unsafe-ws-external"43 ]44 },45 {46 "name": "dave",47 "wsPort": 9877,48 "rpcPort": 9876,49 "port": 30777,50 "flags": [51 "-lparachain::candidate_validation=debug",52 "-lxcm=trace",53 "--rpc-cors=all",54 "--unsafe-rpc-external",55 "--unsafe-ws-external"56 ]57 },58 {59 "name": "eve",60 "wsPort": 9888,61 "rpcPort": 9887,62 "port": 30888,63 "flags": [64 "-lparachain::candidate_validation=debug",65 "-lxcm=trace",66 "--rpc-cors=all",67 "--unsafe-rpc-external",68 "--unsafe-ws-external"69 ]70 }71 ],72 "genesis": {73 "runtime": {74 "runtime_genesis_config": {75 "parachainsConfiguration": {76 "config": {77 "validation_upgrade_frequency": 1,78 "validation_upgrade_delay": 179 }80 }81 }82 }83 }84 },85 "parachains": [86 {87 "bin": "../unique-chain/target/release/unique-collator",88 "balance": "1000000000000000000000000",89 "nodes": [90 {91 "port": 31200,92 "wsPort": 9944,93 "rpcPort": 9933,94 "name": "alice",95 "flags": [96 "--rpc-cors=all",97 "--unsafe-rpc-external",98 "--unsafe-ws-external",99 "-lxcm=trace"100 ]101 },102 {103 "port": 31201,104 "wsPort": 9945,105 "rpcPort": 9934,106 "name": "bob",107 "flags": [108 "--rpc-cors=all",109 "--unsafe-rpc-external",110 "--unsafe-ws-external",111 "-lxcm=trace"112 ]113 },114 {115 "port": 31202,116 "wsPort": 9946,117 "rpcPort": 9935,118 "name": "charlie",119 "flags": [120 "--rpc-cors=all",121 "--unsafe-rpc-external",122 "--unsafe-ws-external",123 "-lxcm=trace"124 ]125 },126 {127 "port": 31203,128 "wsPort": 9947,129 "rpcPort": 9936,130 "name": "dave",131 "flags": [132 "--rpc-cors=all",133 "--unsafe-rpc-external",134 "--unsafe-ws-external",135 "-lxcm=trace"136 ]137 },138 {139 "port": 31204,140 "wsPort": 9948,141 "rpcPort": 9937,142 "name": "eve",143 "flags": [144 "--rpc-cors=all",145 "--unsafe-rpc-external",146 "--unsafe-ws-external",147 "-lxcm=trace"148 ]149 }150 ]151 }152 ],153 "simpleParachains": [],154 "hrmpChannels": [],155 "finalization": false156}tests/package.jsondiffbeforeafterboth--- a/tests/package.json
+++ b/tests/package.json
@@ -75,6 +75,7 @@
"testScheduler": "mocha --timeout 9999999 -r ts-node/register ./**/scheduler.test.ts",
"testSchedulingEVM": "mocha --timeout 9999999 -r ts-node/register ./**/eth/scheduling.test.ts",
"testXcmTransfer": "mocha --timeout 9999999 -r ts-node/register ./**/xcmTransfer.test.ts",
+ "testShuffleCollators": "mocha --timeout 9999999 -r ts-node/register ./**/shuffleCollators.test.ts",
"testPalletPresence": "mocha --timeout 9999999 -r ts-node/register ./**/pallet-presence.test.ts",
"testBlockProduction": "mocha --timeout 9999999 -r ts-node/register ./**/block-production.test.ts",
"testEnableDisableTransfers": "mocha --timeout 9999999 -r ts-node/register ./**/enableDisableTransfer.test.ts",
tests/src/shuffleCollators.test.tsdiffbeforeafterboth--- /dev/null
+++ b/tests/src/shuffleCollators.test.ts
@@ -0,0 +1,88 @@
+// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.
+// This file is part of Unique Network.
+
+// Unique Network is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+
+// Unique Network is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License
+// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
+
+import {ApiPromise} from '@polkadot/api';
+import {IKeyringPair} from '@polkadot/types/types';
+import privateKey from './substrate/privateKey';
+import usingApi, { submitTransactionAsync } from './substrate/substrate-api';
+import waitNewBlocks from './substrate/wait-new-blocks';
+import {expect} from 'chai';
+import { getGenericResult } from './util/helpers';
+//import find from 'find-process';
+
+let alice: IKeyringPair;
+let bob: IKeyringPair;
+let charlie: IKeyringPair;
+let dave: IKeyringPair;
+let eve: IKeyringPair;
+
+const alice_port = 31200;
+const bob_port = 31201;
+
+describe('Make me a big great cloud', () => {
+ before(async () => {
+ await usingApi(async () => {
+ alice = privateKey('//Alice');
+ bob = privateKey('//Bob');
+ charlie = privateKey('//Charlie');
+ dave = privateKey('//Dave');
+ eve = privateKey('//Eve');
+ });
+ });
+
+ it('Can\\t stand the heat', async () => {
+ // let alice_processes = await find('port', alice_port);
+ // expect(alice_processes).to.be.length.above(0);
+ // alice_processes = alice_processes.filter((process) => process.name.includes('unique'));
+ // expect(alice_processes).to.be.length(1);
+
+ // let alice_pid = alice_processes[0].pid;
+ // process.kill(alice_pid, 'SIGINT');
+ // console.log(alice_pid)
+
+ await usingApi(async (api) => {
+ /*const currentDesiredCandidates = (await api.query.collatorSelection.desiredCandidates() as any).toBigInt();
+ if (currentDesiredCandidates < )*/
+ const tx = api.tx.session.setKeys(
+ '0x' + Buffer.from(charlie.addressRaw).toString('hex'),
+ '0x0'
+ );
+ const events = await submitTransactionAsync(charlie, tx);
+ const result = getGenericResult(events);
+ expect(result.success).to.be.true;
+
+ const tx2 = api.tx.collatorSelection.setInvulnerables([
+ bob.address,
+ charlie.address
+ ]);
+ const sudoTx = api.tx.sudo.sudo(tx2 as any);
+ const events2 = await submitTransactionAsync(alice, sudoTx);
+ const result2 = getGenericResult(events2);
+ expect(result2.success).to.be.true;
+
+ let newInvulnerables = (await api.query.collatorSelection.invulnerables()).toJSON();
+ expect(newInvulnerables).to.contain(charlie.address);
+
+ const expectedSessionIndex = (await api.query.session.currentIndex() as any).toNumber() + 2;
+ let currentSessionIndex = -1;
+ while (currentSessionIndex < expectedSessionIndex) {
+ await waitNewBlocks(api, 1);
+ currentSessionIndex = (await api.query.session.currentIndex() as any).toNumber();
+ // todo implement a timeout in case new blocks are not being produced
+ }
+ });
+ });
+});
\ No newline at end of file