-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
767b50e
commit 270f90b
Showing
1 changed file
with
41 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
}) |