Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async function setupDryRunEnvironmentThenRunMigrations(config) {
await Environment.fork(config);
// Copy artifacts to a temporary directory
const temporaryDirectory = temp.mkdirSync("migrate-dry-run-");
await promisifiedCopy(
config.contracts_build_directory,
temporaryDirectory
);
config.contracts_build_directory = temporaryDirectory;
// Note: Create a new artifactor and resolver with the updated config.
// This is because the contracts_build_directory changed.
// Ideally we could architect them to be reactive of the config changes.
config.artifactor = new Artifactor(temporaryDirectory);
config.resolver = new Resolver(config);
return await runMigrations(config);
contracts.map(async ({ contractName, bytecode }) => {
const name = contractName.toString().concat(".json");
const artifactsNetworksPath = fse.readFileSync(
path.join(artifacts, name)
);
const artifactsNetworks = JSON.parse(artifactsNetworksPath.toString())
.networks;
let configNetworks = [];
if (Object.keys(artifactsNetworks).length) {
const config = Config.detect({ workingDirectory: workingDirectory });
for (let network of Object.keys(config.networks)) {
config.network = network;
await Environment.detect(config);
let networkId;
let web3;
try {
web3 = new Web3(config.provider);
networkId = await web3.eth.net.getId();
} catch (err) {}
if (networkId) {
let filteredNetwork = Object.entries(artifactsNetworks).filter(
network => network[0] == networkId
);
//assume length of filteredNetwork is 1 -- shouldn't have multiple networks with same id in one contract
if (filteredNetwork.length > 0) {
const transaction = await web3.eth.getTransaction(
filteredNetwork[0][1]["transactionHash"]
);
.then(async () => {
await Provider.testConnection(conf);
await Environment.detect(conf);
const {
dryRunOnly,
dryRunAndMigrations
} = command.determineDryRunSettings(conf, options);
if (dryRunOnly) {
conf.dryRun = true;
await setupDryRunEnvironmentThenRunMigrations(conf);
} else if (dryRunAndMigrations) {
const currentBuild = conf.contracts_build_directory;
conf.dryRun = true;
await setupDryRunEnvironmentThenRunMigrations(conf);
let {
let accept = true;
if (options.interactive) {
accept = await Migrate.acceptDryRun();
}
if (accept) {
const config = Config.detect(options);
config.contracts_build_directory = buildDir;
config.artifactor = new Artifactor(buildDir);
config.resolver = new Resolver(config);
try {
await Environment.detect(config);
} catch (error) {
throw new Error(error);
}
config.dryRun = false;
return { config, proceed: true };
} else {
return { proceed: false };
}
},