difftreelog
test(CollatorSelection) test polish
in: master
1 file changed
tests/src/shuffleCollators.test.tsdiffbeforeafterboth32const alice_port = 31200;32const alice_port = 31200;33const bob_port = 31201;33const bob_port = 31201;343435describe('Make me a big great cloud', () => {35describe('Integration Test: Dynamic shuffling of collators', () => {36 before(async () => { 36 before(async () => { 37 await usingApi(async () => {37 await usingApi(async () => {38 alice = privateKey('//Alice');38 alice = privateKey('//Alice');43 });43 });44 });44 });454546 it('Can\\t stand the heat', async () => {46 it('Change invulnerables and make sure they start producing blocks', 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) => {47 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(48 const txC = api.tx.session.setKeys(60 '0x' + Buffer.from(charlie.addressRaw).toString('hex'),49 '0x' + Buffer.from(charlie.addressRaw).toString('hex'),61 '0x0'50 '0x0'62 );51 );63 const events = await submitTransactionAsync(charlie, tx);52 const eventsC = await submitTransactionAsync(charlie, txC);64 const result = getGenericResult(events);53 const resultC = getGenericResult(eventsC);65 expect(result.success).to.be.true;54 expect(resultC.success).to.be.true;5556 const txD = api.tx.session.setKeys(57 '0x' + Buffer.from(dave.addressRaw).toString('hex'),58 '0x0'59 );60 const eventsD = await submitTransactionAsync(dave, txD);61 const resultD = getGenericResult(eventsD);62 expect(resultD.success).to.be.true;666367 const tx2 = api.tx.collatorSelection.setInvulnerables([64 const tx = api.tx.collatorSelection.setInvulnerables([68 bob.address,65 charlie.address,69 charlie.address66 dave.address70 ]);67 ]);71 const sudoTx = api.tx.sudo.sudo(tx2 as any);68 const sudoTx = api.tx.sudo.sudo(tx as any);72 const events2 = await submitTransactionAsync(alice, sudoTx);69 const events = await submitTransactionAsync(alice, sudoTx);73 const result2 = getGenericResult(events2);70 const result = getGenericResult(events);74 expect(result2.success).to.be.true;71 expect(result.success).to.be.true;757276 let newInvulnerables = (await api.query.collatorSelection.invulnerables()).toJSON();73 let newInvulnerables = (await api.query.collatorSelection.invulnerables()).toJSON();77 expect(newInvulnerables).to.contain(charlie.address);74 expect(newInvulnerables).to.contain(charlie.address).and.contain(dave.address);75 expect(newInvulnerables).to.be.length(2);787679 const expectedSessionIndex = (await api.query.session.currentIndex() as any).toNumber() + 2;77 const expectedSessionIndex = (await api.query.session.currentIndex() as any).toNumber() + 2;80 let currentSessionIndex = -1;78 let currentSessionIndex = -1;84 // todo implement a timeout in case new blocks are not being produced82 // todo implement a timeout in case new blocks are not being produced85 }83 }8485 let newValidators = (await api.query.session.validators()).toJSON();86 expect(newValidators).to.contain(charlie.address).and.contain(dave.address);87 expect(newValidators).to.be.length(2);86 });88 });87 });89 });88});90});