Skip to content

Commit

Permalink
Merge 6b522dc into 6a7114f
Browse files Browse the repository at this point in the history
  • Loading branch information
fgimenez committed Apr 17, 2018
2 parents 6a7114f + 6b522dc commit e190cac
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 8 deletions.
26 changes: 26 additions & 0 deletions test/Heritable.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import increaseTime from './helpers/increaseTime';
import expectThrow from './helpers/expectThrow';
import assertRevert from './helpers/assertRevert';

const NULL_ADDRESS = '0x0000000000000000000000000000000000000000';

Expand Down Expand Up @@ -38,6 +39,10 @@ contract('Heritable', function (accounts) {
await expectThrow(heritable.setHeir(newHeir, { from: someRandomAddress }));
});

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 });
Expand All @@ -63,6 +68,19 @@ contract('Heritable', function (accounts) {
assert.isTrue(await heritable.heir() === heir);
});

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

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 });
Expand Down Expand Up @@ -107,4 +125,12 @@ contract('Heritable', function (accounts) {
assert.isTrue(heirOwnershipClaimedEvent.args.previousOwner === owner);
assert.isTrue(heirOwnershipClaimedEvent.args.newOwner === heir);
});

it('timeOfDeath can be queried', async function () {
assert.equal(await heritable.timeOfDeath(), 0);
});

it('heartbeatTimeout can be queried', async function () {
assert.equal(await heritable.heartbeatTimeout(), 4141);
});
});
11 changes: 10 additions & 1 deletion test/crowdsale/AllowanceCrowdsale.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import ether from '../helpers/ether';
import assertRevert from '../helpers/assertRevert';

const BigNumber = web3.BigNumber;

Expand All @@ -15,6 +16,7 @@ contract('AllowanceCrowdsale', function ([_, investor, wallet, purchaser, tokenW
const value = ether(0.42);
const expectedTokenAmount = rate.mul(value);
const tokenAllowance = new BigNumber('1e22');
const ZERO_ADDRESS = '0x0000000000000000000000000000000000000000';

beforeEach(async function () {
this.token = await SimpleToken.new({ from: tokenWallet });
Expand All @@ -26,7 +28,7 @@ contract('AllowanceCrowdsale', function ([_, investor, wallet, purchaser, tokenW
it('should accept sends', async function () {
await this.crowdsale.send(value).should.be.fulfilled;
});

it('should accept payments', async function () {
await this.crowdsale.buyTokens(investor, { value: value, from: purchaser }).should.be.fulfilled;
});
Expand Down Expand Up @@ -65,4 +67,11 @@ contract('AllowanceCrowdsale', function ([_, investor, wallet, purchaser, tokenW
tokensRemaining.should.be.bignumber.equal(remainingAllowance);
});
});

describe('when token wallet is different from token address', function () {
it('creation reverts', async function () {
this.token = await SimpleToken.new({ from: tokenWallet });
await assertRevert(AllowanceCrowdsale.new(rate, wallet, this.token.address, ZERO_ADDRESS));
});
});
});
12 changes: 12 additions & 0 deletions test/examples/SampleCrowdsale.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { advanceBlock } from '../helpers/advanceToBlock';
import { increaseTimeTo, duration } from '../helpers/increaseTime';
import latestTime from '../helpers/latestTime';
import EVMRevert from '../helpers/EVMRevert';
import assertRevert from '../helpers/assertRevert';

const BigNumber = web3.BigNumber;

Expand Down Expand Up @@ -111,4 +112,15 @@ contract('SampleCrowdsale', function ([owner, wallet, investor]) {
const balanceAfterRefund = web3.eth.getBalance(investor);
balanceBeforeInvestment.should.be.bignumber.equal(balanceAfterRefund);
});

describe('when goal > cap', function () {
// goal > cap
const HIGH_GOAL = ether(30);

it('creation reverts', async function () {
await assertRevert(SampleCrowdsale.new(
this.openingTime, this.closingTime, RATE, wallet, CAP, this.token.address, HIGH_GOAL
));
});
});
});
26 changes: 22 additions & 4 deletions test/library/Math.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,37 @@ contract('Math', function (accounts) {
math = await MathMock.new();
});

it('returns max correctly', async function () {
it('returns max64 correctly', async function () {
let a = 5678;
let b = 1234;
await math.max64(a, b);
let result = await math.result();
let result = await math.result64();
assert.equal(result, a);
});

it('returns min correctly', async function () {
it('returns min64 correctly', async function () {
let a = 5678;
let b = 1234;
await math.min64(a, b);
let result = await math.result();
let result = await math.result64();

assert.equal(result, b);
});

it('returns max256 correctly', async function () {
let a = 5678;
let b = 1234;
await math.max256(a, b);
let result = await math.result256();
assert.equal(result, a);
});

it('returns min256 correctly', async function () {
let a = 5678;
let b = 1234;
await math.min256(a, b);
let result = await math.result256();

assert.equal(result, b);
});
});
15 changes: 12 additions & 3 deletions test/mocks/MathMock.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,22 @@ import "../../contracts/math/Math.sol";


contract MathMock {
uint64 public result;
uint64 public result64;
uint256 public result256;

function max64(uint64 a, uint64 b) public {
result = Math.max64(a, b);
result64 = Math.max64(a, b);
}

function min64(uint64 a, uint64 b) public {
result = Math.min64(a, b);
result64 = Math.min64(a, b);
}

function max256(uint256 a, uint256 b) public {
result256 = Math.max256(a, b);
}

function min256(uint256 a, uint256 b) public {
result256 = Math.min256(a, b);
}
}

0 comments on commit e190cac

Please sign in to comment.