Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
O
openzeppelin-contracts-upgradeable
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
俞永鹏
openzeppelin-contracts-upgradeable
Commits
1ac1ac98
Commit
1ac1ac98
authored
Oct 19, 2018
by
Nicolás Venturo
Committed by
Leo Arias
Oct 19, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed how allowance crowdsale checks remaining tokens. (#1449)
parent
8204f6a7
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
16 additions
and
1 deletions
+16
-1
AllowanceCrowdsale.sol
contracts/crowdsale/emission/AllowanceCrowdsale.sol
+5
-1
AllowanceCrowdsale.test.js
test/crowdsale/AllowanceCrowdsale.test.js
+11
-0
No files found.
contracts/crowdsale/emission/AllowanceCrowdsale.sol
View file @
1ac1ac98
...
...
@@ -4,6 +4,7 @@ import "../Crowdsale.sol";
import "../../token/ERC20/IERC20.sol";
import "../../token/ERC20/SafeERC20.sol";
import "../../math/SafeMath.sol";
import "../../math/Math.sol";
/**
* @title AllowanceCrowdsale
...
...
@@ -36,7 +37,10 @@ contract AllowanceCrowdsale is Crowdsale {
* @return Amount of tokens left in the allowance
*/
function remainingTokens() public view returns (uint256) {
return token().allowance(_tokenWallet, this);
return Math.min(
token().balanceOf(_tokenWallet),
token().allowance(_tokenWallet, this)
);
}
/**
...
...
test/crowdsale/AllowanceCrowdsale.test.js
View file @
1ac1ac98
...
...
@@ -69,6 +69,17 @@ contract('AllowanceCrowdsale', function ([_, investor, wallet, purchaser, tokenW
await
this
.
crowdsale
.
buyTokens
(
investor
,
{
value
:
value
,
from
:
purchaser
});
(
await
this
.
crowdsale
.
remainingTokens
()).
should
.
be
.
bignumber
.
equal
(
remainingAllowance
);
});
context
(
'when the allowance is larger than the token amount'
,
function
()
{
beforeEach
(
async
function
()
{
const
amount
=
await
this
.
token
.
balanceOf
(
tokenWallet
);
await
this
.
token
.
approve
(
this
.
crowdsale
.
address
,
amount
.
plus
(
1
),
{
from
:
tokenWallet
});
});
it
(
'should report the amount instead of the allowance'
,
async
function
()
{
(
await
this
.
crowdsale
.
remainingTokens
()).
should
.
be
.
bignumber
.
equal
(
await
this
.
token
.
balanceOf
(
tokenWallet
));
});
});
});
describe
(
'when token wallet is different from token address'
,
function
()
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment