Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Merge branch 'master' into refactor/past-tense-events
  • Loading branch information
Leo Arias committed Aug 28, 2018
commit af5f8550c936d3c0175267d9ded5d51848e6a8ed
8 changes: 1 addition & 7 deletions contracts/token/ERC20/BurnableToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,7 @@ contract BurnableToken is StandardToken {
* an additional Burn event.
*/
function _burn(address _who, uint256 _value) internal {
require(_value <= balances[_who]);
// no need to require value <= totalSupply, since that would imply the
// sender's balance is greater than the totalSupply, which *should* be an assertion failure

balances[_who] = balances[_who].sub(_value);
totalSupply_ = totalSupply_.sub(_value);
super._burn(_who, _value);
emit TokensBurned(_who, _value);
emit Transfer(_who, address(0), _value);
}
}
44 changes: 9 additions & 35 deletions test/crowdsale/Crowdsale.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,9 @@ contract('Crowdsale', function ([_, investor, wallet, purchaser]) {
);
});

describe('accepting payments', function () {
it('should accept payments', async function () {
await this.crowdsale.send(value);
await this.crowdsale.buyTokens(investor, { value: value, from: purchaser });
});
});

describe('high-level purchase', function () {
it('should log purchase', async function () {
const { logs } = await this.crowdsale.sendTransaction({ value: value, from: investor });
const event = logs.find(e => e.event === 'TokenPurchased');
should.exist(event);
event.args.purchaser.should.equal(investor);
event.args.beneficiary.should.equal(investor);
event.args.value.should.be.bignumber.equal(value);
event.args.amount.should.be.bignumber.equal(expectedTokenAmount);
context('with token', async function () {
beforeEach(async function () {
this.token = await SimpleToken.new();
});

it('requires a non-zero rate', async function () {
Expand All @@ -48,23 +35,10 @@ contract('Crowdsale', function ([_, investor, wallet, purchaser]) {
);
});

it('should forward funds to wallet', async function () {
const pre = await ethGetBalance(wallet);
await this.crowdsale.sendTransaction({ value, from: investor });
const post = await ethGetBalance(wallet);
post.minus(pre).should.be.bignumber.equal(value);
});
});

describe('low-level purchase', function () {
it('should log purchase', async function () {
const { logs } = await this.crowdsale.buyTokens(investor, { value: value, from: purchaser });
const event = logs.find(e => e.event === 'TokenPurchased');
should.exist(event);
event.args.purchaser.should.equal(purchaser);
event.args.beneficiary.should.equal(investor);
event.args.value.should.be.bignumber.equal(value);
event.args.amount.should.be.bignumber.equal(expectedTokenAmount);
it('requires a non-null wallet', async function () {
await assertRevert(
Crowdsale.new(rate, ZERO_ADDRESS, this.token.address)
);
});

context('once deployed', async function () {
Expand Down Expand Up @@ -108,7 +82,7 @@ contract('Crowdsale', function ([_, investor, wallet, purchaser]) {
describe('high-level purchase', function () {
it('should log purchase', async function () {
const { logs } = await this.crowdsale.sendTransaction({ value: value, from: investor });
const event = logs.find(e => e.event === 'TokenPurchase');
const event = logs.find(e => e.event === 'TokenPurchased');
should.exist(event);
event.args.purchaser.should.equal(investor);
event.args.beneficiary.should.equal(investor);
Expand All @@ -132,7 +106,7 @@ contract('Crowdsale', function ([_, investor, wallet, purchaser]) {
describe('low-level purchase', function () {
it('should log purchase', async function () {
const { logs } = await this.crowdsale.buyTokens(investor, { value: value, from: purchaser });
const event = logs.find(e => e.event === 'TokenPurchase');
const event = logs.find(e => e.event === 'TokenPurchased');
should.exist(event);
event.args.purchaser.should.equal(purchaser);
event.args.beneficiary.should.equal(investor);
Expand Down
23 changes: 11 additions & 12 deletions test/token/ERC20/BurnableToken.behavior.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,17 @@ function shouldBehaveLikeBurnableToken (owner, initialBalance, [burner]) {
shouldBurn(100);
});

it('emits a burn event', async function () {
const event = expectEvent.inLogs(this.logs, 'TokensBurned');
event.args.burner.should.eq(owner);
event.args.value.should.be.bignumber.equal(amount);
});
function shouldBurn (amount) {
beforeEach(async function () {
({ logs: this.logs } = await this.token.burn(amount, { from: owner }));
});

it('burns the requested amount', async function () {
(await this.token.balanceOf(owner)).should.be.bignumber.equal(initialBalance - amount);
});

it('emits a burn event', async function () {
const event = expectEvent.inLogs(this.logs, 'Burn');
const event = expectEvent.inLogs(this.logs, 'TokensBurned');
event.args.burner.should.equal(owner);
event.args.value.should.be.bignumber.equal(amount);
});
Expand Down Expand Up @@ -66,11 +65,11 @@ function shouldBehaveLikeBurnableToken (owner, initialBalance, [burner]) {
function shouldBurnFrom (amount) {
const originalAllowance = amount * 3;

it('emits a burn event', async function () {
const event = expectEvent.inLogs(this.logs, 'TokensBurned');
event.args.burner.should.eq(owner);
event.args.value.should.be.bignumber.equal(amount);
});
beforeEach(async function () {
await this.token.approve(burner, originalAllowance, { from: owner });
const { logs } = await this.token.burnFrom(owner, amount, { from: burner });
this.logs = logs;
});

it('burns the requested amount', async function () {
(await this.token.balanceOf(owner)).should.be.bignumber.equal(initialBalance - amount);
Expand All @@ -81,7 +80,7 @@ function shouldBehaveLikeBurnableToken (owner, initialBalance, [burner]) {
});

it('emits a burn event', async function () {
const event = expectEvent.inLogs(this.logs, 'Burn');
const event = expectEvent.inLogs(this.logs, 'TokensBurned');
event.args.burner.should.equal(owner);
event.args.value.should.be.bignumber.equal(amount);
});
Expand Down
8 changes: 4 additions & 4 deletions test/token/ERC20/PausableToken.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ contract('PausableToken', function ([_, owner, recipient, anotherAccount]) {
it('emits a Pause event', async function () {
const { logs } = await this.token.pause({ from });

assert.equal(logs.length, 1);
assert.equal(logs[0].event, 'Paused');
logs.length.should.equal(1);
logs[0].event.should.equal('Paused');
});
});

Expand Down Expand Up @@ -61,8 +61,8 @@ contract('PausableToken', function ([_, owner, recipient, anotherAccount]) {
it('emits an Unpause event', async function () {
const { logs } = await this.token.unpause({ from });

assert.equal(logs.length, 1);
assert.equal(logs[0].event, 'Unpaused');
logs.length.should.equal(1);
logs[0].event.should.equal('Unpaused');
});
});

Expand Down
You are viewing a condensed version of this merge commit. You can view the full changes here.