VRFCoordinatorV2Mock Error in Lottery project #1552
Answered
by
alymurtazamemon
AwaisTahseencode
asked this question in
Q&A
-
function checkUpkeep(bytes memory /*callData*/)public override
returns (bool upkeepNeeded,bytes memory /*perform data*/ ){
bool isOpen=(raffleState.OPEN==s_rafflePresentState);
//for current time we use global variables like block.timestamp
bool isTimePassed=((block.timestamp-s_lastTimeStamp)>i_interval);
bool hasPlayers=(funders.length>0);
bool hasBalance=(address(this).balance>0);
//we'll return all bools as upkeepNeeded
upkeepNeeded=(isOpen && isTimePassed && hasBalance && hasPlayers);
//perform data is something if we want the checkUpkey to perform something else for us
}
//we can change requestRandomWinners to performUpkeep
//Request Random winners
function performUpkeep(bytes calldata /*performData */)external override{
//i_vrfCoordinator will return a request id that who is requesting it so we can save it
// we have to check the condition in order to proceed further
(bool upkeepNeeded,)=checkUpkeep("");
//we ll pass some params in this error so other people know why this error is going on
if(!upkeepNeeded)
revert Raffle__upkeepNotNeeded(address(this).balance,funders.length,uint256(s_rafflePresentState));
s_rafflePresentState=raffleState.OPEN;
uint256 requestId= i_vrfCoordinator.requestRandomWords(
i_gasLane,
i_subId,
REQUEST_CONFIRMATION,
i_callBackGasLimit,
RANDOM_WORDS
//keyHash,subcriptionId,requestConfirmation,callBackGasLimit,numWords
);
emit raffleEnterWinner(requestId);
} JavaScript File of unit testdescribe("performUpkeep",()=>{
it("checks the performUp keep work when checkUpkeep is true",async()=>{
await raffle.enterRaffle({value:entranceFee})
await network.provider.send("evm_increaseTime",[interval.toNumber()+1])
await network.provider.send("evm_mine",[])
const performUpkeep=await raffle.performUpkeep([])
assert(!performUpkeep)
})
}) Error |
Beta Was this translation helpful? Give feedback.
Answered by
alymurtazamemon
Aug 5, 2022
Replies: 1 comment 2 replies
-
@AwaisTahseencode run |
Beta Was this translation helpful? Give feedback.
2 replies
Answer selected by
AwaisTahseencode
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@AwaisTahseencode run
npm install --save-dev @chainlink/contracts@0.4.1