* Increase test coverage to 93% #549 * cover missing AllowanceCrowdsale branch * improve Heritable coverage * fix lint errors * proper equal assert * address review comments * remove unneeded const definitions and imports * use assertRevert * reword scenario description * Increase test coverage to 93% #549 * cover missing AllowanceCrowdsale branch * improve Heritable coverage * fix lint errors * proper equal assert * address review comments * remove unneeded const definitions and imports * use assertRevert * reword scenario description * move HIGH_GOAL constant to the scope where it's used * remove const at top level * address review comments
This commit is contained in:
committed by
Francisco Giordano
parent
6a7114fdb4
commit
f4bdaf49a1
@ -1,5 +1,6 @@
|
||||
import increaseTime from './helpers/increaseTime';
|
||||
import expectThrow from './helpers/expectThrow';
|
||||
import assertRevert from './helpers/assertRevert';
|
||||
|
||||
const NULL_ADDRESS = '0x0000000000000000000000000000000000000000';
|
||||
|
||||
@ -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 });
|
||||
@ -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 });
|
||||
@ -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);
|
||||
});
|
||||
});
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
import ether from '../helpers/ether';
|
||||
import assertRevert from '../helpers/assertRevert';
|
||||
|
||||
const BigNumber = web3.BigNumber;
|
||||
|
||||
@ -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 });
|
||||
@ -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));
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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
|
||||
));
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@ -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);
|
||||
});
|
||||
});
|
||||
|
||||
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user