Skip to content

Commit

Permalink
Progress with validation on challenges package
Browse files Browse the repository at this point in the history
  • Loading branch information
eternauta1337 committed Mar 15, 2024
1 parent 61a7940 commit 8a82138
Show file tree
Hide file tree
Showing 10 changed files with 30 additions and 12 deletions.
2 changes: 1 addition & 1 deletion packages/ethernaut-ai/src/tasks/config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { types } = require('hardhat/config')
const types = require('ethernaut-common/src/types')
const output = require('ethernaut-common/src/output')
const storage = require('ethernaut-common/src/storage')

Expand Down
2 changes: 1 addition & 1 deletion packages/ethernaut-ai/src/tasks/interpret.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { types } = require('hardhat/config')
const types = require('ethernaut-common/src/types')
const Interpreter = require('../internal/assistants/Interpreter')
const Explainer = require('../internal/assistants/Explainer')
const Thread = require('../internal/threads/Thread')
Expand Down
4 changes: 2 additions & 2 deletions packages/ethernaut-challenges/src/tasks/check.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { types } = require('hardhat/config')
const types = require('ethernaut-common/src/types')
const helper = require('../internal/helper')
const output = require('ethernaut-common/src/output')
const findLevelCompletedEvents = require('../internal/level-completed-logs')
Expand All @@ -9,7 +9,7 @@ require('../scopes/challenges')
'check',
'Checks if the player has completed the specified level by submitting an instance modified as per the levels requirements',
)
.addPositionalParam('level', 'The level number', undefined, types.string)
.addPositionalParam('level', 'The level number', undefined, types.int)
.setAction(async ({ level }, hre) => {
try {
const completed = await checkLevel(level, hre)
Expand Down
4 changes: 2 additions & 2 deletions packages/ethernaut-challenges/src/tasks/info.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { types } = require('hardhat/config')
const types = require('ethernaut-common/src/types')
const helper = require('../internal/helper')
const fs = require('fs')
const path = require('path')
Expand All @@ -11,7 +11,7 @@ require('../scopes/challenges')
'info',
'Shows information about an open zeppelin challenges level. The info includes the level name, contract name, ABI path, address, and description. The ABI path can be used with the interact package call task to interact with the contract.',
)
.addPositionalParam('level', 'The level number', undefined, types.string)
.addPositionalParam('level', 'The level number', undefined, types.int)
.setAction(async ({ level }) => {
try {
const info = await getLevelInfo(level)
Expand Down
4 changes: 2 additions & 2 deletions packages/ethernaut-challenges/src/tasks/instance.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { types } = require('hardhat/config')
const types = require('ethernaut-common/src/types')
const helper = require('../internal/helper')
const output = require('ethernaut-common/src/output')
const { getNetworkName } = require('ethernaut-common/src/network')
Expand All @@ -11,7 +11,7 @@ require('../scopes/challenges')
'instance',
'Creates an instance of a level, so that it can be played. The address of the instance is printed to the console. Use this address to interact with the contract using the ethernaut-cli contract command. Make sure to use the info command to get instructions on how to complete the level.',
)
.addPositionalParam('level', 'The level number', undefined, types.string)
.addPositionalParam('level', 'The level number', undefined, types.int)
.setAction(async ({ level }, hre) => {
try {
const instanceAddress = await createInstance(level, hre)
Expand Down
4 changes: 2 additions & 2 deletions packages/ethernaut-challenges/src/tasks/submit.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { types } = require('hardhat/config')
const types = require('ethernaut-common/src/types')
const output = require('ethernaut-common/src/output')
const debug = require('ethernaut-common/src/debug')
const getEthernautContract = require('../internal/ethernaut-contract')
Expand All @@ -12,7 +12,7 @@ require('../scopes/challenges')
'address',
'The address of the instance to submit',
undefined,
types.string,
types.address,
)
.setAction(async ({ address }, hre) => {
try {
Expand Down
4 changes: 4 additions & 0 deletions packages/ethernaut-common/src/type-address.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ module.exports = {
`"${argValue}" is not an address`,
`Invalid ${argName}`,
)

if (typeof describe === 'function') {
throw err
}
}
},
}
4 changes: 4 additions & 0 deletions packages/ethernaut-common/src/type-ens.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ module.exports = {
}
} catch (err) {
output.errorBoxStr(`"${argValue}" is not an ens`, `Invalid ${argName}`)

if (typeof describe === 'function') {
throw err
}
}
},
}
10 changes: 8 additions & 2 deletions packages/ethernaut-common/src/type-int.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,18 @@ const output = require('./output')

module.exports = {
name: 'int',
parse: types.int.parse,
parse: function (argName, argValue) {
return argValue
},
validate: (argName, argValue) => {
try {
types.int.validate(argName, argValue)
} catch (err) {
output.errorBoxStr(`"${argValue}" is an int`, `Invalid ${argName}`)
output.errorBoxStr(`"${argValue}" is not an int`, `Invalid ${argName}`)

if (typeof describe === 'function') {
throw err
}
}
},
}
4 changes: 4 additions & 0 deletions packages/ethernaut-common/src/type-string.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ module.exports = {
types.string.validate(argName, argValue)
} catch (err) {
output.errorBoxStr(`"${argValue}" is not string`, `Invalid ${argName}`)

if (typeof describe === 'function') {
throw err
}
}
},
}

0 comments on commit 8a82138

Please sign in to comment.