Skip to content

Commit

Permalink
Emit Approval events from burnFrom and transferFrom (Closes #74) (#81)
Browse files Browse the repository at this point in the history
* Emit Approval events from burnFrom and transferFrom (Closes #74)

* Emit absolute approval amounts with approval events
  • Loading branch information
truls authored and peteremiljensen committed Jan 29, 2019
1 parent 579ac24 commit 198a10e
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 6 deletions.
2 changes: 2 additions & 0 deletions contracts/token/ERC20/ExternalERC20.sol
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ contract ExternalERC20 is IERC20 {
_externalERC20Storage.allowed(from, originSender).sub(value)
);
_transfer(from, to, value);
emit Approval(from, originSender, _externalERC20Storage.allowed(from, originSender));
}

/**
Expand Down Expand Up @@ -283,5 +284,6 @@ contract ExternalERC20 is IERC20 {
_externalERC20Storage.allowed(account, burner).sub(value)
);
_burn(account, value);
emit Approval(account, burner, _externalERC20Storage.allowed(account, burner));
}
}
27 changes: 21 additions & 6 deletions test/token/ERC20/behaviors/ERC20.public.behavior.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,13 +186,28 @@ function shouldBehaveLikeERC20PublicAPI (owner, recipient, anotherAccount) {
(await this.token.allowance(owner, spender)).should.be.bignumber.equal(0);
});

it('emits a transfer event', async function () {
const { logs } = await this.token.transferFrom(owner, to, amount, { from: spender });
describe('emits', function () {
let events;

expectEvent.inLogs(logs, 'Transfer', {
from: owner,
to: to,
value: amount
beforeEach(async function () {
const { logs } = await this.token.transferFrom(owner, to, amount, { from: spender });
events = logs;
});

it('a transfer event', async function () {
expectEvent.inLogs(events, 'Transfer', {
from: owner,
to: to,
value: amount
});
});

it('an approval event', async function () {
expectEvent.inLogs(events, 'Approval', {
owner: owner,
spender: spender,
value: 0
});
});
});
});
Expand Down
8 changes: 8 additions & 0 deletions test/token/ERC20/behaviors/ERC20Burnable.behavior.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,14 @@ function shouldBehaveLikeERC20Burnable (owner, initialBalance, [burner]) {
value: amount
});
});

it('emits an approval event', async function () {
expectEvent.inLogs(this.logs, 'Approval', {
owner: owner,
spender: burner,
value: originalAllowance - amount
});
});
}
});

Expand Down

0 comments on commit 198a10e

Please sign in to comment.