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
Senju
  • 701
  • 1
  • 15
  • 28
  • Please share the relevant Truffle test and all of your Truffle migration scripts. – goodvibration Sep 22 '19 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 '19 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 '19 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 '19 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 '19 at 20:20
  • And if you're looking for a solution, then I recently posted it here. – goodvibration Sep 23 '19 at 15:52
  • @goodvibration Got ya. :) Thanks. Not the solution I was looking for but will do for now! – Senju Sep 24 '19 at 07:35
  • @goodvibration Sorry, I think my problem still exists. I prevent truffle test from running a migration and deploy the contract within the test myself. However, it will of course throw the same error since the constructor uses a smart contract, which only exist on the mainnet. Advice? – Senju Oct 02 '19 at 12:06
  • Advice: Don't use mainnet addresses in your Truffle tests! The whole idea about a Truffle test is that you execute it "locally" (i.e., on a private network), in order to test a contract before deploying it to mainnet. – goodvibration Oct 02 '19 at 14:04
  • @goodvibration agree but what if I want to get data from a mainnet contract for the test? Not possible? – Senju Oct 02 '19 at 14:07
  • You can create another Web3 instance connected to mainnet, in order to read data from there. – goodvibration Oct 02 '19 at 14:12
  • BTW, your previous comment is misleading. I believe that it will of course throw the same error is incorrect. You should be getting an error which is different from what's described in your question. – goodvibration Oct 02 '19 at 14:14
  • @goodvibration true. It still reverts but it's probably a different error message. – Senju Oct 02 '19 at 16:19

0 Answers0