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

Migrate from Buidler to Hardhat except docs #214

Merged
merged 23 commits into from
Nov 12, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ module.exports = {
extends: ['eslint:recommended', 'plugin:@typescript-eslint/recommended'],
},
{
files: ['buidler.config.js'],
files: ['hardhat.config.js'],
globals: {
usePlugin: 'readonly',
},
martriay marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
matrix:
package:
- core
- plugin-buidler
- plugin-hardhat
- plugin-truffle

runs-on: ubuntu-latest
Expand Down
2 changes: 1 addition & 1 deletion bundle-pack.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ yarn prepare

mv packages/core/node_modules core-node_modules

for t in buidler truffle; do
for t in hardhat truffle; do
mkdir -p "packages/plugin-$t/node_modules/@openzeppelin"
ln -srf packages/core "packages/plugin-$t/node_modules/@openzeppelin/upgrades-core"
cd "packages/plugin-$t"
Expand Down
File renamed without changes.
8 changes: 4 additions & 4 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,13 @@
"scripts": {
"prepublish": "rimraf artifacts cache dist *.tsbuildinfo",
"prepare": "tsc -b && yarn prepare:contracts",
"prepare:contracts": "buidler compile",
"test": "tsc -b && buidler compile --force && ava",
"test:watch": "buidler compile --force && fgbg 'ava --watch' 'tsc -b --watch'",
"prepare:contracts": "hardhat compile",
"test": "tsc -b && hardhat compile --force && ava",
"test:watch": "hardhat compile --force && fgbg 'ava --watch' 'tsc -b --watch'",
"version": "node ../../scripts/bump-changelog.js"
},
"devDependencies": {
"@ava/typescript": "^1.1.1",
"@nomiclabs/buidler": "^1.3.6",
"@openzeppelin/contracts": "^3.1.0",
"@types/bn.js": "^4.11.6",
"@types/cbor": "^5.0.0",
Expand All @@ -33,6 +32,7 @@
"@types/rimraf": "^3.0.0",
"ava": "^3.9.0",
"fgbg": "^0.1.4",
"hardhat": "^2.0.2",
"rimraf": "^3.0.2",
"typescript": "^4.0.0"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/deployment.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ test('errors if tx is not found', async t => {
});

test('redeploys if tx is not found on dev network', async t => {
const provider = stubProvider(31337); // Buidler EVM chainId
const provider = stubProvider(31337); // Hardhat Network chainId
const fakeDeployment: Deployment = {
address: '0x1aec6468218510f19bb19f52c4767996895ce711',
txHash: '0xc48e21ac9c051922f5ccf1b47b62000f567ef9bbc108d274848b44351a6872cb',
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,6 @@ export const networkNames: { [chainId in number]?: string } = Object.freeze({
export async function isDevelopmentNetwork(provider: EthereumProvider): Promise<boolean> {
const chainId = await getChainId(provider);
// 1337 => ganache and geth --dev
// 31337 => buidler evm
// 31337 => hardhat network
return chainId === 1337 || chainId === 31337;
}
2 changes: 1 addition & 1 deletion packages/core/src/scripts/migrate-oz-cli-project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ function getNetworkName(filename: string): string {

function isDevelopmentNetwork(network: string): boolean {
// 13+ digits => ganache timestamp
// 31337 => buidler evm
// 31337 => hardhat network
return /^dev-(31337|\d{13,})$/.test(network);
}

Expand Down
26 changes: 0 additions & 26 deletions packages/plugin-buidler/src/validations.ts

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,39 +1,24 @@
# OpenZeppelin Buidler Upgrades
# OpenZeppelin Hardhat Upgrades

[![Docs](https://img.shields.io/badge/docs-%F0%9F%93%84-blue)](https://docs.openzeppelin.com/upgrades-plugins/buidler-upgrades)
[![NPM Package](https://img.shields.io/npm/v/@openzeppelin/buidler-upgrades.svg)](https://www.npmjs.org/package/@openzeppelin/buidler-upgrades)
[![Docs](https://img.shields.io/badge/docs-%F0%9F%93%84-blue)](https://docs.openzeppelin.com/upgrades-plugins/hardhat-upgrades)
[![NPM Package](https://img.shields.io/npm/v/@openzeppelin/hardhat-upgrades.svg)](https://www.npmjs.org/package/@openzeppelin/hardhat-upgrades)

**Buidler plugin for deploying and managing upgradeable contracts.** This package adds functions to your Buidler scripts so you can deploy and upgrade proxies for your contracts. Depends on `ethers.js`.
**Hardhat plugin for deploying and managing upgradeable contracts.** This package adds functions to your Hardhat scripts so you can deploy and upgrade proxies for your contracts. Depends on `ethers.js`.

## Installation

```
npm install --save-dev @openzeppelin/buidler-upgrades
npm install --save-dev @nomiclabs/buidler-ethers ethers # peer dependencies
```

And register the plugins in your [`buidler.config.js`](https://buidler.dev/config/):

```js
usePlugin('@nomiclabs/buidler-ethers');
usePlugin('@openzeppelin/buidler-upgrades');
```
martriay marked this conversation as resolved.
Show resolved Hide resolved

If you're using TypeScript, remember to add our [type extensions](https://buidler.dev/guides/typescript.html#plugin-type-extensions) in your `tsconfig.json`:

```json
"files": [
"./node_modules/@openzeppelin/buidler-upgrades/src/type-extensions.d.ts"
]
npm install --save-dev @openzeppelin/hardhat-upgrades
npm install --save-dev @nomiclabs/hardhat-ethers ethers # peer dependencies
```

## Usage in scripts

You can use this plugin in a [Buidler script](https://buidler.dev/guides/scripts.html) to deploy an upgradeable instance of one of your contracts via the `deployProxy` function:
You can use this plugin in a [Hardhat script](https://hardhat.org/guides/scripts.html) to deploy an upgradeable instance of one of your contracts via the `deployProxy` function:

```js
// scripts/create-box.js
const { ethers, upgrades } = require("@nomiclabs/buidler");
const { ethers, upgrades } = require("@nomiclabs/hardhat");
martriay marked this conversation as resolved.
Show resolved Hide resolved

async function main() {
const Box = await ethers.getContractFactory("Box");
Expand All @@ -51,7 +36,7 @@ Then, in another script, you can use the `upgradeProxy` function to upgrade the

```js
// scripts/upgrade-box.js
const { ethers, upgrades } = require("@nomiclabs/buidler");
const { ethers, upgrades } = require("@nomiclabs/hardhat");
martriay marked this conversation as resolved.
Show resolved Hide resolved

async function main() {
const BoxV2 = await ethers.getContractFactory("BoxV2");
Expand All @@ -68,7 +53,7 @@ The plugin will take care of comparing `BoxV2` to the previous one to ensure the

## Usage in tests

You can also use the `deployProxy` and `upgradeProxy` functions from your Buidler tests, in case you want to add tests for upgrading your contracts (which you should!). The API is the same as in scripts.
You can also use the `deployProxy` and `upgradeProxy` functions from your Hardhat tests, in case you want to add tests for upgrading your contracts (which you should!). The API is the same as in scripts.

```js
const { expect } = require("chai");
Expand All @@ -88,5 +73,5 @@ describe("Box", function() {
```

## Learn more
* Refer to the [API documentation](https://docs.openzeppelin.com/upgrades-plugins/api-buidler-upgrades).
* Refer to the [API documentation](https://docs.openzeppelin.com/upgrades-plugins/api-hardhat-upgrades).
* Also see the [main documentation](https://docs.openzeppelin.com/upgrades-plugins) for more info.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
pragma solidity ^0.5.1;

import "@nomiclabs/buidler/console.sol";
import "hardhat/console.sol";

contract Adder {
uint n;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
pragma solidity ^0.5.1;

import "@nomiclabs/buidler/console.sol";
import "hardhat/console.sol";

library SafeAdd {
function add(uint256 a, uint256 b) internal pure returns (uint256) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@

pragma solidity ^0.5.1;

import "@nomiclabs/buidler/console.sol";
import "hardhat/console.sol";

library SafeMath {
function add(uint256 a, uint256 b) external pure returns (uint256) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
pragma solidity ^0.5.1;

import "@nomiclabs/buidler/console.sol";
import "hardhat/console.sol";

contract Invalid {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
pragma solidity ^0.5.1;

import "@nomiclabs/buidler/console.sol";
import "hardhat/console.sol";

contract GreeterStorageConflict {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
pragma solidity ^0.5.1;

import "@nomiclabs/buidler/console.sol";
import "hardhat/console.sol";

contract Portfolio {
struct Asset {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
pragma solidity ^0.5.1;

import "@nomiclabs/buidler/console.sol";
import "hardhat/console.sol";

contract PortfolioV2 {
struct Asset {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
pragma solidity ^0.5.1;

import "@nomiclabs/buidler/console.sol";
import "hardhat/console.sol";
import "./ExternalLibraries.sol";

contract Token {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
pragma solidity ^0.5.1;

import "@nomiclabs/buidler/console.sol";
import "hardhat/console.sol";
import "./Token.sol";

contract TokenV2 is Token {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
usePlugin('@nomiclabs/buidler-ethers');
usePlugin('@openzeppelin/buidler-upgrades');
require('@nomiclabs/buidler-ethers');
require('@openzeppelin/buidler-upgrades');

// You have to export an object to set up your config
// This object can have the following optional entries:
// defaultNetwork, networks, solc, and paths.
// Go to https://buidler.dev/config/ to learn more
module.exports = {
// This is a sample solc configuration that specifies which version of solc to use
solc: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"name": "@openzeppelin/buidler-upgrades",
"name": "@openzeppelin/hardhat-upgrades",
"version": "1.2.1",
"description": "",
"repository": "https://github.com/OpenZeppelin/openzeppelin-upgrades/tree/master/packages/plugin-buidler",
"repository": "https://github.com/OpenZeppelin/openzeppelin-upgrades/tree/master/packages/plugin-hardhat",
"license": "MIT",
"main": "dist/index.js",
"files": [
Expand All @@ -20,20 +20,20 @@
"version": "node ../../scripts/bump-changelog.js"
},
"devDependencies": {
"@nomiclabs/buidler": "^1.3.7",
"@nomiclabs/buidler-ethers": "^2.0.0",
"@nomiclabs/hardhat-ethers": "^2.0.0",
"@types/mocha": "^7.0.2",
"ava": "^3.9.0",
"ethers": "^5.0.5",
"fgbg": "^0.1.4",
"hardhat": "^2.0.2",
"promisified": "^0.5.0",
"rimraf": "^3.0.2"
},
"dependencies": {
"@openzeppelin/upgrades-core": "^1.2.0"
},
"peerDependencies": {
"@nomiclabs/buidler": "^1.3.7",
"@nomiclabs/buidler-ethers": "^2.0.0"
"@nomiclabs/hardhat-ethers": "^2.0.0",
"hardhat": "^2.0.2"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
set -euo pipefail

rimraf .openzeppelin
buidler compile
hardhat compile
ava "$@"
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import type { BuidlerRuntimeEnvironment } from '@nomiclabs/buidler/types';
import type { HardhatRuntimeEnvironment } from 'hardhat/types';
import { Manifest, getAdminAddress } from '@openzeppelin/upgrades-core';
import { Contract } from 'ethers';
import { getProxyAdminFactory } from './proxy-factory';

type ChangeAdminFunction = (proxyAddress: string, newAdmin: string) => Promise<void>;
type TransferProxyAdminOwnershipFunction = (newOwner: string) => Promise<void>;

export function makeChangeProxyAdmin(bre: BuidlerRuntimeEnvironment): ChangeAdminFunction {
export function makeChangeProxyAdmin(hre: HardhatRuntimeEnvironment): ChangeAdminFunction {
return async function changeProxyAdmin(proxyAddress, newAdmin) {
const admin = await getManifestAdmin(bre);
const proxyAdminAddress = await getAdminAddress(bre.network.provider, proxyAddress);
const admin = await getManifestAdmin(hre);
const proxyAdminAddress = await getAdminAddress(hre.network.provider, proxyAddress);

if (admin.address !== proxyAdminAddress) {
throw new Error('Proxy admin is not the one registered in the network manifest');
Expand All @@ -19,22 +19,22 @@ export function makeChangeProxyAdmin(bre: BuidlerRuntimeEnvironment): ChangeAdmi
};
}

export function makeTransferProxyAdminOwnership(bre: BuidlerRuntimeEnvironment): TransferProxyAdminOwnershipFunction {
export function makeTransferProxyAdminOwnership(hre: HardhatRuntimeEnvironment): TransferProxyAdminOwnershipFunction {
return async function transferProxyAdminOwnership(newOwner) {
const admin = await getManifestAdmin(bre);
const admin = await getManifestAdmin(hre);
await admin.transferOwnership(newOwner);
};
}

export async function getManifestAdmin(bre: BuidlerRuntimeEnvironment): Promise<Contract> {
const manifest = await Manifest.forNetwork(bre.network.provider);
export async function getManifestAdmin(hre: HardhatRuntimeEnvironment): Promise<Contract> {
const manifest = await Manifest.forNetwork(hre.network.provider);
const manifestAdmin = await manifest.getAdmin();
const proxyAdminAddress = manifestAdmin?.address;

if (proxyAdminAddress === undefined) {
throw new Error('No ProxyAdmin was found in the network manifest');
}

const AdminFactory = await getProxyAdminFactory(bre);
const AdminFactory = await getProxyAdminFactory(hre);
return AdminFactory.attach(proxyAdminAddress);
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { BuidlerRuntimeEnvironment } from '@nomiclabs/buidler/types';
import type { HardhatRuntimeEnvironment } from 'hardhat/types';
import type { ContractFactory, Contract } from 'ethers';

import {
Expand All @@ -25,10 +25,10 @@ export interface DeployOptions extends ValidationOptions {
initializer?: string | false;
}

export function makeDeployProxy(bre: BuidlerRuntimeEnvironment): DeployFunction {
export function makeDeployProxy(hre: HardhatRuntimeEnvironment): DeployFunction {
return async function deployProxy(ImplFactory, args = [], opts = {}) {
const { provider } = bre.network;
const validations = await readValidations(bre);
const { provider } = hre.network;
const validations = await readValidations(hre);

const unlinkedBytecode: string = getUnlinkedBytecode(validations, ImplFactory.bytecode);
const version = getVersion(unlinkedBytecode, ImplFactory.bytecode);
Expand All @@ -40,11 +40,11 @@ export function makeDeployProxy(bre: BuidlerRuntimeEnvironment): DeployFunction
return { ...deployment, layout };
});

const AdminFactory = await getProxyAdminFactory(bre, ImplFactory.signer);
const AdminFactory = await getProxyAdminFactory(hre, ImplFactory.signer);
const adminAddress = await fetchOrDeployAdmin(provider, () => deploy(AdminFactory));

const data = getInitializerData(ImplFactory, args, opts.initializer);
const ProxyFactory = await getProxyFactory(bre, ImplFactory.signer);
const ProxyFactory = await getProxyFactory(hre, ImplFactory.signer);
const proxy = await ProxyFactory.deploy(impl, adminAddress, data);

const inst = ImplFactory.attach(proxy.address);
Expand Down
Loading