Skip to content

Commit

Permalink
[fix] #1053 Newcomers order is now random
Browse files Browse the repository at this point in the history
  • Loading branch information
c-geek committed Aug 6, 2017
1 parent fa26f78 commit 2704d9e
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 1 deletion.
3 changes: 2 additions & 1 deletion app/modules/prover/lib/blockGenerator.ts
Expand Up @@ -171,7 +171,8 @@ export class BlockGenerator {
const members = await this.dal.getMembers();
const wotMembers = _.pluck(members, 'pubkey');
// Checking step
const newcomers = _(joinData).keys();
let newcomers = _(joinData).keys();
newcomers = _.shuffle(newcomers)
const nextBlockNumber = current ? current.number + 1 : 0;
try {
const realNewcomers = await this.iteratedChecking(newcomers, async (someNewcomers:string[]) => {
Expand Down
58 changes: 58 additions & 0 deletions test/integration/newcomers-shuffling.js
@@ -0,0 +1,58 @@
"use strict";

const _ = require('underscore');
const co = require('co');
const assert = require('assert');
const user = require('./tools/user');
const commit = require('./tools/commit');
const toolbox = require('./tools/toolbox');

let s1, cat, tac, toc, tic

describe("Newcomers shuffling", function() {

before(() => co(function*() {

s1 = toolbox.server({
pair: {
pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd',
sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP'
}
});

cat = user('cat', { pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP'}, { server: s1 });
tac = user('tac', { pub: '2LvDg21dVXvetTD9GdkPLURavLYEqP3whauvPWX4c2qc', sec: '2HuRLWgKgED1bVio1tdpeXrf7zuUszv1yPHDsDj7kcMC4rVSN9RC58ogjtKNfTbH1eFz7rn38U1PywNs3m6Q7UxE'}, { server: s1 });
toc = user('toc', { pub: 'DKpQPUL4ckzXYdnDRvCRKAm1gNvSdmAXnTrJZ7LvM5Qo', sec: '64EYRvdPpTfLGGmaX5nijLXRqWXaVz8r1Z1GtaahXwVSJGQRn7tqkxLb288zwSYzELMEG5ZhXSBYSxsTsz1m9y8F'}, { server: s1 });
tic = user('tic', { pub: 'DNann1Lh55eZMEDXeYt59bzHbA3NJR46DeQYCS2qQdLV', sec: '468Q1XtTq7h84NorZdWBZFJrGkB18CbmbHr9tkp9snt5GiERP7ySs3wM8myLccbAAGejgMRC9rqnXuW3iAfZACm7'}, { server: s1 });

yield s1.prepareForNetwork();

// Publishing identities
yield cat.createIdentity();
yield tac.createIdentity();
yield cat.cert(tac);
yield tac.cert(cat);
yield cat.join();
yield tac.join();
yield s1.commit()
}));

after(() => {
return Promise.all([
s1.closeCluster()
])
})

it('toc and tic could join ', () => co(function*() {
yield toc.createIdentity();
yield tic.createIdentity();
yield toc.join();
yield tic.join();
// same certifier for toc and tic
yield cat.cert(toc)
yield cat.cert(tic)
// We do not known which one of toc or tic will be the first in!
yield s1.commit()
yield s1.commit()
}));
});

0 comments on commit 2704d9e

Please sign in to comment.