2018-06-26 17:34:24 +00:00
|
|
|
const utils = require('../utils/testUtils')
|
|
|
|
const assert = require('assert');
|
|
|
|
const BN = web3.utils.BN;
|
|
|
|
var _ = require('lodash');
|
|
|
|
var rlp = require('rlp');
|
|
|
|
|
|
|
|
config({
|
|
|
|
contracts: {
|
|
|
|
"MiniMeTokenFactory": {
|
|
|
|
"gasLimit": 4000000
|
|
|
|
},
|
|
|
|
"MiniMeToken": {
|
|
|
|
"deploy": false,
|
|
|
|
},
|
|
|
|
"SNT":{
|
|
|
|
"instanceOf": "MiniMeToken",
|
|
|
|
"args": [
|
|
|
|
"$MiniMeTokenFactory",
|
|
|
|
utils.zeroAddress,
|
|
|
|
0,
|
|
|
|
"TestMiniMeToken",
|
|
|
|
18,
|
|
|
|
"TST",
|
|
|
|
true
|
|
|
|
],
|
|
|
|
"gasLimit": 4000000
|
|
|
|
},
|
|
|
|
"PollManager": {
|
|
|
|
"deploy": true,
|
|
|
|
"args": ["$MiniMeTokenFactory", "$SNT"]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
describe("VotingDapp", function () {
|
|
|
|
this.timeout(0);
|
|
|
|
|
|
|
|
let accounts;
|
|
|
|
|
|
|
|
before(function(done) {
|
|
|
|
|
|
|
|
web3.eth.getAccounts().then((acc) => {
|
|
|
|
accounts = acc;
|
2018-06-26 20:34:28 +00:00
|
|
|
return SNT.methods.generateTokens(accounts[0], 6).send()
|
2018-06-26 17:34:24 +00:00
|
|
|
}).then((receipt) => {
|
2018-06-26 20:34:28 +00:00
|
|
|
return SNT.methods.generateTokens(accounts[1], 12).send()
|
2018-06-26 17:34:24 +00:00
|
|
|
}).then((receipt) => {
|
2018-06-26 20:34:28 +00:00
|
|
|
return SNT.methods.generateTokens(accounts[2], 10).send()
|
2018-06-26 17:34:24 +00:00
|
|
|
}).then((receipt) => {
|
2018-06-26 20:34:28 +00:00
|
|
|
return SNT.methods.generateTokens(accounts[3], 7).send()
|
2018-06-26 17:34:24 +00:00
|
|
|
}).then((receipt) => {
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it("Test", async () => {
|
|
|
|
|
|
|
|
const blockNumber = await web3.eth.getBlockNumber();
|
2018-06-27 21:23:27 +00:00
|
|
|
const question = "Move from Slack to Status Desktop";
|
2018-06-26 17:34:24 +00:00
|
|
|
let receipt;
|
|
|
|
|
|
|
|
|
|
|
|
// ===================================================
|
|
|
|
// Creating a proposal without holding SNT SHOULD FAIL!
|
|
|
|
try {
|
|
|
|
receipt = await PollManager.methods.addPoll(
|
|
|
|
blockNumber + 10,
|
|
|
|
question)
|
|
|
|
.send({from: accounts[8]});
|
|
|
|
assert.fail('should have reverted before');
|
|
|
|
} catch(error) {
|
|
|
|
utils.assertJump(error);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ===================================================
|
|
|
|
// Creating a proposal as a SNT holder
|
|
|
|
|
|
|
|
receipt = await PollManager.methods.addPoll(
|
|
|
|
blockNumber + 10,
|
|
|
|
question)
|
|
|
|
.send({from: accounts[0]});
|
|
|
|
|
|
|
|
assert.equal(!!receipt.events.PollCreated, true, "PollCreated not triggered");
|
|
|
|
|
|
|
|
const pollId = receipt.events.PollCreated.returnValues.idPoll;
|
|
|
|
let poll = await PollManager.methods.poll(pollId).call();
|
2018-06-27 21:23:27 +00:00
|
|
|
|
2018-06-26 17:34:24 +00:00
|
|
|
|
|
|
|
// ===================================================
|
|
|
|
// Determining if I can vote por a proposal
|
|
|
|
let canVote = await PollManager.methods.canVote(pollId).call({from: accounts[0]});
|
|
|
|
assert.equal(canVote, true, "User should be able to vote");
|
|
|
|
|
|
|
|
|
|
|
|
// ===================================================
|
|
|
|
// Voting
|
2018-06-27 21:23:27 +00:00
|
|
|
receipt = await PollManager.methods.vote(pollId).send({from: accounts[0]});
|
2018-06-26 17:34:24 +00:00
|
|
|
assert.equal(!!receipt.events.Vote, true, "Vote not triggered");
|
|
|
|
|
2018-06-27 21:23:27 +00:00
|
|
|
receipt = await PollManager.methods.customVote(pollId, 12).send({from: accounts[1]});
|
2018-06-27 17:27:01 +00:00
|
|
|
assert.equal(!!receipt.events.Vote, true, "Vote not triggered");
|
|
|
|
|
2018-06-26 17:34:24 +00:00
|
|
|
|
|
|
|
// ===================================================
|
|
|
|
// Getting what option the voter selected
|
|
|
|
let myVote = await PollManager.methods.getVote(pollId, accounts[0]).call();
|
2018-06-27 21:23:27 +00:00
|
|
|
const balance = await SNT.methods.balanceOf(accounts[0]).call();
|
|
|
|
assert.equal(myVote, balance, "Vote is different from selected");
|
2018-06-26 17:34:24 +00:00
|
|
|
|
|
|
|
|
|
|
|
// ===================================================
|
|
|
|
// Voting when you're not a SNT holder SHOULD FAIL!
|
|
|
|
try {
|
2018-06-27 21:23:27 +00:00
|
|
|
receipt = await PollManager.methods.vote(pollId)
|
2018-06-26 17:34:24 +00:00
|
|
|
.send({from: accounts[8]});
|
|
|
|
assert.fail('should have reverted before');
|
|
|
|
} catch(error) {
|
|
|
|
utils.assertJump(error);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ===================================================
|
|
|
|
// Getting proposal information
|
|
|
|
poll = await PollManager.methods.poll(pollId).call();
|
2018-06-27 21:23:27 +00:00
|
|
|
let tokenVotes = poll._results;
|
|
|
|
let quadraticVotes = poll._qvResults;
|
|
|
|
let voters = poll._voters;
|
2018-06-26 20:34:28 +00:00
|
|
|
|
|
|
|
// Will contain state of the poll
|
|
|
|
// console.dir(poll);
|
|
|
|
|
2018-06-27 21:23:27 +00:00
|
|
|
// Contains how many voters
|
|
|
|
// console.log(voters);
|
2018-06-26 17:34:24 +00:00
|
|
|
|
2018-06-27 21:23:27 +00:00
|
|
|
// Contains how many votes using quadratic voting
|
|
|
|
// console.log(quadraticVotes);
|
2018-06-26 20:34:28 +00:00
|
|
|
|
2018-06-27 21:23:27 +00:00
|
|
|
// Contains how many votes
|
|
|
|
// console.log(tokenVotes);
|
2018-06-26 17:34:24 +00:00
|
|
|
|
|
|
|
// ===================================================
|
|
|
|
// Unvote
|
|
|
|
receipt = await PollManager.methods.unvote(pollId).send({from: accounts[0]});
|
|
|
|
assert.equal(!!receipt.events.Unvote, true, "Unvote not triggered");
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|