1

I am trying to use PancakeSwap contracts in my Foundry Tests. But when I import some of them (for example PancakeRouter) I get an error:

Discovered incompatible solidity versions in following
: test/helpers/Pancake.sol (>=0.4.0) imports:
    lib/pancake-smart-contracts/projects/exchange-protocol/contracts/libraries/WBNB.sol (^0.4.18)
    lib/pancake-smart-contracts/projects/exchange-protocol/contracts/PancakeFactory.sol (=0.5.16)
    lib/pancake-smart-contracts/projects/exchange-protocol/contracts/PancakeRouter.sol (=0.6.6)
    lib/pancake-smart-contracts/projects/exchange-protocol/contracts/interfaces/IPancakeFactory.sol (>=0.5.0)
    lib/pancake-smart-contracts/projects/exchange-protocol/contracts/PancakePair.sol (=0.5.16)

Do you have any idia how to solve such errors?

2 Answers 2

2
+50

Those contracts define conflicting Solidity compiler versions, so they cannot be imported and built in the same contract as you are trying to do in your Pancake.sol file.

You need to separate the tests into different files, defining the correct Solidity version for each group of tests.

So, what is the correct order and organization for those tests?

Inside the official Pancake repository, you can see some examples of how to do it. Even though those tests are in JavaScript, for HardHat, the critical part is how they distribute contracts between tests, i.e., the PancakeRouter.sol (=0.6.6 solc) is compiled and used separately from PancakeFactory.sol (=0.5.16 solc), etc.

And suppose one of your contracts needs to call another one. In that case, you can use an interface defining a minimum shared Solidity compiler version for compilation, i.e. IPancakeFactory.sol (>=0.5.0) like they do here.

-1

You can do this by specifying the desired version in the pragma statement at the top of each Solidity file.

pragma solidity ^0.5.16;

Your Answer

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

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