Solidity 和 openzeppelin 的版本控制问题
我正在尝试在刚刚交给我的项目中运行truffle test
。
我在 Google 上搜索了 TypeErrors,发现这可能是由于使用了错误的可靠性,因此我尝试将安装了最新版本的 ethers
降级到 5.0.31
,但没有成功,因为我得到同样的错误。
据我所知,有两个问题 - 一个是由于我使用的是 M1,另一个是由于 Solidity 版本?
我的包裹要求是;
"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
更新
我已经设法摆脱了有关请求的图像错误的第一个警告,查看了我的 docker 图像,它看起来很好,所以我简单地在 truffle-config.js 中取消注释它。 code>:
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是不能隐式转换为预期类型(第一个返回变量的类型)应付地址。
但是...我无法更改 BaseRelayRecipient...?我知道这个设置几个月前才运行。
I'm trying to run truffle test
in a project I've just been handed.
I googled on the TypeErrors and found that it's probably due to the wrong solidity being used, so I tried downgrading ethers
which installed the latest to 5.0.31
, without success as I get the same errors.
From what I can tell, there are two issues - one due to me being on an M1, and the other due to a solidity version?
My package requirements are;
"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"
}
Here are the error messages:
> 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
UPDATE
I've managed to get rid of the first warnings regarding the requested image being wrong, looked at my docker images which looked fine so I simple uncommented this in the truffle-config.js
:
compilers: {
solc: {
version: '0.8.0',
// docker: true,
// settings: {
// optimizer: {
// enabled: false, // Default: false
// runs: 200, // Default: 200 | consensys default 0
// },
// },
},
},
Thanks to @Yilmaz for the general direction. I've also tried adding a range to the version, version: ">=0.4.22 <0.9.0"
without it making a difference.
Now, I still get the TypeError
.
UPDATE 2
It seems to be the GSN contract BaseRelayRecipient.sol
which is the culprit. The contract seems to have been upgraded recently to instead be named ERC2771Recipient, I have no idea how updating this contract I've been handed actually works so I won't be upgrading GSN at this moment, but continuing to try and get it to work...
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;
}
}
That last return is giving the TypeError: Return argument type address is not implicitly convertible to expected type (type of first return variable) address payable.
But... I can't change the BaseRelayRecipient...? I know this setup was running just a few months back.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您没有告诉 Truffle 您使用的版本,Truffle 将使用默认版本,即
turffle.config.js 中的0.5.16
if you did not tell Truffle what version you are using, truffle will use default which is 0.5.16
in turffle.config.js