Search code examples
ethereumsolidityweb3jstruffle

Does truffle test support ABIEncoderV2?


I want to test a function which returns struct of array.

This is sample code.

struct Hoge {
  uint id;
  string text;
}

・・・

constructor() public {
  hoges.push(Hoge(1, "Hogehoge"));
}

・・・

function hogehoge() external view returns(Hoge memory) {
  return hoges[0];
}

And my test is this.

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);
    })
  })
})

However, error shows

invalid solidity type!: tuple

The function which return struct of array needs ABIEncoderV2.

I heard that web3 is trying to support ABIEncoderV2, but I am not sure web3 supports ABIEncoderV2 now.

My version is this:

  • Truffle v4.1.15 (core: 4.1.15)
  • Solidity v0.4.25 (solc-js)

Could you give me any advice how to test my code, please?


Solution

  • Starting with truffle v5, ABIEncoderV2 is supported. I would suggest upgrading from your current version to v5.

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