Skip to content

Commit

Permalink
more testing for changing ownership and approvals and formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
RyanHealey committed Dec 28, 2023
1 parent dc7f2b7 commit 9f00538
Show file tree
Hide file tree
Showing 2 changed files with 135 additions and 1 deletion.
65 changes: 65 additions & 0 deletions tests/multisigChangeThresholdTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,71 @@ describe("Test changing multisig threshold", async () => {
);
});

it("should not allow threshold greater than number of owners", 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
);

// Create instruction to change multisig threshold
let newThreshold = new BN(4);
let transactionInstruction = await program.methods
.changeThreshold(newThreshold)
.accounts({
multisig: multisig.address,
multisigSigner: multisig.signer,
})
.instruction();

const transactionAddress: PublicKey = await dsl.proposeTransaction(
ownerA,
transactionInstruction,
multisig.address,
1000
);

await dsl.approveTransaction(ownerB, multisig.address, transactionAddress);
try {
await dsl.executeTransaction(
transactionAddress,
transactionInstruction,
multisig.signer,
multisig.address
);
fail("should have failed to execute transaction");
} catch (e) {
assert.ok(
e.message.includes(
"Error Code: InvalidThreshold. Error Number: 6007. Error Message: Threshold must be less than or equal to the number of owners and greater than 0"
)
);
}

let actualMultisig = await program.account.multisig.fetch(multisig.address);
assert.strictEqual(actualMultisig.nonce, multisig.nonce);
assert.ok(
threshold.eq(actualMultisig.threshold),
"Should not have updated threshold"
);
assert.deepStrictEqual(
actualMultisig.owners,
owners,
"Should not have updated owners"
);
assert.ok(
actualMultisig.ownerSetSeqno === 0,
"Should not have incremented owner set seq number"
);
});

// 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
71 changes: 70 additions & 1 deletion tests/mutisigSigningTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { describe } from "mocha";
import { ChildProcess } from "node:child_process";
import { fail } from "node:assert";

describe("Test performing transaction signed by the multisig", async () => {
describe("Test performing signing and execution", async () => {
let provider: AnchorProvider;
let program: Program;
let validatorProcess: ChildProcess;
Expand Down Expand Up @@ -285,4 +285,73 @@ describe("Test performing transaction signed by the multisig", async () => {
);
assert.strictEqual(afterBalance, 1_000_000_000);
});

it("should not allow non owner to sign", 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
);

// Fund the multisig signer account
await provider.sendAndConfirm(
new Transaction().add(
SystemProgram.transfer({
fromPubkey: provider.publicKey,
lamports: new BN(1_000_000_000),
toPubkey: multisig.signer,
})
)
);

// Create instruction to send funds from multisig
let transactionInstruction = SystemProgram.transfer({
fromPubkey: multisig.signer,
lamports: new BN(1_000_000_000),
toPubkey: provider.publicKey,
});

let beforeBalance = await provider.connection.getBalance(
multisig.signer,
"confirmed"
);
assert.strictEqual(beforeBalance, 1_000_000_000);

const transactionAddress: PublicKey = await dsl.proposeTransaction(
ownerA,
transactionInstruction,
multisig.address,
1000
);

const notAnOwner = Keypair.generate();

try {
//Attempt to sign with not an owner
await dsl.approveTransaction(
notAnOwner,
multisig.address,
transactionAddress
);
fail("Should have failed to approve transaction");
} catch (e) {
assert.ok(
e.message.includes(
"Error Code: InvalidOwner. Error Number: 6000. Error Message: The given owner is not part of this multisig"
)
);
}
let afterBalance = await provider.connection.getBalance(
multisig.signer,
"confirmed"
);
assert.strictEqual(afterBalance, 1_000_000_000);
});
});

0 comments on commit 9f00538

Please sign in to comment.