Skip to content

Commit

Permalink
Added account names to some missing contracts.
Browse files Browse the repository at this point in the history
  • Loading branch information
nventuro committed Aug 2, 2018
1 parent f7b431b commit ebada53
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 36 deletions.
35 changes: 10 additions & 25 deletions test/Heritable.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,11 @@ const NULL_ADDRESS = '0x0000000000000000000000000000000000000000';

const Heritable = artifacts.require('Heritable');

contract('Heritable', function (accounts) {
contract('Heritable', function ([_, owner, heir, anyone]) {
let heritable;
let owner;

beforeEach(async function () {
heritable = await Heritable.new(4141);
owner = await heritable.owner();
heritable = await Heritable.new(4141, { from: owner });
});

it('should start off with an owner, but without heir', async function () {
Expand All @@ -31,31 +29,23 @@ contract('Heritable', function (accounts) {
});

it('only owner should set heir', async function () {
const newHeir = accounts[1];
const someRandomAddress = accounts[2];
assert.isTrue(owner !== someRandomAddress);

await heritable.setHeir(newHeir, { from: owner });
await expectThrow(heritable.setHeir(newHeir, { from: someRandomAddress }));
await heritable.setHeir(heir, { from: owner });
await expectThrow(heritable.setHeir(heir, { from: anyone }));
});

it('owner can\'t be heir', async function () {
await assertRevert(heritable.setHeir(owner, { from: owner }));
});

it('owner can remove heir', async function () {
const newHeir = accounts[1];
await heritable.setHeir(newHeir, { from: owner });
let heir = await heritable.heir();

assert.notStrictEqual(heir, NULL_ADDRESS);
await heritable.removeHeir();
heir = await heritable.heir();
assert.isTrue(heir === NULL_ADDRESS);
await heritable.setHeir(heir, { from: owner });
assert.equal(await heritable.heir(), heir);

await heritable.removeHeir({ from: owner });
assert.equal(await heritable.heir(), NULL_ADDRESS);
});

it('heir can claim ownership only if owner is dead and timeout was reached', async function () {
const heir = accounts[1];
await heritable.setHeir(heir, { from: owner });
await expectThrow(heritable.claimHeirOwnership({ from: heir }));

Expand All @@ -69,20 +59,17 @@ contract('Heritable', function (accounts) {
});

it('only heir can proclaim death', async function () {
const someRandomAddress = accounts[2];
await assertRevert(heritable.proclaimDeath({ from: owner }));
await assertRevert(heritable.proclaimDeath({ from: someRandomAddress }));
await assertRevert(heritable.proclaimDeath({ from: anyone }));
});

it('heir can\'t proclaim death if owner is death', async function () {
const heir = accounts[1];
await heritable.setHeir(heir, { from: owner });
await heritable.proclaimDeath({ from: heir });
await assertRevert(heritable.proclaimDeath({ from: heir }));
});

it('heir can\'t claim ownership if owner heartbeats', async function () {
const heir = accounts[1];
await heritable.setHeir(heir, { from: owner });

await heritable.proclaimDeath({ from: heir });
Expand All @@ -96,8 +83,6 @@ contract('Heritable', function (accounts) {
});

it('should log events appropriately', async function () {
const heir = accounts[1];

const setHeirLogs = (await heritable.setHeir(heir, { from: owner })).logs;
const setHeirEvent = setHeirLogs.find(e => e.event === 'HeirChanged');

Expand Down
2 changes: 1 addition & 1 deletion test/LimitBalance.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const { ethGetBalance } = require('./helpers/web3');

const LimitBalanceMock = artifacts.require('LimitBalanceMock');

contract('LimitBalance', function (accounts) {
contract('LimitBalance', function () {
let limitBalance;

beforeEach(async function () {
Expand Down
2 changes: 1 addition & 1 deletion test/ReentrancyGuard.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const { expectThrow } = require('./helpers/expectThrow');
const ReentrancyMock = artifacts.require('ReentrancyMock');
const ReentrancyAttack = artifacts.require('ReentrancyAttack');

contract('ReentrancyGuard', function (accounts) {
contract('ReentrancyGuard', function () {
let reentrancyMock;

beforeEach(async function () {
Expand Down
17 changes: 8 additions & 9 deletions test/SimpleSavingsWallet.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,13 @@ const { ethGetBalance, ethSendTransaction } = require('./helpers/web3');

const SimpleSavingsWallet = artifacts.require('SimpleSavingsWallet');

contract('SimpleSavingsWallet', function (accounts) {
contract('SimpleSavingsWallet', function ([_, owner, anyone]) {
let savingsWallet;
let owner;

const paymentAmount = 4242;

beforeEach(async function () {
savingsWallet = await SimpleSavingsWallet.new(4141);
owner = await savingsWallet.owner();
savingsWallet = await SimpleSavingsWallet.new(4141, { from: owner });
});

it('should receive funds', async function () {
Expand All @@ -22,14 +20,15 @@ contract('SimpleSavingsWallet', function (accounts) {

it('owner can send funds', async function () {
// Receive payment so we have some money to spend.
await ethSendTransaction({ from: accounts[9], to: savingsWallet.address, value: 1000000 });
await ethSendTransaction({ from: anyone, to: savingsWallet.address, value: 1000000 });

await expectThrow(savingsWallet.sendTo(0, paymentAmount, { from: owner }));
await expectThrow(savingsWallet.sendTo(savingsWallet.address, paymentAmount, { from: owner }));
await expectThrow(savingsWallet.sendTo(accounts[1], 0, { from: owner }));
await expectThrow(savingsWallet.sendTo(anyone, 0, { from: owner }));

const balance = await ethGetBalance(accounts[1]);
await savingsWallet.sendTo(accounts[1], paymentAmount, { from: owner });
const updatedBalance = await ethGetBalance(accounts[1]);
const balance = await ethGetBalance(anyone);
await savingsWallet.sendTo(anyone, paymentAmount, { from: owner });
const updatedBalance = await ethGetBalance(anyone);
assert.isTrue(balance.plus(paymentAmount).equals(updatedBalance));
});
});

0 comments on commit ebada53

Please sign in to comment.