首页 > 解决方案 > 松露测试是否支持 ABIEncoderV2?

问题描述

我想测试一个返回数组结构的函数。

这是示例代码。

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,但我不确定 web3ABIEncoderV2现在是否支持。

我的版本是这样的。Truffle v4.1.15(核心:4.1.15) Solidity v0.4.25(solc-js)

你能给我任何建议如何测试我的代码吗?

标签: ethereumweb3truffle

解决方案


支持从 truffle v5 开始ABIEncoderV2。我建议从您当前的版本升级到 v5。

https://truffleframework.com/blog/truffle-v5-has-arrived


推荐阅读