smartcontractkit / full-blockchain-solidity-course-js

Learn Blockchain, Solidity, and Full Stack Web3 Development with Javascript
12.01k stars 2.91k forks source link

TransactionReceipt.events[1].args bug? #5707

Closed eugenekhoo1 closed 1 year ago

eugenekhoo1 commented 1 year ago

I was running test and kept encountering the error Error: invalid BigNumber value (argument="value", value=undefined, code=INVALID_ARGUMENT, version=bignumber/5.7.0)

When I console.log(txReceipt.events[1].args)..i get this output:

[
  BigNumber { _hex: '0x01', _isBigNumber: true },
  '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266',
  requesId: BigNumber { _hex: '0x01', _isBigNumber: true },
  requester: '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266'
]

Is this a bug where the argument is being misspelled as requesId?? or is it likely due to errors in my code?

alymurtazamemon commented 1 year ago

@eugenekhoo1 Please share the test.

eugenekhoo1 commented 1 year ago

I had to use 'requesId' instead to get the arguments out in this test

describe("RandomNFT Unit Tests", function () {
          let randomNft, deployer, vrfCoordinatorV2Mock

          beforeEach(async function () {
              accounts = await ethers.getSigners()
              deployer = accounts[0]
              await deployments.fixture(["mocks", "randomnft"])
              randomNft = await ethers.getContract("RandomIpfsNFT", deployer)
              vrfCoordinatorV2Mock = await ethers.getContract(
                  "VRFCoordinatorV2Mock"
              )
          })
          describe("fulfillRandomWords", function () {
              it("mints nft after random number is returned", async function () {
                  await new Promise(async (resolve, reject) => {
                      randomNft.once("NftMinted", async function () {
                          console.log("Event emitted!")
                          // check stuff
                          try {
                              const firstTokenUri =
                                  await randomNft.getTokenUris(0) // returns ipfs hash
                              const tokenCounter =
                                  await randomNft.getTokenCounter()
                              assert(
                                  firstTokenUri.toString().includes("ipfs://")
                              )
                              assert.equal(tokenCounter.toString(), "1")
                              resolve()
                          } catch (e) {
                              console.log(e)
                              reject(e)
                          }
                      })
                      try {
                          const mintFee = await randomNft.getMintFee()
                          const tx = await randomNft.requestNft({
                              value: mintFee,
                          })
                          const txReceipt = await tx.wait(1)
                          await vrfCoordinatorV2Mock.fulfillRandomWords(
                              txReceipt.events[1].args.requesId,
                              randomNft.address
                          )
                      } catch (e) {
                          console.log(e)
                          reject(e)
                      }
                  })
              })
          })
alymurtazamemon commented 1 year ago

@eugenekhoo1 And what does your event look like? Can you show it? It is better if you leave your repository link so I can see all things at once.

eugenekhoo1 commented 1 year ago

@alymurtazamemon Ahhhh..now that you mentioned that..i see that its misspelled....my bad..thanks!