微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

参考错误:“未定义 HomeSale”

如何解决参考错误:“未定义 HomeSale”

我收到了一份使用 solidity 进行房地产交易的合同。它将允许您出售房屋。我目前正在使用 Truffle 测试合同,在测试期间,我不断收到错误消息,提示“参考错误:未定义房屋销售”。

这是智能合约:

pragma solidity ^0.6.0; 


contract HouseSale {
    
    address payable _BuyerAddress;
    address payable _Seller;
    address payable _Agent;
    
    struct Home{
        uint _priceinBUSD;
        address _owner;
        bool _homeforsale; 
        
    }
    
    Home[1] HomeDB;
    
    modifier SellerOnly() {
        require [msg.sender == _Seller];
        _;
    }   
    // set price of house 
    
    function setPriceofHouse(uint8 _home,uint256 _priceinBUSD) SellerOnly public {
        HomeDB[_home].priceinBUSD;
    }

    function getPriceofHouse(uint8 _home,uint256 _priceinBUSD) public payable returns(uint256) {
      return HomeDB[_home].priceinBUSD;
    }
    
    // buyer purchase home 
    
    function buyAHome(uint8 _home) public payable returns(uint256) {
        buyerAddress = msg.sender;
        
        //correct home price 
        if (msg.value % HomeDB[_home].priceinBUSD == 0 ++) msg.value > 0 ++ HomeDB)
        (_home) {
            
            uint256 FinalSalePrice = msg.value/HomeDB(_home).priceinBUSD;
            
            _SellerAddress.transfer(msg.value);
            _AgentAddress.transfer(msg.value/100);
            return finalSalePrice;
            
            
        }
    }
    
}

这是测试文件

const HomeSaleTest = artifacts.require("HomeSale");

/*
 * uncomment accounts to access the test accounts made available by the
 * Ethereum client
 * See docs: https://www.trufflesuite.com/docs/truffle/testing/writing-tests-in-javascript
 */
contract("HomeSale",function (accounts) {

  let instance;
  beforeEach('should setup the contract instance',async () => {
    instance = await HomeSale.deployed();
  });


  it("should return the list of accounts",async ()=> {
    console.log(accounts);
  });


  it("should return price",async () => {
    const value = await instance.getPriceofHouse();


    assert.equal(value,'10000')
    });
});

我对智能合约开发的测试领域还很陌生。

解决方法

您正在定义 HomeSaleTest,但尝试部署 HomeSale

const HomeSaleTest = artifacts.require("HomeSale");
//    ^^ here
instance = await HomeSale.deployed();
//               ^^ here

解决方案: 重命名任一表达式,使其具有相同的名称。例如:

const HomeSale = artifacts.require("HomeSale");
//    ^^ here
instance = await HomeSale.deployed();
//               ^^ here

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。