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

fix(governance,networks): remove localhost from networks (again) #13321

Merged
merged 28 commits into from Mar 20, 2024
Merged
Show file tree
Hide file tree
Changes from 25 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
e9ca71e
remove localhost from networks package
clemsos Feb 5, 2024
20452b2
remove localhost from keys in helpers
clemsos Feb 5, 2024
97f97d4
fix localhost network
clemsos Feb 6, 2024
1de9ea0
trigger ci
clemsos Feb 6, 2024
390253c
fix hardhat plugin tests
clemsos Feb 12, 2024
81a826a
add script to create localhost file
clemsos Mar 18, 2024
0637571
generate localhost in integration tests
clemsos Mar 18, 2024
274beb9
mock localhost network file in locksmith tests
clemsos Mar 18, 2024
3dbec2c
Merge branch 'master' into remove-localhost-fix
clemsos Mar 18, 2024
c5d7b55
fix export in test
clemsos Mar 19, 2024
d99b561
Merge branch 'remove-localhost-fix' of github.com:unlock-protocol/unl…
clemsos Mar 19, 2024
96f8dd4
Merge branch 'master' into remove-localhost-fix
clemsos Mar 19, 2024
2218112
use latest versions of contracts
clemsos Mar 20, 2024
868e12b
Merge branch 'master' into remove-localhost-fix
clemsos Mar 20, 2024
afbcaf3
take address as param
clemsos Mar 20, 2024
21e5a49
fix yarn lock
clemsos Mar 20, 2024
98d35b3
readme info
clemsos Mar 20, 2024
9cac0c0
ignore localhost file
clemsos Mar 20, 2024
fea6343
pass unlock address via CLI
clemsos Mar 20, 2024
6a299f7
actually add localhost to networks in integration tests
clemsos Mar 20, 2024
2843e70
actually use the localhost network file in integration tests
clemsos Mar 20, 2024
5bfebbe
remove localhost from index
clemsos Mar 20, 2024
3868027
fix integration tests command
clemsos Mar 20, 2024
108e806
remove unwanted lines
clemsos Mar 20, 2024
d210809
remove use of jq
clemsos Mar 20, 2024
4437330
remove console log
clemsos Mar 20, 2024
bcd2c4c
Update package.json
clemsos Mar 20, 2024
0031f64
pass docker graph url
clemsos Mar 20, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 6 additions & 4 deletions governance/scripts/deployments/index.js
Expand Up @@ -2,7 +2,11 @@
const { ethers, run, upgrades, network } = require('hardhat')
const { networks } = require('@unlock-protocol/networks')
const createLock = require('../lock/create')
const { getUnlock, ADDRESS_ZERO } = require('@unlock-protocol/hardhat-helpers')
const {
getUnlock,
ADDRESS_ZERO,
getNetwork,
} = require('@unlock-protocol/hardhat-helpers')

