Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
'use strict';
const DataStore = artifacts.require('../contracts/DataStore.sol');
const Organisation = artifacts.require('../contracts/Organisation.sol');
const sha3 = require('solidity-sha3').default;
contract('Organisation', function(accounts) {
let bookStore, memberStore, org;
beforeEach(async function() {
bookStore = await DataStore.new();
memberStore = await DataStore.new();
org = await Organisation.new({value: web3.toWei(0.1)});
// Transfer ownership of stores from default account to organisation. This allows modifying the data store.
bookStore.transferOwnership(org.address);
memberStore.transferOwnership(org.address);
await org.setDataStore(bookStore.address, memberStore.address);
await org.addMember('name', 'email', accounts[0]);
// await org.setDataStore(0x0, 0x0);
// TODO Investigate why org works with 0x0 data stores too.
});
describe('addMember', function() {
it('should add the member', async function() {
let count = await org.memberCount();
assert.equal(count.valueOf(), 1);
let member = await org.getMember(1);
let attr = member.split(';');
assert.equal(attr[0], '1');
assert.equal('0x' + attr[1], accounts[0]);
assert.equal(attr[2], '0');
assert.isAtMost(attr[3], Math.floor(Date.now() / 1000));
assert.isAbove(attr[3], Math.floor(Date.now() / 1000) - 300);
});
it('should not add the member again', async function() {
let count = await org.memberCount();
assert.equal(count.valueOf(), 1);
let res = await org.addMember('name', 'email', accounts[0]);
assert.equal(res.logs[0].args.statusCode.c[0], 102);
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment