truffle 测试是否支持 ABIEncoderV2?
Does truffle test support ABIEncoderV2?
我想测试一个 return 数组结构的函数。
这是示例代码。
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
。
return数组结构需要的函数ABIEncoderV2
.
我听说 web3 正在尝试支持 ABIEncoderV2
,但我不确定 web3 现在是否支持 ABIEncoderV2
。
我的版本是这样的。
松露 v4.1.15(核心:4.1.15)
Solidity v0.4.25 (solc-js)
你能告诉我如何测试我的代码吗?
从 truffle v5 ABIEncoderV2
开始支持。
我建议从您当前的版本升级到 v5。
我想测试一个 return 数组结构的函数。
这是示例代码。
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
。
return数组结构需要的函数ABIEncoderV2
.
我听说 web3 正在尝试支持 ABIEncoderV2
,但我不确定 web3 现在是否支持 ABIEncoderV2
。
我的版本是这样的。 松露 v4.1.15(核心:4.1.15) Solidity v0.4.25 (solc-js)
你能告诉我如何测试我的代码吗?
从 truffle v5 ABIEncoderV2
开始支持。
我建议从您当前的版本升级到 v5。