Ackee-Blockchain / trident

Rust-based framework to Fuzz and Integration test Solana programs to help you ship secure code.
https://ackee.xyz/
MIT License
185 stars 18 forks source link

`Error: Idl(MissingOrInvalidProgramItems("account mod: struct not found"))` when running `trident inti` #160

Closed cryptopapi997 closed 3 months ago

cryptopapi997 commented 3 months ago

Hey guys,

I have a project using Anchor 0.30.0 on which I'm trying to run trident init. An important specification here is I have anchor-spl as a dependency and I have it as version 0.30.0 as downgrading to 0.29.0 (like the docs recommend) would break everything in my program. Additionally, I tested a different 0.30.0 program with anchor-spl at 0.30.0 as well and there it worked fine.

My issue is, when I try to run trident init on this project it keeps giving me Error: Idl(MissingOrInvalidProgramItems("account mod: struct not found")). I tried checking the source code, but I'm not exactly sure what this error means exactly. I tried deleting most of my program so that all that gets generated as an idl is the below, but still the same issue. Any tips on how to fix this?

{
  "address": "85R8U76mZMurovUW3Houj4oeJ4W3SH6PXbJuHoMzbQDZ",
  "metadata": {
    "name": "my_program",
    "version": "0.1.0",
    "spec": "0.1.0"
  },
  "docs": [
    "Some docs"
  ],
  "instructions": [],
  "errors": [
    {
      "code": 6000,
      "name": "MyError1"
    },
    {
      "code": 6001,
      "name": "MyError2"
    },
    {
      "code": 6002,
      "name": "MyError3"
    },
    {
      "code": 6003,
      "name": "MyError4"
    }
  ]
}
lukacan commented 3 months ago

Hello, we will look into it, do you have the source code available in any repository? :)

cryptopapi997 commented 3 months ago

Yes, but it's closed source. Let me try creating a MRE and get back to you

cryptopapi997 commented 3 months ago

Alright, added an MRE here:

https://github.com/cryptopapi997/trident-mre

I just tried it again with a fresh git clone and trident init and it throws the same error.

Small thing to note: This uses the latest commit from the anchor repo instead of the official 0.30.0 release. You can switch it to 0.30.0 if you'd like, it still throws the same error

Ikrk commented 3 months ago

The problem is in the name of the context struct InitPersistentMXE which is converted by Anchor to kebab case as init_persistent_mxe and then by Trident back to camel case as InitPersistentMxe which does not correspond to the original name and is thus not found.

As a temporary workaround, if you rename InitPersistentMXE to InitPersistentMxe, then the Trident initialization (of your MRE) works.

cryptopapi997 commented 3 months ago

Makes sense, thank you! I understand changing this is no simple undertaking as it would require parsing the names from Rust directly. However, I feel like if the error message specified the (incorrectly spelled) struct that caused this, it would've been a lot easier to guess what the problem is without bothering you guys. Opened a quick PR for this here: https://github.com/Ackee-Blockchain/trident/pull/164

cryptopapi997 commented 3 months ago

Can be closed since https://github.com/Ackee-Blockchain/trident/pull/164 was merged