Skip to content

Commit

Permalink
add support for confirmTransaction using getSignatureStatus
Browse files Browse the repository at this point in the history
  • Loading branch information
heyAyushh committed Sep 10, 2024
1 parent 46b2424 commit d45fb1e
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
20 changes: 20 additions & 0 deletions src/lib/bankrun-context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,26 @@ export class BankrunConnection {
return signature;
}

async confirmTransaction(
signature: TransactionSignature,
_commitment?: Commitment
): Promise<RpcResponseAndContext<SignatureStatus | null>> {
const status = await this.getSignatureStatus(signature);

if (status.value === null) {
throw new Error('Transaction not found');
}

// In bankrun, if the transaction exists, it's always "finalized"
return {
context: status.context,
value: {
...status.value,
confirmationStatus: 'finalized',
},
};
}

private async updateSlotAndClock() {
const currentSlot = await this.getSlot();
const nextSlot = currentSlot + BigInt(1);
Expand Down
8 changes: 6 additions & 2 deletions tests/bankrun_test/tests/bankrun.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,23 @@ describe("bankrun_test", async () => {
[]
);
const provider = new BankrunProvider(context);
const wallet = provider.wallet as anchor.Wallet;
const bankrunContextWrapper = new BankrunContextWrapper(context);
const connection = bankrunContextWrapper.connection.toConnection();
const program = new anchor.Program<BankrunTest>(IDL, {
...provider,
connection: connection,
});
const wallet = provider.wallet;
const client = context.banksClient;

it("Is initialized!", async () => {
const { blockhash, lastValidBlockHeight } = await connection.getLatestBlockhash();
const ix = await program.methods.initialize().instruction();
const tx = new Transaction().add(ix);
const { blockhash, lastValidBlockHeight } = await connection.getLatestBlockhash();
tx.recentBlockhash = blockhash;
tx.feePayer = wallet.payer.publicKey;
tx.sign(wallet.payer);

const sig = await sendAndConfirmTransaction(connection, tx, [wallet.payer]);
const status = await client.getTransactionStatus(sig);

Expand Down

0 comments on commit d45fb1e

Please sign in to comment.