dreddit-dapp/test/contract_spec.js

65 lines
1.7 KiB
JavaScript

// our contract object to test
const DReddit = require('Embark/contracts/DReddit');
// contract methods we'll be testing
const {numPosts, create, vote, posts, canVote, getVote} = DReddit.methods;
// 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 () {
this.timeout(0);
it("should be able to create a post and receive it via contract event", async function () {
// TODO:
});
it("post should have correct data", async function (){
// TODO:
});
it("one post should be registered", async function () {
const n = await numPosts().call();
assert.equal(n, 1);
});
it("should not be able to vote in an unexisting post", async function () {
const userCanVote = await canVote(123).call();
assert.equal(userCanVote, false);
});
it("should be able to vote in a post if account hasn't voted before", async function () {
const userCanVote = await canVote(postId).call();
assert.equal(userCanVote, true);
});
it("should be able to vote in a post", async function () {
const receipt = await vote(postId, 1).send();
const Vote = receipt.events.Vote;
assert.equal(Vote.returnValues.voter, accounts[0]);
});
it("should't be able to vote twice", async function () {
// TODO:
});
});