Skip to content

metaDAOproject/spl-token-bankrun

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SPL Token Bankrun

Bankrun is a framework for writing very fast Solana and Anchor tests. However, it doesn't work natively with SPL token. This package bridges the gap, allowing you to easily manipulate SPL tokens from your Bankrun tests.

Example

import * as anchor from "@project-serum/anchor";
import * as token from "@solana/spl-token";
import { BankrunProvider } from "anchor-bankrun";

import { AutocratV0 } from "../target/types/autocrat_v0";
import * as AutocratIDL from "../target/idl/autocrat_v0.json";
export type AutocratProgram = Program<AutocratV0>;

import {
  createMint,
  createAccount,
  createAssociatedTokenAccount,
  mintTo,
  getAccount,
} from "spl-token-bankrun";


const AUTOCRAT_PROGRAM_ID = new PublicKey(
  "5QBbGKFSoL1hS4s5dsCBdNRVnJcMuHXFwhooKk2ar25S"
);

describe("autocrat_v0", async function () {
  let autocrat,
    payer,
    context,
    banksClient;

  before(async function () {
    context = await startAnchor("./", [], []);
    banksClient = context.banksClient;
    anchor.setProvider(new BankrunProvider(context));

    autocrat = new anchor.Program<AutocratProgram>(
      AutocratIDL,
      AUTOCRAT_PROGRAM_ID,
      provider
    );

    payer = autocrat.provider.wallet.payer;
  });

  describe("#initialize_dao", async function () {
    it("token stuff", async function () {
      const authority = anchor.web3.Keypair.generate();

      const mint = await createMint(banksClient, payer, authority.publicKey, authority.piblicKey, 9);

      const acc = await createAccount(
	banksClient,
	payer,
	mint,
	authority.publicKey
      );

      const storedAcc = await getAccount(
	banksClient,
	acc
      );
      
      console.log(storedAcc);
    });
  });
});