问题描述
我正在 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 (将#修改为@)