3

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?

3 Answers 3

3
+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.

0

In my case, I just updated foundry to the newest version and I was able to compile and run tests.

foundryup
forge clean
-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 you have read our privacy policy.

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