Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/hex-f-cli-argument-types.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"hardhat": patch
---

Fixed the `int`, `bigint` and `float` CLI argument types rejecting hexadecimal values containing the digit `f`/`F` (e.g. `0xff`, `0xdeadbeef`).
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export const int: CLIArgumentType<number> = {
name: "int",
parse: (argName, strValue) => {
const decimalPattern = /^\d+(?:[eE]\d+)?$/;
const hexPattern = /^0[xX][\dABCDEabcde]+$/;
const hexPattern = /^0[xX][\dA-Fa-f]+$/;

if (
strValue.match(decimalPattern) === null &&
Expand Down Expand Up @@ -130,7 +130,7 @@ export const bigint: CLIArgumentType<bigint> = {
name: "bigint",
parse: (argName, strValue) => {
const decimalPattern = /^\d+(?:n)?$/;
const hexPattern = /^0[xX][\dABCDEabcde]+$/;
const hexPattern = /^0[xX][\dA-Fa-f]+$/;

if (
strValue.match(decimalPattern) === null &&
Expand Down Expand Up @@ -174,7 +174,7 @@ export const float: CLIArgumentType<number> = {
name: "float",
parse: (argName, strValue) => {
const decimalPattern = /^(?:\d+(?:\.\d*)?|\.\d+)(?:[eE]\d+)?$/;
const hexPattern = /^0[xX][\dABCDEabcde]+$/;
const hexPattern = /^0[xX][\dA-Fa-f]+$/;

if (
strValue.match(decimalPattern) === null &&
Expand Down
27 changes: 27 additions & 0 deletions packages/hardhat-core/test/internal/core/params/argumentTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@ describe("argumentTypes", () => {
assert.equal(types.int.parse("arg", "0xA"), 0xa);
assert.equal(types.int.parse("arg", "0xa"), 0xa);
assert.equal(types.int.parse("arg", "0x0a"), 0x0a);
assert.equal(types.int.parse("arg", "0xF"), 0xf);
assert.equal(types.int.parse("arg", "0xf"), 0xf);
assert.equal(types.int.parse("arg", "0xff"), 0xff);
assert.equal(types.int.parse("arg", "0xdeadbeef"), 0xdeadbeef);
assert.equal(types.int.parse("arg", "0xABCDEF"), 0xabcdef);
});

it("should work with decimal scientific notation", () => {
Expand Down Expand Up @@ -124,6 +129,10 @@ describe("argumentTypes", () => {
() => types.int.parse("arg", "x123"),
ERRORS.ARGUMENTS.INVALID_VALUE_FOR_TYPE
);
expectHardhatError(
() => types.int.parse("arg", "0xg"),
ERRORS.ARGUMENTS.INVALID_VALUE_FOR_TYPE
);
});
});

Expand All @@ -145,6 +154,11 @@ describe("argumentTypes", () => {
assert.equal(types.bigint.parse("arg", "0xA"), BigInt(0xa));
assert.equal(types.bigint.parse("arg", "0xa"), BigInt(0xa));
assert.equal(types.bigint.parse("arg", "0x0a"), BigInt(0x0a));
assert.equal(types.bigint.parse("arg", "0xF"), BigInt(0xf));
assert.equal(types.bigint.parse("arg", "0xf"), BigInt(0xf));
assert.equal(types.bigint.parse("arg", "0xff"), BigInt(0xff));
assert.equal(types.bigint.parse("arg", "0xdeadbeef"), BigInt(0xdeadbeef));
assert.equal(types.bigint.parse("arg", "0xABCDEF"), BigInt(0xabcdef));
assert.equal(
types.bigint.parse("arg", "0x20000000000000"),
BigInt("0x20000000000000")
Expand Down Expand Up @@ -192,6 +206,10 @@ describe("argumentTypes", () => {
() => types.bigint.parse("arg", "x123"),
ERRORS.ARGUMENTS.INVALID_VALUE_FOR_TYPE
);
expectHardhatError(
() => types.bigint.parse("arg", "0xg"),
ERRORS.ARGUMENTS.INVALID_VALUE_FOR_TYPE
);
expectHardhatError(
() => types.bigint.parse("arg", "1e0"),
ERRORS.ARGUMENTS.INVALID_VALUE_FOR_TYPE
Expand Down Expand Up @@ -224,6 +242,11 @@ describe("argumentTypes", () => {
assert.equal(types.float.parse("arg", "0xA"), 0xa);
assert.equal(types.float.parse("arg", "0xa"), 0xa);
assert.equal(types.float.parse("arg", "0x0a"), 0x0a);
assert.equal(types.float.parse("arg", "0xF"), 0xf);
assert.equal(types.float.parse("arg", "0xf"), 0xf);
assert.equal(types.float.parse("arg", "0xff"), 0xff);
assert.equal(types.float.parse("arg", "0xdeadbeef"), 0xdeadbeef);
assert.equal(types.float.parse("arg", "0xABCDEF"), 0xabcdef);
});

it("should work with decimal scientific notation", () => {
Expand Down Expand Up @@ -282,6 +305,10 @@ describe("argumentTypes", () => {
() => types.float.parse("arg", "x123"),
ERRORS.ARGUMENTS.INVALID_VALUE_FOR_TYPE
);
expectHardhatError(
() => types.float.parse("arg", "0xg"),
ERRORS.ARGUMENTS.INVALID_VALUE_FOR_TYPE
);
});
});

Expand Down
Loading