0

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.

Cookie
  • 364
  • 1
  • 2
  • 12

1 Answers1

0

if you did not tell Truffle what version you are using, truffle will use default which is 0.5.16

in 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",
    }
  }
Yilmaz
  • 35,338
  • 10
  • 157
  • 202
  • Hmm, it is specified as 0.8.0 in the config. I'm starting to think it's a versioning issue with the @openzeppelin contracts. – Cookie Feb 28 '22 at 10:02
  • Put a range instead of specific version. Like >=0.4.22 <0.9.0", – Yilmaz Feb 28 '22 at 10:45
  • So seems like it's a docker image, so now I get why the first error happens, ``` compilers: { solc: { version: ">=0.4.22 <0.9.0", docker: true, settings: { optimizer: { enabled: false, // Default: false runs: 200, // Default: 200 | consensys default 0 }, }, }, }, ``` Now I get the error "Please ensure that >=0.4.22 <0.9.0 is a valid docker image name." – Cookie Feb 28 '22 at 11:04
  • you shoud have mentioned that you are using docker – Yilmaz Feb 28 '22 at 11:18
  • right, sorry about that, I was literally handed the project and just tried to run the test command without success. Not quite familiar with truffle yet. But, uncommenting the docker bit seems to have solved the first problem. – Cookie Feb 28 '22 at 11:24
  • if problem is not resolved, update the question with details – Yilmaz Feb 28 '22 at 11:25
  • BTW - I have tried the version range just now without success, I get the same TypeError related to BaseRelayRecipient.sol:37:20 – Cookie Feb 28 '22 at 11:25
  • Yes, I've updated the question. – Cookie Feb 28 '22 at 11:26
  • so as far as I understood, you are running truffle on docker, right? – Yilmaz Feb 28 '22 at 11:29
  • I commented out the docker part in the config, so now it looks like the compiler is being fetched from solc-bin. – Cookie Feb 28 '22 at 11:31