【发布时间】:2019-05-21 10:51:44
【问题描述】:
我想测试一个返回数组结构的函数。
这是示例代码。
struct Hoge {
uint id;
string text;
}
・・・
constructor() public {
hoges.push(Hoge(1, "Hogehoge"));
}
・・・
function hogehoge() external view returns(Hoge memory) {
return hoges[0];
}
我的测试是这样的。
var Sample = artifacts.require('./Sample.sol');
contract('sample', function(accounts) {
it('facilitates number of place and check-in', function() {
return Sample.deployed().then(function(instance) {
sampleInstance = instance;
return sampleInstance.hogehoge()
}).then(function(result) {
hoges = result;
assert.equal(hoges.id, 1);
})
})
})
但是,错误显示invalid solidity type!: tuple。
返回数组结构的函数需要ABIEncoderV2。
听说 web3 正在尝试支持ABIEncoderV2,但我不确定 web3 现在是否支持ABIEncoderV2。
我的版本是这样的。 松露 v4.1.15(核心:4.1.15) Solidity v0.4.25 (solc-js)
您能给我一些建议如何测试我的代码吗?
【问题讨论】: