I have a mapping uint256=>bool. I am giving projectId to see is it registered or not. I registered a project. I use chainlink automation for do something. But when i call checkuppkeep function for testing, mapping returns false but function returns true after registration. Basicly is_funding public view function returns true as it should be but in the contract _isFunding[projectId] mapping return false. What is going on?
_isFunding[projectId] = true;
function checkUpkeep(
bytes memory /* checkData */
)
public
view
override
returns (
bool upkeepNeeded,
bytes memory /* performData */
)
{
bool isFunded = _isFunding[projectId];
bool timePassed = (block.timestamp -
(projectToTime[projectId][time[projectId]])) > time[projectId];
upkeepNeeded = (isFunded);
}
function getTimeleft(uint256 _projectID)
public
view
returns (uint256 a, uint256 b)
{
a = block.timestamp - projectToTime[_projectID][time[_projectID]];
b = time[_projectID];
}
function is_funding(uint256 _projectID) public view returns (bool) {
return _isFunding[_projectID];
}
Hardhat test file :
it("return false if project hasnt submit", async () => {
blockNumber = await ethers.provider.getBlockNumber();
console.log(`Before ${blockNumber}`);
await moveTime(s_fundingTime + 1);
await moveBlocks(s_fundingTime + 1);
blockNumber = await ethers.provider.getBlockNumber();
console.log(`Before ${blockNumber}`);
const { upkeepNeeded } = await governor.checkUpkeep([]);
const { a, b } = await governor.getTimeleft(projectId);
console.log(await governor.is_funding(projectId));
console.log(a.toString(), b.toString());
console.log(upkeepNeeded);
// assert(!upkeepNeeded);
console of test result:
Before 226
Moving time...
Moved forward 61 seconds..
Moving blocks...
Before 287
true
121 60
false
checkUpkeep
works as expected before registering upkeep.