# Truffle Migrations run only if not dry run (different account0 in dry run)

I noticed that using HDWalletProvider using the account parameter in the migration you get random/unexpected accounts during dryRun. I added a safety line that an address should be as expected but because of dryRun this always fails.

Can I have a condition that code in the migration is only executed if not in dryRun?

Here a minimal example of my migration (truffle.js needs to be configured to use HDWalletProvider and have expected address as account0):

const expected = "0xcFbB1f35EF57b96cA51221a331165fF9B2c828FD";

module.exports = function(deployer, network, account) {

console.log("This accounts are not from HDWalletProvider on dryRun and are always different");
console.log(account);

//this fails even if HDWalletProvider is configured correctly in truffle.js
if (account[0].toLowerCase() !== expected.toLowerCase()) {
throw new Error(
Unexpected account0: account0=${account[0]} instead of${expected}
);
}
};


Just add skipDryRun: true to your network config in truffle-config.js.

Running different code in "real" and "dry-run" modes is highly unrecommended. This is why I think Truffle should use same accounts in dry-run as the ones that would be used during real migration.

However, for the time being, if you still want to detect dry-run in your migration code, it seems that Truffle adds "-fork" as suffix to network name. Perhaps, this code will help:

if (network.split('-')[1] === "fork") {
// dry-run specific code
}
`
• Good idea. Should work. I decided to just get rid of dry run altogether because we run it locally then on testenet and then on mainnet. So dryRun is just slowing everything down anyway – CodingYourLife Sep 9 at 10:30