Skip to content

Commit

Permalink
Support private networks and forked networks with Defender (#25)
Browse files Browse the repository at this point in the history
  • Loading branch information
ericglau authored Mar 11, 2024
1 parent 3347b97 commit c50a796
Show file tree
Hide file tree
Showing 8 changed files with 76 additions and 30 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 0.1.0 (2024-03-11)

- Support private networks and forked networks with Defender.

## 0.0.2 (2024-02-20)

- Support constructor arguments for Defender deployments. ([#16](https://github.com/OpenZeppelin/openzeppelin-foundry-upgrades/pull/16))
Expand Down
12 changes: 12 additions & 0 deletions DEFENDER.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,18 @@ DEFENDER_KEY=<Your API key>
DEFENDER_SECRET<Your API secret>
```

## Network Selection

The network that is used with OpenZeppelin Defender is determined by the network that Foundry is connected to.
If you want to ensure that a specific network is used with Defender, set the `DEFENDER_NETWORK` environment variable in your `.env` file, for example:
```
DEFENDER_NETWORK=my-mainnet-fork
```
If set, this must be the name of a public, private or forked network in Defender. If the `chainId` parameter corresponds to a different network while this is set, the deployment will not occur and will throw an error instead.

> **Note**
> This is required if you have multiple forked networks in Defender with the same chainId, in which case the one with name matching the `DEFENDER_NETWORK` environment variable will be used.
## Usage

### Upgradeable Contracts
Expand Down
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
# OpenZeppelin Foundry Upgrades

Foundry library for deploying and managing upgradeable contracts, which includes upgrade safety checks.
[![Docs](https://img.shields.io/badge/docs-%F0%9F%93%84-blue)](https://docs.openzeppelin.com/upgrades-plugins/foundry-upgrades)

> **Warning**
> This repository contains experimental code. It is available as a technology preview and its functionality is subject to change. Breaking changes may be introduced at any point while it is in preview.
Foundry library for deploying and managing upgradeable contracts, which includes upgrade safety checks.

## Installing

Expand Down
12 changes: 12 additions & 0 deletions docs/modules/pages/foundry-defender.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,18 @@ DEFENDER_KEY=<Your API key>
DEFENDER_SECRET<Your API secret>
----

== Network Selection

The network that is used with OpenZeppelin Defender is determined by the network that Foundry is connected to.
If you want to ensure that a specific network is used with Defender, set the `DEFENDER_NETWORK` environment variable in your `.env` file, for example:
[source]
----
DEFENDER_NETWORK=my-mainnet-fork
----
If set, this must be the name of a public, private or forked network in Defender. If Foundry is connected to a different network while this is set, the deployment will not occur and will throw an error instead.

NOTE: This is required if you have multiple forked networks in Defender with the same chainId, in which case the one with name matching the `DEFENDER_NETWORK` environment variable will be used.

== Usage

=== Upgradeable Contracts
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"devDependencies": {
"@nomicfoundation/hardhat-foundry": "^1.1.1",
"@openzeppelin/contracts": "^5.0.0",
"@openzeppelin/defender-deploy-client-cli": "0.0.1-alpha.4",
"@openzeppelin/defender-deploy-client-cli": "0.0.1-alpha.5",
"@openzeppelin/upgrades-core": "^1.32.3",
"hardhat": "^2.21.0",
"prettier": "^3.0.0",
Expand Down
2 changes: 1 addition & 1 deletion src/internal/Versions.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ pragma solidity ^0.8.20;
library Versions {
// TODO add a workflow to update this automatically based on package.json
string constant UPGRADES_CORE = "^1.32.3";
string constant DEFENDER_DEPLOY_CLIENT_CLI = "0.0.1-alpha.4";
string constant DEFENDER_DEPLOY_CLIENT_CLI = "0.0.1-alpha.5";
}
22 changes: 15 additions & 7 deletions test/UpgradesUseDefenderDeploy.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@ contract UpgradesUseDefenderDeployTest is Test {
d = new Deployer();
}

function _assertDefenderNotAvailable(strings.slice memory slice) private {
assertTrue(
slice.contains(
"The current network with chainId 31337 is not supported by OpenZeppelin Defender".toSlice()
) || slice.contains("DEFENDER_KEY and DEFENDER_SECRET must be set in environment variables".toSlice())
);
}

function testDeployUUPSProxy() public {
Options memory opts;
opts.defender.useDefenderDeploy = true;
Expand All @@ -37,7 +45,7 @@ contract UpgradesUseDefenderDeployTest is Test {
} catch Error(string memory reason) {
strings.slice memory slice = reason.toSlice();
assertTrue(slice.contains("Failed to deploy contract GreeterProxiable.sol".toSlice()));
assertTrue(slice.contains("Network 31337 is not supported by OpenZeppelin Defender".toSlice()));
_assertDefenderNotAvailable(slice);
}
}

Expand All @@ -50,7 +58,7 @@ contract UpgradesUseDefenderDeployTest is Test {
} catch Error(string memory reason) {
strings.slice memory slice = reason.toSlice();
assertTrue(slice.contains("Failed to deploy contract Greeter.sol".toSlice()));
assertTrue(slice.contains("Network 31337 is not supported by OpenZeppelin Defender".toSlice()));
_assertDefenderNotAvailable(slice);
}
}

Expand All @@ -67,7 +75,7 @@ contract UpgradesUseDefenderDeployTest is Test {
} catch Error(string memory reason) {
strings.slice memory slice = reason.toSlice();
assertTrue(slice.contains("Failed to deploy contract GreeterV2Proxiable.sol".toSlice()));
assertTrue(slice.contains("Network 31337 is not supported by OpenZeppelin Defender".toSlice()));
_assertDefenderNotAvailable(slice);
}
}

Expand All @@ -80,7 +88,7 @@ contract UpgradesUseDefenderDeployTest is Test {
} catch Error(string memory reason) {
strings.slice memory slice = reason.toSlice();
assertTrue(slice.contains("Failed to deploy contract Greeter.sol".toSlice()));
assertTrue(slice.contains("Network 31337 is not supported by OpenZeppelin Defender".toSlice()));
_assertDefenderNotAvailable(slice);
}
}

Expand All @@ -96,7 +104,7 @@ contract UpgradesUseDefenderDeployTest is Test {
strings.slice memory slice = reason.toSlice();
// Note the below is not the implementation contract, because this function only deploys the BeaconProxy contract
assertTrue(slice.contains("Failed to deploy contract BeaconProxy.sol".toSlice()));
assertTrue(slice.contains("Network 31337 is not supported by OpenZeppelin Defender".toSlice()));
_assertDefenderNotAvailable(slice);
}
}

Expand All @@ -111,7 +119,7 @@ contract UpgradesUseDefenderDeployTest is Test {
} catch Error(string memory reason) {
strings.slice memory slice = reason.toSlice();
assertTrue(slice.contains("Failed to deploy contract GreeterV2.sol".toSlice()));
assertTrue(slice.contains("Network 31337 is not supported by OpenZeppelin Defender".toSlice()));
_assertDefenderNotAvailable(slice);
}
}

Expand All @@ -124,7 +132,7 @@ contract UpgradesUseDefenderDeployTest is Test {
} catch Error(string memory reason) {
strings.slice memory slice = reason.toSlice();
assertTrue(slice.contains("Failed to deploy contract GreeterV2.sol".toSlice()));
assertTrue(slice.contains("Network 31337 is not supported by OpenZeppelin Defender".toSlice()));
_assertDefenderNotAvailable(slice);
}
}

Expand Down
47 changes: 29 additions & 18 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -428,32 +428,43 @@
resolved "https://registry.yarnpkg.com/@openzeppelin/contracts/-/contracts-5.0.0.tgz#ee0e4b4564f101a5c4ee398cd4d73c0bd92b289c"
integrity sha512-bv2sdS6LKqVVMLI5+zqnNrNU/CA+6z6CmwFXm/MzmOPBRSO5reEJN7z0Gbzvs0/bv/MZZXNklubpwy3v2+azsw==

"@openzeppelin/[email protected]":
version "0.0.1-alpha.4"
resolved "https://registry.yarnpkg.com/@openzeppelin/defender-deploy-client-cli/-/defender-deploy-client-cli-0.0.1-alpha.4.tgz#b45be069a5ac9625b54be3f9035b5b81d896a9e7"
integrity sha512-1NagEny1oMazIEpHUxyLzfDBAYPFOJ6XGwGtVv/aLfus0imeLShbVQu4ibGANY3xNLUxJ2/jPzBif9FZiUKNsw==
dependencies:
"@openzeppelin/defender-sdk-base-client" "^1.9.0"
"@openzeppelin/defender-sdk-deploy-client" "^1.9.0"
"@openzeppelin/[email protected]":
version "0.0.1-alpha.5"
resolved "https://registry.yarnpkg.com/@openzeppelin/defender-deploy-client-cli/-/defender-deploy-client-cli-0.0.1-alpha.5.tgz#088643b9574c6ede1fab538b52c772bfe6cc7465"
integrity sha512-Ict4BAiV6Xa6MjGaXFoHYif+LG9MqZ4IihDkKswbceoxAx1QosMA36tRV4CV/24ZLt2FZKH7QJjZtWhjVX7CZQ==
dependencies:
"@openzeppelin/defender-sdk-base-client" "^1.10.0"
"@openzeppelin/defender-sdk-deploy-client" "^1.10.0"
"@openzeppelin/defender-sdk-network-client" "^1.10.0"
dotenv "^16.3.1"
minimist "^1.2.8"

"@openzeppelin/defender-sdk-base-client@^1.9.0":
version "1.9.0"
resolved "https://registry.yarnpkg.com/@openzeppelin/defender-sdk-base-client/-/defender-sdk-base-client-1.9.0.tgz#2596ab12edc44236290720cd4a89cedbc480b3c0"
integrity sha512-ywxZslKaY7Z5z9APpBunIDp4nXkGnYZAStaIhzzh8vbbzu7lxiZO98tsX3B9vCefqWC4oyX0mm78CdyYUgW5KQ==
"@openzeppelin/defender-sdk-base-client@^1.10.0":
version "1.10.0"
resolved "https://registry.yarnpkg.com/@openzeppelin/defender-sdk-base-client/-/defender-sdk-base-client-1.10.0.tgz#038a5b13f92e03de42382ec331b670f40a915816"
integrity sha512-V21oI4G54sdEJ9lVN8q5OqfFRUoVDzjeXfWgpQvUpfy69r56NnE57D6e5RLG1fRp1J0APfW3lFjaaLwl0kqZpg==
dependencies:
amazon-cognito-identity-js "^6.3.6"
async-retry "^1.3.3"

"@openzeppelin/defender-sdk-deploy-client@^1.9.0":
version "1.9.0"
resolved "https://registry.yarnpkg.com/@openzeppelin/defender-sdk-deploy-client/-/defender-sdk-deploy-client-1.9.0.tgz#ad2f61912f066386a22221bdcbd73d52b91e4c74"
integrity sha512-xw3qRJzE3XQRBoBBqOC7VOEtaVnzeN9EgsBZSjWlDUcmfJ6jdUuUsoqEkwYBZVEi+Dr3ujURY2DsmEvs0gFoNw==
"@openzeppelin/defender-sdk-deploy-client@^1.10.0":
version "1.10.0"
resolved "https://registry.yarnpkg.com/@openzeppelin/defender-sdk-deploy-client/-/defender-sdk-deploy-client-1.10.0.tgz#64d7789eceede36ec12dcdae0dc4b67ffa7ae97d"
integrity sha512-PckmUQYwe26/u/s3sjLateSNtKQ0tdAaOyP6spsgaT+us+XUUqAt/EUfEJdGpt8JApsRWYzrQzH6Z0ywoUyqyw==
dependencies:
"@ethersproject/abi" "^5.7.0"
"@openzeppelin/defender-sdk-base-client" "^1.10.0"
axios "^1.6.7"
lodash "^4.17.21"

"@openzeppelin/defender-sdk-network-client@^1.10.0":
version "1.10.0"
resolved "https://registry.yarnpkg.com/@openzeppelin/defender-sdk-network-client/-/defender-sdk-network-client-1.10.0.tgz#0da6113d994f1b48a4cee4313e1befc31acab800"
integrity sha512-nrSuJ4KKhTIO2f1WIKtCq0XbeHb4ExqvpIE2g4yf/k8DmZuM9SR6xNDLz7wuKt11u+U88AYBN9MoiKRo/ybp6w==
dependencies:
"@ethersproject/abi" "^5.7.0"
"@openzeppelin/defender-sdk-base-client" "^1.9.0"
axios "^1.4.0"
"@openzeppelin/defender-sdk-base-client" "^1.10.0"
axios "^1.6.7"
lodash "^4.17.21"

"@openzeppelin/upgrades-core@^1.32.3":
Expand Down Expand Up @@ -790,7 +801,7 @@ available-typed-arrays@^1.0.5:
resolved "https://registry.yarnpkg.com/available-typed-arrays/-/available-typed-arrays-1.0.5.tgz#92f95616501069d07d10edb2fc37d3e1c65123b7"
integrity sha512-DMD0KiN46eipeziST1LPP/STfDU0sufISXmjSgvVsoU2tqxctQeASejWcfNtxYKqETM1UxQ8sp2OrSBWpHY6sw==

axios@^1.4.0:
axios@^1.6.7:
version "1.6.7"
resolved "https://registry.yarnpkg.com/axios/-/axios-1.6.7.tgz#7b48c2e27c96f9c68a2f8f31e2ab19f59b06b0a7"
integrity sha512-/hDJGff6/c7u0hDkvkGxR/oy6CbCs8ziCsC7SqmhjfozqiJGc8Z11wrv9z9lYfY4K8l+H9TpjcMDX0xOZmx+RA==
Expand Down

0 comments on commit c50a796

Please sign in to comment.