关于坚固性和openzepelin的版本问题 [英] Versioning issues with solidity and openzeppelin

查看:0
本文介绍了关于坚固性和openzepelin的版本问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在刚刚收到的项目中运行truffle test

我在谷歌上搜索了TypeErrors,发现可能是由于使用了错误的可靠性,所以我尝试将安装了最新版本的ethers降级为5.0.31,但没有成功,因为我收到了相同的错误。

据我所知,有两个问题-一个是由于我使用的是M1,另一个是由于坚固版本?

我的包裹要求是;

  "dependencies": {
    "@opengsn/contracts": "^2.2.2",
    "@openzeppelin/contracts": "^4.1.0",
    "ethers": "^5.0.29",
    "truffle-hdwallet-provider": "^1.0.17"
  },
  "devDependencies": {
    "chai": "^4.3.0",
    "openzeppelin-test-helpers": "^0.5.1",
    "truffle-flattener": "^1.6.0"
  }

以下是错误消息:

> truffle test

Using network 'development'.


Compiling your contracts...
===========================
WARNING: The requested image's platform (linux/amd64) does not match the detected host platform (linux/arm64/v8) and no specific platform was requested
WARNING: The requested image's platform (linux/amd64) does not match the detected host platform (linux/arm64/v8) and no specific platform was requested
WARNING: The requested image's platform (linux/amd64) does not match the detected host platform (linux/arm64/v8) and no specific platform was requested
WARNING: The requested image's platform (linux/amd64) does not match the detected host platform (linux/arm64/v8) and no specific platform was requested
WARNING: The requested image's platform (linux/amd64) does not match the detected host platform (linux/arm64/v8) and no specific platform was requested
WARNING: The requested image's platform (linux/amd64) does not match the detected host platform (linux/arm64/v8) and no specific platform was requested
WARNING: The requested image's platform (linux/amd64) does not match the detected host platform (linux/arm64/v8) and no specific platform was requested
WARNING: The requested image's platform (linux/amd64) does not match the detected host platform (linux/arm64/v8) and no specific platform was requested
WARNING: The requested image's platform (linux/amd64) does not match the detected host platform (linux/arm64/v8) and no specific platform was requested
WARNING: The requested image's platform (linux/amd64) does not match the detected host platform (linux/arm64/v8) and no specific platform was requested
> Compiling ./contracts/MetaWhat.sol
> Compiling ./contracts/Migrations.sol
> Compiling ./node_modules/@opengsn/contracts/src/BaseRelayRecipient.sol
> Compiling ./node_modules/@opengsn/contracts/src/interfaces/IRelayRecipient.sol
> Compiling ./node_modules/@openzeppelin/contracts/access/Ownable.sol
> Compiling ./node_modules/@openzeppelin/contracts/token/ERC20/ERC20.sol
> Compiling ./node_modules/@openzeppelin/contracts/token/ERC20/IERC20.sol
> Compiling ./node_modules/@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol
> Compiling ./node_modules/@openzeppelin/contracts/utils/Context.sol

> Compilation warnings encountered:

    Warning: SPDX license identifier not provided in source file. Before publishing, consider adding a comment containing "SPDX-License-Identifier: <SPDX-License>" to each source file. Use "SPDX-License-Identifier: UNLICENSED" for non-open-source code. Please see https://spdx.org for more information.
--> project:/contracts/MetaWhat.sol


TypeError: Overriding function return types differ.
   --> project:/contracts/MetaWhat.sol:197:5:
    |
197 |     function _msgSender() internal override(Context, BaseRelayRecipient) view returns (address payable) {
    |     ^ (Relevant source part starts here and spans across multiple lines).
Note: Overridden function is here:
  --> project:/node_modules/@openzeppelin/contracts/utils/Context.sol:16:5:
   |
16 |     function _msgSender() internal view virtual returns (address) {
   |     ^ (Relevant source part starts here and spans across multiple lines).

,TypeError: Overriding function return types differ.
   --> project:/contracts/MetaWhat.sol:197:5:
    |
197 |     function _msgSender() internal override(Context, BaseRelayRecipient) view returns (address payable) {
    |     ^ (Relevant source part starts here and spans across multiple lines).
Note: Overridden function is here:
  --> project:/node_modules/@openzeppelin/contracts/utils/Context.sol:16:5:
   |
16 |     function _msgSender() internal view virtual returns (address) {
   |     ^ (Relevant source part starts here and spans across multiple lines).

,TypeError: Return argument type address is not implicitly convertible to expected type (type of first return variable) address payable.
  --> project:/node_modules/@opengsn/contracts/src/BaseRelayRecipient.sol:37:20:
   |
37 |             return msg.sender;
   |                    ^^^^^^^^^^

Compilation failed. See above.
Truffle v5.4.32 (core: 5.4.32)
Node v16.13.2

更新

我已经设法摆脱了关于请求的图像错误的第一个警告,查看了我的停靠站图像,这些图像看起来很好,所以我在truffle-config.js中简单地取消了对此的注释:

compilers: {
    solc: {
      version: '0.8.0',
      // docker: true,
      // settings: {
      //   optimizer: {
      //     enabled: false, // Default: false
      //     runs: 200, // Default: 200 | consensys default 0
      //   },
      // },
    },
  },

感谢@Yilmaz的大方向。我还尝试在版本中添加一个范围,version: ">=0.4.22 <0.9.0",但没有产生任何影响。

现在,我仍然可以使用TypeError

更新%2

似乎是GSN合同BaseRelayRecipient.sol的罪魁祸首。合同最近似乎已升级,取而代之的是ERC2771Recipient,我不知道更新我收到的合同的实际工作方式,因此目前我不会升级GSN,但会继续尝试使其工作...

    function _msgSender() internal override virtual view returns (address payable ret) {
        if (msg.data.length >= 20 && isTrustedForwarder(msg.sender)) {
            // At this point we know that the sender is a trusted forwarder,
            // so we trust that the last bytes of msg.data are the verified sender address.
            // extract sender address from the end of msg.data
            assembly {
                ret := shr(96,calldataload(sub(calldatasize(),20)))
            }
        } else {
            return msg.sender;
        }
    }

最后一个返回给TypeError: Return argument type address is not implicitly convertible to expected type (type of first return variable) address payable.

但是...我无法更改BaseRelayRecipient...?我知道这个安装程序几个月前还在运行。

推荐答案

如果您没有告诉Truffle您使用的是哪个版本,则Truffle将使用默认版本0.5.16

在turffle.config.js中

compilers: {
    solc: {
      // whatever version you are using
      version: "0.8.4",

     // you could also put a range here 
     // version: ">=0.4.22 <0.9.0",
    }
  }

这篇关于关于坚固性和openzepelin的版本问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