错误:无效的BigNumber值(argument=“值”,value=undefined,code=INVALID_ARGUMENT,version=bignumber/5.7.0)
PS E:\Block Chain Projects\FUND_ME_FULLSTACK> yarn hardhat test
yarn run v1.22.15
warning ..\package.json: No license field
$ "E:\Block Chain Projects\FUND_ME_FULLSTACK\node_modules\.bin\hardhat" test
Funde
constructor
✔ Sets the aggregator address correctly (50ms)
Fund
✔ Fails if u don't send enought ethers (147ms)
✔ Update the amount funded data structure (104ms)
✔ Funder Upated to fund array (108ms)
Withdraw
1) Withdraw Eth From a single Founder
4 passing (2s)
1 failing
1) Funde
Withdraw
Withdraw Eth From a single Founder:
Error: invalid BigNumber value (argument="value", value=undefined, code=INVALID_ARGUMENT, version=bignumber/5.7.0)
at Logger.makeError (node_modules\@ethersproject\logger\src.ts\index.ts:269:28)
at Logger.throwError (node_modules\@ethersproject\logger\src.ts\index.ts:281:20)
at Logger.throwArgumentError (node_modules\@ethersproject\logger\src.ts\index.ts:285:21)
at Function.BigNumber.from (node_modules\@ethersproject\bignumber\src.ts\bignumber.ts:289:23)
at toBN (node_modules\@ethersproject\bignumber\src.ts\bignumber.ts:345:27)
at BigNumber.mul (node_modules\@ethersproject\bignumber\src.ts\bignumber.ts:90:43)
at Context.<anonymous> (test\units\FundMe.test.js:58:42)
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)MY FundMe.test.js问题是在撤回描述(错误的BIGNUMBER )中找不到错误
const {deployments, ethers,getNamedAccounts} = require("hardhat");
const {assert, expect} = require("chai");
describe("Funde",async function () {
let fundme;
let deployer;
let mockV3Aggregator;
let sendvalue = ethers.utils.parseEther("1"); //! Ether
beforeEach(async ()=>
{
// DEPLOY THE CONTRACT USING HARDHAT DEPLOY
deployer = (await getNamedAccounts()).deployer;
await deployments.fixture("all"); // -> with one line of code deploy all deploy.js files
// fixture uses tags given in the deploy folders using module.exports\
//console.log(deployer);
fundme = await ethers.getContract("FundMe",deployer);
mockV3Aggregator = await ethers.getContract("MockV3Aggregator",deployer);
});
describe("constructor",async function()
{
it("Sets the aggregator address correctly",async function()
{ const response = await fundme.getPriceFeed();
////console.log(response);
//console.log(mockV3Aggregator.address);
assert.equal(response,mockV3Aggregator.address);
});
});
describe("Fund",async function()
{
it("Fails if u don't send enought ethers",async function ()
{
await expect(fundme.fund()).to.be.revertedWith("You need to spend more ETH!");
});
it("Update the amount funded data structure",async ()=>{
await fundme.fund({value:sendvalue})
const response = await fundme.getAddressToAmountFunded(deployer);
assert.equal(response.toString(),sendvalue.toString());
});
it("Funder Upated to fund array",async () =>{
await fundme.fund({value:sendvalue})
const response = await fundme.getFunder(0);
assert.equal(response,deployer);
});
});
describe("Withdraw",async function(){
beforeEach(async function(){
await fundme.fund({value:sendvalue});
})
it("Withdraw Eth From a single Founder",async function()
{
//Arrange
const initialbalance = await fundme.provider.getBalance(fundme.address);
const initialdeploybalance = await fundme.provider.getBalance(deployer);
//ACT
const withdrawfund = await fundme.withdraw();
const Transactionreciept = await withdrawfund.wait();
const {gasUsed,effecttiveGasPrice} = Transactionreciept;
const totalgasused = gasUsed.mul(effecttiveGasPrice);
console.log(totalgasused);
const Endingbalance = await fundme.provider.getBalance(fundme.address);
const Endingdeployerbalance = await fundme.provider.getBalance(deployer);
//ASSERT
assert.equal(Endingbalance,0);
assert.equal(initialbalance.add(initialdeploybalance)
.toString(),
Endingdeployerbalance.add(totalgasused)
.toString());
});
});
});我想错误就在这一行,为什么我不能得到全部数据。我尝试了JS-调试器,但是找不到这个错误。
发布于 2022-09-04 15:14:52
此错误类型“错误:无效的BigNumber值(value=undefined)”表示您传递的是“未定义的”,这是一个错误的参数。错误堆栈指示此部分为at BigNumber.mul。这意味着您在这里传递了错误的论点:gasUsed.mul(effecttiveGasPrice);
所以这个声明有问题
const {gasUsed,effecttiveGasPrice} = Transactionreciept;很可能你没有正确地破坏结构。变量effecttiveGasPrice有2 "t“应该是effectiveGasPrice。您在这里传递未定义的内容:gasUsed.mul(undefined);
https://stackoverflow.com/questions/73598517
复制相似问题