diff --git a/src/deploy/campaign/deploy-campaign.ts b/src/deploy/campaign/deploy-campaign.ts index 4fb7d7e10..90750cf06 100644 --- a/src/deploy/campaign/deploy-campaign.ts +++ b/src/deploy/campaign/deploy-campaign.ts @@ -22,7 +22,7 @@ export class DeployCampaign { config : IDeployCampaignConfig; version : string; - // TODO dep: figure out typing here so that methods of each contract type are resolved in Mission classes! + // TODO dep: improve typing here so that methods of each contract type are resolved in Mission classes! // eslint-disable-next-line @typescript-eslint/no-explicit-any [name : string | symbol] : any; @@ -75,13 +75,13 @@ export class DeployCampaign { {} ); - this.logger.debug("Deploy Campaign initialized."); + this.logger.info("Deploy Campaign initialized."); return campaignProxy; } async execute () { - this.logger.debug("Deploy Campaign execution started."); + this.logger.info("Deploy Campaign execution started."); await Object.values(this.state.instances).reduce( async ( @@ -102,12 +102,11 @@ export class DeployCampaign { await this.monitor(); } - this.logger.debug("Deploy Campaign execution finished successfully."); + this.logger.info("Deploy Campaign execution finished successfully."); } updateStateContract (instanceName : string, contractName : string, contract : Contract) { this.state.contracts[instanceName] = contract; - // TODO dep: make better logger and decide which levels to call where this.logger.debug(`Data of deployed contract '${contractName}' is added to Campaign state at '${instanceName}'.`); } diff --git a/src/deploy/db/mongo-adapter/constants.ts b/src/deploy/db/mongo-adapter/constants.ts index 8dc0ca7cb..1b0e4ded9 100644 --- a/src/deploy/db/mongo-adapter/constants.ts +++ b/src/deploy/db/mongo-adapter/constants.ts @@ -10,6 +10,5 @@ export const VERSION_TYPES = { archived: "ARCHIVED", }; -// TODO dep: move these to default ENV config export const DEFAULT_MONGO_URI = "mongodb://localhost:27018"; export const DEFAULT_MONGO_DB_NAME = "zns-campaign"; diff --git a/src/deploy/db/mongo-adapter/get-adapter.ts b/src/deploy/db/mongo-adapter/get-adapter.ts index c83cbe8ef..f1d4313a7 100644 --- a/src/deploy/db/mongo-adapter/get-adapter.ts +++ b/src/deploy/db/mongo-adapter/get-adapter.ts @@ -27,7 +27,9 @@ export const getMongoAdapter = async (logger ?: TLogger) : Promise, version ?: string) { if (!version) { ({ dbVersion: version } = await this.getCheckLatestVersion()); } @@ -115,7 +114,6 @@ export class MongoDBAdapter { } // Versioning methods - // TODO dep: add logging to all versioning stages and methods !! async configureVersioning (version ?: string) { // TODO dep: add archiving logic once determined on how to handle it const tempV = await this.getTempVersion(); @@ -260,7 +258,6 @@ export class MongoDBAdapter { } async clearDBForVersion (version : string) { - // TODO dep: add more collections here when added await this.contracts.deleteMany({ version, }); diff --git a/src/deploy/logger/create-logger.ts b/src/deploy/logger/create-logger.ts index 5f5bf5979..8a1d7ad21 100644 --- a/src/deploy/logger/create-logger.ts +++ b/src/deploy/logger/create-logger.ts @@ -1,28 +1,25 @@ import winston from "winston"; import { TLogger } from "../campaign/types"; +import { includes } from "hardhat/internal/hardhat-network/provider/filter"; let logger : TLogger | null = null; -// TODO dep: refine this function and configurability of this logger export const createLogger = (logLevel ?: string, silent ?: boolean) => winston.createLogger({ level: logLevel, format: winston.format.combine( - // TODO dep: adjust the format to what we need winston.format.json(), winston.format.timestamp(), winston.format.prettyPrint(), ), transports: [ - // TODO dep: figure out where to transport this in production new winston.transports.Console(), ], - // TODO dep: make sure we need this to be set! + // TODO dep: do we need this to be set ? exitOnError: false, silent, }); -// TODO dep: add more ENV vars here so we don't have to pass anything export const getLogger = () : TLogger => { if (logger) return logger; @@ -31,5 +28,15 @@ export const getLogger = () : TLogger => { process.env.SILENT_LOGGER === "true" ); + const logFileName = `deploy-${Date.now()}.log`; + + if (process.env.ENV_LEVEL?.includes("prod") || process.env.ENV_LEVEL?.includes("test")) { + logger.add( + new winston.transports.File({ filename: logFileName }), + ); + + logger.debug(`The ENV_LEVEL is ${process.env.ENV_LEVEL}, logs will be saved in ${ logFileName } file`); + } + return logger; }; diff --git a/src/deploy/missions/base-deploy-mission.ts b/src/deploy/missions/base-deploy-mission.ts index a44792225..0e6bf0db9 100644 --- a/src/deploy/missions/base-deploy-mission.ts +++ b/src/deploy/missions/base-deploy-mission.ts @@ -12,9 +12,6 @@ import { ProxyKinds } from "../constants"; import { ContractByName } from "@tenderly/hardhat-tenderly/dist/tenderly/types"; -// TODO dep: -// 1. add better logging for each step -// 2. add proper error handling export class BaseDeployMission { contractName! : string; instanceName! : string; @@ -57,11 +54,10 @@ export class BaseDeployMission { async needsDeploy () { const dbContract = await this.getFromDB(); - // TODO dep: refine these if (!dbContract) { - this.logger.debug(`${this.contractName} not found in DB, proceeding to deploy...`); + this.logger.info(`${this.contractName} not found in DB, proceeding to deploy...`); } else { - this.logger.debug(`${this.contractName} found in DB at ${dbContract.address}, no deployment needed.`); + this.logger.info(`${this.contractName} found in DB at ${dbContract.address}, no deployment needed.`); const contract = await this.campaign.deployer.getContractObject( this.contractName, @@ -84,7 +80,7 @@ export class BaseDeployMission { return this.campaign.deployer.getContractArtifact(this.contractName); } - buildDbObject (hhContract : Contract, implAddress : string | null) : IContractDbData { + buildDbObject (hhContract : Contract, implAddress : string | null) : Omit { const { abi, bytecode } = this.getArtifact(); return { name: this.contractName, @@ -92,9 +88,6 @@ export class BaseDeployMission { abi: JSON.stringify(abi), bytecode, implementation: implAddress, - // TODO dep: this might not be needed here since MongoAdapter will add it - // upon writing to DB - version: this.campaign.version, }; } @@ -142,7 +135,7 @@ export class BaseDeployMission { } async verify () { - this.logger.info(`Verifying ${this.contractName} on Etherscan...`); + this.logger.debug(`Verifying ${this.contractName} on Etherscan...`); const { address } = await this.campaign[this.instanceName]; const ctorArgs = !this.proxyData.isProxy ? this.deployArgs() : undefined; @@ -152,7 +145,7 @@ export class BaseDeployMission { ctorArgs, }); - this.logger.info(`Etherscan verification for ${this.contractName} finished successfully.`); + this.logger.debug(`Etherscan verification for ${this.contractName} finished successfully.`); } async getMonitoringData () : Promise> { diff --git a/src/deploy/missions/contracts/access-controller.ts b/src/deploy/missions/contracts/access-controller.ts index a2b95c65a..6d4e74717 100644 --- a/src/deploy/missions/contracts/access-controller.ts +++ b/src/deploy/missions/contracts/access-controller.ts @@ -7,8 +7,7 @@ export class ZNSAccessControllerDM extends BaseDeployMission { proxyData = { isProxy: false, }; - // TODO dep: make constants available for both this and tests. - // possibly use ones from the helpers + contractName = znsNames.accessController.contract; instanceName = znsNames.accessController.instance; diff --git a/src/deploy/storage/base-storage-adapter.ts b/src/deploy/storage/base-storage-adapter.ts deleted file mode 100644 index 1f99370e5..000000000 --- a/src/deploy/storage/base-storage-adapter.ts +++ /dev/null @@ -1,22 +0,0 @@ -import { TLogger } from "../campaign/types"; -import { IContractDbData, TContractDBDoc } from "../db/types"; - - -// TODO dep: do we need this class at all? remove this if not used -export class BaseStorageAdapter { - logger : TLogger; - - constructor (logger : TLogger) { - this.logger = logger; - } - - // eslint-disable-next-line @typescript-eslint/no-unused-vars - async writeContract (contractDbName : string, data : IContractDbData) { - throw new Error("This class can NOT be used as storage adapter. It needs to be inherited and implemented."); - } - - // eslint-disable-next-line @typescript-eslint/no-unused-vars - async getContract (contractDbName : string) : Promise { - throw new Error("This class can NOT be used as storage adapter. It needs to be inherited and implemented."); - } -} diff --git a/src/deploy/storage/file-storage.ts b/src/deploy/storage/file-storage.ts deleted file mode 100644 index 68b394b0b..000000000 --- a/src/deploy/storage/file-storage.ts +++ /dev/null @@ -1,52 +0,0 @@ -import fs from "fs"; -import path from "path"; -import { BaseStorageAdapter } from "./base-storage-adapter"; -import { TLogger } from "../campaign/types"; -import { IContractDbData } from "../db/types"; - - -export const fileStoragePath = path.join(process.cwd(), "./db"); - - -export class FileStorageAdapter extends BaseStorageAdapter { - private writeLocal : boolean; - - constructor (logger : TLogger, writeLocal = true) { - super(logger); - - this.writeLocal = writeLocal; - - if (!this.writeLocal) return; - - if (!fs.existsSync(fileStoragePath)) { - this.logger.info("Creating temp db directory."); - fs.mkdirSync(fileStoragePath); - } else { - this.logger.info(`Temp db directory exists and will be used at: ${fileStoragePath}.`); - } - } - - async writeContract (contractDbName : string, data : IContractDbData) { - if (!this.writeLocal) return; - - const filePath = path.join(fileStoragePath, `/${contractDbName}.json`); - const fileData = JSON.stringify(data, null, "\t"); - - fs.writeFileSync(filePath, fileData); - - this.logger.info(`Contract data for ${contractDbName} saved to file: ${filePath}.`); - } - - async getContract (contractDbName : string) : Promise { - const filePath = path.join(fileStoragePath, `/${contractDbName}.json`); - - if (!fs.existsSync(filePath)) { - this.logger.debug(`Contract data for ${contractDbName} not found at: ${filePath}.`); - return null; - } - - const fileData = fs.readFileSync(filePath, "utf8"); - - return JSON.parse(fileData); - } -} diff --git a/src/deploy/storage/utils.ts b/src/deploy/storage/utils.ts deleted file mode 100644 index d0b58b3a7..000000000 --- a/src/deploy/storage/utils.ts +++ /dev/null @@ -1,9 +0,0 @@ -import fs from "fs"; -import { fileStoragePath } from "./file-storage"; - - -export const wipeFileStorage = () => { - if (fs.existsSync(fileStoragePath)) { - fs.rmSync(fileStoragePath, { recursive: true, force: true }); - } -}; diff --git a/src/deploy/zns-campaign.ts b/src/deploy/zns-campaign.ts index b1bba1681..f8faa0096 100644 --- a/src/deploy/zns-campaign.ts +++ b/src/deploy/zns-campaign.ts @@ -23,7 +23,6 @@ export const runZnsCampaign = async ({ dbVersion ?: string; deployer ?: HardhatDeployer; }) => { - // TODO dep: figure out the best place to put this at! hre.upgrades.silenceWarnings(); const logger = getLogger(); @@ -53,7 +52,6 @@ export const runZnsCampaign = async ({ await campaign.execute(); - // TODO dep: find the best place to call these ! await dbAdapter.finalizeDeployedVersion(dbVersion); return campaign; diff --git a/test/DeployCampaignInt.test.ts b/test/DeployCampaignInt.test.ts index 2c25f17f0..881d920d9 100644 --- a/test/DeployCampaignInt.test.ts +++ b/test/DeployCampaignInt.test.ts @@ -867,8 +867,6 @@ describe("Deploy Campaign Test", () => { before (async () => { [deployAdmin, admin, zeroVault] = await hre.ethers.getSigners(); - // TODO dep ver: add proper checks for the new config values - // and make sure tenderly and etherscan ENV data is acquired correctly config = { deployAdmin, governorAddresses: [deployAdmin.address], diff --git a/test/ZNSRootRegistrar.test.ts b/test/ZNSRootRegistrar.test.ts index b7f7a5c94..6d682280a 100644 --- a/test/ZNSRootRegistrar.test.ts +++ b/test/ZNSRootRegistrar.test.ts @@ -48,8 +48,8 @@ import { access } from "fs"; require("@nomicfoundation/hardhat-chai-matchers"); -// TODO dep: this is the only test converted to use the new Campaign -// others need to be converted once the Campaign is ready in full +// This is the only test converted to use the new Campaign, other +// contract specific tests are using `deployZNS()` helper describe("ZNSRootRegistrar", () => { let deployer : SignerWithAddress; let user : SignerWithAddress;