Skip to content

Commit

Permalink
Add hex util
Browse files Browse the repository at this point in the history
  • Loading branch information
eternauta1337 committed Sep 18, 2024
1 parent f2d6714 commit 56a93d5
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/ethernaut-util/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ This plugin adds the tasks listed below.
- unit Converts between different units of Ether
- gas Fetch gas info on the current network
- chain Finds a network name from a chain ID, or vice versa
- hex Converts integers to hex

## Environment extensions

Expand Down
13 changes: 13 additions & 0 deletions packages/ethernaut-util/src/tasks/hex.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const types = require('ethernaut-common/src/validation/types')
const output = require('ethernaut-common/src/ui/output')

require('../scopes/util')
.task('hex', 'Converts integers to hex')
.addPositionalParam('value', 'The value to convert.', undefined, types.int)
.setAction(async ({ value }, hre) => {
try {
return output.resultBox(hre.ethers.toQuantity(value))
} catch (err) {
return output.errorBox(err)
}
})
10 changes: 10 additions & 0 deletions packages/ethernaut-util/test/tasks/hex.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const assert = require('assert')

describe('hex', function () {
it('converts "42" to hex', async function () {
assert.equal(
await hre.run({ scope: 'util', task: 'hex' }, { value: '42' }),
'0x2a',
)
})
})

0 comments on commit 56a93d5

Please sign in to comment.