Skip to content

Commit

Permalink
Display level info
Browse files Browse the repository at this point in the history
  • Loading branch information
eternauta1337 committed Sep 24, 2024
1 parent 767b50e commit 270f90b
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions packages/ethernaut-zeronaut/src/tasks/get-level.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
const types = require('ethernaut-common/src/validation/types')
const output = require('ethernaut-common/src/ui/output')
const { getChainId } = require('ethernaut-common/src/util/network')
const { connect } = require('../internal/connect')

require('../scopes/zeronaut')
.task('get-level', 'finds an existing campaign')
.addPositionalParam(
'name',
'The name of the campaign',
undefined,
types.string,
)
.addPositionalParam(
'level',
'The index of level to get',
undefined,
types.string,
)
.setAction(async ({ name, level }, hre) => {
try {
const chainId = await getChainId(hre)
const contract = await connect(`chain-${chainId}`, hre)

const id = hre.ethers.encodeBytes32String(name)
const campaign = await contract.getCampaign(id)

const levelAddress = campaign.levels[level]
const levelName = await contract.getLevelName(levelAddress)
const levelInstructions =
await contract.getLevelInstructions(levelAddress)

let str = ''
str += ` name: ${hre.ethers.decodeBytes32String(levelName)}`
str += `\n instructions: ${levelInstructions}`

return output.resultBox(str)
} catch (err) {
return output.errorBox(err)
}
})

0 comments on commit 270f90b

Please sign in to comment.