Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ describe("normalizeFunctionParams", () => {
});

it("should throw an error if a parameter name is missing", () => {
const abiFunction: AbiFunction = {
let abiFunction: AbiFunction = {
inputs: [{ name: undefined, type: "uint256" }],
type: "function",
stateMutability: "pure",
Expand All @@ -67,6 +67,31 @@ describe("normalizeFunctionParams", () => {
expect(() => normalizeFunctionParams(abiFunction, {})).toThrow(
"Missing named parameter for test at index 0",
);

abiFunction = {
inputs: [{ name: "", type: "uint256" }],
type: "function",
stateMutability: "pure",
name: "test",
outputs: [],
};

expect(() => normalizeFunctionParams(abiFunction, {})).toThrow(
"Missing named parameter for test at index 0",
);

abiFunction = {
inputs: [{ name: undefined, type: "uint256" }],
type: "function",
stateMutability: "pure",
name: "test",
outputs: [],
};

const normalized = normalizeFunctionParams(abiFunction, { "*": 123 });

expect(normalized.length).to.eq(1);
expect(normalized[0]).to.eq(123);
});

it("should throw an error if a parameter value is missing", () => {
Expand Down
13 changes: 9 additions & 4 deletions packages/thirdweb/src/utils/abi/normalizeFunctionParams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,15 @@ export function normalizeFunctionParams(
abiFunction.inputs.map((i) => i.type),
abiFunction.inputs.map((input, index) => {
const value = input.name;
if (value === undefined) {
throw new Error(
`Missing named parameter for ${"name" in abiFunction ? abiFunction.name : "constructor"} at index ${index}`,
);
if (value === undefined || value.length === 0) {
// TODO: Handle multiple unnamed params
if (!params["*"]) {
throw new Error(
`Missing named parameter for ${"name" in abiFunction ? abiFunction.name : "constructor"} at index ${index}`,
);
}

return params["*"];
}
const valueWithoutUnderscore = value.replace(/^_+/, "");
const normalizedValue =
Expand Down
Loading