Skip to content

Commit

Permalink
fix(tests): updates to test suite and helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
ogmedia committed Feb 3, 2023
1 parent c965d89 commit ffdbbe5
Show file tree
Hide file tree
Showing 11 changed files with 257 additions and 306 deletions.
2 changes: 1 addition & 1 deletion helpers/roles.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as anchor from "@project-serum/anchor";
import * as anchor from "@coral-xyz/anchor";
import { getIxPDA } from "@sqds/sdk";
import { SquadsMpl } from "../idl/squads_mpl";
import { Roles } from "../idl/roles";
Expand Down
32 changes: 32 additions & 0 deletions helpers/sdkExecute.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { createBlankTransaction } from "./transactions";

export const agnosticExecute = async (squads, txPDA, member) => {
try {
const executeIx = await squads.buildExecuteTransaction(txPDA, member.publicKey);
const executeTx = await createBlankTransaction(
squads.connection,
member.publicKey
);
executeTx.add(executeIx);
//get the latest blockhash and attach it to the transaction
const blockhash = await squads.connection.getLatestBlockhash();
executeTx.recentBlockhash = blockhash.blockhash;

// airdrop a small amount to member2 for feepaying
await squads.connection.requestAirdrop(member.publicKey, 1000000);
// sign the transaction on behalf of member2
await executeTx.sign(member);
// send the transaction
const sig = await squads.connection.sendRawTransaction(executeTx.serialize(), {
skipPreflight: true,
commitment: "confirmed",
});

await squads.connection.confirmTransaction(sig, "confirmed");
return sig;
} catch (e) {
console.log("unable to execute add member tx on behalf of ", member.publicKey.toBase58());
throw e;
}
};

23 changes: 1 addition & 22 deletions helpers/transactions.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as anchor from "@project-serum/anchor";
import * as anchor from "@coral-xyz/anchor";
import { Connection } from "@solana/web3.js";
import { getIxPDA } from "@sqds/sdk";
import { Mesh } from "../target/types/mesh";
Expand Down Expand Up @@ -53,29 +53,8 @@ async function _executeTransaction(
.map(({ pubkey, ixItem }) => {
const ixKeys: anchor.web3.AccountMeta[] =
ixItem.keys as anchor.web3.AccountMeta[];
const addSig = anchor.utils.sha256.hash("global:add_member");
const ixDiscriminator = Buffer.from(addSig, "hex");
const addData = Buffer.concat([ixDiscriminator.slice(0, 8)]);
const addAndThreshSig = anchor.utils.sha256.hash(
"global:add_member_and_change_threshold"
);
const ixAndThreshDiscriminator = Buffer.from(addAndThreshSig, "hex");
const addAndThreshData = Buffer.concat([
ixAndThreshDiscriminator.slice(0, 8),
]);
const ixData = ixItem.data as any;

const formattedKeys = ixKeys.map((ixKey, keyInd) => {
if (
(ixData.includes(addData) || ixData.includes(addAndThreshData)) &&
keyInd === 2
) {
return {
pubkey: feePayer,
isSigner: false,
isWritable: ixKey.isWritable,
};
}
return {
pubkey: ixKey.pubkey,
isSigner: false,
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"private": true,
"dependencies": {
"@project-serum/anchor": "^0.25.0",
"@coral-xyz/anchor": "^0.26.0",
"@solana/spl-token": "^0.3.7",
"@sqds/sdk": "^1.0.4",
"bn.js": "^5.2.1"
},
Expand Down
4 changes: 2 additions & 2 deletions sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
"build": "./build.sh"
},
"dependencies": {
"@project-serum/anchor": "^0.25.0",
"@solana/web3.js": "^1.53.0",
"@coral-xyz/anchor": "^0.26.0",
"@solana/web3.js": "^1.73.2",
"bn.js": "^5.2.1"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion sdk/src/address.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { PublicKey } from "@solana/web3.js";
import { utils } from "@project-serum/anchor";
import { utils } from "@coral-xyz/anchor";
import BN from "bn.js";

export const getMsPDA = (create_key: PublicKey, programId: PublicKey) =>
Expand Down
26 changes: 14 additions & 12 deletions sdk/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ import {
DEFAULT_PROGRAM_MANAGER_PROGRAM_ID,
} from "./constants";
import squadsMplJSON from "../../target/idl/squads_mpl.json";
import {SquadsMpl} from "../../target/types/squads_mpl";
import {SquadsMpl} from "../../idl/squads_mpl";
import programManagerJSON from "../../target/idl/program_manager.json";
import {ProgramManager} from "../../target/types/program_manager";
import {Wallet} from "@project-serum/anchor/dist/cjs/provider";
import {AnchorProvider, Program} from "@project-serum/anchor";
import {ProgramManager} from "../../idl/program_manager";
import {Wallet} from "@coral-xyz/anchor/dist/cjs/provider";
import {AnchorProvider, Program} from "@coral-xyz/anchor";
import {
InstructionAccount,
ManagedProgramAccount,
Expand All @@ -35,8 +35,9 @@ import {
getTxPDA,
} from "./address";
import BN from "bn.js";
import * as anchor from "@project-serum/anchor";
import * as anchor from "@coral-xyz/anchor";
import {TransactionBuilder} from "./tx_builder";
import { program } from "@coral-xyz/anchor/dist/cjs/native/system";

class Squads {
readonly connection: Connection;
Expand Down Expand Up @@ -171,25 +172,26 @@ class Squads {
);
}

async getMultisig(address: PublicKey): Promise<MultisigAccount> {
const accountData = await this.multisig.account.ms.fetch(address, "processed");
async getMultisig(address: PublicKey, commitment = "processed"): Promise<MultisigAccount> {
const accountData = await this.multisig.account.ms.fetch(address, commitment as Commitment);
return {...accountData, publicKey: address} as MultisigAccount;
}

async getMultisigs(
addresses: PublicKey[]
addresses: PublicKey[],
commitment = "processed"
): Promise<(MultisigAccount | null)[]> {
const accountData = await this.multisig.account.ms.fetchMultiple(addresses, "processed");
const accountData = await this.multisig.account.ms.fetchMultiple(addresses, commitment as Commitment);
return this._addPublicKeys(
accountData,
addresses
) as (MultisigAccount | null)[];
}

async getTransaction(address: PublicKey): Promise<TransactionAccount> {
async getTransaction(address: PublicKey, commitment = "processed"): Promise<TransactionAccount> {
const accountData = await this.multisig.account.msTransaction.fetch(
address,
"processed"
commitment as Commitment
);
return {...accountData, publicKey: address};
}
Expand All @@ -212,7 +214,7 @@ class Squads {
address,
"processed"
);
return {...accountData, publicKey: address};
return {...accountData, publicKey: address} as unknown as InstructionAccount;
}

async getInstructions(
Expand Down
4 changes: 2 additions & 2 deletions sdk/src/tx_builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import {
import { PublicKey, TransactionInstruction } from "@solana/web3.js";
import { getAuthorityPDA, getIxPDA, getTxPDA } from "./address";
import BN from "bn.js";
import { AnchorProvider } from "@project-serum/anchor";
import * as anchor from "@project-serum/anchor";
import { AnchorProvider } from "@coral-xyz/anchor";
import * as anchor from "@coral-xyz/anchor";

export class TransactionBuilder {
multisig: MultisigAccount;
Expand Down
8 changes: 4 additions & 4 deletions sdk/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { SquadsMpl } from "../../target/types/squads_mpl";
import { ProgramManager } from "../../target/types/program_manager";
import { Idl, IdlTypes, MethodsNamespace } from "@project-serum/anchor";
import { IdlTypeDef } from "@project-serum/anchor/dist/cjs/idl";
import { Idl, IdlTypes, MethodsNamespace } from "@coral-xyz/anchor";
import { IdlTypeDef } from "@coral-xyz/anchor/dist/cjs/idl";
import {
AllInstructions,
TypeDef,
} from "@project-serum/anchor/dist/cjs/program/namespace/types";
} from "@coral-xyz/anchor/dist/cjs/program/namespace/types";
import { PublicKey } from "@solana/web3.js";
import { MethodsBuilder } from "@project-serum/anchor/dist/cjs/program/namespace/methods";
import { MethodsBuilder } from "@coral-xyz/anchor/dist/cjs/program/namespace/methods";

// Copied (with slight modification) from @project-serum/anchor/src/program/namespace/types (not exported)
type TypeDefDictionary<T extends IdlTypeDef[], Defined> = {
Expand Down
Loading

0 comments on commit ffdbbe5

Please sign in to comment.