Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getter added for an array of tokens held by an owner #1522

Merged
merged 34 commits into from
Dec 5, 2018
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
f2e5ed1
signing prefix added
Aniket-Engg Mar 10, 2018
ebdae17
Merge branch 'master' into master
Aniket-Engg Mar 13, 2018
2bf341c
Minor improvement
Aniket-Engg Mar 13, 2018
27c614a
Merge branch 'master' of https://github.com/Aniket-Engg/zeppelin-soli…
Aniket-Engg Mar 13, 2018
bc7ea7a
Tests changed
Aniket-Engg Mar 13, 2018
5a72021
Successfully tested
Aniket-Engg Mar 13, 2018
de0d2d4
Minor improvements
Aniket-Engg Mar 13, 2018
7f32e5c
Minor improvements
Aniket-Engg Mar 13, 2018
c3fb8a8
minor changes
Aniket-Engg Oct 1, 2018
68de840
Revert "Dangling commas are now required. (#1359)"
Aniket-Engg Oct 1, 2018
92b725f
Merge remote-tracking branch 'upstream/master'
Aniket-Engg Oct 1, 2018
1fe2cdf
Merge remote-tracking branch 'upstream/master'
Aniket-Engg Oct 1, 2018
75bc310
updates
Aniket-Engg Oct 1, 2018
9d9a5a0
Merge remote-tracking branch 'upstream/master'
Aniket-Engg Oct 3, 2018
10b1898
Merge remote-tracking branch 'upstream/master'
Aniket-Engg Oct 4, 2018
3858a0c
Merge remote-tracking branch 'upstream/master'
Aniket-Engg Oct 4, 2018
9484daa
Merge remote-tracking branch 'upstream/master'
Aniket-Engg Oct 5, 2018
5139019
Merge remote-tracking branch 'upstream/master'
Aniket-Engg Oct 8, 2018
3097a48
Merge remote-tracking branch 'upstream/master'
Aniket-Engg Oct 9, 2018
a46e176
Merge remote-tracking branch 'upstream/master'
Aniket-Engg Oct 10, 2018
fc9d1a7
Merge remote-tracking branch 'upstream/master'
Aniket-Engg Oct 11, 2018
23df893
fixes #1404
Aniket-Engg Oct 11, 2018
d8dd5ec
approve failing test
Aniket-Engg Oct 11, 2018
ae96caa
suggested changes done
Aniket-Engg Oct 16, 2018
e2fb20a
ISafeERC20 removed
Aniket-Engg Oct 16, 2018
52c7870
Merge remote-tracking branch 'upstream/master'
Aniket-Engg Oct 16, 2018
998dfd7
Merge branch 'fix/#1404' of https://github.com/Aniket-Engg/zeppelin-s…
Aniket-Engg Oct 16, 2018
c8963b1
Merge remote-tracking branch 'upstream/master'
Aniket-Engg Oct 17, 2018
7ffe179
conflicts
Aniket-Engg Oct 22, 2018
5f88845
conflict fixes
Aniket-Engg Oct 22, 2018
6b40c91
Merge remote-tracking branch 'upstream/master'
Aniket-Engg Nov 2, 2018
7f9725e
Merge remote-tracking branch 'upstream/master'
Aniket-Engg Nov 28, 2018
ac8c493
fixes #1512
Aniket-Engg Nov 28, 2018
94fa635
Update test/token/ERC721/ERC721Full.test.js
frangio Dec 5, 2018
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
50 changes: 49 additions & 1 deletion contracts/mocks/SafeERC20Helper.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import "../token/ERC20/IERC20.sol";
import "../token/ERC20/SafeERC20.sol";

contract ERC20FailingMock is IERC20 {
uint256 private _allowance;
function totalSupply() public view returns (uint256) {
return 0;
}
Expand All @@ -20,16 +21,30 @@ contract ERC20FailingMock is IERC20 {
return false;
}

function increaseAllowance(address, uint256) public returns (bool){
return false;
}

function decreaseAllowance(address, uint256) public returns (bool){
return false;
}

function balanceOf(address) public view returns (uint256) {
return 0;
}

function allowance(address, address) public view returns (uint256) {
return 0;
}

function setAllowance(uint256 value) public {
_allowance = value;
}
}

contract ERC20SucceedingMock is IERC20 {
uint256 private _allowance;

function totalSupply() public view returns (uint256) {
return 0;
}
Expand All @@ -46,12 +61,24 @@ contract ERC20SucceedingMock is IERC20 {
return true;
}

function increaseAllowance(address, uint256) public returns (bool){
return true;
}

function decreaseAllowance(address, uint256) public returns (bool){
return true;
}

function balanceOf(address) public view returns (uint256) {
return 0;
}

function allowance(address, address) public view returns (uint256) {
return 0;
return _allowance;
}

function setAllowance(uint256 value) public {
_allowance = value;
}
}

Expand All @@ -78,6 +105,14 @@ contract SafeERC20Helper {
_failing.safeApprove(address(0), 0);
}

