【问题标题】:Does truffle test support ABIEncoderV2?松露测试是否支持 ABIEncoderV2?
【发布时间】: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)

您能给我一些建议如何测试我的代码吗?

【问题讨论】:

    标签: ethereum web3 truffle


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 2021-09-15
      • 1970-01-01
      • 2018-04-11
      • 2011-09-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-09-25
      相关资源
      最近更新 更多