meritocracy/test/Meritocracy_spec.js

151 lines
4.9 KiB
JavaScript
Raw Permalink Normal View History

2019-02-02 16:04:55 +00:00
/*global contract, config, it, assert*/
const Meritocracy = require('Embark/contracts/Meritocracy');
// const StandardToken = require('Embark/contracts/StandardToken');
const SNT = require('Embark/contracts/SNT');
let accounts;
2019-02-08 16:08:02 +00:00
let owner;
let admins;
let ownerInitTokens;
2019-02-02 16:04:55 +00:00
2019-04-10 22:02:22 +00:00
const IPFS_HASH = web3.utils.toHex('QmREHBNWoJCx8KDz7PBAThv8mrxGRWimbzqZsL8aDzfLHW');
2019-02-02 16:04:55 +00:00
// For documentation please see https://embark.status.im/docs/contracts_testing.html
config({
2019-02-08 16:08:02 +00:00
deployment: {
accounts: [
{
"mnemonic": "example exile argue silk regular smile grass bomb merge arm assist farm",
"balance": "5 ether",
numAddresses: 10
}
// you can configure custom accounts with a custom balance
// see https://embark.status.im/docs/contracts_testing.html#Configuring-accounts
]
2019-02-08 16:08:02 +00:00
},
2019-02-02 16:04:55 +00:00
contracts: {
"MiniMeToken": {"deploy": false, "args": []},
"MiniMeTokenFactory": {},
2019-02-02 16:04:55 +00:00
"SNT": {
"instanceOf": "MiniMeToken",
"args": [
"$MiniMeTokenFactory",
"0x0000000000000000000000000000000000000000",
0,
"TestMiniMeToken",
18,
"STT",
true
]
},
"Meritocracy": {
"fromIndex": 0, // accounts[0]
"args": ["$SNT", 10, IPFS_HASH] // Bind to SNT Contract, max 10 contributors.
2019-02-02 16:04:55 +00:00
}
}
}, (_err, web3_accounts) => {
2019-02-08 16:08:02 +00:00
accounts = web3_accounts;
owner = accounts[0];
admins = [accounts[0], accounts[1], accounts[2]];
ownerInitTokens = 10000;
2019-02-02 16:04:55 +00:00
});
contract("Meritocracy", function () {
2019-02-08 16:08:02 +00:00
before(async () => {
await SNT.methods.generateTokens(owner, ownerInitTokens).send();
});
// Owner Tests
it("owned == owner, maxContributors == 10", async function () {
var result;
result = await Meritocracy.methods.owner().call();
assert.strictEqual(result, owner);
result = await Meritocracy.methods.maxContributors().call();
assert.strictEqual(parseInt(result), 10);
});
it("registry.length == 3, allocate(1000);", async function () {
2019-02-08 16:08:02 +00:00
var result;
let allocationAmount = 1000;
let contributorCount = 3;
let individualAllocation = parseInt(allocationAmount / contributorCount); // 333
// Add 3 Contributors and check registry length matches
2019-02-08 16:08:02 +00:00
var i = 0;
while (i < contributorCount) {
result = await Meritocracy.methods.addContributor(accounts[i], IPFS_HASH).send({from: owner});
2019-02-08 16:08:02 +00:00
i++;
}
let registry = await Meritocracy.methods.getRegistry().call(); // TODO check if this works
assert.strictEqual(parseInt(registry.length), contributorCount); // 3
2019-02-08 16:08:02 +00:00
// Approve and allocate 1000 SNT for Meritocracy use
result = await SNT.methods.approve(Meritocracy.options.address, allocationAmount).send({from: owner});
2019-02-08 16:08:02 +00:00
result = await Meritocracy.methods.allocate(allocationAmount).send({from: owner});
// FIXME these don't work. Looks like the allocation doesn't go through
2019-02-08 16:08:02 +00:00
result = await SNT.methods.balanceOf(Meritocracy.address).call();
// assert.strictEqual(parseInt(result), allocationAmount); // 1000
2019-02-08 16:08:02 +00:00
result = await SNT.methods.balanceOf(owner).call();
// assert.strictEqual(parseInt(result), ownerInitTokens - allocationAmount); // 9000
2019-02-08 16:08:02 +00:00
// Check Individual Contributor amount is 333
const contributor = await Meritocracy.methods.contributors(admins[0]).call();
// assert.strictEqual(parseInt(contributor.allocation), individualAllocation); // 333
2019-02-08 16:08:02 +00:00
});
2019-02-08 16:21:53 +00:00
// TODO Addadmin
// TODO RemoveAdmin
it("maxContributor + 1 fails", async function() {
2019-02-08 16:21:53 +00:00
// TODO change so admin adds them
2019-02-08 16:08:02 +00:00
var result;
let contributorCount = 3;
let additionalContributorsToMax = 7;
var i = 0;
while (i < additionalContributorsToMax) {
result = await Meritocracy.methods.addContributor(accounts[contributorCount + i], IPFS_HASH).send({from: owner});
2019-02-08 16:08:02 +00:00
i++;
}
try {
result = await Meritocracy.methods.addContributor(accounts[i], IPFS_HASH).send({from: owner});
2019-02-08 16:08:02 +00:00
assert.fail('should have reverted');
} catch (error) {
assert.strictEqual(error.message, "VM Exception while processing transaction: revert");
}
});
describe('removeContributor', () => {
it('removes with normal values', async () => {
let oldRegistry = await Meritocracy.methods.getRegistry().call();
let result = await Meritocracy.methods.removeContributor(1, IPFS_HASH).send({from: owner});
let registry = await Meritocracy.methods.getRegistry().call();
assert.strictEqual(registry.length, oldRegistry.length - 1);
})
})
2019-02-08 16:21:53 +00:00
// TODO award
// TODO withdraw before and after
// TODO forfeitAllocations
// TODO withdraw after forfeitAllocations
2019-02-02 16:04:55 +00:00
2019-02-08 16:21:53 +00:00
// TODO setMaxContributors smaller than max
// TODO setMaxContributors again
// TODO addContributors
// TODO changeOwner
2019-02-02 16:04:55 +00:00
2019-02-08 16:21:53 +00:00
// TODO escape
// TODO changeToken
// TODO escape overload?
2019-02-02 16:04:55 +00:00
});