Skip to content
This repository was archived by the owner on Mar 5, 2025. It is now read-only.

Commit 53e2466

Browse files
MaxMustermann2Alex
andauthored
fix(validator): generate abi name if not provided (#6981)
* fix(validator): generate abi name if not provided In the case of public mappings, the ABI generated has a blank name set. This results in blank ids for such inputs within the JSON schema. Post 1f81ff0, the number of unique ids is used to convert the JSON scheme into Zod, and hence the presence of blank ids is a concern. This commit generates the `abiName` if one is not provided to a value equal to the `${level}/${index}`. Fixes #6965. * fix: add validator changes to root CHANGELOG --------- Co-authored-by: Alex <alex.luu@mail.utoronto.ca>
1 parent d4e937d commit 53e2466

File tree

4 files changed

+37
-2
lines changed

4 files changed

+37
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2477,3 +2477,4 @@ If there are any bugs, improvements, optimizations or any new feature proposal f
24772477

24782478
#### web3-validator
24792479

2480+
- The JSON schema conversion process now correctly assigns an id when the `abi.name` is not available, for example, in the case of public mappings. (#6981)

packages/web3-validator/CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,4 +172,4 @@ Documentation:
172172

173173
### Fixed
174174

175-
- Nodejs Buffer is not recognized as valid bytes value
175+
- The JSON schema conversion process now correctly assigns an id when the `abi.name` is not available, for example, in the case of public mappings.

packages/web3-validator/src/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ export const abiSchemaToJsonSchema = (
141141
// e.g. {name: 'a', type: 'uint'}
142142
if (isAbiParameterSchema(abi)) {
143143
abiType = abi.type;
144-
abiName = abi.name;
144+
abiName = abi.name || `${level}/${index}`;
145145
abiComponents = abi.components as FullValidationSchema;
146146
// If its short form string value e.g. ['uint']
147147
} else if (typeof abi === 'string') {

packages/web3-validator/test/fixtures/abi_to_json_schema.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,40 @@ const abiToJsonSchemaCases: AbiToJsonSchemaCase[] = [
157157
},
158158
},
159159

160+
// this is for public mappings case where the abi has no name
161+
{
162+
title: 'multiple params of different types without name',
163+
abi: {
164+
fullSchema: [
165+
{ name: '', type: 'uint' },
166+
{ name: '', type: 'int' },
167+
],
168+
shortSchema: ['uint', 'int'],
169+
data: [12, -1],
170+
},
171+
json: {
172+
fullSchema: {
173+
type: 'array',
174+
items: [
175+
{ $id: '/0/0', format: 'uint', required: true },
176+
{ $id: '/0/1', format: 'int', required: true },
177+
],
178+
minItems: 2,
179+
maxItems: 2,
180+
},
181+
shortSchema: {
182+
type: 'array',
183+
items: [
184+
{ $id: '/0/0', format: 'uint', required: true },
185+
{ $id: '/0/1', format: 'int', required: true },
186+
],
187+
minItems: 2,
188+
maxItems: 2,
189+
},
190+
data: [12, -1],
191+
},
192+
},
193+
160194
{
161195
title: 'single param array',
162196
abi: {

0 commit comments

Comments
 (0)