I am facing a bug with openzepplin ERC20 contracts. In my code, I implement a burn tax
and implement it this way:
--- SNIP---
function _afterTokenTransfer(
ReflectionValues memory reflectionValues,
TokenValues memory tokenValues
) private {
if (_burnTax != 0) {
_tokenBalances[address(this)] += tokenValues.burnFee;
_reflectionBalances[address(this)] += reflectionValues.burnFee;
// This _approve is required for some reasons...
_approve(address(this), _msgSender(), tokenValues.burnFee);
burnFrom(address(this), tokenValues.burnFee);
}
--- SNIP---
function burnFrom(address account, uint256 amount) public virtual {
uint256 currentAllowance = allowance(account, _msgSender());
require(currentAllowance >= amount, "ERC20: burn amount exceeds allowance");
_approve(account, _msgSender(), currentAllowance - amount);
_burn(account, amount);
}
}
--- SNIP ---
But this code snippets triggers this require
exception:
function _approve(address owner, address spender, uint256 amount) internal virtual {
require(owner != address(0), "ERC20: approve from the zero address");
require(spender != address(0), "ERC20: approve to the zero address");
_allowances[owner][spender] = amount;
emit Approval(owner, spender, amount);
}
As far as I know, address(this)
is different from address(0)
… Spent two days on that already and can’t figure out what is going on… See:
Contract: Transfers
senderBalance 1000000000000000000000000000000000
recipientBalance 0
1) should charge taxes on transfers from non-excluded accounts
AssertionError: expected promise to be fulfilled but it was rejected with 'Error: Returned error: VM Exception while processing transaction: revert ERC20: approve to the zero
address caca -- Reason given: ERC20: approve to the zero address caca.'
2) "after each" hook: after test for "should charge taxes on transfers from non-excluded accounts"
0 passing (4s)
2 failing
1) Contract: Transfers
should charge taxes on transfers from non-excluded accounts:
AssertionError: expected '0' to equal '1000000000000000000000000000000000'
+ expected - actual
-0
+1000000000000000000000000000000000
at Context.<anonymous> (test\ERC20Deflationary.test.js:152:46)
at processTicksAndRejections (internal/process/task_queues.js:93:5)
2) Contract: Transfers
"after each" hook: after test for "should charge taxes on transfers from non-excluded accounts":
Uncaught RuntimeError: abort(AssertionError: expected promise to be fulfilled but it was rejected with 'Error: Returned error: VM Exception while processing transaction:
revert ERC20: approve to the zero address -- Reason given: ERC20: approve to the zero address caca.'). Build with -s ASSERTIONS=1 for more info.
at process.abort (C:\Users\ateyar\.config\truffle\compilers\node_modules\soljson-v0.8.4+commit.c7e474f2.js:1:13012)
at process.emit (C:\Users\ateyar\AppData\Roaming\npm\node_modules\truffle\build\webpack:\node_modules\source-map-support\source-map-support.js:495:1)
at processPromiseRejections (internal/process/promises.js:245:33)
at processTicksAndRejections (internal/process/task_queues.js:94:32)