Lesson14: Can I use the following code instead of Promise? #2522
-
i write some code here for "fulfillRandomWords" Test, but i don't use "New Promise" function like in the video, is it OK? describe("fulfillRandomWords", async () => {
beforeEach(async () => {
const txResponse = await randomIpfsNft.requestNft({
value: sendValue,
})
const txReceipt = await txResponse.wait(1)
const requestId = txReceipt.events[1].args.requestId
await vrfCoodinatorV2Mock.fulfillRandomWords(
requestId,
randomIpfsNft.address
)
})
it("mints NFT after random number is returned", async () => {
randomIpfsNft.once("NftMinted", async () => {
const tokenUri = await randomIpfsNft.tokenURI(0)
const tokenCounter = await randomIpfsNft.getTokenCounter()
assert.equal(
tokenUri.toString().includes("ipfs://"),
true
)
assert.equal(tokenCounter.toString(), "1")
})
})
}) I'm afraid it's a coincidence... |
Beta Was this translation helpful? Give feedback.
Answered by
othaime-en
Sep 12, 2022
Replies: 1 comment 1 reply
-
Hey @f-hk you could totally use the code as it is above. We use the promise just to be safe incase the blockchain moves fast or slow i.e. the events gets emitted faster before we can "catch" it/ listen for it. But this is totally workable. |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
f-hk
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hey @f-hk you could totally use the code as it is above. We use the promise just to be safe incase the blockchain moves fast or slow i.e. the events gets emitted faster before we can "catch" it/ listen for it. But this is totally workable.