The smart contract I want to unit test instantiates IUniswapV2Router02(0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D). Obviously this contract does not exist on the local chain that is spawned by truffle test.

The solution seems to be to test on a local chain that is a fork of the main/rinkeby chain? How does one configure truffle test to run as such?

Thanks :D

Edit 1

I have tried the following configuration, however it doesn't work yet:

module.exports = {
    networks: {
        development: {
            fork: "https://eth-rinkeby.alchemyapi.io/v2/{myKey}",
            network_id: 4

It returns the following error:

$ npx truffle test
> Something went wrong while attempting to connect to the network. Check your network configuration.

Could not connect to your Ethereum client.
Please check that your Ethereum client:
    - is running
    - is accepting RPC connections (i.e., "--rpc" option is used in geth)
    - is accessible over the network
    - is properly configured in your Truffle configuration file (truffle-config.js)

Truffle v5.3.6 (core: 5.3.6)
Node v14.16.0

Edit 2

Filed in a Github issue on the trufflesuite/truffle repo in the meantime.


The truffle team might have provided a solution in the github ticket, so check that out, but in the meantime, my solution is to spawn a fork with the ganache cli: ganache-cli -f https://eth-rinkeby.alchemyapi.io/v2/${ALCHEMY_API_KEY_RINKEBY}

Using the following test network:

test: {
    host: "",
    port: 8545,
    network_id: "*",

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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