I am testing an ERC20 contract based on Openzeppelin-solidity template. But I am observing a curious behavior with reading a global variable. Here is the contract:
pragma solidity ^0.4.24;
import "../node_modules/openzeppelin-solidity/contracts/token/ERC20/ERC20.sol";
contract FunnyToken is ERC20 {
string public constant name = "FunnyToken";
string public constant symbol = "FYT";
uint8 public constant decimals = 18;
uint256 private _totalSupply = 10000 * (10 ** uint256(decimals));
address private owner;
constructor() public {
owner = msg.sender;
}
}
then I truffle migrate
it to ganache-cli and run the following commands on truffle console:
FunnyToken.deployed().then(inst=> tok=inst);
tok.totalSupply();
the value returne is: BigNumber { s: 1, e: 0, c: [ 0 ] }
. So I conclude that the _totalSupply global variable is not being initialized properly, because the function totalSupply
is implemented like this:
function totalSupply() public view returns (uint256) {
return _totalSupply;
}
Can anyone explain me what is going on?
totalSupply
?