Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Testing the Multisig Program

Pre-alpha. The devnet pre-alpha is a mock network with no MPC. Read the warning in the introduction first.

Test Matrix (Mollusk)

Every negative test asserts the exact MultisigError code.

TestInstructionExpected Result
test_create_multisig_successCreateMultisig2-of-3 with correct fields at the canonical PDA
test_create_multisig_rejects_non_ownerCreateMultisigCustom(3) NotDWalletOwner
test_create_multisig_rejects_dwallet_not_owned_by_dwallet_programCreateMultisigCustom(4) InvalidDWalletAccount
test_create_multisig_zero_threshold_failsCreateMultisigCustom(5) InvalidThreshold
test_create_multisig_threshold_exceeds_members_failsCreateMultisigCustom(5) InvalidThreshold
test_create_multisig_rejects_duplicate_memberCreateMultisigCustom(6) DuplicateMember
test_create_multisig_rejects_non_canonical_addressCreateMultisigCustom(9) InvalidMultisig
test_create_transaction_successCreateTransactionMessage data stored, tx_index incremented
test_create_transaction_rejects_a_future_sign_flag_other_than_0_or_1CreateTransactionInvalidInstructionData
test_create_transaction_non_member_failsCreateTransactionCustom(0) NotAMember
test_create_transaction_rejects_forged_multisig_accountCreateTransactionCustom(9) InvalidMultisig
test_approve_successApproveapproval_count incremented, still Active
test_approve_double_vote_failsApproveApprovalRecord already exists
test_approve_non_member_failsApproveCustom(0) NotAMember
test_approve_rejects_transaction_of_another_multisigApproveCustom(8) TransactionMismatch
test_approve_at_threshold_rejects_wrong_dwalletApproveCustom(1) DWalletMismatch, before any CPI
test_reject_successRejectrejection_count incremented, still Active
test_reject_threshold_marks_rejectedReject2nd rejection → status=Rejected
test_reject_non_member_failsRejectCustom(0) NotAMember
test_vote_on_closed_transaction_failsApproveCustom(7) TransactionNotActive

All 20 tests run for both Pinocchio and Native variants.

Test Matrix (LiteSVM, real dWallet program)

TestExpected Result
test_multisig_full_lifecyclemultisig → transfer → propose → 2 approvals → SignatureVoucher created
test_multisig_issues_a_future_signature_voucher_owned_by_the_proposera transaction proposed as a future sign gets a FutureSignatureVoucher at the voucher PDA; its owner is the proposer and its signing key is the transaction’s user_pubkey
test_outsider_cannot_approve_or_recreate_multisigoutsider approval NotAMember; multisig (re)creation NotDWalletOwner
test_threshold_cannot_be_redirected_to_another_multisigs_dwalletattacker’s own 1-of-1 multisig reaching threshold with the victim’s dWallet as CPI target fails DWalletMismatch; no voucher for the victim
test_a_member_cannot_approve_twice_with_a_second_bumpa second approval with another valid approval-record bump fails InvalidBump (12); the count stays 1
test_a_member_cannot_reject_twice_with_a_second_bumpthe same for a rejection
test_create_transaction_refuses_a_non_canonical_transaction_bumpa transaction at a non-canonical bump fails InvalidBump; nothing is written there

The three bump tests failed against the program without the canonical-bump check, and pass with it. The Pinocchio and native variants run all seven. The Anchor variant runs the first four: Anchor derives every canonical bump itself.

Running Tests

# from the repository root
# SBF builds the tests load (the ika program itself is shipped in bin/)
cargo build-sbf --tools-version v1.54 --arch v3 --manifest-path examples/multisig/pinocchio/Cargo.toml
cargo build-sbf --tools-version v1.54 --arch v3 --manifest-path examples/multisig/native/Cargo.toml
cargo build-sbf --tools-version v1.54 --arch v3 --manifest-path examples/multisig/anchor/Cargo.toml

# Mollusk + LiteSVM
cargo test -p ika-example-multisig
cargo test -p ika-example-multisig-native
cargo test -p ika-example-multisig-anchor

Source

  • Pinocchio: examples/multisig/pinocchio/tests/{mollusk,litesvm}.rs
  • Native: examples/multisig/native/tests/{mollusk,litesvm}.rs
  • Anchor: examples/multisig/anchor/tests/litesvm.rs