Skip to content

Commit

Permalink
more testing for change of owners and threshold atomic function
Browse files Browse the repository at this point in the history
  • Loading branch information
RyanHealey committed Dec 28, 2023
1 parent 9f00538 commit a7a072c
Show file tree
Hide file tree
Showing 3 changed files with 692 additions and 0 deletions.
75 changes: 75 additions & 0 deletions tests/multisigChangeThresholdTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,81 @@ describe("Test changing multisig threshold", async () => {
);
});

it("should not allow threshold to be changed by non multisig signer", async () => {
const ownerA = Keypair.generate();
const ownerB = Keypair.generate();
const ownerC = Keypair.generate();
const owners = [ownerA.publicKey, ownerB.publicKey, ownerC.publicKey];
const multisigSize = 200; // Big enough.
const threshold = new BN(2);

const multisig: MultisigAccount = await dsl.createMultisig(
owners,
multisigSize,
threshold
);

const newOwnerA = Keypair.generate();
const newOwnerB = Keypair.generate();
const newOwnerC = Keypair.generate();
const newOwners = [
newOwnerA.publicKey,
newOwnerB.publicKey,
newOwnerC.publicKey,
];

try {
// Attempt to change the multisig threshold
await program.methods
.changeThreshold(new BN(1))
.accounts({
multisig: multisig.address,
multisigSigner: multisig.signer,
})
.rpc();
fail("Should have failed to execute transaction");
} catch (e) {
assert.ok(e.message.includes("Signature verification failed"));
}

try {
// Attempt to change the multisig threshold with provider key as signer
await program.methods
.changeThreshold(new BN(1))
.accounts({
multisig: multisig.address,
multisigSigner: provider.publicKey,
})
.rpc();
fail("Should have failed to execute transaction");
} catch (e) {
assert.ok(
e.message.includes(
"Error Code: ConstraintSeeds. Error Number: 2006. Error Message: A seeds constraint was violated"
)
);
}

try {
// Attempt to change the multisig threshold with an owner key as signer
await program.methods
.changeThreshold(new BN(1))
.accounts({
multisig: multisig.address,
multisigSigner: ownerA.publicKey,
})
.signers([ownerA])
.rpc();
fail("Should have failed to execute transaction");
} catch (e) {
assert.ok(
e.message.includes(
"Error Code: ConstraintSeeds. Error Number: 2006. Error Message: A seeds constraint was violated"
)
);
}
});

// Threshold is of type u64, BN(-1) will actually be interpreted as 1
it("ignores negatives on updated threshold", async () => {
const ownerA = Keypair.generate();
Expand Down
Loading

0 comments on commit a7a072c

Please sign in to comment.