git.delta.rocks / unique-network / refs/commits / e5bbfb13d3e4

difftreelog

test(CollatorSelection) invulnerables shuffling

Fahrrader2022-03-30parent: #9667dc5.patch.diff
in: master

3 files changed

modifiedlaunch-config.jsondiffbeforeafterboth
--- a/launch-config.json
+++ b/launch-config.json
@@ -85,7 +85,6 @@
     "parachains": [
         {
             "bin": "../unique-chain/target/release/unique-collator",
-            "id": "1000",
             "balance": "1000000000000000000000000",
             "nodes": [
                 {
@@ -111,6 +110,42 @@
                         "--unsafe-ws-external",
                         "-lxcm=trace"
                     ]
+                },
+                {
+                    "port": 31202,
+                    "wsPort": 9946,
+                    "rpcPort": 9935,
+                    "name": "charlie",
+                    "flags": [
+                        "--rpc-cors=all",
+                        "--unsafe-rpc-external",
+                        "--unsafe-ws-external",
+                        "-lxcm=trace"
+                    ]
+                },
+                {
+                    "port": 31203,
+                    "wsPort": 9947,
+                    "rpcPort": 9936,
+                    "name": "dave",
+                    "flags": [
+                        "--rpc-cors=all",
+                        "--unsafe-rpc-external",
+                        "--unsafe-ws-external",
+                        "-lxcm=trace"
+                    ]
+                },
+                {
+                    "port": 31204,
+                    "wsPort": 9948,
+                    "rpcPort": 9937,
+                    "name": "eve",
+                    "flags": [
+                        "--rpc-cors=all",
+                        "--unsafe-rpc-external",
+                        "--unsafe-ws-external",
+                        "-lxcm=trace"
+                    ]
                 }
             ]
         }
modifiedtests/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",
addedtests/src/shuffleCollators.test.tsdiffbeforeafterboth
after · tests/src/shuffleCollators.test.ts
1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617import {ApiPromise} from '@polkadot/api';18import {IKeyringPair} from '@polkadot/types/types';19import privateKey from './substrate/privateKey';20import usingApi, { submitTransactionAsync } from './substrate/substrate-api';21import waitNewBlocks from './substrate/wait-new-blocks';22import {expect} from 'chai';23import { getGenericResult } from './util/helpers';24//import find from 'find-process';2526let alice: IKeyringPair;27let bob: IKeyringPair;28let charlie: IKeyringPair;29let dave: IKeyringPair;30let eve: IKeyringPair;3132const alice_port = 31200;33const bob_port = 31201;3435describe('Make me a big great cloud', () => {36    before(async () => {    37        await usingApi(async () => {38            alice = privateKey('//Alice');39            bob = privateKey('//Bob');40            charlie = privateKey('//Charlie');41            dave = privateKey('//Dave');42            eve = privateKey('//Eve');43        });44    });4546    it('Can\\t stand the heat', async () => {47        // let alice_processes = await find('port', alice_port);48        // expect(alice_processes).to.be.length.above(0);49        // alice_processes = alice_processes.filter((process) => process.name.includes('unique'));50        // expect(alice_processes).to.be.length(1);5152        // let alice_pid = alice_processes[0].pid;53        // process.kill(alice_pid, 'SIGINT');54        // console.log(alice_pid)5556        await usingApi(async (api) => {57            /*const currentDesiredCandidates = (await api.query.collatorSelection.desiredCandidates() as any).toBigInt();58            if (currentDesiredCandidates < )*/59            const tx = api.tx.session.setKeys(60                '0x' + Buffer.from(charlie.addressRaw).toString('hex'),61                '0x0'62            );63            const events = await submitTransactionAsync(charlie, tx);64            const result = getGenericResult(events);65            expect(result.success).to.be.true;6667            const tx2 = api.tx.collatorSelection.setInvulnerables([68                bob.address,69                charlie.address70            ]);71            const sudoTx = api.tx.sudo.sudo(tx2 as any);72            const events2 = await submitTransactionAsync(alice, sudoTx);73            const result2 = getGenericResult(events2);74            expect(result2.success).to.be.true;7576            let newInvulnerables = (await api.query.collatorSelection.invulnerables()).toJSON();77            expect(newInvulnerables).to.contain(charlie.address);7879            const expectedSessionIndex = (await api.query.session.currentIndex() as any).toNumber() + 2;80            let currentSessionIndex = -1;81            while (currentSessionIndex < expectedSessionIndex) {82                await waitNewBlocks(api, 1);83                currentSessionIndex = (await api.query.session.currentIndex() as any).toNumber();84                // todo implement a timeout in case new blocks are not being produced85            }86        });87    });88});