diff --git a/packages/ethernaut-zeronaut/src/tasks/get-campaign.js b/packages/ethernaut-zeronaut/src/tasks/get-campaign.js index d87e9069..19978df5 100644 --- a/packages/ethernaut-zeronaut/src/tasks/get-campaign.js +++ b/packages/ethernaut-zeronaut/src/tasks/get-campaign.js @@ -13,24 +13,33 @@ require('../scopes/zeronaut') ) .setAction(async ({ name }, hre) => { try { + // Connect to the game contract const chainId = await getChainId(hre) const contract = await connect(`chain-${chainId}`, hre) + // Get the campaign details const id = hre.ethers.encodeBytes32String(name) const campaign = await contract.getCampaign(id) + // Get the player address + const signer = (await hre.ethers.getSigners())[0] + const playerAddress = signer.address + + // Print general campaign details let str = '' str += ` name: ${hre.ethers.decodeBytes32String(campaign.id)}` str += `\n owner: ${campaign.owner}` str += `\n levels: ${campaign.levels.length}` + // Get each level's details for (let i = 0; i < campaign.levels.length; i++) { const levelId = campaign.levels[i] const levelData = await contract.getLevel(levelId) const levelAddress = levelData.addr const level = await getLevelContract(hre, levelAddress) + const solved = await contract.isLevelSolved(levelId, playerAddress) const levelName = hre.ethers.decodeBytes32String(await level.name()) - str += `\n [${i + 1}] "${levelName}"` + str += `\n [${i + 1}] "${levelName}" ${solved ? '✅' : '❌'}` } return output.resultBox(str) diff --git a/packages/ethernaut-zeronaut/src/tasks/get-level.js b/packages/ethernaut-zeronaut/src/tasks/get-level.js index d6b2d5bd..d1b526f1 100644 --- a/packages/ethernaut-zeronaut/src/tasks/get-level.js +++ b/packages/ethernaut-zeronaut/src/tasks/get-level.js @@ -17,6 +17,10 @@ require('../scopes/zeronaut') const chainId = await getChainId(hre) const contract = await connect(`chain-${chainId}`, hre) + // Get the player address + const signer = (await hre.ethers.getSigners())[0] + const playerAddress = signer.address + // Retrieve the level address const id = hre.ethers.encodeBytes32String(name) const levelData = await contract.getLevel(id) @@ -29,10 +33,15 @@ require('../scopes/zeronaut') const levelName = await level.name() const levelInstructions = await level.instructions() + // Check if the level is completed + const solved = await contract.isLevelSolved(id, playerAddress) + // Display the level details let str = '' str += ` name: ${hre.ethers.decodeBytes32String(levelName)}` + str += `\n solved: ${solved}` str += `\n instructions: ${levelInstructions}` + return output.resultBox(str) } catch (err) { return output.errorBox(err) diff --git a/packages/ethernaut-zeronaut/src/tasks/play-level.js b/packages/ethernaut-zeronaut/src/tasks/play-level.js index e1e600da..eecb3d78 100644 --- a/packages/ethernaut-zeronaut/src/tasks/play-level.js +++ b/packages/ethernaut-zeronaut/src/tasks/play-level.js @@ -43,9 +43,10 @@ require('../scopes/zeronaut') const success = await level.check(proof, publicInputs) // Submit the proof - // TODO + const tx = await contract.solveLevel(levelId, proof, publicInputs) + await tx.wait() - return output.resultBox(`Success: ${success}`) + return output.resultBox(`Level solved: ${success}`) } catch (err) { return output.errorBox(err) }