I'm trying to call a function[propose] from Openzeppelin governor.sol. The function is like this...
function propose(
address[] memory targets,
uint256[] memory values,
bytes[] memory calldatas,
string memory description
) public virtual override returns (uint256) {
require(
getVotes(msg.sender, block.number - 1) >= proposalThreshold(),
"GovernorCompatibilityBravo: proposer votes below proposal threshold"
);
uint256 proposalId = hashProposal(targets, values, calldatas, keccak256(bytes(description)));
require(targets.length == values.length, "Governor: invalid proposal length");
require(targets.length == calldatas.length, "Governor: invalid proposal length");
require(targets.length > 0, "Governor: empty proposal");
ProposalCore storage proposal = _proposals[proposalId];
require(proposal.voteStart.isUnset(), "Governor: proposal already exists");
uint64 snapshot = block.number.toUint64() + votingDelay().toUint64();
uint64 deadline = snapshot + votingPeriod().toUint64();
proposal.voteStart.setDeadline(snapshot);
proposal.voteEnd.setDeadline(deadline);
emit ProposalCreated(
proposalId,
_msgSender(),
targets,
values,
new string[](targets.length),
calldatas,
snapshot,
deadline,
description
);
return proposalId;
}
I've used this function in my different contract like this...
function propose(
address[] memory targets,
uint256[] memory values,
bytes[] memory calldatas,
string memory description
) public override(Governor, IGovernor) returns (uint256) {
return super.propose(targets, values, calldatas, description);
}
finally, after successfully deploying it and when it comes to using it for a function proposal, I'm using the Box.sol's store function to govern on.
// Stores a new value in the contract
function store(uint256 newValue) public onlyOwner {
value = newValue;
emit ValueChanged(newValue);
}
First I made the, function selector like this...
const governor = await ethers.getContract("GovernorContract");
const box = await ethers.getContract("Box");
const encodedFunctionCall = box.interface.encodeFunctionData('store', [77]);
and on consoling, I'm getting this selector in bytes...
0x6057361d000000000000000000000000000000000000000000000000000000000000004d
Now, I'm calling the propose function...
const proposeTx = await governor.propose(
[box.address],
[0],
[encodedFunctionCall],
proposalDescription
);
But here, I'm getting the error...
Error: Transaction reverted: function selector was not recognized and there's no fallback function
at Box.<unrecognized-selector> (contracts/Box.sol:6)
Actually, it is not recognizing the store function of box.sol. I've already compiled the contract many time, but getting the same error.