lite-rpc/tests/main.test.ts

31 lines
1.1 KiB
TypeScript
Raw Normal View History

2022-12-03 21:30:11 -08:00
import { Connection, Keypair, LAMPORTS_PER_SOL, Message, VersionedTransaction } from "@solana/web3.js";
import { url } from "./urls";
2022-12-09 23:21:41 -08:00
jest.setTimeout(60000);
2022-12-03 21:30:11 -08:00
test('send and confirm transaction', async () => {
const connection = new Connection(url, 'confirmed');
const payer = Keypair.generate();
await connection.requestAirdrop(payer.publicKey, LAMPORTS_PER_SOL);
2022-12-03 23:05:04 -08:00
const recentBlockhash = (await connection.getLatestBlockhash('confirmed')).blockhash;
const versionedTx = new VersionedTransaction(
new Message({
header: {
numRequiredSignatures: 1,
numReadonlySignedAccounts: 0,
numReadonlyUnsignedAccounts: 0,
},
recentBlockhash,
instructions: [],
accountKeys: [payer.publicKey.toBase58()],
}),
);
2022-12-09 23:21:41 -08:00
2022-12-03 23:05:04 -08:00
versionedTx.sign([payer]);
const signature = await connection.sendTransaction(versionedTx);
const latestBlockHash = await connection.getLatestBlockhash();
await connection.confirmTransaction({
blockhash: latestBlockHash.blockhash,
lastValidBlockHeight: latestBlockHash.lastValidBlockHeight,
signature: signature,
});
2022-12-03 21:30:11 -08:00
});