Skip to content

Commit

Permalink
Fix for unstructured storage abis (codegen) (#1976)
Browse files Browse the repository at this point in the history
* add test for fix

* update changelog

* add lower case

* add test
  • Loading branch information
bz888 authored Aug 30, 2023
1 parent 504137b commit 681c1d1
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 3 deletions.
2 changes: 2 additions & 0 deletions packages/cli/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
### Fixed
- Fix incorrect codegen on unstructured storage proxy contract abis (#1976)

## [3.6.1] - 2023-08-29
### Fixed
Expand Down
42 changes: 41 additions & 1 deletion packages/cli/src/controller/codegen-controller.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import fs from 'fs';
import path from 'path';
import rimraf from 'rimraf';
import {abiInterface, codegen, processAbis, validateEntityName} from './codegen-controller';
import {abiInterface, codegen, joinInputAbiName, processAbis, validateEntityName} from './codegen-controller';

jest.mock('fs', () => {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
Expand Down Expand Up @@ -123,4 +123,44 @@ describe('Codegen can generate schema (mocked)', () => {
'Provided ABI is not a valid ABI or Artifact'
);
});

it('should replace [] in input abi name', () => {
const mockAbiInterface = {
type: 'function',
name: 'initialize',
inputs: [
{
name: '__name',
type: 'string',
},
{
name: '__symbol',
type: 'string',
},
{
name: '__baseURI',
type: 'string',
},
{
name: 'admins',
type: 'address[]',
},
],
} as abiInterface;

expect(joinInputAbiName(mockAbiInterface)).toMatch('initialize_string_string_string_address_arr_');
});
it('ensure correct output when input does not contain []', () => {
const mockAbiInterface = {
type: 'function',
name: 'initialize',
inputs: [
{
name: '__name',
type: 'STRING',
},
],
} as abiInterface;
expect(joinInputAbiName(mockAbiInterface)).toMatch('initialize_string_');
});
});
4 changes: 2 additions & 2 deletions packages/cli/src/controller/codegen-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -306,9 +306,9 @@ export function processAbis(
return renderInterfaceJobs;
}

function joinInputAbiName(abiObject: abiInterface) {
export function joinInputAbiName(abiObject: abiInterface): string {
// example: "TextChanged_bytes32_string_string_string_Event", Event name/Function type name will be joined in ejs
const inputToSnake: string = abiObject.inputs.map((obj) => obj.type.toLowerCase()).join('_');
const inputToSnake = abiObject.inputs.map((obj) => obj.type.replace(/\[\]/g, '_arr').toLowerCase()).join('_');
return `${abiObject.name}_${inputToSnake}_`;
}

Expand Down

0 comments on commit 681c1d1

Please sign in to comment.