Skip to content

Commit

Permalink
resize organization wallet account on update
Browse files Browse the repository at this point in the history
  • Loading branch information
solanamonk committed Jun 7, 2024
1 parent 04cea6e commit 63c91df
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::error::ErrorCode;
use crate::state::OrganizationWalletV0;
use crate::{resize_to_fit::resize_to_fit, state::OrganizationWalletV0};
use anchor_lang::prelude::*;
use organization::state::OrganizationV0;

Expand All @@ -25,6 +25,7 @@ pub struct UpdateOrganizationWalletV0<'info> {
)]
pub organization: Account<'info, OrganizationV0>,
pub authority: Signer<'info>,
pub system_program: Program<'info, System>,
}

pub fn handler(
Expand All @@ -37,5 +38,12 @@ pub fn handler(
if let Some(proposal_configs) = args.proposal_configs {
ctx.accounts.organization_wallet.proposal_configs = proposal_configs;
}

resize_to_fit(
&ctx.accounts.payer.to_account_info(),
&ctx.accounts.system_program.to_account_info(),
&ctx.accounts.organization_wallet,
)?;

Ok(())
}
24 changes: 24 additions & 0 deletions tests/organization-wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,30 @@ describe("organization wallet", () => {
expect(acct.proposalConfigs[0].equals(otherProposalConfig!)).to.be;
});

it("should resize proposal configs", async () => {
const proposalConfigs = Array.from({ length: 20 }).map(
() => Keypair.generate().publicKey
);

await program.methods
.updateOrganizationWalletV0({
name: null,
proposalConfigs,
})
.accounts({
organizationWallet,
organization,
authority: me,
})
.rpc({ skipPreflight: true });

const acct = await program.account.organizationWalletV0.fetch(
organizationWallet!
);

expect(acct.proposalConfigs).to.have.length(proposalConfigs.length);
});

it("should fail if not the authority", async () => {
const authority = Keypair.generate().publicKey;

Expand Down

0 comments on commit 63c91df

Please sign in to comment.