2

I'm developing some smart contracts sing solc 0.7.0. I'm able to successfully compile and deploy the contracts, but when I try to run $truffle test I get the following error:

Using network 'development'.

Compiling your contracts...
===========================
> Compiling ./test/TestSupperApp.sol

truffle/Assert.sol:5:1: ParserError: Source file requires different compiler version (current compiler is 0.7.0+commit.9e61f92b.Emscripten.clang) - note that nightly builds are considered to be strictly less than the released version
pragma solidity >= 0.4.15 < 0.7.0;
^--------------------------------^
,truffle/DeployedAddresses.sol:2:1: ParserError: Source file requires different compiler version (current compiler is 0.7.0+commit.9e61f92b.Emscripten.clang) - note that nightly builds are considered to be strictly less than the released version
pragma solidity >= 0.7.0 < 0.7.0; 
^-------------------------------^

Error: Truffle is currently using solc 0.7.0, but one or more of your contracts specify "pragma solidity >= 0.4.15 < 0.7.0".
Please update your truffle config or pragma statement(s).
(See https://truffleframework.com/docs/truffle/reference/configuration#compiler-configuration for information on
configuring Truffle to use a specific solc compiler version.)

Compilation failed. See above.
Truffle v5.1.41 (core: 5.1.41)
Node v11.14.0

That's the beginning of the testing code:

// SPDX-License-Identifier: MIT
pragma solidity >=0.4.22 <0.8.0;

import "truffle/Assert.sol";
import "truffle/DeployedAddresses.sol";
import "../contracts/SuperApp.sol";

contract TestSuperApp
{

And the compiler configuration of my truffle-config looks like this:

  // Configure your compilers
  compilers: {
    solc: {
      version: "0.7.0",    // Fetch exact version from solc-bin (default: truffle's version)
      // docker: true,        // Use "0.5.1" you've installed locally with docker (default: false)
      // settings: {          // See the solidity docs for advice about optimization and evmVersion
      //  optimizer: {
      //    enabled: false,
      //    runs: 200
      //  },
      //  evmVersion: "byzantium"
      // }
    },
  },

How is it that DeployedAddresses.sol requires the compiler to use >=0.7.0 AND <0.7.0? And how can I fix it?

(OBS.: Obviously I should change the pragma statement, but since DeployedAddresses.sol is dynamically created at test time, it does not seems possible to directly change it)

1 Answer 1

1

You should be referencing what version of solidity compiler you should be using for truffle. This can be updated within the truffle-config.js.

compilers: {
    solc: {
      version: "^0.7.0"
    }
 }

(See https://trufflesuite.com/docs/truffle/reference/configuration#compiler-configuration for information on configuring Truffle to use a specific solc compiler version.)

You should then ensure that all smart contracts and smart contract tests are using this compiler function.

pragma solidity ^0.7.0;

If you refer again to the error, it states the contracts do not match the solidity compiler version. (Assert.sol / DeployedAddresses.sol) - Just update the pragma statement to reference the version as above and to match what is set from your truffle-config.js and you should be good.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.