coral-xyz / anchor

⚓ Solana Sealevel Framework
https://anchor-lang.com
Apache License 2.0
3.71k stars 1.36k forks source link

IdlError: Type not found: {"name":"inner","type":{"defined":"StakeState"}} in anchor-cli version 0.18.2 #1065

Closed kAsky53 closed 2 years ago

kAsky53 commented 2 years ago

Hello, I have used solana_program::stake::state::StakeState in my state.

#[account]
pub struct StakeWrapper {
    pub inner: StakeState,
}

It doesn't seem like anchor serialize enum with tuples properly.

#[derive(Debug, Serialize, Deserialize, PartialEq, Clone, Copy, AbiExample)]
#[allow(clippy::large_enum_variant)]
pub enum StakeState {
    Uninitialized,
    Initialized(Meta),
    Stake(Meta, Stake),
    RewardsPool,
}

When I run anchor test it throws the following error.

IdlError: Type not found: {"name":"inner","type":{"defined":"StakeState"}}
    at Function.fieldLayout (/home/wantanabe/Marinade/liquid-staking-referral-program/node_modules/@project-serum/anchor/src/coder/idl.ts:89:19)
    at /home/wantanabe/Marinade/liquid-staking-referral-program/node_modules/@project-serum/anchor/src/coder/idl.ts:117:28
    at Array.map (<anonymous>)
    at Function.typeDefLayout (/home/wantanabe/Marinade/liquid-staking-referral-program/node_modules/@project-serum/anchor/src/coder/idl.ts:116:48)
    at /home/wantanabe/Marinade/liquid-staking-referral-program/node_modules/@project-serum/anchor/src/coder/accounts.ts:27:39
    at Array.map (<anonymous>)
    at new AccountsCoder (/home/wantanabe/Marinade/liquid-staking-referral-program/node_modules/@project-serum/anchor/src/coder/accounts.ts:26:49)
    at new Coder (/home/wantanabe/Marinade/liquid-staking-referral-program/node_modules/@project-serum/anchor/src/coder/index.ts:40:21)
    at new Program (/home/wantanabe/Marinade/liquid-staking-referral-program/node_modules/@project-serum/anchor/src/program/index.ts:264:19)
    at /home/wantanabe/Marinade/liquid-staking-referral-program/node_modules/@project-serum/anchor/src/workspace.ts:58:34
    at Array.forEach (<anonymous>)
    at Object.get (/home/wantanabe/Marinade/liquid-staking-referral-program/node_modules/@project-serum/anchor/src/workspace.ts:51:33)
    at Suite.<anonymous> (/home/wantanabe/Marinade/liquid-staking-referral-program/tests/marinade-referral.ts:13:10)
    at Object.create (/home/wantanabe/Marinade/liquid-staking-referral-program/node_modules/mocha/lib/interfaces/common.js:148:19)
    at context.describe.context.context (/home/wantanabe/Marinade/liquid-staking-referral-program/node_modules/mocha/lib/interfaces/bdd.js:42:27)
    at Object.<anonymous> (/home/wantanabe/Marinade/liquid-staking-referral-program/tests/marinade-referral.ts:5:1)
    at Module._compile (internal/modules/cjs/loader.js:1085:14)
    at Module.m._compile (/home/wantanabe/Marinade/liquid-staking-referral-program/node_modules/ts-node/src/index.ts:439:23)
    at Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
    at Object.require.extensions.<computed> [as .ts] (/home/wantanabe/Marinade/liquid-staking-referral-program/node_modules/ts-node/src/index.ts:442:12)
    at Module.load (internal/modules/cjs/loader.js:950:32)
    at Function.Module._load (internal/modules/cjs/loader.js:790:12)
    at Module.require (internal/modules/cjs/loader.js:974:19)
    at require (internal/modules/cjs/helpers.js:93:18)
    at Object.exports.requireOrImport (/home/wantanabe/Marinade/liquid-staking-referral-program/node_modules/mocha/lib/nodejs/esm-utils.js:56:20)
    at Object.exports.loadFilesAsync (/home/wantanabe/Marinade/liquid-staking-referral-program/node_modules/mocha/lib/nodejs/esm-utils.js:88:20)
    at singleRun (/home/wantanabe/Marinade/liquid-staking-referral-program/node_modules/mocha/lib/cli/run-helpers.js:125:3)
    at Object.exports.handler (/home/wantanabe/Marinade/liquid-staking-referral-program/node_modules/mocha/lib/cli/run.js:374:5)
error Command failed with exit code 1.

Is there anyone who have resolved this sort of issue before?

Thank you!

fanatid commented 2 years ago

I guess this happens because StakeState is defined in the external crate. You can modify IDL in runtime before loading and add StakeState definition. But I can be wrong.

kAsky53 commented 2 years ago

@fanatid Thanks for your kind reply, however I am not sure how can I modify IDL in runtime especially when I am doing anchor test. Do you have any idea about this?

Thank you!

fanatid commented 2 years ago

You can build first anchor build, then modify IDL definitions and run tests without building anchor test --skip-build.

kAsky53 commented 2 years ago

Got it - thank you so much @fanatid !