Adding tests for versioned transactions (#406)
This commit is contained in:
parent
129d6a830e
commit
78afa5d8a5
|
@ -21,7 +21,7 @@ use solana_lite_rpc_core::{
|
|||
};
|
||||
use solana_sdk::{
|
||||
compute_budget::{self, ComputeBudgetInstruction},
|
||||
transaction::{Transaction, VersionedTransaction},
|
||||
transaction::VersionedTransaction,
|
||||
};
|
||||
use tokio::{
|
||||
sync::mpsc::{self, Sender, UnboundedSender},
|
||||
|
@ -122,7 +122,7 @@ pub struct TransactionService {
|
|||
impl TransactionService {
|
||||
pub async fn send_transaction(
|
||||
&self,
|
||||
tx: Transaction,
|
||||
tx: VersionedTransaction,
|
||||
max_retries: Option<u16>,
|
||||
) -> anyhow::Result<String> {
|
||||
let raw_tx = bincode::serialize(&tx)?;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { Connection, Keypair, sendAndConfirmTransaction, Transaction, PublicKey, TransactionInstruction, BlockheightBasedTransactionConfirmationStrategy, TransactionMessage, VersionedTransaction } from "@solana/web3.js";
|
||||
import { Connection, Keypair, sendAndConfirmTransaction, Transaction, PublicKey, TransactionInstruction, BlockheightBasedTransactionConfirmationStrategy, TransactionMessage, VersionedTransaction, VersionedMessage, MessageV0 } from "@solana/web3.js";
|
||||
import * as fs from "fs";
|
||||
import * as os from "os";
|
||||
import * as crypto from "crypto";
|
||||
|
@ -24,10 +24,28 @@ function createTransaction(): Transaction {
|
|||
return transaction;
|
||||
}
|
||||
|
||||
function createVersionedMessage(blockhash: string, payer: PublicKey): MessageV0 {
|
||||
return new MessageV0({
|
||||
header: {
|
||||
numRequiredSignatures: 1,
|
||||
numReadonlySignedAccounts: 0,
|
||||
numReadonlyUnsignedAccounts: 0,
|
||||
},
|
||||
staticAccountKeys: [payer, MEMO_PROGRAM_ID],
|
||||
recentBlockhash: blockhash,
|
||||
compiledInstructions: [{
|
||||
programIdIndex: 1,
|
||||
accountKeyIndexes: [],
|
||||
data: Buffer.from(crypto.randomBytes(20).toString('hex')),
|
||||
}],
|
||||
addressTableLookups: [],
|
||||
})
|
||||
}
|
||||
|
||||
test('send and confirm transaction BlockheightBasedTransactionConfirmationStrategy', async () => {
|
||||
const tx = createTransaction();
|
||||
const { blockhash, lastValidBlockHeight } = await connection.getLatestBlockhash();
|
||||
const signature = await connection.sendTransaction(tx, [payer]);
|
||||
const signature = await connection.sendTransaction(tx, [payer], {});
|
||||
console.log(`https://explorer.solana.com/tx/${signature}`);
|
||||
await connection.confirmTransaction({
|
||||
blockhash,
|
||||
|
@ -45,6 +63,21 @@ test('send and confirm transaction legacy confrim', async () => {
|
|||
await connection.confirmTransaction(signature);
|
||||
});
|
||||
|
||||
test('send and confirm versioned transaction', async () => {
|
||||
const { blockhash, lastValidBlockHeight } = await connection.getLatestBlockhash();
|
||||
const message = createVersionedMessage(blockhash, payer.publicKey);
|
||||
let versionedTransaction = new VersionedTransaction( message, [payer.secretKey])
|
||||
versionedTransaction.sign([payer])
|
||||
const signature = await connection.sendRawTransaction(versionedTransaction.serialize(), {});
|
||||
console.log(`https://explorer.solana.com/tx/${signature}`);
|
||||
await connection.confirmTransaction({
|
||||
blockhash,
|
||||
lastValidBlockHeight,
|
||||
signature,
|
||||
abortSignal: undefined
|
||||
});
|
||||
});
|
||||
|
||||
test('send and confirm transaction', async () => {
|
||||
const tx = createTransaction();
|
||||
|
||||
|
|
Loading…
Reference in New Issue