Why my ERC20 token doesn't have voting weights

Hi dear community

I was trying to implement a customized DAO using my own ERC20 token. When I was testing it, I found votes were not counted because the calculated weight was 0. It turns out even my test address owns tons of my token, when calling the getVotes function, it still shows weight as 0.

Can anyone help me understand what might be missing here?

:1234: Code to reproduce

This is how I declared my token

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;

import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts/token/ERC20/extensions/draft-ERC20Permit.sol";
import "@openzeppelin/contracts/token/ERC20/extensions/ERC20Votes.sol";

contract PricerToken is ERC20, ERC20Permit, ERC20Votes {
    constructor() ERC20("MyToken", "MTK") ERC20Permit("MyToken") {
      _mint(msg.sender, 100 * 10 ** decimals());

    function _afterTokenTransfer(address from, address to, uint256 amount)
        override(ERC20, ERC20Votes)
        super._afterTokenTransfer(from, to, amount);

    function _mint(address to, uint256 amount)
        override(ERC20, ERC20Votes)
        super._mint(to, amount);

    function _burn(address account, uint256 amount)
        override(ERC20, ERC20Votes)
        super._burn(account, amount);

This is how my governor were declared:

contract MyGovernor is Governor, GovernorSettings, GovernorCountingSimple, GovernorVotes, GovernorVotesQuorumFraction {
    constructor(ERC20Votes _token)
        GovernorSettings(1 /* 1 block */, 45818 /* 1 week */, 0)

This is how my javascript test looks like:

  1. Deploy token and governor contracts
    const VoteToken = await ethers.getContractFactory("MyToken")
    const voteToken = await VoteToken.deploy()
    await voteToken.deployed()
    const voteTokenAddress = voteToken.address

    const Governor = await ethers.getContractFactory("MyGovernor")
    const governor = await Governor.deploy(voteTokenAddress)
    await governor.deployed()
    const governorAddress = governor.address
  1. print out some tests
    const balance = await voteToken.balanceOf(accounts[0].address)
    console.log("account 0 address: " + accounts[0].address) // This prints: account 0 balance of pricer token: 100000000000000000000

    console.log("current weight is: " + await voteToken.getVotes(accounts[0].address)) // This prints: current weight is: 0

:computer: Environment

I used Hardhat and ethers.js

I think you need to delegate to yourself account to have a try.