首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在硬帽子测试中知道错误在哪一行?

如何在硬帽子测试中知道错误在哪一行?
EN

Ethereum用户
提问于 2022-11-15 09:16:58
回答 1查看 117关注 0票数 1

我遵循一个房地产web3.0项目教程。我正在做和他完全一样的事情,但我不知道为什么我仍然会犯错误。

这是我的合同Escrow.sol

代码语言:javascript
复制
contract Escrow {
address public nftAddress;
address payable public seller;
address public inspector;
address public lender;

mapping(uint256 => bool) public isListed;
mapping(uint256 => uint256) public purchasePrice;
mapping(uint256 => uint256) public escrowAmount;
mapping(uint256 => address) public buyer;

constructor(
    address _nftAddress,
    address payable _seller,
    address _inspector,
    address _lender
) {
    nftAddress = _nftAddress;
    seller = _seller;
    inspector = _inspector;
    lender = _lender;
}

function list(
    uint256 _nftID,
    uint256 _purchasePrice,
    uint256 _escrowAmount,
    address _buyer
) public {
    // transfer NFTs from seller to this contract
    IERC721(nftAddress).transferFrom(msg.sender, address(this), _nftID);

    isListed[_nftID] = true;
    purchasePrice[_nftID] = _purchasePrice;
    escrowAmount[_nftID] = _escrowAmount;
    buyer[_nftID] = _buyer;
}

}

我像这样测试它

代码语言:javascript
复制
 const { expect } = require("chai");
const { ethers } = require("hardhat");

const tokens = (n) => {
  return ethers.utils.parseUnits(n.toString(), "ether");
};

describe("Escrow", () => {
  let buyer, seller, inspector, lender;
  let realEstate, escrow;

  beforeEach(async () => {
    // setup Accounts
    [buyer, seller, inspector, lender] = await ethers.getSigners();

    //Deploying Real Estate contract
    const RealEstate = await ethers.getContractFactory("RealEstate");
    realEstate = await RealEstate.deploy();

    //Mint
    let transaction = await realEstate
      .connect(seller)
      .mint(
        "https://ipfs.io/ipfs/QmQVcpsjrA6cr1iJjZAodYwmPekYgbnXGo4DFubJiLc2EB/1.json"
      );
    await transaction.wait();

   

 const Escrow = await ethers.getContractFactory("Escrow");
    escrow = await Escrow.deploy(
      realEstate.address,
      seller.address,
      inspector.address,
      lender.address
    );

    //Approve property
    transaction = await realEstate.connect(seller).approve(escrow.address, 1);
    await transaction.wait();

    //List property
    transaction = await escrow
      .connect(seller)
      .list(1, buyer.address, tokens(10), tokens(5));
    await transaction.wait();
  });

 

  describe("Listing", () => {
    it("Updates as listed", async () => {
      const result = await escrow.isListed(1);
      expect(result).to.be.equal(true);
    });

    it("Returns buyer", async () => {
      const result = await escrow.buyer(1);
      expect(result).to.be.equal(buyer.address);
    });

    it("Returns Purchase Price", async () => {
      const result = await escrow.purchasePrice(1);
      expect(result).to.be.equal(tokens(10));
    });

    it("Returns escrow Amount", async () => {
      const result = await escrow.escrowAmount(1);
      expect(result).to.be.equal(tokens(5));
    });

    it("Updates Ownership", async () => {
      expect(await realEstate.ownerOf(1)).to.be.equal(escrow.address);
    });
  });
});

但是在使用npx hardhat test之后,我得到了错误

代码语言:javascript
复制
 1) Escrow
   "before each" hook for "Updates as listed":
 Error: invalid address or ENS name (argument="name", value={"type":"BigNumber","hex":"0x4563918244f40000"}, code=INVALID_ARGUMENT, version=contracts/5.7.0)

我找不到错误在哪一行,尽管我已经检查了他的GitHub回购中的所有内容,而且所有的内容都是一样的。如果你们能告诉我如何找到错误所在以及如何解决

EN

回答 1

Ethereum用户

发布于 2022-11-17 10:02:57

在合同中,以下函数的前3个参数是uint256,最后一个是address

代码语言:javascript
复制
function list(
    uint256 _nftID,
    uint256 _purchasePrice,
    uint256 _escrowAmount,
    address _buyer
)

查看一下在beforeEach中使用的代码片段

代码语言:javascript
复制
//List property
 transaction = await escrow
   .connect(seller)
   .list(1, buyer.address, tokens(10), tokens(5));

这里,您传递的是第二个参数中的address,在创建该问题的第四个参数中传递uint256。只需交换这些论点的立场,它就会起作用。

票数 0
EN
页面原文内容由Ethereum提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://ethereum.stackexchange.com/questions/139423

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档