Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: localhost and hardhat deploy can be run with zero config #539

Merged
merged 19 commits into from
Feb 19, 2024

Conversation

jordaniza
Copy link
Contributor

@jordaniza jordaniza commented Feb 14, 2024

Description

Currently, running the deploy script requires several steps and env var config. Default values are suggested in the README so this PR uses the default values as fallbacks when the network is localhost or hardhat.

Implementing this properly required:

  1. Creating the fallback values as functions in a helper file in the utils folder, and adding a quick set of tests.
  2. Replacing calls to process.env with the fallback functions.
  3. Adding a pre-deploy environment check to prevent script execution in a live environment, if the env vars are not set (this is extensible for the future)
  4. Some changes to the README to reflect the code changes, along with some utility commands in package.json
  5. Some changes to hardhat.config to setup the localhost runner.

Task ID: OS-1040

Type of change

  • New feature (non-breaking change which adds functionality)

Checklist:

  • I have selected the correct base branch.
  • I have performed a self-review of my own code.
  • I have commented my code, particularly in hard-to-understand areas.
  • My changes generate no new warnings.
  • Any dependent changes have been merged and published in downstream modules.
  • I ran all tests with success and extended them if necessary.
  • I have updated the CHANGELOG.md file in the root folder.
  • I have updated the DEPLOYMENT_CHECKLIST file in the root folder.
  • I have updated the UPDATE_CHECKLIST file in the root folder.

network,
'MANAGEMENT_DAO_MULTISIG_APPROVERS',
// random address
'0x6B2b5d4F0a40134189330e2d46a9CDD01C01AECD'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What are the implications of using a random address here?

Instead of a random address, we could think about using the known hardhat default address (derived from hardhat's default mnemonic 'test test test test test test test test test test test junk'.
I think it is 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266.

This could result in tests passing (that mostly use signers[0]), although this could be equally undesirable.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We already use the private key for the HH address you listed as default. So possibly we can use the next derived address from that same mnemonic.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, sounds good. Maybe for the default, we can have two or three approvers (and a 1/2 or 2/3 threshold) - all from the default mnemonic.

I am wondering how this will work in combination with local fork tests.
In the future, we might want to do similar fork testing like I did it for the osx-plugin-template-hardhat.
I guess we can adapt these functions once we decide to work on this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think adding multiple approvers is a good improvement that should be added to the backlog for fork tests. I would avoid changing that inside this PR

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, can you add a task and link it here?

Proper punctuation in doc comments

Co-authored-by: Michael Heuer <[email protected]>
typo

Co-authored-by: Michael Heuer <[email protected]>
@@ -18,7 +22,7 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
const {ethers, network} = hre;
const [deployer] = await ethers.getSigners();

if (network.name !== 'localhost' && network.name !== 'hardhat') {
if (!['localhost', 'hardhat'].includes(network.name)) {
Copy link
Contributor

@heueristik heueristik Feb 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

@heueristik heueristik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's double-check that there is no scenario, in which a wrong list of approvers can be set accidentally (see my comment about || [deployer].

In production, we should throw errors if env variables are not set, which we do in the script tagged 'Env' check. However, you can select/exclude certain tags which could result in the 00-env-check.ts not being run.
In this case, the script must throw an error too and not silently run with a wrong approver list.
Let's make sure that this is the case

@jordaniza
Copy link
Contributor Author

Let's double-check that there is no scenario, in which a wrong list of approvers can be set accidentally (see my comment about || [deployer].

In production, we should throw errors if env variables are not set, which we do in the script tagged 'Env' check. However, you can select/exclude certain tags which could result in the 00-env-check.ts not being run. In this case, the script must throw an error too and not silently run with a wrong approver list. Let's make sure that this is the case

Yeah so any time one of the XXXenv functions is called, it throws internally if:

  • We are on a real network
  • The required env variable is not set

In this way, the Env check is a redundancy but also helps to signpost all the required variables before any transactions run. If the required env variable is not set and a deploy script is run, we will still throw when the variable is accessed with a helpful error message.

UPDATE_CHECKLIST.md Outdated Show resolved Hide resolved
@Rekard0 Rekard0 merged commit 959e1c1 into develop Feb 19, 2024
3 checks passed
@Rekard0 Rekard0 deleted the f/default-env branch February 19, 2024 10:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants