Skip to content

Commit

Permalink
fix(tests): use test-program-keypair in integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
vovacodes committed Nov 11, 2023
1 parent 14bcf9c commit 77686cc
Show file tree
Hide file tree
Showing 69 changed files with 541 additions and 139 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
],
"scripts": {
"build": "turbo run build",
"test": "turbo run build && anchor test",
"ts": "turbo run ts && yarn tsc --noEmit",
"deploy": "anchor deploy --provider.cluster mainnet-beta --provider.wallet .keys/upgrade-authority-staging-and-devnet.json --program-name multisig"
"test": "turbo run build && anchor test -- --features=testing && echo \"\n⚠️ Don't forget to recompile the .so file before deployment\n\"",
"pretest": "mkdir -p target/deploy && cp ./test-program-keypair.json ./target/deploy/squads_multisig_program-keypair.json",
"ts": "turbo run ts && yarn tsc --noEmit"
},
"devDependencies": {
"@solana/spl-token": "*",
Expand Down
1 change: 1 addition & 0 deletions programs/squads_multisig_program/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ no-entrypoint = []
no-idl = []
no-log-ix-name = []
cpi = ["no-entrypoint"]
testing = []
default = []

[dependencies]
Expand Down
4 changes: 4 additions & 0 deletions programs/squads_multisig_program/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,12 @@ security_txt! {
auditors: "OtterSec, Neodyme"
}

#[cfg(not(feature = "testing"))]
declare_id!("SQDS4ep65T869zMMBKyuUq6aD6EgTu8psMjkvj52pCf");

#[cfg(feature = "testing")]
declare_id!("GyhGAqjokLwF9UXdQ2dR5Zwiup242j4mX4J1tSMKyAmD");

#[program]
pub mod squads_multisig_program {
use super::*;
Expand Down
25 changes: 1 addition & 24 deletions sdk/multisig/.solitarc.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,33 +18,10 @@ const ignoredTypes = new Set([
"MessageAddressTableLookup",
]);

function loadKeypairFromFile(relativePath) {
try {
const absolutePath = path.join(__dirname, relativePath);
return Keypair.fromSecretKey(
Buffer.from(JSON.parse(readFileSync(absolutePath, "utf-8")))
);
} catch (error) {
console.error("Error reading keypair from file:", error);
return {
publicKey: {
toBase58: () => "SQDS4ep65T869zMMBKyuUq6aD6EgTu8psMjkvj52pCf",
},
};
}
}

const keypair = loadKeypairFromFile(
`../../target/deploy/${PROGRAM_NAME}-keypair.json`
);

const pubkey = keypair.publicKey.toBase58();
console.log("Generating SDK for Program ID:", pubkey);

module.exports = {
idlGenerator: "anchor",
programName: PROGRAM_NAME,
programId: pubkey,
programId: "SQDS4ep65T869zMMBKyuUq6aD6EgTu8psMjkvj52pCf",
idlDir,
sdkDir,
binaryInstallDir,
Expand Down
11 changes: 9 additions & 2 deletions sdk/multisig/src/instructions/batchAddTransaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
PublicKey,
TransactionMessage,
} from "@solana/web3.js";
import { createBatchAddTransactionInstruction } from "../generated";
import { createBatchAddTransactionInstruction, PROGRAM_ID } from "../generated";
import {
getBatchTransactionPda,
getProposalPda,
Expand All @@ -22,6 +22,7 @@ export function batchAddTransaction({
ephemeralSigners,
transactionMessage,
addressLookupTableAccounts,
programId = PROGRAM_ID,
}: {
vaultIndex: number;
multisigPda: PublicKey;
Expand All @@ -37,23 +38,28 @@ export function batchAddTransaction({
transactionMessage: TransactionMessage;
/** `AddressLookupTableAccount`s referenced in `transaction_message`. */
addressLookupTableAccounts?: AddressLookupTableAccount[];
programId?: PublicKey;
}) {
const [proposalPda] = getProposalPda({
multisigPda,
transactionIndex: batchIndex,
programId,
});
const [batchPda] = getTransactionPda({
multisigPda,
index: batchIndex,
programId,
});
const [batchTransactionPda] = getBatchTransactionPda({
multisigPda,
batchIndex,
transactionIndex,
programId,
});
const [vaultPda] = getVaultPda({
multisigPda,
index: vaultIndex,
programId,
});

const transactionMessageBytes =
Expand All @@ -77,6 +83,7 @@ export function batchAddTransaction({
ephemeralSigners,
transactionMessage: transactionMessageBytes,
},
}
},
programId
);
}
8 changes: 6 additions & 2 deletions sdk/multisig/src/instructions/batchCreate.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { PublicKey } from "@solana/web3.js";
import { createBatchCreateInstruction } from "../generated";
import { createBatchCreateInstruction, PROGRAM_ID } from "../generated";
import { getTransactionPda } from "../pda";

export function batchCreate({
Expand All @@ -9,6 +9,7 @@ export function batchCreate({
batchIndex,
vaultIndex,
memo,
programId = PROGRAM_ID,
}: {
multisigPda: PublicKey;
/** Member of the multisig that is creating the batch. */
Expand All @@ -18,10 +19,12 @@ export function batchCreate({
batchIndex: bigint;
vaultIndex: number;
memo?: string;
programId?: PublicKey;
}) {
const [batchPda] = getTransactionPda({
multisigPda,
index: batchIndex,
programId,
});

return createBatchCreateInstruction(
Expand All @@ -31,6 +34,7 @@ export function batchCreate({
rentPayer: rentPayer ?? creator,
batch: batchPda,
},
{ args: { vaultIndex, memo: memo ?? null } }
{ args: { vaultIndex, memo: memo ?? null } },
programId
);
}
26 changes: 18 additions & 8 deletions sdk/multisig/src/instructions/batchExecuteTransaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
import {
Batch,
createBatchExecuteTransactionInstruction,
PROGRAM_ID,
VaultBatchTransaction,
} from "../generated";
import {
Expand All @@ -23,34 +24,40 @@ export async function batchExecuteTransaction({
member,
batchIndex,
transactionIndex,
programId = PROGRAM_ID,
}: {
connection: Connection;
multisigPda: PublicKey;
member: PublicKey;
batchIndex: bigint;
transactionIndex: number;
programId?: PublicKey;
}): Promise<{
instruction: TransactionInstruction;
lookupTableAccounts: AddressLookupTableAccount[];
}> {
const [proposalPda] = getProposalPda({
multisigPda,
transactionIndex: batchIndex,
programId,
});
const [batchPda] = getTransactionPda({
multisigPda,
index: batchIndex,
programId,
});
const [batchTransactionPda] = getBatchTransactionPda({
multisigPda,
batchIndex,
transactionIndex,
programId,
});

const batchAccount = await Batch.fromAccountAddress(connection, batchPda);
const [vaultPda] = getVaultPda({
multisigPda,
index: batchAccount.vaultIndex,
programId,
});

const batchTransactionAccount =
Expand All @@ -69,14 +76,17 @@ export async function batchExecuteTransaction({
});

return {
instruction: createBatchExecuteTransactionInstruction({
multisig: multisigPda,
member,
proposal: proposalPda,
batch: batchPda,
transaction: batchTransactionPda,
anchorRemainingAccounts: accountMetas,
}),
instruction: createBatchExecuteTransactionInstruction(
{
multisig: multisigPda,
member,
proposal: proposalPda,
batch: batchPda,
transaction: batchTransactionPda,
anchorRemainingAccounts: accountMetas,
},
programId
),
lookupTableAccounts,
};
}
7 changes: 6 additions & 1 deletion sdk/multisig/src/instructions/configTransactionCreate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { PublicKey } from "@solana/web3.js";
import {
ConfigAction,
createConfigTransactionCreateInstruction,
PROGRAM_ID,
} from "../generated";
import { getTransactionPda } from "../pda";

Expand All @@ -12,6 +13,7 @@ export function configTransactionCreate({
rentPayer,
actions,
memo,
programId = PROGRAM_ID,
}: {
multisigPda: PublicKey;
/** Member of the multisig that is creating the transaction. */
Expand All @@ -21,10 +23,12 @@ export function configTransactionCreate({
transactionIndex: bigint;
actions: ConfigAction[];
memo?: string;
programId?: PublicKey;
}) {
const [transactionPda] = getTransactionPda({
multisigPda,
index: transactionIndex,
programId,
});

return createConfigTransactionCreateInstruction(
Expand All @@ -34,6 +38,7 @@ export function configTransactionCreate({
creator,
rentPayer: rentPayer ?? creator,
},
{ args: { actions, memo: memo ?? null } }
{ args: { actions, memo: memo ?? null } },
programId
);
}
38 changes: 24 additions & 14 deletions sdk/multisig/src/instructions/configTransactionExecute.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { PublicKey, SystemProgram } from "@solana/web3.js";
import { createConfigTransactionExecuteInstruction } from "../generated";
import {
createConfigTransactionExecuteInstruction,
PROGRAM_ID,
} from "../generated";
import { getProposalPda, getTransactionPda } from "../pda";

export function configTransactionExecute({
Expand All @@ -8,34 +11,41 @@ export function configTransactionExecute({
member,
rentPayer,
spendingLimits,
programId = PROGRAM_ID,
}: {
multisigPda: PublicKey;
transactionIndex: bigint;
member: PublicKey;
rentPayer?: PublicKey;
/** In case the transaction adds or removes SpendingLimits, pass the array of their Pubkeys here. */
spendingLimits?: PublicKey[];
programId?: PublicKey;
}) {
const [proposalPda] = getProposalPda({
multisigPda,
transactionIndex,
programId,
});
const [transactionPda] = getTransactionPda({
multisigPda,
index: transactionIndex,
programId,
});

return createConfigTransactionExecuteInstruction({
multisig: multisigPda,
member,
proposal: proposalPda,
transaction: transactionPda,
rentPayer,
systemProgram: SystemProgram.programId,
anchorRemainingAccounts: spendingLimits?.map((spendingLimit) => ({
pubkey: spendingLimit,
isWritable: true,
isSigner: false,
})),
});
return createConfigTransactionExecuteInstruction(
{
multisig: multisigPda,
member,
proposal: proposalPda,
transaction: transactionPda,
rentPayer,
systemProgram: SystemProgram.programId,
anchorRemainingAccounts: spendingLimits?.map((spendingLimit) => ({
pubkey: spendingLimit,
isWritable: true,
isSigner: false,
})),
},
programId
);
}
11 changes: 9 additions & 2 deletions sdk/multisig/src/instructions/multisigAddMember.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
import { PublicKey, SystemProgram } from "@solana/web3.js";
import { createMultisigAddMemberInstruction, Member } from "../generated";
import {
createMultisigAddMemberInstruction,
Member,
PROGRAM_ID,
} from "../generated";

export function multisigAddMember({
multisigPda,
configAuthority,
rentPayer,
newMember,
memo,
programId = PROGRAM_ID,
}: {
multisigPda: PublicKey;
configAuthority: PublicKey;
rentPayer: PublicKey;
newMember: Member;
memo?: string;
programId?: PublicKey;
}) {
return createMultisigAddMemberInstruction(
{
Expand All @@ -21,6 +27,7 @@ export function multisigAddMember({
rentPayer,
systemProgram: SystemProgram.programId,
},
{ args: { newMember, memo: memo ?? null } }
{ args: { newMember, memo: memo ?? null } },
programId
);
}
Loading

0 comments on commit 77686cc

Please sign in to comment.