smartcontractkit / full-blockchain-solidity-course-js

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

Lesson 9: staging test throws off unit test #1640

Closed cah311 closed 2 years ago

cah311 commented 2 years ago

this worked! Thank you! Unfortunatly this now throws off my unit test. It wont even get past the very first test.

When I run hh test, I now get this error:

 Raffle Unit Tests
    constructor
      1) "before each" hook for "initializes the raffle correctly"

  0 passing (1s)
  1 failing

  1) Raffle Unit Tests
       "before each" hook for "initializes the raffle correctly":
     ERROR processing /Users/carson/repos/freeCodeCamp_lessons/full-blockchain-solidity-course-js/hardhat-smartcontract-lottery-fcc/deploy/01-deploy-raffle.js:
Error: invalid BigNumber value (argument="value", value=undefined, code=INVALID_ARGUMENT, version=bignumber/5.6.2)
    at Logger.makeError (/Users/carson/repos/freeCodeCamp_lessons/full-blockchain-solidity-course-js/hardhat-smartcontract-lottery-fcc/node_modules/@ethersproject/logger/src.ts/index.ts:261:28)
    at Logger.throwError (/Users/carson/repos/freeCodeCamp_lessons/full-blockchain-solidity-course-js/hardhat-smartcontract-lottery-fcc/node_modules/@ethersproject/logger/src.ts/index.ts:273:20)
    at Logger.throwArgumentError (/Users/carson/repos/freeCodeCamp_lessons/full-blockchain-solidity-course-js/hardhat-smartcontract-lottery-fcc/node_modules/@ethersproject/logger/src.ts/index.ts:277:21)
    at Function.BigNumber.from (/Users/carson/repos/freeCodeCamp_lessons/full-blockchain-solidity-course-js/hardhat-smartcontract-lottery-fcc/node_modules/@ethersproject/bignumber/src.ts/bignumber.ts:289:23)
    at NumberCoder.encode (/Users/carson/repos/freeCodeCamp_lessons/full-blockchain-solidity-course-js/hardhat-smartcontract-lottery-fcc/node_modules/@ethersproject/abi/src.ts/coders/number.ts:25:27)
    at /Users/carson/repos/freeCodeCamp_lessons/full-blockchain-solidity-course-js/hardhat-smartcontract-lottery-fcc/node_modules/@ethersproject/abi/src.ts/coders/array.ts:71:19
    at Array.forEach (<anonymous>)
    at pack (/Users/carson/repos/freeCodeCamp_lessons/full-blockchain-solidity-course-js/hardhat-smartcontract-lottery-fcc/node_modules/@ethersproject/abi/src.ts/coders/array.ts:54:12)
    at TupleCoder.encode (/Users/carson/repos/freeCodeCamp_lessons/full-blockchain-solidity-course-js/hardhat-smartcontract-lottery-fcc/node_modules/@ethersproject/abi/src.ts/coders/tuple.ts:54:20)
    at AbiCoder.encode (/Users/carson/repos/freeCodeCamp_lessons/full-blockchain-solidity-course-js/hardhat-smartcontract-lottery-fcc/node_modules/@ethersproject/abi/src.ts/abi-coder.ts:111:15)
  Error: ERROR processing /Users/carson/repos/freeCodeCamp_lessons/full-blockchain-solidity-course-js/hardhat-smartcontract-lottery-fcc/deploy/01-deploy-raffle.js:
  Error: invalid BigNumber value (argument="value", value=undefined, code=INVALID_ARGUMENT, version=bignumber/5.6.2)
      at Logger.makeError (node_modules/@ethersproject/logger/src.ts/index.ts:261:28)
      at Logger.throwError (node_modules/@ethersproject/logger/src.ts/index.ts:273:20)
      at Logger.throwArgumentError (node_modules/@ethersproject/logger/src.ts/index.ts:277:21)
      at Function.BigNumber.from (node_modules/@ethersproject/bignumber/src.ts/bignumber.ts:289:23)
      at NumberCoder.encode (node_modules/@ethersproject/abi/src.ts/coders/number.ts:25:27)
      at /Users/carson/repos/freeCodeCamp_lessons/full-blockchain-solidity-course-js/hardhat-smartcontract-lottery-fcc/node_modules/@ethersproject/abi/src.ts/coders/array.ts:71:19
      at Array.forEach (<anonymous>)
      at pack (node_modules/@ethersproject/abi/src.ts/coders/array.ts:54:12)
      at TupleCoder.encode (node_modules/@ethersproject/abi/src.ts/coders/tuple.ts:54:20)
      at AbiCoder.encode (node_modules/@ethersproject/abi/src.ts/abi-coder.ts:111:15)
      at DeploymentsManager.executeDeployScripts (node_modules/hardhat-deploy/src/DeploymentsManager.ts:1222:19)
      at processTicksAndRejections (node:internal/process/task_queues:96:5)
      at runNextTicks (node:internal/process/task_queues:65:3)
      at listOnTimeout (node:internal/timers:528:9)
      at processTimers (node:internal/timers:502:7)
      at DeploymentsManager.runDeploy (node_modules/hardhat-deploy/src/DeploymentsManager.ts:1052:5)
      at Object.fixture (node_modules/hardhat-deploy/src/DeploymentsManager.ts:315:9)
      at Context.<anonymous> (test/unit/Raffle.test.js:13:15)

