Skip to content

Commit

Permalink
Add sig list task
Browse files Browse the repository at this point in the history
  • Loading branch information
eternauta1337 committed Feb 28, 2024
1 parent c361d38 commit 599ca95
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
18 changes: 18 additions & 0 deletions packages/ethernaut-signer/src/tasks/list.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
const output = require('common/src/output')
const storage = require('../internal/storage')

require('../scopes/sig')
.task('list', 'Prints all signers')
.setAction(async () => {
try {
const signers = storage.readSigners()
const strs = []
Object.entries(signers).forEach(([name, signer]) => {
if (name === 'activeSigner') return
strs.push(`- ${name} (${signer.address})`)
})
output.resultBox(strs.join('\n'))
} catch (err) {
return output.errorBox(err)
}
})
31 changes: 31 additions & 0 deletions packages/ethernaut-signer/test/tasks/list.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
const { Terminal } = require('common/src/terminal')
const storage = require('../../src/internal/storage')

describe('list', function () {
const terminal = new Terminal()

before('add some signers', async function () {
const signers = storage.readSigners()
if (!('test__3' in signers)) signers.test__3 = { address: 'poop1' }
if (!('test__4' in signers)) signers.test__4 = { address: 'poop2' }
storage.storeSigners(signers)
})

after('remove signers', async function () {
const signers = storage.readSigners()
if ('test__3' in signers) delete signers.test__3
if ('test__4' in signers) delete signers.test__4
storage.storeSigners(signers)
})

describe('when calling list', function () {
before('call', async function () {
await terminal.run('npx hardhat sig list')
})

it('prints the signers', async function () {
terminal.has('- test__3 (poop1)')
terminal.has('- test__4 (poop2)')
})
})
})

0 comments on commit 599ca95

Please sign in to comment.