Skip to content

Commit

Permalink
fix(validator): generate abi name if not provided (#6981)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
MaxMustermann2 and Alex authored Apr 22, 2024
1 parent d4e937d commit 53e2466
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 2 deletions.
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

1 comment on commit 53e2466

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Benchmark

Benchmark suite Current: 53e2466 Previous: 6c075db Ratio
processingTx 9238 ops/sec (±4.05%) 9301 ops/sec (±4.81%) 1.01
processingContractDeploy 40322 ops/sec (±6.08%) 39129 ops/sec (±7.62%) 0.97
processingContractMethodSend 19715 ops/sec (±7.38%) 19443 ops/sec (±5.19%) 0.99
processingContractMethodCall 40521 ops/sec (±5.96%) 38971 ops/sec (±6.34%) 0.96
abiEncode 46271 ops/sec (±6.29%) 44252 ops/sec (±6.92%) 0.96
abiDecode 31281 ops/sec (±8.11%) 30419 ops/sec (±8.89%) 0.97
sign 1603 ops/sec (±3.79%) 1656 ops/sec (±4.08%) 1.03
verify 379 ops/sec (±0.42%) 373 ops/sec (±0.78%) 0.98

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.