``

I was getting this error before and the issue was my arangement of arguments. I changed their order back to what worked before and this made both the staging test and unit test not work.

Here is my 1-deploy-raffle.js file for reference

const { getNamedAccounts, deployments, network, run } = require("hardhat") const { networkConfig, developmentChains, VERIFICATION_BLOCK_CONFIRMATIONS, } = require("../helper-hardhat-config") const { verify } = require("../utils/verify")

const FUND_AMOUNT = "1000000000000000000000"

module.exports = async ({ getNamedAccounts, deployments }) => { const { deploy, log } = deployments const { deployer } = await getNamedAccounts() const chainId = network.config.chainId let vrfCoordinatorV2Address, subscriptionId

if (chainId == 31337) {
    // create VRFV2 Subscription
    const vrfCoordinatorV2Mock = await ethers.getContract("VRFCoordinatorV2Mock")
    vrfCoordinatorV2Address = vrfCoordinatorV2Mock.address
    const transactionResponse = await vrfCoordinatorV2Mock.createSubscription()
    const transactionReceipt = await transactionResponse.wait()
    subscriptionId = transactionReceipt.events[0].args.subId.toString()
    // Fund the subscription
    // Our mock makes it so we don't actually have to worry about sending fund
    await vrfCoordinatorV2Mock.fundSubscription(subscriptionId, FUND_AMOUNT)
} else {
    // vrfCoordinatorV2Address = networkConfig[chainId]["vrfCoordinatorV2"]
    vrfCoordinatorV2Address = networkConfig[chainId]["vrfCoordinatorV2Address"]
    subscriptionId = networkConfig[chainId]["subscriptionId"]
}

/*
const entranceFee = networkConfig[chainId]["entranceFee"]
const gasLane = networkConfig[chainId]["gasLane"]
const callBackGasLimit = networkConfig[chainId]["callBackGasLimit"]
const interval = networkConfig[chainId]["interval"]
*/

// console.log(`-------------1---------${entranceFee}------------------------------`)
// console.log(`-------------2---------${gasLane}------------------------------`)
// console.log(`-------------3---------${callBackGasLimit}------------------------------`)
// console.log(`-------------4---------${interval}------------------------------`)
// console.log(`-------------5---------${subscriptionId}------------------------------`)

const waitBlockConfirmations = developmentChains.includes(network.name)
    ? 1
    : VERIFICATION_BLOCK_CONFIRMATIONS

log("----------------------------------------------------")
const arguments = [
    vrfCoordinatorV2Address,
    subscriptionId,
    networkConfig[chainId]["gasLane"],
    networkConfig[chainId]["keepersUpdateInterval"],
    networkConfig[chainId]["raffleEntranceFee"],
    networkConfig[chainId]["callbackGasLimit"],
]
const raffle = await deploy("Raffle", {
    from: deployer,
    args: arguments,
    log: true,
    waitConfirmations: waitBlockConfirmations,
})

// Verify the deployment
if (!developmentChains.includes(network.name) && process.env.ETHERSCAN_API_KEY) {
    log("Verifying...")
    await verify(raffle.address, arguments)
}

log("Enter lottery with command:")
const networkName = network.name == "hardhat" ? "localhost" : network.name
log(`yarn hardhat run scripts/enterRaffle.js --network ${networkName}`)
log("----------------------------------------------------")

}

module.exports.tags = ["all", "raffle"] `` here is my repo as well:

https://github.com/cah311/hardhat-lottery-fcc

Originally posted by @cah311 in https://github.com/smartcontractkit/full-blockchain-solidity-course-js/discussions/1613#discussioncomment-3357036