Skip to content

Commit 2b87b7b

Browse files
committed
Cleanup code
1 parent 1ba2091 commit 2b87b7b

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

packages/hardhat-verify/src/internal/utilities.ts

+12-11
Original file line numberDiff line numberDiff line change
@@ -229,21 +229,22 @@ export async function encodeArguments(
229229
const contractInterface = new Interface(abi);
230230
let encodedConstructorArguments;
231231
try {
232-
// Check if the constructor arguments are of the correct type.
233-
const constructorArgType = contractInterface.deploy.inputs?.map(
234-
(ci) => ci?.type
235-
);
236-
constructorArguments?.forEach((item, index) => {
232+
// encodeDeploy doesn't catch subtle type mismatches, such as a number
233+
// being passed when a string is expected, so we have to validate the
234+
// scenario manually.
235+
const expectedConstructorArgs = contractInterface.deploy.inputs;
236+
constructorArguments.forEach((arg, i) => {
237237
if (
238-
typeof item !== constructorArgType[index] &&
239-
constructorArgType[index] === "string"
240-
)
238+
expectedConstructorArgs[i]?.type === "string" &&
239+
typeof arg !== "string"
240+
) {
241241
throw new ABIArgumentTypeError({
242242
code: "INVALID_ARGUMENT",
243-
argument: "constructor argument",
244-
value: item,
245-
reason: `Expected type 'string', but got '${typeof item}'`,
243+
argument: expectedConstructorArgs[i].name,
244+
value: arg,
245+
reason: "invalid string value",
246246
} as ABIArgumentTypeErrorType);
247+
}
247248
});
248249

249250
encodedConstructorArguments = contractInterface

0 commit comments

Comments
 (0)