--- a/runtime/common/mod.rs +++ b/runtime/common/mod.rs @@ -224,7 +224,7 @@ .collect::>(), ) .expect("Existing collators/invulnerables are more than MaxInvulnerables"); - + >::put(bounded_invulnerables); >::put(0); >::put(EXISTENTIAL_DEPOSIT * 16); @@ -248,7 +248,7 @@ // todo exercise caution, the following is taken from genesis if frame_system::Pallet::::inc_consumers_without_limit(&account).is_err() { log::warn!( - "We have entered an error with incrementing consumers without limit" + "We have entered an error with incrementing consumers without limit during the migration" ); // This will leak a provider reference, however it only happens once (at // genesis) so it's really not a big deal and we assume that the user wants to --- a/tests/src/shuffleCollators.test.ts +++ b/tests/src/shuffleCollators.test.ts @@ -16,85 +16,89 @@ import {IKeyringPair} from '@polkadot/types/types'; import privateKey from './substrate/privateKey'; -import usingApi, { submitTransactionAsync } from './substrate/substrate-api'; +import usingApi, {submitTransactionAsync} from './substrate/substrate-api'; import waitNewBlocks from './substrate/wait-new-blocks'; import {expect} from 'chai'; -import { getGenericResult } from './util/helpers'; +import {getBlockNumber, getGenericResult} from './util/helpers'; let alice: IKeyringPair; let bob: IKeyringPair; let charlie: IKeyringPair; let dave: IKeyringPair; -let eve: IKeyringPair; +//let eve: IKeyringPair; describe('Integration Test: Dynamic shuffling of collators', () => { - before(async () => { - await usingApi(async () => { - alice = privateKey('//Alice'); - bob = privateKey('//Bob'); - charlie = privateKey('//Charlie'); - dave = privateKey('//Dave'); - eve = privateKey('//Eve'); - }); + before(async () => { + await usingApi(async () => { + alice = privateKey('//Alice'); + bob = privateKey('//Bob'); + charlie = privateKey('//Charlie'); + dave = privateKey('//Dave'); + //eve = privateKey('//Eve'); }); + }); - it('Change invulnerables and make sure they start producing blocks', async () => { - await usingApi(async (api) => { - const txC = api.tx.session.setKeys( - '0x' + Buffer.from(charlie.addressRaw).toString('hex'), - '0x0' - ); - const eventsC = await submitTransactionAsync(charlie, txC); - const resultC = getGenericResult(eventsC); - expect(resultC.success).to.be.true; + it('Change invulnerables and make sure they start producing blocks', async () => { + await usingApi(async (api) => { + const txC = api.tx.session.setKeys( + '0x' + Buffer.from(charlie.addressRaw).toString('hex'), + '0x0', + ); + const eventsC = await submitTransactionAsync(charlie, txC); + const resultC = getGenericResult(eventsC); + expect(resultC.success).to.be.true; - const txD = api.tx.session.setKeys( - '0x' + Buffer.from(dave.addressRaw).toString('hex'), - '0x0' - ); - const eventsD = await submitTransactionAsync(dave, txD); - const resultD = getGenericResult(eventsD); - expect(resultD.success).to.be.true; + const txD = api.tx.session.setKeys( + '0x' + Buffer.from(dave.addressRaw).toString('hex'), + '0x0', + ); + const eventsD = await submitTransactionAsync(dave, txD); + const resultD = getGenericResult(eventsD); + expect(resultD.success).to.be.true; - const tx = api.tx.collatorSelection.setInvulnerables([ - charlie.address, - dave.address - ]); - const sudoTx = api.tx.sudo.sudo(tx as any); - const events = await submitTransactionAsync(alice, sudoTx); - const result = getGenericResult(events); - expect(result.success).to.be.true; + const tx = api.tx.collatorSelection.setInvulnerables([ + charlie.address, + dave.address, + ]); + const sudoTx = api.tx.sudo.sudo(tx as any); + const events = await submitTransactionAsync(alice, sudoTx); + const result = getGenericResult(events); + expect(result.success).to.be.true; - let newInvulnerables = (await api.query.collatorSelection.invulnerables()).toJSON(); - expect(newInvulnerables).to.contain(charlie.address).and.contain(dave.address); - expect(newInvulnerables).to.be.length(2); + const newInvulnerables = (await api.query.collatorSelection.invulnerables()).toJSON(); + expect(newInvulnerables).to.contain(charlie.address).and.contain(dave.address); + expect(newInvulnerables).to.be.length(2); - 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 - } + 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? session length needed + } - let newValidators = (await api.query.session.validators()).toJSON(); - expect(newValidators).to.contain(charlie.address).and.contain(dave.address); - expect(newValidators).to.be.length(2); + const newValidators = (await api.query.session.validators()).toJSON(); + expect(newValidators).to.contain(charlie.address).and.contain(dave.address); + expect(newValidators).to.be.length(2); - // todo add delay to check that new blocks are authored by these - }); + const lastBlockNumber = await getBlockNumber(api); + await waitNewBlocks(api, 1); + const lastCharlieBlock = (await api.query.collatorSelection.lastAuthoredBlock(charlie.address) as any).toNumber(); + const lastDaveBlock = (await api.query.collatorSelection.lastAuthoredBlock(dave.address) as any).toNumber(); + expect(lastCharlieBlock >= lastBlockNumber || lastDaveBlock >= lastBlockNumber).to.be.true; }); + }); - after(async () => { - await usingApi(async (api) => { - const tx = api.tx.collatorSelection.setInvulnerables([ - alice.address, - bob.address - ]); - const sudoTx = api.tx.sudo.sudo(tx as any); - const events = await submitTransactionAsync(alice, sudoTx); - const result = getGenericResult(events); - expect(result.success).to.be.true; - }); + after(async () => { + await usingApi(async (api) => { + const tx = api.tx.collatorSelection.setInvulnerables([ + alice.address, + bob.address, + ]); + const sudoTx = api.tx.sudo.sudo(tx as any); + const events = await submitTransactionAsync(alice, sudoTx); + const result = getGenericResult(events); + expect(result.success).to.be.true; }); + }); });