Skip to content

Commit

Permalink
feat(hardhat-plugin): remove needs for fs-extra
Browse files Browse the repository at this point in the history
  • Loading branch information
clemsos committed Apr 23, 2024
1 parent 16ea998 commit bf3ebe1
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 40 deletions.
8 changes: 3 additions & 5 deletions packages/hardhat-plugin/package.json
Expand Up @@ -19,11 +19,10 @@
"lint": "eslint --resolve-plugins-relative-to ../eslint-config --ext .tsx,.ts,.js src/ test/",
"test": "ts-mocha --exit --recursive 'test/**/*.ts'",
"ci": "yarn build && yarn lint && yarn test",
"build": "yarn networks && tsc",
"build": "tsc",
"watch": "tsc -w",
"clean": "rm -rf dist test/fixture-projects/hardhat-project/.openzeppelin test/fixture-projects/hardhat-project/artifacts test/fixture-projects/hardhat-project/cache test/fixture-projects/hardhat-project/contracts",
"prepublishOnly": "yarn clean && yarn build",
"networks": "node scripts/parseNetworks.js"
"prepublishOnly": "yarn clean && yarn build"
},
"files": [
"dist/src/**/*",
Expand All @@ -36,8 +35,7 @@
"directory": "packages/hardhat-plugin"
},
"devDependencies": {
"@types/chai": "4.3.14",
"@types/fs-extra": "11.0.4",
"@types/chai": "4.3.12",
"@types/mocha": "10.0.6",
"@types/node": "20.10.1",
"@unlock-protocol/contracts": "workspace:^",
Expand Down
18 changes: 0 additions & 18 deletions packages/hardhat-plugin/scripts/parseNetworks.js

This file was deleted.

11 changes: 10 additions & 1 deletion packages/hardhat-plugin/src/index.ts
Expand Up @@ -8,7 +8,7 @@ import './type-extensions'
import { TASK_CREATE_LOCK } from './constants'

import { deployLockTask } from './tasks'
import networks from './networks.json'
import { networks as defaultNetworks } from '@unlock-protocol/networks'

// types
import { UnlockNetworkConfigs } from './types'
Expand All @@ -31,6 +31,15 @@ export interface HardhatUnlockPlugin {
networks: UnlockNetworkConfigs
}

// parse networks to remove providers
const networks = Object.keys(defaultNetworks).reduce((parsed, chainId) => {
const { publicProvider, provider, ...network } = defaultNetworks[chainId]
return {
...parsed,
[chainId]: network,
}
}, {})

extendEnvironment((hre) => {
hre.unlock = lazyObject(() => {
const { createLock } = require('./createLock')
Expand Down
10 changes: 4 additions & 6 deletions packages/hardhat-plugin/src/utils.ts
@@ -1,9 +1,10 @@
import { contracts } from '@unlock-protocol/contracts'
import { HardhatRuntimeEnvironment } from 'hardhat/types'
import type { Signer, Contract, ContractFactory } from 'ethers'

import fs from 'fs-extra'
import path from 'path'
import {
bytecode as proxyBytecode,
abi as proxyAbi,
} from './abis/ERC1967Proxy.json'

export const contractExists = (contractName: string, versionNumber: number) => {
// make sure contract exists
Expand Down Expand Up @@ -58,9 +59,6 @@ export async function deployUpgreadableContract(
const data = impl.interface.encodeFunctionData(fragment, initializerArguments)

// deploy proxy
const { bytecode: proxyBytecode, abi: proxyAbi } = await fs.readJSON(
path.join(__dirname, 'abis', 'ERC1967Proxy.json')
)
const ERC1967Proxy = await hre.ethers.getContractFactory(
proxyAbi,
proxyBytecode,
Expand Down
Expand Up @@ -17,8 +17,9 @@ const config: HardhatUserConfig = {
},
defaultNetwork: 'hardhat',
unlock: {
31337: {
name: 'Custom Localhost Name',
// extend an existing network
100: {
name: 'Custom Polygon Name',
subgraph: {
endpoint: 'here goes a subgraph URI',
},
Expand Down
14 changes: 6 additions & 8 deletions packages/hardhat-plugin/test/index.test.ts
Expand Up @@ -41,13 +41,11 @@ describe('Unlock Hardhat plugin', function () {
assert.equal(this.hre.unlock.networks['1'].unlockAddress, 'newAddress')
})
it('should store additional networks info', function () {
assert.isTrue(Object.keys(this.hre.unlock.networks).includes('31337'))
assert.isTrue(Object.keys(this.hre.unlock.networks).includes('100'))
assert.isTrue(Object.keys(this.hre.unlock.networks).includes('12345'))
assert.equal(this.hre.unlock.networks['100'].name, 'Custom Polygon Name')
assert.equal(
this.hre.unlock.networks['31337'].name,
'Custom Localhost Name'
)
assert.equal(
this.hre.unlock.networks['31337'].subgraph?.endpoint,
this.hre.unlock.networks['100'].subgraph?.endpoint,
'here goes a subgraph URI'
)
})
Expand Down Expand Up @@ -218,12 +216,12 @@ describe('HardhatConfig unlock extension', function () {
assert.isTrue(Object.keys(this.hre.config).includes('unlock'))
assert.deepEqual(
Object.keys(this.hre.config.unlock).sort(),
[...Object.keys(networks), '12345', '31337'].sort()
[...Object.keys(networks), '12345'].sort()
)
})

it('Should allow user to configure exsiting network', function () {
assert.equal(this.hre.config.unlock['31337'].name, 'Custom Localhost Name')
assert.equal(this.hre.config.unlock['100'].name, 'Custom Polygon Name')
})

it('Should allow user to pass a new network', function () {
Expand Down

0 comments on commit bf3ebe1

Please sign in to comment.