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
Next Next commit
rename {increase,decrease}Approval to {increase,decrease}Allowance
  • Loading branch information
frangio committed Sep 6, 2018
commit f306cc8095fdbd2124b1718fe270f9ded54cf107
12 changes: 4 additions & 8 deletions contracts/token/ERC20/ERC20.sol
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ contract ERC20 is IERC20 {
* @param _spender The address which will spend the funds.
* @param _addedValue The amount of tokens to increase the allowance by.
*/
function increaseApproval(
function increaseAllowance(
address _spender,
uint256 _addedValue
)
Expand All @@ -139,19 +139,15 @@ contract ERC20 is IERC20 {
* @param _spender The address which will spend the funds.
* @param _subtractedValue The amount of tokens to decrease the allowance by.
*/
function decreaseApproval(
function decreaseAllowance(
address _spender,
uint256 _subtractedValue
)
public
returns (bool)
{
uint256 oldValue = allowed_[msg.sender][_spender];
if (_subtractedValue >= oldValue) {
allowed_[msg.sender][_spender] = 0;
} else {
allowed_[msg.sender][_spender] = oldValue.sub(_subtractedValue);
}
allowed_[msg.sender][_spender] = (
allowed_[msg.sender][_spender].sub(_subtractedValue));
emit Approval(msg.sender, _spender, allowed_[msg.sender][_spender]);
return true;
}
Expand Down
8 changes: 4 additions & 4 deletions contracts/token/ERC20/ERC20Pausable.sol
Original file line number Diff line number Diff line change
Expand Up @@ -44,25 +44,25 @@ contract ERC20Pausable is ERC20, Pausable {
return super.approve(_spender, _value);
}

function increaseApproval(
function increaseAllowance(
address _spender,
uint _addedValue
)
public
whenNotPaused
returns (bool success)
{
return super.increaseApproval(_spender, _addedValue);
return super.increaseAllowance(_spender, _addedValue);
}

function decreaseApproval(
function decreaseAllowance(
address _spender,
uint _subtractedValue
)
public
whenNotPaused
returns (bool success)
{
return super.decreaseApproval(_spender, _subtractedValue);
return super.decreaseAllowance(_spender, _subtractedValue);
}
}
40 changes: 20 additions & 20 deletions test/token/ERC20/ERC20.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -261,15 +261,15 @@ contract('ERC20', function ([_, owner, recipient, anotherAccount]) {
});
});

describe('decrease approval', function () {
describe('decrease allowance', function () {
describe('when the spender is not the zero address', function () {
const spender = recipient;

describe('when the sender has enough balance', function () {
const amount = 100;

it('emits an approval event', async function () {
const { logs } = await this.token.decreaseApproval(spender, amount, { from: owner });
const { logs } = await this.token.decreaseAllowance(spender, amount, { from: owner });

logs.length.should.equal(1);
logs[0].event.should.equal('Approval');
Expand All @@ -280,7 +280,7 @@ contract('ERC20', function ([_, owner, recipient, anotherAccount]) {

describe('when there was no approved amount before', function () {
it('keeps the allowance to zero', async function () {
await this.token.decreaseApproval(spender, amount, { from: owner });
await this.token.decreaseAllowance(spender, amount, { from: owner });

(await this.token.allowance(owner, spender)).should.be.bignumber.equal(0);
});
Expand All @@ -294,18 +294,18 @@ contract('ERC20', function ([_, owner, recipient, anotherAccount]) {
});

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

(await this.token.allowance(owner, spender)).should.be.bignumber.equal(5);
});

it('sets the allowance to zero when all allowance is removed', async function () {
await this.token.decreaseApproval(spender, approvedAmount, { from: owner });
await this.token.decreaseAllowance(spender, approvedAmount, { from: owner });
(await this.token.allowance(owner, spender)).should.be.bignumber.equal(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 });
await this.token.decreaseAllowance(spender, approvedAmount + 5, { from: owner });
(await this.token.allowance(owner, spender)).should.be.bignumber.equal(0);
});
});
Expand All @@ -315,7 +315,7 @@ contract('ERC20', function ([_, owner, recipient, anotherAccount]) {
const amount = 101;

it('emits an approval event', async function () {
const { logs } = await this.token.decreaseApproval(spender, amount, { from: owner });
const { logs } = await this.token.decreaseAllowance(spender, amount, { from: owner });

logs.length.should.equal(1);
logs[0].event.should.equal('Approval');
Expand All @@ -326,7 +326,7 @@ contract('ERC20', function ([_, owner, recipient, anotherAccount]) {

describe('when there was no approved amount before', function () {
it('keeps the allowance to zero', async function () {
await this.token.decreaseApproval(spender, amount, { from: owner });
await this.token.decreaseAllowance(spender, amount, { from: owner });

(await this.token.allowance(owner, spender)).should.be.bignumber.equal(0);
});
Expand All @@ -338,7 +338,7 @@ contract('ERC20', function ([_, owner, recipient, anotherAccount]) {
});

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

(await this.token.allowance(owner, spender)).should.be.bignumber.equal(1);
});
Expand All @@ -351,13 +351,13 @@ contract('ERC20', function ([_, owner, recipient, anotherAccount]) {
const spender = ZERO_ADDRESS;

it('decreases the requested amount', async function () {
await this.token.decreaseApproval(spender, amount, { from: owner });
await this.token.decreaseAllowance(spender, amount, { from: owner });

(await this.token.allowance(owner, spender)).should.be.bignumber.equal(0);
});

it('emits an approval event', async function () {
const { logs } = await this.token.decreaseApproval(spender, amount, { from: owner });
const { logs } = await this.token.decreaseAllowance(spender, amount, { from: owner });

logs.length.should.equal(1);
logs[0].event.should.equal('Approval');
Expand All @@ -368,15 +368,15 @@ contract('ERC20', function ([_, owner, recipient, anotherAccount]) {
});
});

describe('increase approval', function () {
describe('increase allowance', function () {
const amount = 100;

describe('when the spender is not the zero address', function () {
const spender = recipient;

describe('when the sender has enough balance', function () {
it('emits an approval event', async function () {
const { logs } = await this.token.increaseApproval(spender, amount, { from: owner });
const { logs } = await this.token.increaseAllowance(spender, amount, { from: owner });

logs.length.should.equal(1);
logs[0].event.should.equal('Approval');
Expand All @@ -387,7 +387,7 @@ contract('ERC20', function ([_, owner, recipient, anotherAccount]) {

describe('when there was no approved amount before', function () {
it('approves the requested amount', async function () {
await this.token.increaseApproval(spender, amount, { from: owner });
await this.token.increaseAllowance(spender, amount, { from: owner });

(await this.token.allowance(owner, spender)).should.be.bignumber.equal(amount);
});
Expand All @@ -399,7 +399,7 @@ contract('ERC20', function ([_, owner, recipient, anotherAccount]) {
});

it('increases the spender allowance adding the requested amount', async function () {
await this.token.increaseApproval(spender, amount, { from: owner });
await this.token.increaseAllowance(spender, amount, { from: owner });

(await this.token.allowance(owner, spender)).should.be.bignumber.equal(amount + 1);
});
Expand All @@ -410,7 +410,7 @@ contract('ERC20', function ([_, owner, recipient, anotherAccount]) {
const amount = 101;

it('emits an approval event', async function () {
const { logs } = await this.token.increaseApproval(spender, amount, { from: owner });
const { logs } = await this.token.increaseAllowance(spender, amount, { from: owner });

logs.length.should.equal(1);
logs[0].event.should.equal('Approval');
Expand All @@ -421,7 +421,7 @@ contract('ERC20', function ([_, owner, recipient, anotherAccount]) {

describe('when there was no approved amount before', function () {
it('approves the requested amount', async function () {
await this.token.increaseApproval(spender, amount, { from: owner });
await this.token.increaseAllowance(spender, amount, { from: owner });

(await this.token.allowance(owner, spender)).should.be.bignumber.equal(amount);
});
Expand All @@ -433,7 +433,7 @@ contract('ERC20', function ([_, owner, recipient, anotherAccount]) {
});

it('increases the spender allowance adding the requested amount', async function () {
await this.token.increaseApproval(spender, amount, { from: owner });
await this.token.increaseAllowance(spender, amount, { from: owner });

(await this.token.allowance(owner, spender)).should.be.bignumber.equal(amount + 1);
});
Expand All @@ -445,13 +445,13 @@ contract('ERC20', function ([_, owner, recipient, anotherAccount]) {
const spender = ZERO_ADDRESS;

it('approves the requested amount', async function () {
await this.token.increaseApproval(spender, amount, { from: owner });
await this.token.increaseAllowance(spender, amount, { from: owner });

(await this.token.allowance(owner, spender)).should.be.bignumber.equal(amount);
});

it('emits an approval event', async function () {
const { logs } = await this.token.increaseApproval(spender, amount, { from: owner });
const { logs } = await this.token.increaseAllowance(spender, amount, { from: owner });

logs.length.should.equal(1);
logs[0].event.should.equal('Approval');
Expand Down