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
truffle test
, and instantiate them yourself in each one of your tests as needed. – goodvibration Sep 22 '19 at 13:38truffle migrate
will result in an error as well. – Senju Sep 22 '19 at 19:05truffle 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