diff --git a/docs/modules/ROOT/pages/api-hardhat-upgrades.adoc b/docs/modules/ROOT/pages/api-hardhat-upgrades.adoc index 51764ad63..001a2fb18 100644 --- a/docs/modules/ROOT/pages/api-hardhat-upgrades.adoc +++ b/docs/modules/ROOT/pages/api-hardhat-upgrades.adoc @@ -84,3 +84,14 @@ async function transferProxyAdminOwnership( newAdmin: string, ): Promise ---- + +== silenceWarnings + +Silences all subsequent warnings about the use of unsafe flags. Prints a last warning before doing so. + +NOTE: This function is useful for tests, but its use in production deployment scripts is discouraged. + +[source,ts] +---- +function silenceWarnings() +---- diff --git a/docs/modules/ROOT/pages/api-truffle-upgrades.adoc b/docs/modules/ROOT/pages/api-truffle-upgrades.adoc index 21a8dd8a4..086ee9fbe 100644 --- a/docs/modules/ROOT/pages/api-truffle-upgrades.adoc +++ b/docs/modules/ROOT/pages/api-truffle-upgrades.adoc @@ -89,3 +89,14 @@ async function transferProxyAdminOwnership( newAdmin: string, ): Promise ---- + +== silenceWarnings + +Silences all subsequent warnings about the use of unsafe flags. Prints a last warning before doing so. + +NOTE: This function is useful for tests, but its use in production deployment scripts is discouraged. + +[source,ts] +---- +function silenceWarnings() +---- diff --git a/packages/core/CHANGELOG.md b/packages/core/CHANGELOG.md index d1a2110e1..24bff57d5 100644 --- a/packages/core/CHANGELOG.md +++ b/packages/core/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## Unreleased + +- Add `silenceWarnings` to emit a single warning and silence all subsequent ones. ([#228](https://github.com/OpenZeppelin/openzeppelin-upgrades/pull/228)) + ## 1.3.1 (2020-11-13) - Add missing artifact files in the package. diff --git a/packages/core/src/validate.ts b/packages/core/src/validate.ts index 826a73f37..e58163985 100644 --- a/packages/core/src/validate.ts +++ b/packages/core/src/validate.ts @@ -250,7 +250,7 @@ function processOverride( return !isException; }); - if (exceptionsFound) { + if (exceptionsFound && !silenced) { console.error( '\n' + chalk.keyword('orange').bold('Warning: ') + @@ -447,3 +447,17 @@ function* getEnumErrors(contractDef: ContractDefinition, decodeSrc: SrcDecoder): }; } } + +let silenced = false; + +export function silenceWarnings(): void { + if (!silenced) { + console.error( + '\n' + + chalk.keyword('orange').bold('Warning: ') + + `All subsequent Upgrades warnings will be silenced.\n\n` + + ` Make sure you have manually checked all uses of unsafe flags.\n`, + ); + silenced = true; + } +} diff --git a/packages/plugin-hardhat/CHANGELOG.md b/packages/plugin-hardhat/CHANGELOG.md index 5d2798281..5c78a4751 100644 --- a/packages/plugin-hardhat/CHANGELOG.md +++ b/packages/plugin-hardhat/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## Unreleased + +- Add `silenceWarnings` to emit a single warning and silence all subsequent ones. ([#228](https://github.com/OpenZeppelin/openzeppelin-upgrades/pull/228)) + ## 1.3.1 (2020-11-18) - Allow ommitting `args` in `deployProxy` when it's an empty array. diff --git a/packages/plugin-hardhat/src/index.ts b/packages/plugin-hardhat/src/index.ts index 4e990b8dd..1b62559d7 100644 --- a/packages/plugin-hardhat/src/index.ts +++ b/packages/plugin-hardhat/src/index.ts @@ -26,8 +26,10 @@ extendEnvironment(hre => { const { makeChangeProxyAdmin, makeTransferProxyAdminOwnership } = require('./admin'); const { makeDeployProxy } = require('./deploy-proxy'); const { makeUpgradeProxy, makePrepareUpgrade } = require('./upgrade-proxy'); + const { silenceWarnings } = require('@openzeppelin/upgrades-core'); return { + silenceWarnings, deployProxy: makeDeployProxy(hre), upgradeProxy: makeUpgradeProxy(hre), prepareUpgrade: makePrepareUpgrade(hre), diff --git a/packages/plugin-hardhat/src/type-extensions.ts b/packages/plugin-hardhat/src/type-extensions.ts index 7339d506a..a074188d8 100644 --- a/packages/plugin-hardhat/src/type-extensions.ts +++ b/packages/plugin-hardhat/src/type-extensions.ts @@ -1,5 +1,6 @@ import 'hardhat/types/runtime'; +import type { silenceWarnings } from '@openzeppelin/upgrades-core'; import type { DeployFunction } from './deploy-proxy'; import type { UpgradeFunction, PrepareUpgradeFunction } from './upgrade-proxy'; @@ -9,6 +10,7 @@ declare module 'hardhat/types/runtime' { deployProxy: DeployFunction; upgradeProxy: UpgradeFunction; prepareUpgrade: PrepareUpgradeFunction; + silenceWarnings: typeof silenceWarnings; }; } } diff --git a/packages/plugin-hardhat/test/happy-path-with-enums.js b/packages/plugin-hardhat/test/happy-path-with-enums.js index 09079e788..51bf576c0 100644 --- a/packages/plugin-hardhat/test/happy-path-with-enums.js +++ b/packages/plugin-hardhat/test/happy-path-with-enums.js @@ -2,6 +2,8 @@ const test = require('ava'); const { ethers, upgrades } = require('hardhat'); +upgrades.silenceWarnings(); + test.before(async t => { t.context.Action = await ethers.getContractFactory('Action'); t.context.ActionV2 = await ethers.getContractFactory('ActionV2'); diff --git a/packages/plugin-hardhat/test/happy-path-with-structs.js b/packages/plugin-hardhat/test/happy-path-with-structs.js index 45c673bab..f4042111b 100644 --- a/packages/plugin-hardhat/test/happy-path-with-structs.js +++ b/packages/plugin-hardhat/test/happy-path-with-structs.js @@ -2,6 +2,8 @@ const test = require('ava'); const { ethers, upgrades } = require('hardhat'); +upgrades.silenceWarnings(); + test.before(async t => { t.context.Portfolio = await ethers.getContractFactory('Portfolio'); t.context.PortfolioV2 = await ethers.getContractFactory('PortfolioV2'); diff --git a/packages/plugin-hardhat/test/linked-libraries.js b/packages/plugin-hardhat/test/linked-libraries.js index 611be6de4..c5bd18ba4 100644 --- a/packages/plugin-hardhat/test/linked-libraries.js +++ b/packages/plugin-hardhat/test/linked-libraries.js @@ -4,6 +4,8 @@ const { ethers, upgrades, artifacts } = require('hardhat'); const testAddress = '0x1E6876a6C2757de611c9F12B23211dBaBd1C9028'; +upgrades.silenceWarnings(); + test('without flag', async t => { // Deploying library const safeMathLib = await deployLibrary('SafeMath'); diff --git a/packages/plugin-truffle/CHANGELOG.md b/packages/plugin-truffle/CHANGELOG.md index f3cbe338b..f89599950 100644 --- a/packages/plugin-truffle/CHANGELOG.md +++ b/packages/plugin-truffle/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## Unreleased + +- Add `silenceWarnings` to emit a single warning and silence all subsequent ones. ([#228](https://github.com/OpenZeppelin/openzeppelin-upgrades/pull/228)) + ## 1.2.5 (2020-11-18) - Allow ommitting `args` in `deployProxy` when it's an empty array. diff --git a/packages/plugin-truffle/src/index.ts b/packages/plugin-truffle/src/index.ts index 0fb83a491..fb8450c81 100644 --- a/packages/plugin-truffle/src/index.ts +++ b/packages/plugin-truffle/src/index.ts @@ -1,3 +1,5 @@ export * from './deploy-proxy'; export * from './upgrade-proxy'; export { admin } from './admin'; + +export { silenceWarnings } from '@openzeppelin/upgrades-core'; diff --git a/packages/plugin-truffle/test.sh b/packages/plugin-truffle/test.sh index 2ce7070df..7951f956f 100644 --- a/packages/plugin-truffle/test.sh +++ b/packages/plugin-truffle/test.sh @@ -4,4 +4,4 @@ set -euo pipefail rimraf test/.openzeppelin -yarn --cwd test truffle test +yarn --cwd test truffle test "$@" diff --git a/packages/plugin-truffle/test/migrations/1_initial_migration.js b/packages/plugin-truffle/test/migrations/1_initial_migration.js index 5ec88e464..0b545e725 100644 --- a/packages/plugin-truffle/test/migrations/1_initial_migration.js +++ b/packages/plugin-truffle/test/migrations/1_initial_migration.js @@ -1,3 +1,7 @@ +const upgrades = require('@openzeppelin/truffle-upgrades'); + +upgrades.silenceWarnings(); + const Migrations = artifacts.require('Migrations'); module.exports = function (deployer) {