Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Anchor IDL Does Not Support Calling RPCs With "Numbers" In The Handler Name #279

Closed
bonedaddy opened this issue May 12, 2021 · 4 comments
Closed
Labels
bug Something isn't working lang PRs welcome ts

Comments

@bonedaddy
Copy link
Contributor

Overview

Attempting to call anchor programs that have rpcs which include a number in the handler name. Attempting to call these functions results in the fallback function error (Fallback functions are not supported. If you have a use case, please file an issue.)

For example using the following program you will be unable to call test_log_1 or test_log_2:

use anchor_lang::prelude::*;

#[program]
pub mod margin {
    use super::*;
    pub fn initialize(ctx: Context<Initialize>) -> ProgramResult {
        Ok(())
    }
    pub fn test_log_1(ctx: Context<Initialize>) -> ProgramResult {
        msg!("{}", "a");
        Ok(())
    }
    pub fn test_log_2(ctx: Context<Initialize>) -> ProgramResult {
        msg!(format!("{}", "a").as_ref());
        Ok(())
    }
}

#[derive(Accounts)]
pub struct Initialize {}

Test code:

import * as anchor from '@project-serum/anchor';

describe('margin', () => {

  // Configure the client to use the local cluster.
  anchor.setProvider(anchor.Provider.env());
    // Add your test here.
    const program = anchor.workspace.Margin;
  it('Is initialized!', async () => {
    const tx = await program.rpc.initialize();
    console.log("Your transaction signature", tx);
  });
  it("tests log 1", async () => {
    await program.rpc.testLog1();
  })
  it("tests log 2", async () => {
    await program.rpc.testLog2();
  })
});

If you change the handler names to test_log_one and test_log_two everything works:

use anchor_lang::prelude::*;

#[program]
pub mod margin {
    use super::*;
    pub fn initialize(ctx: Context<Initialize>) -> ProgramResult {
        Ok(())
    }
    pub fn test_log_one(ctx: Context<Initialize>) -> ProgramResult {
        msg!("{}", "a");
        Ok(())
    }
    pub fn test_log_two(ctx: Context<Initialize>) -> ProgramResult {
        msg!(format!("{}", "a").as_ref());
        Ok(())
    }
}

#[derive(Accounts)]
pub struct Initialize {}

test code

import * as anchor from '@project-serum/anchor';

describe('margin', () => {

  // Configure the client to use the local cluster.
  anchor.setProvider(anchor.Provider.env());
    // Add your test here.
    const program = anchor.workspace.Margin;
  it('Is initialized!', async () => {
    const tx = await program.rpc.initialize();
    console.log("Your transaction signature", tx);
  });
  it("tests log 1", async () => {
    await program.rpc.testLogOne();
  })
  it("tests log 2", async () => {
    await program.rpc.testLogTwo();
  })
});

Version

anchor-cli 0.5.0

@callensm
Copy link
Member

this does not apply to instructions that don't have an underscore proceeding the number.

(i.e. my_ix5 workings properly, but my_ix_5 does not)

@barelooksrare
Copy link
Contributor

This issue occurs whenever a token containing a single case glyph after an underscore is converted to camel case.

Any name with an underscore preceding a number will be converted to the same camel case as with no underscore preceding the number, and therefore hashed as if no underscore preceded the number e.g. do_5_times -> do5Times -> do5_times

@GuidoDipietro
Copy link

Bug that might be related:

Naming an instruction hello1a will give Error: program.methods.hello1a is not a function when calling it from the TS client.

Removing the trailing a makes it work again.

@acheroncrypto acheroncrypto mentioned this issue Feb 25, 2024
@acheroncrypto
Copy link
Collaborator

Fixed in #2824.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working lang PRs welcome ts
Projects
None yet
Development

No branches or pull requests

6 participants