git.delta.rocks / unique-network / refs/commits / 5489e8c40ab3

difftreelog

test(CollatorSelection) test polish

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

1 file changed

modifiedtests/src/shuffleCollators.test.tsdiffbeforeafterboth
32const alice_port = 31200;32const alice_port = 31200;
33const bob_port = 31201;33const bob_port = 31201;
3434
35describe('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 });
4545
46 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);
51
52 // let alice_pid = alice_processes[0].pid;
53 // process.kill(alice_pid, 'SIGINT');
54 // console.log(alice_pid)
55
56 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;
55
56 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;
6663
67 const tx2 = api.tx.collatorSelection.setInvulnerables([64 const tx = api.tx.collatorSelection.setInvulnerables([
68 bob.address,65 charlie.address,
69 charlie.address66 dave.address
70 ]);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;
7572
76 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);
7876
79 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 produced
85 }83 }
84
85 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});