JSPM

@mitchcivic/phan-wallet-mock

0.1.1
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • 0
  • Score
    100M100P100Q21510F
  • License MIT

Mock version of Phantom Wallet. ONLY USE FOR TESTING!!!

Package Exports

  • @mitchcivic/phan-wallet-mock
  • @mitchcivic/phan-wallet-mock/dist/src/phan-wallet-mock.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@mitchcivic/phan-wallet-mock) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

phan-wallet-mock Build and Test

Mock version of Phantom Wallet. ONLY USE FOR TESTING!!!

export async function setupWithPayer(
  payer = Keypair.generate(),
  net = LOCALNET
): Promise<{ payer: Keypair; wallet: PhantomWalletMock }> {
  const wallet = PhantomWalletMock.create(net, payer, 'confirmed')

  // NOTE: no user approval needed
  await wallet.connect()
  const signature = await wallet.connection.requestAirdrop(
    payer.publicKey,
    LAMPORTS_PER_SOL * 5
  )
  // NOTE: no user approval needed here either
  await wallet.connection.confirmTransaction(signature)

  return { payer, wallet }
}

const { wallet, payer } = await setupWithPayer()

// NOTE: this only works when no actual Phantom extension is present as then `window.solana`
// cannot be overwritten
window.solana = wallet

assets/cypress.png

API

API documentation

How it Works

Unlike with real wallets phan-wallet-mock requires the user to provide a full Keypair which it uses under the hood to sign transactions and messages.

To do that it never requires the user's approval like the original does in order to ease testing.

THEREFORE MAKE SURE TO ONLY USE THIS WHILE RUNNING TESTS WITH FRESHLY GENERATED KEYPAIRS!!!

Apps using phan-wallet-mock

LICENSE

MIT