Commit ebd4b5e7 by zaryab Committed by Nicolás Venturo

decrease approval condition fix (greater than and equal to) (#1063)

* decrease approval condition fix (greater than and equal to)

* sol lint fixed

* Improved standard token decreaseApprovalTests.
parent 1ecda544
...@@ -112,7 +112,7 @@ contract StandardToken is ERC20, BasicToken { ...@@ -112,7 +112,7 @@ contract StandardToken is ERC20, BasicToken {
returns (bool) returns (bool)
{ {
uint256 oldValue = allowed[msg.sender][_spender]; uint256 oldValue = allowed[msg.sender][_spender];
if (_subtractedValue > oldValue) { if (_subtractedValue >= oldValue) {
allowed[msg.sender][_spender] = 0; allowed[msg.sender][_spender] = 0;
} else { } else {
allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue); allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue);
......
...@@ -295,15 +295,29 @@ contract('StandardToken', function ([_, owner, recipient, anotherAccount]) { ...@@ -295,15 +295,29 @@ contract('StandardToken', function ([_, owner, recipient, anotherAccount]) {
}); });
describe('when the spender had an approved amount', function () { describe('when the spender had an approved amount', function () {
const approvedAmount = amount;
beforeEach(async function () { 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 () { 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); 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);
}); });
}); });
}); });
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment