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

Add remaining accounts test #2683

Merged

Conversation

Arrowana
Copy link
Contributor

It is quite common to have to rely on remaining accounts, add basic tests/misc/programs/remaining-accounts to cover usage

@vercel
Copy link

vercel bot commented Oct 24, 2023

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

A member of the Team first needs to authorize it.

@Arrowana Arrowana force-pushed the tests/add-remaining-accounts branch from a53d3f9 to 94917be Compare October 24, 2023 21:45
ts/yarn.lock Outdated Show resolved Hide resolved
@Arrowana Arrowana force-pushed the tests/add-remaining-accounts branch from 94917be to c500a1c Compare October 25, 2023 21:36
Copy link
Collaborator

@acheroncrypto acheroncrypto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have some tests that use remaining_accounts but they don't use Account::try_from. Thank you for covering this case too.

@acheroncrypto acheroncrypto merged commit 9331908 into coral-xyz:master Oct 25, 2023
47 checks passed
@Arrowana Arrowana deleted the tests/add-remaining-accounts branch October 25, 2023 23:33
@akuzni2
Copy link

akuzni2 commented Dec 4, 2024

Is it possible to make this compatible with a zero copy account?

for example this will not compile

use anchor_lang::prelude::*;
use anchor_spl::token::{Token, TokenAccount};

declare_id!("G1ZiJVXBjDkBY9R8UFKTS3cUC7YXjaxvu7XHMMKbBqVW");

#[program]
pub mod zero_copy_loader {
    use super::*;

    pub fn test_zero_copy_account<'c: 'info, 'info>(
        ctx: Context<'_, '_, 'c, 'info, TestZeroCopy>,
    ) -> Result<()> {

        let account_to_load = ctx.accounts.account.as_ref();
        let loader = AccountLoader::<Data>::try_from(account_to_load)?;

        Ok(())
    }
}

#[derive(Accounts)]
pub struct TestZeroCopy<'info> {
    pub account: AccountInfo<'info>, // also doesn't work when UncheckedAccount<'info> is used
}


#[account(zero_copy)]
pub struct Data {
    pub data: [u8; 32]
}

error: lifetime may not live long enough
--> programs/test_project/src/lib.rs:14:31
|
11 | ctx: Context<', ', 'c, 'info, TestZeroCopy>,
| ---
| |
| has type anchor_lang::context::Context<'_, '1, '_, '_, TestZeroCopy<'_>>
| has type anchor_lang::context::Context<'_, '_, '_, '_, TestZeroCopy<'2>>
...
14 | let account_to_load = ctx.accounts.account.as_ref();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ argument requires that '1 must outlive '2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants