Skip to content

Commit

Permalink
Fix network tests
Browse files Browse the repository at this point in the history
  • Loading branch information
eternauta1337 committed Feb 28, 2024
1 parent b18a317 commit 4e2e7d2
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 2 deletions.
4 changes: 2 additions & 2 deletions packages/common/src/terminal.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,11 @@ class Terminal {
}

has(output) {
assert.ok(this.output.includes(output), this.output)
assert.ok(this.output.includes(output), `Output: >${this.output}<`)
}

notHas(output) {
assert.ok(!this.output.includes(output), this.output)
assert.ok(!this.output.includes(output), `Output: >${this.output}`)
}
}

Expand Down
6 changes: 6 additions & 0 deletions packages/ethernaut-network/src/internal/set-network.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,13 @@ async function setActiveNetwork(hre) {
}

debug.log('Setting active network', 'network')

const networks = storage.readNetworks()
if (!networks.activeNetwork || !networks[networks.activeNetwork]) {
networks.activeNetwork = 'localhost'
storage.storeNetworks(networks)
}

await setNetwork(networks.activeNetwork, hre)
}

Expand Down
14 changes: 14 additions & 0 deletions packages/ethernaut-network/test/tasks/active.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,20 @@ describe('active', function () {
let activeNetwork
const terminal = new Terminal()

before('add test network', async function () {
const networks = storage.readNetworks()
if (!('test__8' in networks))
networks.test__8 = { url: 'https://ethereum-rpc.publicnode.com' }
networks.activeNetwork = 'test__8'
storage.storeNetworks(networks)
})

after('remove test network', async function () {
const networks = storage.readNetworks()
if ('test__8' in networks) delete networks.test__8
storage.storeNetworks(networks)
})

before('get the active network', async function () {
activeNetwork = storage.readNetworks().activeNetwork
})
Expand Down
12 changes: 12 additions & 0 deletions packages/ethernaut-network/test/tasks/local.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,18 @@ const storage = require('../../src/internal/storage')
describe('local', function () {
const terminal = new Terminal()

before('add test network', async function () {
const networks = storage.readNetworks()
if (!('test__9' in networks)) networks.test__9 = { url: 'poop' }
storage.storeNetworks(networks)
})

after('remove test network', async function () {
const networks = storage.readNetworks()
if ('test__9' in networks) delete networks.test__9
storage.storeNetworks(networks)
})

describe('when parameters are not provided', function () {
before('run', async function () {
await terminal.run('npx hardhat net local', 2000)
Expand Down

0 comments on commit 4e2e7d2

Please sign in to comment.