function doFailingIncreaseAllowance() public {
_failing.safeIncreaseAllowance(address(0), 0);
}

function doFailingDecreaseAllowance() public {
_failing.safeDecreaseAllowance(address(0), 0);
}

function doSucceedingTransfer() public {
_succeeding.safeTransfer(address(0), 0);
}
Expand All @@ -89,4 +124,17 @@ contract SafeERC20Helper {
function doSucceedingApprove() public {
_succeeding.safeApprove(address(0), 0);
}

function doFailingApproveByValue() public {
_succeeding.setAllowance(10);
_succeeding.safeApprove(address(0), 10);
}

function doSucceedingIncreaseAllowance() public {
_succeeding.safeIncreaseAllowance(address(0), 0);
}

function doSucceedingDecreaseAllowance() public {
_succeeding.safeDecreaseAllowance(address(0), 0);
}
}
9 changes: 9 additions & 0 deletions contracts/token/ERC20/IERC20.sol
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,15 @@ interface IERC20 {
function transferFrom(address from, address to, uint256 value)
external returns (bool);

function increaseAllowance(address spender, uint256 addedValue)
external returns (bool);

function decreaseAllowance(address spender, uint256 subtractedValue)
external returns (bool);

function setAllowance(uint256 value)
external returns (bool);

event Transfer(
address indexed from,
address indexed to,
Expand Down
24 changes: 24 additions & 0 deletions contracts/token/ERC20/SafeERC20.sol
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,30 @@ library SafeERC20 {
)
internal
{
// safeApprove should only be called when setting an initial allowance,
// or when resetting it to zero. To increase and decrease it, use
// 'safeIncreaseAllowance' and 'safeDecreaseAllowance'
require((value == 0) || (token.allowance(msg.sender, spender) == 0));
require(token.approve(spender, value));
}

function safeIncreaseAllowance(
IERC20 token,
address spender,
uint256 addedValue
)
internal
{
require(token.increaseAllowance(spender, addedValue));
}

function safeDecreaseAllowance(
IERC20 token,
address spender,
uint256 subtractedValue
)
internal
{
require(token.decreaseAllowance(spender, subtractedValue));
}
}
2 changes: 1 addition & 1 deletion test/crowdsale/AllowanceCrowdsale.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ contract('AllowanceCrowdsale', function ([_, investor, wallet, purchaser, tokenW
purchaser: investor,
beneficiary: investor,
value: value,
amount: expectedTokenAmount
amount: expectedTokenAmount,
});
});

Expand Down
4 changes: 2 additions & 2 deletions test/crowdsale/Crowdsale.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ contract('Crowdsale', function ([_, investor, wallet, purchaser]) {
purchaser: investor,
beneficiary: investor,
value: value,
amount: expectedTokenAmount
amount: expectedTokenAmount,
});
});

Expand All @@ -111,7 +111,7 @@ contract('Crowdsale', function ([_, investor, wallet, purchaser]) {
purchaser: purchaser,
beneficiary: investor,
value: value,
amount: expectedTokenAmount
amount: expectedTokenAmount,
});
});

Expand Down
2 changes: 1 addition & 1 deletion test/crowdsale/MintedCrowdsale.behavior.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ function shouldBehaveLikeMintedCrowdsale ([_, investor, wallet, purchaser], rate
purchaser: investor,
beneficiary: investor,
value: value,
amount: expectedTokenAmount
amount: expectedTokenAmount,
});
});

Expand Down
4 changes: 2 additions & 2 deletions test/payment/Escrow.behavior.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ function shouldBehaveLikeEscrow (primary, [payee1, payee2]) {
const { logs } = await this.escrow.deposit(payee1, { from: primary, value: amount });
expectEvent.inLogs(logs, 'Deposited', {
payee: payee1,
weiAmount: amount
weiAmount: amount,
});
});

Expand Down Expand Up @@ -87,7 +87,7 @@ function shouldBehaveLikeEscrow (primary, [payee1, payee2]) {
const { logs } = await this.escrow.withdraw(payee1, { from: primary });
expectEvent.inLogs(logs, 'Withdrawn', {
payee: payee1,
weiAmount: amount
weiAmount: amount,
});
});
});
Expand Down
14 changes: 7 additions & 7 deletions test/token/ERC20/ERC20.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ contract('ERC20', function ([_, owner, recipient, anotherAccount]) {
expectEvent.inLogs(logs, 'Transfer', {
from: owner,
to: to,
value: amount
value: amount,
});
});
});
Expand Down Expand Up @@ -92,7 +92,7 @@ contract('ERC20', function ([_, owner, recipient, anotherAccount]) {
expectEvent.inLogs(logs, 'Approval', {
owner: owner,
spender: spender,
value: amount
value: amount,
});
});

Expand Down Expand Up @@ -126,7 +126,7 @@ contract('ERC20', function ([_, owner, recipient, anotherAccount]) {
expectEvent.inLogs(logs, 'Approval', {
owner: owner,
spender: spender,
value: amount
value: amount,
});
});

