2018-08-20 18:42:27 +00:00
|
|
|
|
|
|
|
// our contract object to test
|
2018-10-09 23:00:32 +00:00
|
|
|
const DReddit = embark.require('Embark/contracts/DReddit');
|
2018-08-20 18:42:27 +00:00
|
|
|
|
|
|
|
// variables that will be updated in the tests
|
|
|
|
let accounts;
|
|
|
|
let postId;
|
|
|
|
|
|
|
|
// set up our config test parameters
|
|
|
|
config({
|
|
|
|
contracts: {
|
|
|
|
DReddit: {
|
|
|
|
// would pass constructor args here if needed
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}, (err, theAccounts) => {
|
|
|
|
// this is the list of accounts our node / wallet controls.
|
|
|
|
accounts = theAccounts;
|
|
|
|
});
|
|
|
|
|
|
|
|
// other test parameters
|
|
|
|
const ipfsHash = 'Qmc5gCcjYypU7y28oCALwfSvxCBskLuPKWpK4qpterKC7z';
|
|
|
|
|
|
|
|
// Embark exposes a global contract method as an alias
|
|
|
|
// for Mocha.describe
|
|
|
|
contract("DReddit contract", function () {
|
2018-10-09 23:00:32 +00:00
|
|
|
|
2018-08-20 18:42:27 +00:00
|
|
|
this.timeout(0);
|
|
|
|
|
|
|
|
it("should be able to create a post and receive it via contract event", async function () {
|
2018-10-09 23:00:32 +00:00
|
|
|
// TODO:
|
2018-08-20 18:42:27 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it("post should have correct data", async function (){
|
2018-10-09 23:00:32 +00:00
|
|
|
// TODO:
|
2018-08-20 18:42:27 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it("one post should be registered", async function () {
|
2018-10-09 23:00:32 +00:00
|
|
|
const n = await DReddit.methods.numPosts().call();
|
2018-08-20 18:42:27 +00:00
|
|
|
assert.equal(n, 1);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should not be able to vote in an unexisting post", async function () {
|
2018-10-09 23:00:32 +00:00
|
|
|
const userCanVote = await DReddit.methods.canVote("123").call();
|
2018-08-20 18:42:27 +00:00
|
|
|
assert.equal(userCanVote, false);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should be able to vote in a post if account hasn't voted before", async function () {
|
2018-10-09 23:00:32 +00:00
|
|
|
const userCanVote = await DReddit.methods.canVote(postId).call();
|
2018-08-20 18:42:27 +00:00
|
|
|
assert.equal(userCanVote, true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should be able to vote in a post", async function () {
|
2018-10-09 23:00:32 +00:00
|
|
|
const receipt = await DReddit.methods.vote(postId, 1).send();
|
2018-08-20 18:42:27 +00:00
|
|
|
const Vote = receipt.events.Vote;
|
|
|
|
assert.equal(Vote.returnValues.voter, accounts[0]);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should't be able to vote twice", async function () {
|
2018-10-09 23:00:32 +00:00
|
|
|
// TODO:
|
2018-08-20 18:42:27 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
});
|