PatrickAlphaC / hardhat-nft-fcc

100 stars 139 forks source link

Error: invalid BigNumber string (argument="value", value="[object Promise]", code=INVALID_ARGUMENT, version=bignumber/5.7.0) when trying to test the function of requestrandomwords #95

Closed Yehezkiel-simbuang closed 1 year ago

Yehezkiel-simbuang commented 1 year ago

I get some errors when trying to write a test code by myself.

This is the smart contract function that get an error

    function openCase() public returns (uint256 requestId) {
        if (numCase[msg.sender] == 0) {
            revert YouDontHaveAnyCase();
        } else {
            requestId = vrfCoordinator.requestRandomWords(
                keyHash,
                subId,
                minimumRequestConfirmations,
                callbackGasLimit,
                numWords
            );
            requestToSender[requestId] = msg.sender;
            numCase[msg.sender] -= 1;
        }
    }

This is the test script

              it("return a requestID and update the requestToSender and numCase variable", async () => {
                  fee = gachaContract.getPrice();
                  for (const i = 1; i < 3; i++) {
                      await gachaContract.payCase({ value: fee.toString() });
                  }
                  const openCaseResponse = await gachaContract.openCase();
                  assert.equal(
                      await getrequestToSender(openCaseResponse),
                      accounts[0].address
                  );
                  numCaseResponse = await gachaContract.getNumCase(
                      accounts[0].address
                  );
                  assert.equal(numCaseResponse, 1);
              });

And this is the error

Error: invalid BigNumber string (argument="value", value="[object Promise]", code=INVALID_ARGUMENT, version=bignumber/5.7.0)

Any suggestions and answers from you guys are very helpful. Thank You!!

FIXED, THAT'S MY MISTAKE. I forgot to put "await" keyword on getPrice function in test code.