From 270f90bdd6fae78f9976069110ec96f67eb7c026 Mon Sep 17 00:00:00 2001 From: Alejandro Date: Tue, 24 Sep 2024 10:22:20 -0300 Subject: [PATCH] Display level info --- .../ethernaut-zeronaut/src/tasks/get-level.js | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 packages/ethernaut-zeronaut/src/tasks/get-level.js diff --git a/packages/ethernaut-zeronaut/src/tasks/get-level.js b/packages/ethernaut-zeronaut/src/tasks/get-level.js new file mode 100644 index 0000000..8cf6da7 --- /dev/null +++ b/packages/ethernaut-zeronaut/src/tasks/get-level.js @@ -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) + } + })