Skip to content

Commit

Permalink
Progress with network autocomplete port
Browse files Browse the repository at this point in the history
  • Loading branch information
eternauta1337 committed Mar 2, 2024
1 parent a4f344e commit a6aaf74
Show file tree
Hide file tree
Showing 18 changed files with 69 additions and 63 deletions.
17 changes: 17 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,23 @@ jobs:
- run: npm run build --if-present
- run: npm run compile --if-present
- run: cd packages/ethernaut-network && npm t
ethernaut-network-ui:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [20.x]
steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}
- name: Install Foundry
uses: foundry-rs/foundry-toolchain@v1
- run: npm ci
- run: npm run build --if-present
- run: npm run compile --if-present
- run: cd packages/ethernaut-network-ui && npm t
ethernaut-wallet:
runs-on: ubuntu-latest
strategy:
Expand Down
25 changes: 0 additions & 25 deletions packages/ethernaut-network-ui/src/autocomplete/activate.js

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
const prompt = require('common/src/prompt')
const storage = require('../../internal/storage')
const storage = require('ethernaut-network/src/internal/storage')

module.exports = (message = 'Select a network') => {
module.exports = function autocompleteAlias(message = 'Select a network') {
return async function autocompleteAlias({ alias }) {
if (alias) return undefined

const choices = Object.keys(storage.readNetworks()).filter(
(alias) => alias !== 'activeNetwork',
)

return await prompt({
type: 'autocomplete',
message,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const prompt = require('common/src/prompt')
const storage = require('../../internal/storage')
const storage = require('ethernaut-network/src/internal/storage')

module.exports = async function autocompleteFork({ fork, paramDefault }) {
const valueProvided = fork !== undefined
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,7 @@ const strategies = {
MANUAL: 'Enter url manually',
}

module.exports = function setup(hre) {
const add = hre.scopes.network.tasks.add

add.paramDefinitions.url.autocomplete = autocompleteUrl
}

async function autocompleteUrl({ url }) {
module.exports = async function autocompleteUrl({ url }) {
if (url) return undefined

const choice = await selectStrategy()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = function setup(hre) {
const activate = hre.scopes.network.tasks.activate

activate.positionalParamDefinitions.find(
(p) => p.name === 'alias',
).autocomplete = require('../params/alias')('Select a network to activate')
}
5 changes: 5 additions & 0 deletions packages/ethernaut-network-ui/src/autocomplete/tasks/add.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = function setup(hre) {
const add = hre.scopes.network.tasks.add

add.paramDefinitions.url.autocomplete = require('../params/url')
}
6 changes: 6 additions & 0 deletions packages/ethernaut-network-ui/src/autocomplete/tasks/edit.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = function setup(hre) {
const edit = hre.scopes.network.tasks.edit

edit.positionalParamDefinitions.find((p) => p.name === 'alias').autocomplete =
require('../params/alias')('Select a network to edit')
}
6 changes: 6 additions & 0 deletions packages/ethernaut-network-ui/src/autocomplete/tasks/info.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = function setup(hre) {
const info = hre.scopes.network.tasks.info

info.positionalParamDefinitions.find((p) => p.name === 'alias').autocomplete =
require('../params/alias')('Select a network')
}
5 changes: 5 additions & 0 deletions packages/ethernaut-network-ui/src/autocomplete/tasks/node.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = function setup(hre) {
const node = hre.scopes.network.tasks.node

node.paramDefinitions.fork.autocomplete = require('../params/fork')
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = function setup(hre) {
const remove = hre.scopes.network.tasks.remove

remove.positionalParamDefinitions.find(
(p) => p.name === 'alias',
).autocomplete = require('../params/alias')('Select a network')
}
12 changes: 6 additions & 6 deletions packages/ethernaut-network-ui/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ require('ethernaut-ui/src/index')
require('ethernaut-network/src/index')

extendEnvironment((hre) => {
require('./autocomplete/activate')(hre)
require('./autocomplete/add')(hre)
// require('./autocomplete/edit')(hre)
// require('./autocomplete/info')(hre)
// require('./autocomplete/node')(hre)
// require('./autocomplete/remove')(hre)
require('./autocomplete/tasks/activate')(hre)
require('./autocomplete/tasks/add')(hre)
require('./autocomplete/tasks/edit')(hre)
require('./autocomplete/tasks/info')(hre)
require('./autocomplete/tasks/node')(hre)
require('./autocomplete/tasks/remove')(hre)
})
6 changes: 1 addition & 5 deletions packages/ethernaut-network/src/tasks/edit.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
const { types } = require('hardhat/config')
const output = require('common/src/output')
const autocompleteAlias = require('./autocomplete/alias')
const storage = require('../internal/storage')

const edit = require('../scopes/network')
require('../scopes/network')
.task('edit', 'Edits a network')
.addPositionalParam(
'alias',
Expand All @@ -29,6 +28,3 @@ const edit = require('../scopes/network')
return output.errorBox(err)
}
})

edit.positionalParamDefinitions.find((p) => p.name === 'alias').autocomplete =
autocompleteAlias('Select a network to edit')
6 changes: 1 addition & 5 deletions packages/ethernaut-network/src/tasks/info.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@ const output = require('common/src/output')
const storage = require('../internal/storage')
const { chains } = require('common/src/chains')
const { isUrl } = require('common/src/url')
const autocompleteAlias = require('./autocomplete/alias')

const info = require('../scopes/network')
require('../scopes/network')
.task('info', 'Provides information about a network')
.addPositionalParam(
'alias',
Expand Down Expand Up @@ -77,6 +76,3 @@ async function populateRemoteChainInfo(info, hre) {

return info
}

info.positionalParamDefinitions.find((p) => p.name === 'alias').autocomplete =
autocompleteAlias('Select a network')
6 changes: 2 additions & 4 deletions packages/ethernaut-network/src/tasks/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ const output = require('common/src/output')
const { execSync } = require('child_process')
const { isUrl } = require('common/src/url')
const storage = require('../internal/storage')
const autocompleteFork = require('./autocomplete/fork')
// const autocompleteFork = require('./autocomplete/fork')
const applyEnvVars = require('../internal/apply-env-vars')

const local = require('../scopes/network')
require('../scopes/network')
.task('node', 'Starts a local development chain, potentially with a fork.')
.addOptionalParam(
'fork',
Expand Down Expand Up @@ -70,5 +70,3 @@ function startAnvil(forkUrl, port) {
execSync(`anvil --fork-url ${forkUrl} --port ${port}`, { stdio: 'inherit' })
}
}

local.paramDefinitions.fork.autocomplete = autocompleteFork
6 changes: 1 addition & 5 deletions packages/ethernaut-network/src/tasks/remove.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
const { types } = require('hardhat/config')
const output = require('common/src/output')
const autocompleteAlias = require('./autocomplete/alias')
const storage = require('../internal/storage')

const remove = require('../scopes/network')
require('../scopes/network')
.task('remove', 'Removes a network from the cli')
.addPositionalParam(
'alias',
Expand Down Expand Up @@ -32,6 +31,3 @@ const remove = require('../scopes/network')
return output.errorBox(err)
}
})

remove.positionalParamDefinitions.find((p) => p.name === 'alias').autocomplete =
autocompleteAlias('Select a network to remove')
2 changes: 1 addition & 1 deletion packages/ethernaut-util-ui/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ require('ethernaut-ui/src/index')
require('ethernaut-util/src/index')

extendEnvironment((hre) => {
require('./autocomplete/unit')(hre)
require('./autocomplete/tasks/unit')(hre)
})

0 comments on commit a6aaf74

Please sign in to comment.