const log = (...message) => {
// eslint-disable-next-line no-console
Expand All @@ -26,8 +30,7 @@ async function main({
const [deployer, minter] = await ethers.getSigners()

// fetch chain info
const { chainId } = await ethers.provider.getNetwork()
const networkName = networks[chainId].name
const { id: chainId, name: networkName, multisig } = await getNetwork()
const isLocalNet = networkName === 'localhost'
log(
`Deploying contracts on ${networkName} with the account: ${deployer.address}`
Expand Down Expand Up @@ -107,7 +110,6 @@ async function main({
}

// Transfer ownership of Unlock + Proxy admin
const multisig = networks[chainId.toString()].multisig
if (!owner && multisig) {
owner = multisig
if (owner) {
Expand Down
39 changes: 15 additions & 24 deletions governance/tasks/deploy.js
Expand Up @@ -34,30 +34,21 @@ task('deploy', 'Deploy the entire Unlock protocol')
)
.addFlag('setTemplate', 'set the PublicLock instance in Unlock')
.setAction(
async (
{
unlockAddress,
unlockVersion,
publicLockVersion,
udtAddress,
publicLockAddress,
wethAddress,
oracleAddress,
premintAmount,
liquidity,
setTemplate,
estimatedGasForPurchase,
locksmithURI,
owner,
},
{ ethers }
) => {
const { chainId } = await ethers.provider.getNetwork()
const networkName = networks[chainId].name

// eslint-disable-next-line no-console
console.log(`Starting deployments on ${networkName}...`)

async ({
unlockAddress,
unlockVersion,
publicLockVersion,
udtAddress,
publicLockAddress,
wethAddress,
oracleAddress,
premintAmount,
liquidity,
setTemplate,
estimatedGasForPurchase,
locksmithURI,
owner,
}) => {
// eslint-disable-next-line global-require
const mainDeployer = require('../scripts/deployments')
const {
Expand Down
9 changes: 9 additions & 0 deletions locksmith/__tests__/fulfillment/dispatcher.test.ts
Expand Up @@ -62,6 +62,15 @@ vi.mock('@unlock-protocol/unlock-js', () => ({
},
}))

vi.mock('@unlock-protocol/networks', () => ({
default: {
31337: {
provider: 'http://127.0.0.1:8545',
publicProvider: 'http://127.0.0.1:8545',
},
},
}))

vi.mock('../../src/utils/gasSettings', () => ({
getGasSettings: vi.fn(() => {
return {
Expand Down
2 changes: 1 addition & 1 deletion packages/hardhat-helpers/src/networks.js
Expand Up @@ -50,7 +50,7 @@ const hardhatNetworks = {
}

Object.keys(networks).forEach((key) => {
if (['default', 'networks', 'localhost'].indexOf(key) === -1) {
if (['default', 'networks'].indexOf(key) === -1) {
hardhatNetworks[key] = {
chainId: networks[key].id,
name: networks[key].name,
Expand Down
2 changes: 1 addition & 1 deletion packages/hardhat-helpers/src/unlock.js
Expand Up @@ -30,7 +30,7 @@ export const getNetwork = async (chainId) => {
if (!chainId) {
;({ chainId } = await ethers.provider.getNetwork())
}
return networks[chainId]
return networks[chainId] || { name: 'localhost', id: chainId }
}

export default {
Expand Down
Expand Up @@ -23,6 +23,9 @@ const config: HardhatUserConfig = {
endpoint: 'here goes a subgraph URI',
},
},
1: {
unlockAddress: 'newAddress',
},
12345: {
name: 'New Network',
id: 12345,
Expand Down
11 changes: 8 additions & 3 deletions packages/hardhat-plugin/test/index.test.ts
Expand Up @@ -34,13 +34,18 @@ describe('Unlock Hardhat plugin', function () {
assert.instanceOf(this.hre.unlock, Object)
})

it('should store networks info', function () {
it('should store and extend existing networks info', function () {
assert.isTrue(Object.keys(this.hre.unlock.networks).includes('1'))
assert.equal(this.hre.unlock.networks['1'].name, networks['1'].name)
assert.equal(this.hre.unlock.networks['1'].id, networks['1'].id)
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.equal(
this.hre.unlock.networks['31337'].name,
'Custom Localhost Name'
)
assert.equal(this.hre.unlock.networks['31337'].id, networks['31337'].id)
assert.equal(
this.hre.unlock.networks['31337'].subgraph?.endpoint,
'here goes a subgraph URI'
Expand Down Expand Up @@ -213,7 +218,7 @@ 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'].sort()
[...Object.keys(networks), '12345', '31337'].sort()
)
})

Expand Down
3 changes: 2 additions & 1 deletion packages/networks/.gitignore
@@ -1,2 +1,3 @@
dist
build
build
src/networks/localhost.ts
33 changes: 33 additions & 0 deletions packages/networks/README.md
Expand Up @@ -19,6 +19,39 @@ console.log(networks[1].name) // mainnet
yarn start
```

## Localhost

You can create a `localhost` network file with the following command:

```sh
# create file
yarn create-localhost <unlockAddress> <subgraphEnpoint>

# export file by appending to network index
echo "export * from './localhost'" >> src/networks/index.ts

# rebuild
yarn build
```

#### Read Unlock Address from a file

Optionally, you can parse the Unlock address from a subgraph manifest file formatted as follow

```json
{
"localhost": {
"Unlock": { "address": "0x2279B7A0a67DB372996a5FaB50D91eAA73d2eBe6" }
}
}
```

with the following command

```sh
yarn workspace @unlock-protocol/networks unlock-address <filepath>.json
```

## Scripts

- Check that networks are configured correctly: `yarn run check`. Some networks might be missing some properties.
Expand Down
73 changes: 73 additions & 0 deletions packages/networks/bin/localhost.js
@@ -0,0 +1,73 @@
import fs from 'fs-extra'
Copy link
Member

Choose a reason for hiding this comment

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

Can you add a quick note in the README how the localhost network is different from he other ones?

Copy link
Member Author

Choose a reason for hiding this comment

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

yep added

import path from 'path'

// We use Partial<NetworkConfig> for localhost as we don't have all the information
const defaultLocalhost = {
chain: 'localhost',
description: 'Localhost network.',
featured: false,
fullySubsidizedGas: true,
id: 31337,
isTestNetwork: true,
name: 'Localhost',
nativeCurrency: {
coingecko: 'ethereum',
decimals: 18,
name: 'ETH',
symbol: 'ETH',
},
provider: 'http://127.0.0.1:8545',
publicLockVersionToDeploy: 13,
publicProvider: 'http://127.0.0.1:8545',
subgraph: {
endpoint: '',
},
}

const generateLocalhostNetworkFile = ({
unlockAddress,
subgraphEnpoint = 'http://localhost:8000/subgraphs/name/testgraph',
}) => {
const localhost = {
...defaultLocalhost,
subgraph: {
endpoint: subgraphEnpoint,
},
unlockAddress,
}

// log for debug purposes on CI
console.log(localhost)
Copy link
Member

Choose a reason for hiding this comment

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

Do you wnat to keep that?

Copy link
Member Author

Choose a reason for hiding this comment

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

yes lets keep that one so we have it to debug on CI


// output to js file
const parsed = `import { NetworkConfig } from '@unlock-protocol/types'

// We use Partial<NetworkConfig> for localhost as we don't have all the information
export const localhost: Partial<NetworkConfig> = ${JSON.stringify(localhost)}
export default localhost
`
return parsed
}

const run = async () => {
const [unlockAddress, subgraphEnpoint] = process.argv.slice(2)
console.log(`Creating localhost file for unlockAddress ${unlockAddress}`)

if (!unlockAddress) {
throw new Error('Missing unlockAddress arg')
}

const fileContent = generateLocalhostNetworkFile({
subgraphEnpoint,
unlockAddress,
})

const filePath = path.resolve('./src/networks/localhost.ts')

await fs.writeFile(filePath, fileContent)
}
run()
.then(() => console.log('done'))
.catch((err) => {
throw err
})
20 changes: 20 additions & 0 deletions packages/networks/bin/readSubgraphInfo.js
@@ -0,0 +1,20 @@
import fs from 'fs-extra'

// this is used to read a network
const run = async () => {
const [networkInfoPath] = process.argv.slice(2)
const networkInfo = await fs.readJSON(networkInfoPath)
const {
localhost: {
Unlock: { address: unlockAddress },
},
} = networkInfo
console.log(networkInfo)
clemsos marked this conversation as resolved.
Show resolved Hide resolved
return unlockAddress
}

run()
.then((unlockAddress) => console.log(unlockAddress))
.catch((err) => {
throw err
})
3 changes: 3 additions & 0 deletions packages/networks/package.json
Expand Up @@ -18,6 +18,8 @@
"build": "tsup src/index.ts --dts --format esm,cjs",
"check-tokens": "tsx ./bin/check-tokens",
"clean": "rm -rf ./dist",
"create-localhost": "tsx ./bin/localhost",
"unlock-address": "tsx ./bin/readSubgraphInfo",
"check": "tsx ./bin/keys",
"prepublish": "yarn build",
"doc": "node ./bin/doc.js",
Expand All @@ -32,6 +34,7 @@
"@unlock-protocol/tsconfig": "workspace:^",
"@unlock-protocol/types": "workspace:^",
"eslint": "8.54.0",
"fs-extra": "11.2.0",
"tsup": "8.0.2",
"typescript": "5.3.3"
},
Expand Down
1 change: 0 additions & 1 deletion packages/networks/src/networks/index.ts
@@ -1,4 +1,3 @@
export * from './localhost'
export * from './mainnet'
export * from './gnosis'
export * from './polygon'
Expand Down
24 changes: 0 additions & 24 deletions packages/networks/src/networks/localhost.ts

This file was deleted.

16 changes: 13 additions & 3 deletions scripts/integration-tests.sh
Expand Up @@ -3,11 +3,21 @@ set -e

# First this script will deploy
REPO_ROOT=`dirname "$0"`/..
INTEGRATION_TESTS_FOLDER=$REPO_ROOT/tests
EXTRA_ARGS=$*

# fetch compose config paths
BASE_DOCKER_FOLDER=$REPO_ROOT/docker
BASE_DOCKER_COMPOSE=$BASE_DOCKER_FOLDER/docker-compose.yml
DOCKER_COMPOSE_FILE=$BASE_DOCKER_FOLDER/docker-compose.integration.yml
COMPOSE_CONFIG="-f $BASE_DOCKER_COMPOSE -f $DOCKER_COMPOSE_FILE"

# run Unlock Protocol stack
sh -c "$REPO_ROOT/scripts/run-stack-dockerized.sh"

# Setting the right env var
export UNLOCK_ENV=test

# run the actual tests
sh $INTEGRATION_TESTS_FOLDER/bin/tests.sh
echo "Running integration tests \n"
COMMAND="yarn workspace tests ci --network docker"
docker-compose $COMPOSE_CONFIG build integration-tests
docker-compose $COMPOSE_CONFIG run -e UNLOCK_ENV=test -e CI=true $EXTRA_ARGS integration-tests bash -c "$COMMAND"
1 change: 0 additions & 1 deletion tests/.eslintrc.js
Expand Up @@ -6,7 +6,6 @@ const rulesToIgnore = [

module.exports = {
extends: ['@unlock-protocol/eslint-config'],
plugins: ['mocha'],
globals: {
it: true,
artifacts: true,
Expand Down