Skip to content

Commit

Permalink
Stop using undefined value
Browse files Browse the repository at this point in the history
  • Loading branch information
DimaStebaev committed Sep 18, 2023
1 parent 6fd5b75 commit 465669c
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 17 deletions.
1 change: 0 additions & 1 deletion .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ module.exports = {
"never"
],

"no-undefined": "warn",
"no-underscore-dangle": "warn",
"no-use-before-define": "warn",
"no-warning-comments": "warn",
Expand Down
4 changes: 2 additions & 2 deletions src/contractFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const getSkaleManifest = async () => {
await getManifestFile(),
"utf-8"
));
if (manifest.libraries === undefined) {
if (typeof manifest.libraries === "undefined") {
manifest.libraries = {};
}
return manifest as SkaleManifestData;
Expand Down Expand Up @@ -119,7 +119,7 @@ const getLibrariesToUpgrade = async (
const librariesNames = getLibrariesNames(linkReferences);
const byteCodes = await loadBytesCodes(librariesNames);
for (const libraryName of librariesNames) {
if (manifest.libraries[libraryName] === undefined) {
if (typeof manifest.libraries[libraryName] === "undefined") {
librariesToUpgrade.push(libraryName);
} else if (
hashBytecode(byteCodes.get(libraryName) as string) ===
Expand Down
2 changes: 1 addition & 1 deletion src/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ const updateManifest = async (libraryArtifacts: LibraryArtifacts) => {
await getManifestFile(),
"utf-8"
)) as SkaleManifestData;
if (manifest.libraries === undefined) {
if (typeof manifest.libraries === "undefined") {
Object.assign(
manifest,
{"libraries": libraryArtifacts}
Expand Down
2 changes: 1 addition & 1 deletion src/submitters/safe-to-ima-submitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export class SafeToImaSubmitter extends SafeSubmitter {
}

private async _getMessageProxyForMainnet () {
if (this._messageProxyForMainnet === undefined) {
if (typeof this._messageProxyForMainnet === "undefined") {
this._messageProxyForMainnet =
await this.imaInstance.getContract("MessageProxyForMainnet");
}
Expand Down
21 changes: 10 additions & 11 deletions src/upgrader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ interface Target {
contractNamesToUpgrade: string[]
}

const withoutUndefined = <T>(array: Array<T | undefined>) => array.
filter((element) => element !== undefined) as Array<T>;
const withoutNull = <T>(array: Array<T | null>) => array.
filter((element) => element !== null) as Array<T>;


export abstract class Upgrader {
Expand Down Expand Up @@ -106,13 +106,13 @@ export abstract class Upgrader {
// Private

private async callInitialize () {
if (this.initialize !== undefined) {
if (typeof this.initialize !== "undefined") {
await this.initialize();
}
}

private async callDeployNewContracts () {
if (this.deployNewContracts !== undefined) {
if (typeof this.deployNewContracts !== "undefined") {
// Deploy new contracts
await this.deployNewContracts();
}
Expand Down Expand Up @@ -176,7 +176,7 @@ export abstract class Upgrader {
private async deployNewImplementations () {
const contracts = await Promise.all(this.contractNamesToUpgrade.
map(this.deployNewImplementation));
return withoutUndefined(contracts);
return withoutNull(contracts);
}

private async deployNewImplementation (contract: string) {
Expand All @@ -186,11 +186,10 @@ export abstract class Upgrader {
(await this.instance.getContract(contract)).address;

console.log(`Prepare upgrade of ${contract}`);
const
currentImplementationAddress = await getImplementationAddress(
network.provider,
proxyAddress
);
const currentImplementationAddress = await getImplementationAddress(
network.provider,
proxyAddress
);
const newImplementationAddress = await upgrades.prepareUpgrade(
proxyAddress,
contractFactory,
Expand All @@ -207,7 +206,7 @@ export abstract class Upgrader {
};
}
console.log(chalk.gray(`Contract ${contract} is up to date`));
return undefined;
return null;
}

private async getNormalizedDeployedVersion () {
Expand Down
2 changes: 1 addition & 1 deletion src/version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const exec = util.promisify(asyncExec);
class VersionNotFound extends Error {}

const getVersionFilename = async (folder?: string): Promise<string> => {
if (folder === undefined) {
if (typeof folder === "undefined") {
return getVersionFilename((
await exec("git rev-parse --show-toplevel")
).stdout.trim());
Expand Down

0 comments on commit 465669c

Please sign in to comment.