Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(validator): generate abi name if not provided #6981

Merged
merged 4 commits into from
Apr 22, 2024
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2477,3 +2477,4 @@ If there are any bugs, improvements, optimizations or any new feature proposal f

#### web3-validator

- 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)
2 changes: 1 addition & 1 deletion packages/web3-validator/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -172,4 +172,4 @@ Documentation:

### Fixed

- Nodejs Buffer is not recognized as valid bytes value
- 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.
2 changes: 1 addition & 1 deletion packages/web3-validator/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ export const abiSchemaToJsonSchema = (
// e.g. {name: 'a', type: 'uint'}
if (isAbiParameterSchema(abi)) {
abiType = abi.type;
abiName = abi.name;
abiName = abi.name || `${level}/${index}`;
abiComponents = abi.components as FullValidationSchema;
// If its short form string value e.g. ['uint']
} else if (typeof abi === 'string') {
Expand Down
34 changes: 34 additions & 0 deletions packages/web3-validator/test/fixtures/abi_to_json_schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,40 @@ const abiToJsonSchemaCases: AbiToJsonSchemaCase[] = [
},
},

// this is for public mappings case where the abi has no name
{
title: 'multiple params of different types without name',
abi: {
fullSchema: [
{ name: '', type: 'uint' },
{ name: '', type: 'int' },
],
shortSchema: ['uint', 'int'],
data: [12, -1],
},
json: {
fullSchema: {
type: 'array',
items: [
{ $id: '/0/0', format: 'uint', required: true },
{ $id: '/0/1', format: 'int', required: true },
],
minItems: 2,
maxItems: 2,
},
shortSchema: {
type: 'array',
items: [
{ $id: '/0/0', format: 'uint', required: true },
{ $id: '/0/1', format: 'int', required: true },
],
minItems: 2,
maxItems: 2,
},
data: [12, -1],
},
},

{
title: 'single param array',
abi: {
Expand Down
Loading