Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save inovizz/28908af740f72f94d54f4e4b811da75d to your computer and use it in GitHub Desktop.
Save inovizz/28908af740f72f94d54f4e4b811da75d to your computer and use it in GitHub Desktop.
'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