Hello,
I'd like to test the core functionalities of the Governor smart contract using hardhat automatic testing framework. I'm trying to emulate a full workflow but it constantly fails at vote counting, apparently no votes get registered.
I guess it has to do with the governance token distribution, for that I just used a mint.
// Distribute governance tokens
const votes = ethers.utils.parseUnits("100.0", 18);
await governanceToken.connect(userA).mint(userA.address, votes);
await governanceToken.connect(userB).mint(userB.address, votes);
await governanceToken.connect(userC).mint(userC.address, votes);
// Create new proposal
const grant = ethers.utils.parseUnits("500.0", 18);
const newProposal = {
grantAmount: grant,
transferCalldata: governanceToken.interface.encodeFunctionData('mint', [admin.address, grant]),
descriptionHash: ethers.utils.id("Proposal #2: Give admin some tokens")
};
const proposeTx = await governor.connect(userA).propose(
[governanceToken.address],
[0],
[newProposal.transferCalldata],
newProposal.descriptionHash,
);
const tx = await proposeTx.wait();
await network.provider.send('evm_mine'); // wait 1 block before opening voting
const proposalId = tx.events.find((e) => e.event == 'ProposalCreated').args.proposalId;
// Let's vote
await governor.connect(userA).castVote(proposalId, VoteType.For);
await governor.connect(userB).castVote(proposalId, VoteType.For);
await governor.connect(userC).castVote(proposalId, VoteType.Against);
await governor.connect(admin).castVote(proposalId, VoteType.Abstain);
const votes = await governor.proposalVotes(proposalId);
assert(votes.forVotes.eq(2), "Vote count mismatch"); // < FAILS votes is an array and all its members, "forVotes", "againstVotes", etc are all 0
// Exec
await governor.execute(
[governanceToken.address],
[0],
[newProposal.transferCalldata],
newProposal.descriptionHash,
);
VoteType is defined in a separate file
export const VoteType: Enum('Against', 'For', 'Abstain'),
function Enum(...options) {
return Object.fromEntries(options.map((key, i) => [key, i]))
}