如何解决类型错误:变量查找后找不到匹配的声明
我正在 solidity 中编写一个简单的房地产智能合约,在 Truffle 中进行测试时,我不断收到此错误。 “类型错误:变量查找后未找到匹配的声明”。目标是让卖家成为唯一确定房屋价格的人。
这是合同代码供您参考。
pragma solidity ^0.5.16;
contract HomeSale {
address payable _buyerAddress;
address payable _seller;
address payable _agent;
struct Home{
uint _priceinBUSD;
address _owner;
bool _homeforsale;
}
Home[1] HomeDB;
modifier onlySeller() {
require [msg.sender == _seller];
_;
}
// set price of house
function price(uint8 _home,uint256 _priceinBUSD) onlySeller public returns (uint64){
require(msg.sender);
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)(_home);
uint256 finalSalePrice = msg.value/HomeDB(_home).priceinBUSD;
_seller.transfer(msg.value);
_agent.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')
});
});
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。