Lesson 12 testing _burn function ERC20 #1649
-
I have been trying to test the _burn function from the openZeppelin contract but once called from the test it sends me the error that the function does not exist, anyone understand why? describe("Burn amount", async function () {//
it("Burning from the second account", async function () {
const {second} = await getNamedAccounts()
console.log(`Second: ${second}`)
await OurToken.transfer(second, Quantity)
const balanceAddr1 = await OurToken.balanceOf(second)
console.log(`Balance: ${balanceAddr1}`)
await OurToken._burn(second, 1000000)
const balanceburn = await OurToken.balanceOf(second)
console.log(`BalanceBurned: ${balanceburn}`)
assert.equal(balanceburn, 0)
const InitSupply = await OurToken.totalSupply()
console.log(`NewSupply: ${InitSupply}`)
assert.equal(InitSupply, "4000000")
})
}) Initialpply is 5000000, and Im sending 1000000 to a second account that calls function _burn(address account, uint256 amount) internal virtual {
require(account != address(0), "ERC20: burn from the zero address");
_beforeTokenTransfer(account, address(0), amount);
uint256 accountBalance = _balances[account];
require(accountBalance >= amount, "ERC20: burn amount exceeds balance");
unchecked {
_balances[account] = accountBalance - amount;
}
_totalSupply -= amount;
emit Transfer(account, address(0), amount);
_afterTokenTransfer(account, address(0), amount);
} Thansk guys I appreciate you all. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
You are getting error because _burn function is an internal function function _burn(address account, uint256 amount) internal virtual {...} which means that it can only be called within the contract. |
Beta Was this translation helpful? Give feedback.
You are getting error because _burn function is an internal function
which means that it can only be called within the contract.