Skip to content

Commit

Permalink
add tests for update_organization_wallet_v0
Browse files Browse the repository at this point in the history
  • Loading branch information
solanamonk committed May 31, 2024
1 parent f408c73 commit 04cea6e
Showing 1 changed file with 134 additions and 0 deletions.
134 changes: 134 additions & 0 deletions tests/organization-wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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/
);
}
});
});
});
});
});

0 comments on commit 04cea6e

Please sign in to comment.