From 63c91dffd534cd9803e217c946fd32c061476f0b Mon Sep 17 00:00:00 2001 From: Solanamonk Date: Fri, 7 Jun 2024 11:50:34 +0200 Subject: [PATCH] resize organization wallet account on update --- .../update_organization_wallet_v0.rs | 10 +++++++- tests/organization-wallet.ts | 24 +++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/programs/organization_wallet/src/instructions/update_organization_wallet_v0.rs b/programs/organization_wallet/src/instructions/update_organization_wallet_v0.rs index 62ed125..e7f3544 100644 --- a/programs/organization_wallet/src/instructions/update_organization_wallet_v0.rs +++ b/programs/organization_wallet/src/instructions/update_organization_wallet_v0.rs @@ -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; @@ -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( @@ -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(()) } diff --git a/tests/organization-wallet.ts b/tests/organization-wallet.ts index fd19967..e935d28 100644 --- a/tests/organization-wallet.ts +++ b/tests/organization-wallet.ts @@ -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;