Expand Down Expand Up @@ -196,7 +196,7 @@ contract('ERC20', function ([_, owner, recipient, anotherAccount]) {
expectEvent.inLogs(logs, 'Transfer', {
from: owner,
to: to,
value: amount
value: amount,
});
});
});
Expand Down Expand Up @@ -271,7 +271,7 @@ contract('ERC20', function ([_, owner, recipient, anotherAccount]) {
expectEvent.inLogs(logs, 'Approval', {
owner: owner,
spender: spender,
value: 0
value: 0,
});
});

Expand Down Expand Up @@ -328,7 +328,7 @@ contract('ERC20', function ([_, owner, recipient, anotherAccount]) {
expectEvent.inLogs(logs, 'Approval', {
owner: owner,
spender: spender,
value: amount
value: amount,
});
});

Expand Down Expand Up @@ -362,7 +362,7 @@ contract('ERC20', function ([_, owner, recipient, anotherAccount]) {
expectEvent.inLogs(logs, 'Approval', {
owner: owner,
spender: spender,
value: amount
value: amount,
});
});

Expand Down
20 changes: 20 additions & 0 deletions test/token/ERC20/SafeERC20.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@ contract('SafeERC20', function () {
await shouldFail.reverting(this.helper.doFailingApprove());
});

it('should throw on failed increaseAllowance', async function () {
await shouldFail.reverting(this.helper.doFailingIncreaseAllowance());
});

it('should throw on failed decreaseAllowance', async function () {
await shouldFail.reverting(this.helper.doFailingDecreaseAllowance());
});

it('should not throw on succeeding transfer', async function () {
await this.helper.doSucceedingTransfer();
});
Expand All @@ -33,4 +41,16 @@ contract('SafeERC20', function () {
it('should not throw on succeeding approve', async function () {
await this.helper.doSucceedingApprove();
});

it('should throw while approving with non-zero existing allowance', async function () {
await shouldFail.reverting(this.helper.doFailingApproveByValue());
});

it('should not throw on succeeding increaseAllowance', async function () {
await this.helper.doSucceedingIncreaseAllowance();
});

it('should not throw on succeeding decreaseAllowance', async function () {
await this.helper.doSucceedingDecreaseAllowance();
});
});
4 changes: 2 additions & 2 deletions test/token/ERC20/behaviors/ERC20Burnable.behavior.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ function shouldBehaveLikeERC20Burnable (owner, initialBalance, [burner]) {
expectEvent.inLogs(this.logs, 'Transfer', {
from: owner,
to: ZERO_ADDRESS,
value: amount
value: amount,
});
});
}
Expand Down Expand Up @@ -78,7 +78,7 @@ function shouldBehaveLikeERC20Burnable (owner, initialBalance, [burner]) {
expectEvent.inLogs(this.logs, 'Transfer', {
from: owner,
to: ZERO_ADDRESS,
value: amount
value: amount,
});
});
}
Expand Down
2 changes: 1 addition & 1 deletion test/token/ERC20/behaviors/ERC20Mintable.behavior.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ function shouldBehaveLikeERC20Mintable (minter, [anyone]) {
expectEvent.inLogs(this.logs, 'Transfer', {
from: ZERO_ADDRESS,
to: anyone,
value: amount
value: amount,
});
});
}
Expand Down
14 changes: 7 additions & 7 deletions test/token/ERC721/ERC721.behavior.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,15 @@ function shouldBehaveLikeERC721 (
expectEvent.inLogs(logs, 'Transfer', {
from: owner,
to: this.toWhom,
tokenId: tokenId
tokenId: tokenId,
});
});
} else {
it('emits only a transfer event', async function () {
expectEvent.inLogs(logs, 'Transfer', {
from: owner,
to: this.toWhom,
tokenId: tokenId
tokenId: tokenId,
});
});
}
Expand Down Expand Up @@ -165,7 +165,7 @@ function shouldBehaveLikeERC721 (
expectEvent.inLogs(logs, 'Transfer', {
from: owner,
to: owner,
tokenId: tokenId
tokenId: tokenId,
});
});

Expand Down Expand Up @@ -347,7 +347,7 @@ function shouldBehaveLikeERC721 (
expectEvent.inLogs(logs, 'Approval', {
owner: owner,
approved: address,
tokenId: tokenId
tokenId: tokenId,
});
});
};
Expand Down Expand Up @@ -457,7 +457,7 @@ function shouldBehaveLikeERC721 (
expectEvent.inLogs(logs, 'ApprovalForAll', {
owner: owner,
operator: operator,
approved: true
approved: true,
});
});
});
Expand All @@ -479,7 +479,7 @@ function shouldBehaveLikeERC721 (
expectEvent.inLogs(logs, 'ApprovalForAll', {
owner: owner,
operator: operator,
approved: true
approved: true,
});
});

Expand Down Expand Up @@ -507,7 +507,7 @@ function shouldBehaveLikeERC721 (
expectEvent.inLogs(logs, 'ApprovalForAll', {
owner: owner,
operator: operator,
approved: true
approved: true,
});
});
});
Expand Down
Loading