Am writing tests for an proxy token contract, need a second set of eyes for my tests. If there are test cases/ design pattern am missing, would love to know
Here is the contract
pragma solidity 0.8.0;
import '@openzeppelin/contracts/proxy/utils/Initializable.sol';
import '../erc20/ERC20.sol';
contract Token is ERC20, Initializable {
address private _owner;
/**
* Constructs a Token with 18 decimals
*
* @param __name The name of the token
* @param __symbol The symbol of the token
* @param __owner The owner of this contract
*/
function initialize(
string calldata __name,
string calldata __symbol,
address __owner
) external initializer {
_name = __name;
_symbol = __symbol;
_owner = __owner;
}
/**
* Mints a given amount of tokens to an address
*
* @param account The address to receive the minted tokens
* @param amount The amount of tokens to mint
*/
function mint(address account, uint256 amount) external {
require(_owner == msg.sender, 'Caller must be owner');
_mint(account, amount);
}
/**
* Burns a given amount of tokens from an address
*
* @param account The address for the tokens to be burned from
* @param amount The amount of tokens to be burned
*/
function burn(address account, uint256 amount) external {
require(_owner == msg.sender, 'Caller must be owner');
_burn(account, amount);
}
/**
* @dev Returns the address of the current owner.
*/
function owner() public view returns (address) {
return _owner;
}
}
And here are my tests
const { ethers } = require('ethers');
const { isCallTrace } = require('hardhat/internal/hardhat-network/stack-traces/message-trace');
describe('Token', ()=> {
let Token, token, owner, addr1, addr2;
beforeEach(async () => {
Token = await ethers.getContractFactory('Token');
token = await Token.deploy();
await token.deployed();
[owner, addr1, addr2, _] = await ethers.getSigners();
});
it('should initialize properly', async () => {
await token.initialize("TestToken", "TT", owner);
expect(await token._owner().to.equal(owner.address));
expect(await token.symbol().to.equal('TT'));
expect(await token.name().to.equal('TestToken'));
});
it('should mint tokens successfully', async () => {
await token.mint(addr2, 100);
assert.equal(token.balanceOf(addr2), '100');
});
it('should only allow owner to mint tokens', async () => {
await expectRevert(token.mint(addr2, 100, { from: addr1 }),
'Caller must be owner');
await token.mint(addr2, 100, { from: owner });
assert.equal(token.balanceOf(addr2), '100');
});
it('should only allow owner to burn tokens', async () => {
await expectRevert(token.connect(addr1).burn(addr1, 100 ),
'Caller must be owner');
await token.burn(addr1, 100);
assert.equal(token.balanceOf(addr1, '0'));
});
it('should burn tokens successfully', async () => {
await token.burn(addr2, 100);
assert.equal(token.balanceOf(addr2), '0');
});
})```