fulfillRandomWords callback is not getting executed after calling fulfillRandomWords on the VRF v2 contract locally when unit testing #2440
Replies: 3 comments 10 replies
-
Hey @alatiqueeagle first, change the category of this discussion to be Second, There should be an async anonymous function here |
Beta Was this translation helpful? Give feedback.
-
Hey, assuming @othaime-en looked into the logic already, are you running on Rinkeby? If so, that is precisely the problem. Use Goerli/Kovan and let me know if it persists. Note: in accordance with the network in your subscriptionId (also check if this is correct) as well as the funds if it is insufficient :) |
Beta Was this translation helpful? Give feedback.
-
The error is, it('the vrf fulfillRandomWords sends the randomWords and emits NFTMinted', async function () {
await new Promise(async (resolve, reject) => {
randomApeYachtClub.on('NFTMinted', () => {
try {
// This right here is never executed
} catch (error) {
console.log(error);
}
});
try {
// mint NFT
const tx = await randomApeYachtClub.mintNft({ value: mintFee });
const receipt = await tx.wait(1);
const requestId = receipt.events.find(e => e.event === 'NFTRequested').args['requestId'];
// call fulfillRandomWords
// and watch for the event
await vrfCoordinatorV2Mock.fulfillRandomWords(requestId, randomApeYachtClub.address);
} catch (error) {
console.log(error);
}
})
});
}); Here resolve statement is missing, which results in promise never getting resolved and the execution exceeding time out duration. it('the vrf fulfillRandomWords sends the randomWords and emits NFTMinted', async function () {
await new Promise(async (resolve, reject) => {
randomApeYachtClub.on('NFTMinted', () => {
try {
// This right here is never executed
} catch (error) {
console.log(error);
reject(error);
}
reslove();
});
try {
// mint NFT
const tx = await randomApeYachtClub.mintNft({ value: mintFee });
const receipt = await tx.wait(1);
const requestId = receipt.events.find(e => e.event === 'NFTRequested').args['requestId'];
// call fulfillRandomWords
// and watch for the event
await vrfCoordinatorV2Mock.fulfillRandomWords(requestId, randomApeYachtClub.address);
} catch (error) {
console.log(error);
}
})
});
}); |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
When doing unit tests, the
fulfillRandomWords
on my contract is not executing after manually callingfulfillRandomWords
from the VRF v2 mock contract. The unit test just times out without emitting an event that's in my contract'sfulfillRandomWords
. I am following lesson 14 and this happened to me in lesson 9 also.Here is my contract:
Here is my unit test file (the last test is the issue):
I am not sure what I'm doing wrong. Any help or guidance is appreciated.
Beta Was this translation helpful? Give feedback.
All reactions