Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion contracts/token/ERC20/StandardToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ contract StandardToken is ERC20, BasicToken {
returns (bool)
{
uint256 oldValue = allowed[msg.sender][_spender];
if (_subtractedValue > oldValue) {
if (_subtractedValue >= oldValue) {
allowed[msg.sender][_spender] = 0;
} else {
allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue);
Expand Down
20 changes: 17 additions & 3 deletions test/token/ERC20/StandardToken.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -295,15 +295,29 @@ contract('StandardToken', function ([_, owner, recipient, anotherAccount]) {
});

describe('when the spender had an approved amount', function () {
const approvedAmount = amount;

beforeEach(async function () {
await this.token.approve(spender, amount + 1, { from: owner });
await this.token.approve(spender, approvedAmount, { from: owner });
});

it('decreases the spender allowance subtracting the requested amount', async function () {
await this.token.decreaseApproval(spender, amount, { from: owner });
await this.token.decreaseApproval(spender, approvedAmount - 5, { from: owner });

const allowance = await this.token.allowance(owner, spender);
assert.equal(allowance, 1);
assert.equal(allowance, 5);
});

it('sets the allowance to zero when all allowance is removed', async function () {
await this.token.decreaseApproval(spender, approvedAmount, { from: owner });
const allowance = await this.token.allowance(owner, spender);
assert.equal(allowance, 0);
});

it('sets the allowance to zero when more than the full allowance is removed', async function () {
await this.token.decreaseApproval(spender, approvedAmount + 5, { from: owner });
const allowance = await this.token.allowance(owner, spender);
assert.equal(allowance, 0);
});
});
});
Expand Down