solana-testcontainers
TypeScript icon, indicating that this package has built-in type declarations

0.2.5 • Public • Published

Provides a Docker image for running solana-test-validator in a container for toolchain isolation.

npm i -D solana-testcontainers @solana/web3.js
import { afterAll, beforeAll, expect, it } from '@jest/globals';
import { Connection, PublicKey } from '@solana/web3.js';

import { SolanaContainer, StartedSolanaContainer } from './index';

let container: StartedSolanaContainer;
let connection: Connection;

beforeAll(async () => {
  container = await new SolanaContainer().start();
  connection = container.connection;
});

afterAll(async () => {
  await container.stop();
});

it('should get block 0', async () => {
  const block = await connection.getBlock(0);
  expect(block).toMatchObject({
    blockHeight: 0,
    blockhash: expect.any(String),
  });
});

it('should fund address with 5129000000 lamports with confirmation', async () => {
  const publicKey = new PublicKey('Emp8JcXpFnCXzdWBC3ChRPtNQHiiQW6kr61wopT3hbNL');
  const lamports = 5_129_000_000;

  const block = await connection.getLatestBlockhash('processed');
  const signature = await connection.requestAirdrop(publicKey, lamports);
  await connection.confirmTransaction({ signature, ...block }, 'processed');

  const balance = await connection.getBalance(publicKey, 'processed');
  expect(balance).toStrictEqual(lamports);
});

Readme

Keywords

none

Package Sidebar

Install

npm i solana-testcontainers

Weekly Downloads

0

Version

0.2.5

License

MPL-2.0

Unpacked Size

21.7 kB

Total Files

6

Last publish

Collaborators

  • fuxingloh