/
create-vote.spec.js
60 lines (45 loc) · 2.24 KB
/
create-vote.spec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
const { FactomCli } = require('factom'),
assert = require('chai').assert,
createVote = require('../src/write-vote/create-vote');
require('dotenv').config();
const cli = new FactomCli({ host: process.env.FACTOM_HOST });
describe('Create vote', function () {
it('should create a vote', async function () {
this.timeout(20000);
const registrationChainId = 'a968e880ee3a7002f25ade15ae36a77c15f4dbc9d8c11fdd5fe86ba6af73a475';
const definition = await getVoteDefinition();
const eligibleVoters = require('./data/eligible-voters');
const identity = { chainId: '2d98021e3cf71580102224b2fcb4c5c60595e8fdf6fd1b97c6ef63e9fb3ed635', key: 'idsec2Vn3VT8FdE1YpcDms8zSvXR4DGzQeMMdeLRP2RbMCSWCFoQDbS' };
const voteData = {
definition, registrationChainId, eligibleVoters, identity
};
const result = await createVote.createVote(cli, voteData, process.env.EC_PRIVATE_KEY);
assert.isObject(result);
assert.isObject(result.eligibleVoters);
assert.isObject(result.vote);
assert.isObject(result.registration);
});
async function getVoteDefinition() {
const definition = JSON.parse(JSON.stringify(require('./data/vote-definition')));
delete definition.vote.eligibleVotersChainId;
const currentHeight = await cli.getHeights().then(h => h.leaderHeight);
definition.vote.phasesBlockHeights = {
commitStart: currentHeight + 10,
commitEnd: currentHeight + 20,
revealStart: currentHeight + 30,
revealEnd: currentHeight + 40
};
return definition;
}
xit('should append eligible voters', async function () {
this.timeout(10000);
const identityKey = 'idsec2Vn3VT8FdE1YpcDms8zSvXR4DGzQeMMdeLRP2RbMCSWCFoQDbS';
const eligibleVotersChainId = '2e51ae1d84831b04f75c51e1d352d6e186ac8aeea47bfb412749774a5dd53907';
const eligibleVoters = require('./data/eligible-voters');
const appendEligibleVotersData = {
eligibleVoters, eligibleVotersChainId, identityKey
};
const result = await createVote.appendEligibleVoters(cli, appendEligibleVotersData, process.env.EC_PRIVATE_KEY);
assert.isObject(result);
});
});