-
Notifications
You must be signed in to change notification settings - Fork 24
/
votable.spec.ts
71 lines (56 loc) · 2.37 KB
/
votable.spec.ts
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
60
61
62
63
64
65
66
67
68
69
70
71
import {Votable, Web3Connection} from '../../src';
import {defaultWeb3Connection, erc20Deployer, hasTxBlockNumber, increaseTime} from '../utils/';
import {toSmartContractDecimals} from '../../src/';
import {expect} from 'chai';
describe(`Votable`, () => {
let accountAddress: string;
let contractAddress: string;
let tokenContractAddress: string;
let contract: Votable;
const cap = 1000;
const smartContractCap = toSmartContractDecimals(cap);
let web3Connection: Web3Connection;
before(async () => {
web3Connection = await defaultWeb3Connection(true, true);
accountAddress = web3Connection.Account.address;
});
it(`Deploys`, async () => {
const erc = await erc20Deployer(`Voting`, `$voting`, smartContractCap, web3Connection);
const deployer = new Votable(web3Connection);
deployer.loadAbi();
const deployed = await deployer.deployJsonAbi(erc.contractAddress!);
expect(deployed.contractAddress).to.exist;
contractAddress = deployed.contractAddress!;
tokenContractAddress = erc.contractAddress!;
});
describe(`Methods`, () => {
let pollId!: number;
before(async () => {
contract = new Votable(web3Connection, contractAddress, tokenContractAddress);
await contract.start();
});
it(`Creates a poll`, async () => {
const tx = await contract.createPoll(`Test poll`, 3600, [0, 1]);
expect(tx.transactionHash).to.not.be.empty;
const events =
await contract.contract.self
.getPastEvents(`pollCreated`,
{fromBlock: tx.blockNumber, address: accountAddress});
expect(events[0].returnValues["pollID"], `Event opener`).to.not.be.undefined;
pollId = events[0].returnValues["pollID"];
});
it(`Casts a vote`, async () => {
await hasTxBlockNumber(contract.castVote(pollId, 0));
})
it(`Asserts casted vote`, async () => {
expect(await contract.userHasVoted(pollId, accountAddress)).to.be.true;
});
it(`Ends poll and asserts winner`, async () => {
await increaseTime(3602, web3Connection.Web3);
await hasTxBlockNumber(contract.endPoll(pollId), `Should have ended Poll`);
const pollWinner = await contract.getPoolWinner(pollId);
const pollInfo = await contract.getPoolInformation(pollId);
expect(pollInfo.voters[pollWinner.winnerId]).to.be.eq(accountAddress);
});
});
})