0

I would like to run a truffle test on a smart contract that includes a smart contract address deployed on mainnet. However, this results in the following error

Error: Error: Error: while migrating WhitelistAdvanced: Returned error: VM Exception while processing transaction: revert

It seems like the migration process running before the actual test fails because the mainnet contract can obviously not be found on my local test chain.

contract WhitelistAdvanced {
    Whitelist internal whitelistContract = Whitelist(0x6198149b79AFE8114dc07b46A01d94a6af304ED9);

    constructor() public {
        address[] memory subscriberList = whitelistContract.getSubscriberList();
        for (uint256 i = 0; i < subscriberList.length; i++) {
            _subscribe(subscriberList[i]);
        }
    }

EDIT: deploy_contracts.js

const Whitelist = artifacts.require("Whitelist");
const WhitelistAdvanced = artifacts.require("WhitelistAdvanced");

module.exports = function (deployer) {
  deployer.deploy(Whitelist);
  deployer.deploy(WhitelistAdvanced);
};

EDIT: console output

$ truffle test test/TESTWhitelistAdvanced.js 

Compiling your contracts...
===========================
> Compiling ./contracts/Migrations.sol
> Compiling ./contracts/Whitelist.sol
> Compiling ./contracts/WhitelistAdvanced.sol

Error: Error: Error: while migrating WhitelistAdvanced: Returned error: VM Exception while processing transaction: revert
    at Object.run (/Users/X/.nvm/versions/node/v8.9.4/lib/node_modules/truffle/build/webpack:/packages/truffle-migrate/index.js:92:1)
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:188:7)
Truffle v5.0.33 (core: 5.0.33)
Node v8.9.4
  • Please share the relevant Truffle test and all of your Truffle migration scripts. – goodvibration Sep 22 at 12:28
  • @goodvibration I update the migration file. However, the tests are irrelevant because the error happens already before the actually tests run. – Senju Sep 22 at 13:17
  • Then prevent them from running during truffle test, and instantiate them yourself in each one of your tests as needed. – goodvibration Sep 22 at 13:38
  • @goodvibration sorry, I probably didn't make the question clear. The error happens for the migration already, which is just the step before the actual test. Meaning truffle migrate will result in an error as well. – Senju Sep 22 at 19:05
  • Perhaps I didn't make myself clear - prevent your migration scripts from running during truffle test, and the problem is solved. While your migration scripts are designated to run on mainnet, truffle test is obviously not. It therefore seems like the right thing to do. If you want to know how, then check this question (which I asked here myself a while ago). – goodvibration Sep 22 at 20:20

Your Answer

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

Browse other questions tagged or ask your own question.