-
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
143d84c
commit 767b50e
Showing
4 changed files
with
76 additions
and
1 deletion.
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
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
const { scope } = require('hardhat/config') | ||
const { description } = require('../../package.json') | ||
|
||
module.exports = scope('zeronaut', description) | ||
module.exports = scope('zero', description) |
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,33 @@ | ||
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('create-level', 'Adds a level to a campaign') | ||
.addPositionalParam( | ||
'level', | ||
'The address of the level', | ||
undefined, | ||
types.address, | ||
) | ||
.addPositionalParam( | ||
'campaign', | ||
'The name of the campaign', | ||
undefined, | ||
types.string, | ||
) | ||
.setAction(async ({ campaign, level }, hre) => { | ||
try { | ||
const chainId = await getChainId(hre) | ||
const contract = await connect(`chain-${chainId}`, hre) | ||
|
||
const id = hre.ethers.encodeBytes32String(campaign) | ||
const tx = await contract.createLevel(id, level) | ||
await tx.wait() | ||
|
||
return output.resultBox(`Added level ${level} to campaign ${campaign}`) | ||
} catch (err) { | ||
return output.errorBox(err) | ||
} | ||
}) |
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,37 @@ | ||
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') | ||
const debug = require('ethernaut-common/src/ui/debug') | ||
|
||
require('../scopes/zeronaut') | ||
.task('get-campaign', 'finds an existing campaign') | ||
.addPositionalParam( | ||
'name', | ||
'The name of the campaign', | ||
undefined, | ||
types.string, | ||
) | ||
.setAction(async ({ name }, 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) | ||
|
||
let str = '' | ||
str += `\n name: ${hre.ethers.decodeBytes32String(campaign.id)}` | ||
str += `\n levels: ${campaign.levels.length}` | ||
|
||
for (let i = 0; i < campaign.levels.length; i++) { | ||
const levelAddress = campaign.levels[i] | ||
const levelName = await contract.getLevelName(levelAddress) | ||
str += `\n - Level ${i}: "${hre.ethers.decodeBytes32String(levelName)}"` | ||
} | ||
|
||
return output.resultBox(str) | ||
} catch (err) { | ||
return output.errorBox(err) | ||
} | ||
}) |