Skip to content

make idl enum fields which are snake case have proper typing to camel case#2378

Merged
Henry-E merged 5 commits into
otter-sec:masterfrom
pplisd:enum_snake_case_types_fix
Feb 1, 2023
Merged

make idl enum fields which are snake case have proper typing to camel case#2378
Henry-E merged 5 commits into
otter-sec:masterfrom
pplisd:enum_snake_case_types_fix

Conversation

@pplisd

@pplisd pplisd commented Feb 1, 2023

Copy link
Copy Markdown
Contributor

solves #2374

fixes:
ts: idl enum field types properly convert from snake case to camel case

@vercel

vercel Bot commented Feb 1, 2023

Copy link
Copy Markdown

@nojob1 is attempting to deploy a commit to the coral-xyz Team on Vercel.

A member of the Team first needs to authorize it.

@Henry-E

Henry-E commented Feb 1, 2023

Copy link
Copy Markdown

Looks great, would you mind to

  • Add a change log
  • Add a small test. Just add some enums to a program tests/misc and try to load them in a typescript test it() to verify that the naming is correct.
  • Run prettier on the ts code

For my own curiosity, just so that I can understand why this is broken but the struct stuff isn't broken, would you be able to share a link to where the same parsing is done correctly for structs? I'd just like to verify they now have the same logic.

@pplisd

pplisd commented Feb 1, 2023

Copy link
Copy Markdown
Contributor Author

for why the struct ones are fine I'm not 100% sure but I think it's just because the idl json generated for structs converts the fields to camelcase whereas the enum one does not. so they were parsing the idl basically the same (see https://github.com/coral-xyz/anchor/blob/master/ts/packages/anchor/src/coder/borsh/idl.ts#L121) but the idl itself was just different.

in misc tests it doesn't even build for me because some errors which i guess fixing might be against your guys maintainer stuff but can just decide after.

@Henry-E

Henry-E commented Feb 1, 2023

Copy link
Copy Markdown

Here's the program for misc, you could try adding some custom types maybe? I don't think you need to go all the way to actually add them to an account or load data into them since this is just to test the IDL.

program: https://github.com/coral-xyz/anchor/tree/master/tests/misc/programs/misc/src
ts test: https://github.com/coral-xyz/anchor/blob/master/tests/misc/tests/misc/misc.ts

@pplisd

pplisd commented Feb 1, 2023

Copy link
Copy Markdown
Contributor Author

i think the test uses an idl that gets built (it's not committed) im fixing it so i can add.

@Henry-E

Henry-E commented Feb 1, 2023

Copy link
Copy Markdown

We want a test though in which the IDL gets built? Please don't commit the IDL itself.

Also the test just failed because the ts code needs prettier run on it

@vercel

vercel Bot commented Feb 1, 2023

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Ignored Deployment
Name Status Preview Comments Updated
anchor-docs ⬜️ Ignored (Inspect) Feb 1, 2023 at 10:23AM (UTC)

@pplisd

pplisd commented Feb 1, 2023

Copy link
Copy Markdown
Contributor Author

idk the issue i was having was that the program had a bunch of UncheckedAccount or similar without /// Check: so i couldn't build the idl for misc. i just added the check and added my enum account and it worked. I wasn't trying to commit the idl

@Henry-E

Henry-E commented Feb 1, 2023

Copy link
Copy Markdown

Ah right, you need to run with anchor test --skip-lint

@pplisd

pplisd commented Feb 1, 2023

Copy link
Copy Markdown
Contributor Author

ah well, i guess not anymore

seems tests worked

@Henry-E

Henry-E commented Feb 1, 2023

Copy link
Copy Markdown

Great, looks good to me. Thanks for the PR!

@Henry-E Henry-E merged commit cb68080 into otter-sec:master Feb 1, 2023
@Henry-E

Henry-E commented Feb 1, 2023

Copy link
Copy Markdown

closes: #2374

@pplisd

pplisd commented Feb 2, 2023

Copy link
Copy Markdown
Contributor Author

oh cool thanks.

ohh i put my changelog in the comment not in the file lmao didn't know about that. Issue was just for the types not the actual object but i guess it's close enough.

@Henry-E

Henry-E commented Feb 6, 2023

Copy link
Copy Markdown

So what would be a more accurate changelog?

  • ts: Fields inside enum variants weren't being converted to camelCase correctly

Otter-0x4ka5h pushed a commit to Otter-0x4ka5h/anchor that referenced this pull request Mar 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants