Skip to content

Commit

Permalink
fix(BaseERC20Guild-and-SnapshotERC20Guild): added checks to prevent u…
Browse files Browse the repository at this point in the history
…sers withdrawing zero tokens, also added correspondig tests
  • Loading branch information
dcrescimbeni committed Jun 16, 2022
1 parent 54410e2 commit 9332a60
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 0 deletions.
1 change: 1 addition & 0 deletions contracts/erc20guild/BaseERC20Guild.sol
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,7 @@ contract BaseERC20Guild {
function withdrawTokens(uint256 tokenAmount) external virtual {
require(votingPowerOf(msg.sender) >= tokenAmount, "ERC20Guild: Unable to withdraw more tokens than locked");
require(tokensLocked[msg.sender].timestamp < block.timestamp, "ERC20Guild: Tokens still locked");
require(tokenAmount > 0, "ERC20Guild: amount of tokens to withdraw must be greater than 0");
tokensLocked[msg.sender].amount = tokensLocked[msg.sender].amount.sub(tokenAmount);
totalLocked = totalLocked.sub(tokenAmount);
tokenVault.withdraw(msg.sender, tokenAmount);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ contract SnapshotERC20Guild is ERC20GuildUpgradeable {
"SnapshotERC20Guild: Unable to withdraw more tokens than locked"
);
require(tokensLocked[msg.sender].timestamp < block.timestamp, "SnapshotERC20Guild: Tokens still locked");
require(tokenAmount > 0, "ERC20Guild: amount of tokens to withdraw must be greater than 0");
_updateAccountSnapshot(msg.sender);
_updateTotalSupplySnapshot();
tokensLocked[msg.sender].amount = tokensLocked[msg.sender].amount.sub(tokenAmount);
Expand Down
6 changes: 6 additions & 0 deletions test/erc20guild/ERC20Guild.js
Original file line number Diff line number Diff line change
Expand Up @@ -1290,6 +1290,12 @@ contract("ERC20Guild", function (accounts) {
"ERC20: transfer amount exceeds balance"
);

// Cannot withdraw zero tokens
await expectRevert(
erc20Guild.withdrawTokens(0, { from: accounts[1] }),
"ERC20Guild: amount of tokens to withdraw must be greater than 0"
);

// try to release more than locked and fail
await expectRevert(
erc20Guild.withdrawTokens(50001, { from: accounts[1] }),
Expand Down
6 changes: 6 additions & 0 deletions test/erc20guild/implementations/SnapshotERC2Guild.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,12 @@ contract("SnapshotERC20Guild", function (accounts) {
"ERC20: transfer amount exceeds balance"
);

// Cannot withdraw zero tokens
await expectRevert(
erc20Guild.withdrawTokens(0, { from: accounts[1] }),
"ERC20Guild: amount of tokens to withdraw must be greater than 0"
);

// try to release more than locked and fail
await expectRevert(
erc20Guild.withdrawTokens(50001, { from: accounts[1] }),
Expand Down

0 comments on commit 9332a60

Please sign in to comment.