From 04cea6eb0b6c6c533106925a38e15d2d1d6420e4 Mon Sep 17 00:00:00 2001 From: Solanamonk Date: Fri, 31 May 2024 17:05:07 +0200 Subject: [PATCH] add tests for update_organization_wallet_v0 --- tests/organization-wallet.ts | 134 +++++++++++++++++++++++++++++++++++ 1 file changed, 134 insertions(+) diff --git a/tests/organization-wallet.ts b/tests/organization-wallet.ts index c1d3cf6..fd19967 100644 --- a/tests/organization-wallet.ts +++ b/tests/organization-wallet.ts @@ -4,6 +4,7 @@ import { Proposal } from "../target/types/proposal"; import { Organization } from "../target/types/organization"; import { OrganizationWallet } from "../target/types/organization_wallet"; import { + Keypair, PublicKey, SystemProgram, TransactionInstruction, @@ -236,6 +237,139 @@ describe("organization wallet", () => { }) ).rpc({ skipPreflight: true }); }); + + describe("update_organization_wallet_v0", () => { + let otherName; + let otherProposalConfig: PublicKey | undefined; + + beforeEach(async () => { + otherName = makeid(10); + + ({ + pubkeys: { proposalConfig: otherProposalConfig }, + } = await proposalProgram.methods + .initializeProposalConfigV0({ + name: otherName, + voteController: me, + stateController: me, + onVoteHook: PublicKey.default, + }) + .rpcAndKeys({ skipPreflight: true })); + }); + + it("should update the name", async () => { + await program.methods + .updateOrganizationWalletV0({ + name: otherName, + proposalConfigs: null, + }) + .accounts({ + organizationWallet, + organization, + authority: me, + }) + .rpc({ skipPreflight: true }); + + const acct = await program.account.organizationWalletV0.fetch( + organizationWallet! + ); + + expect(acct.index).to.eq(0); + expect(acct.name).to.eq(otherName); + expect(acct.proposalConfigs).to.have.length(1); + expect(acct.proposalConfigs[0].equals(proposalConfig!)).to.be; + }); + + it("should update proposal configs", async () => { + await program.methods + .updateOrganizationWalletV0({ + name: null, + proposalConfigs: [otherProposalConfig!], + }) + .accounts({ + organizationWallet, + organization, + authority: me, + }) + .rpc({ skipPreflight: true }); + + const acct = await program.account.organizationWalletV0.fetch( + organizationWallet! + ); + + expect(acct.index).to.eq(0); + expect(acct.name).to.eq("My Wallet"); + expect(acct.proposalConfigs).to.have.length(1); + expect(acct.proposalConfigs[0].equals(otherProposalConfig!)).to.be; + }); + + it("should fail if not the authority", async () => { + const authority = Keypair.generate().publicKey; + + await organizationProgram.methods + .updateOrganizationV0({ + authority, + defaultProposalConfig: null, + proposalProgram: null, + uri: null, + }) + .accounts({ + organization, + authority: me, + }) + .rpc({ skipPreflight: true }); + + try { + await program.methods + .updateOrganizationWalletV0({ + name: otherName, + proposalConfigs: [otherProposalConfig!], + }) + .accounts({ + organizationWallet, + organization, + authority: me, + }) + .simulate(); + } catch (err) { + expect(err.simulationResponse?.logs).to.match( + /caused by account: organization\..*ConstraintHasOne/ + ); + } + }); + + it("should fail if wrong organization", async () => { + const { + pubkeys: { organization: otherOrganization }, + } = await organizationProgram.methods + .initializeOrganizationV0({ + name: otherName, + authority: me, + defaultProposalConfig: proposalConfig!, + proposalProgram: proposalProgram.programId, + uri: "https://example.com", + }) + .rpcAndKeys({ skipPreflight: true }); + + try { + await program.methods + .updateOrganizationWalletV0({ + name: otherName, + proposalConfigs: [otherProposalConfig!], + }) + .accounts({ + organizationWallet, + organization: otherOrganization, + authority: me, + }) + .simulate(); + } catch (err) { + expect(err.simulationResponse?.logs).to.match( + /caused by account: organization_wallet\..*InvalidOrganization/ + ); + } + }); + }); }); }); });