1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- import * as anchor from "@coral-xyz/anchor"
- import { AnchorProgramExample } from "../target/types/anchor_program_example"
- import {
- Keypair,
- SystemProgram,
- Transaction,
- sendAndConfirmTransaction,
- } from "@solana/web3.js"
- describe("Anchor example", () => {
- const provider = anchor.AnchorProvider.env()
- anchor.setProvider(provider)
- const program = anchor.workspace
- .AnchorProgramExample as anchor.Program<AnchorProgramExample>
- const wallet = provider.wallet as anchor.Wallet
- // We'll create this ahead of time.
- // Our program will try to modify it.
- const accountToChange = new Keypair()
- // Our program will create this.
- const accountToCreate = new Keypair()
- it("Create an account owned by our program", async () => {
- let instruction = SystemProgram.createAccount({
- fromPubkey: provider.wallet.publicKey,
- newAccountPubkey: accountToChange.publicKey,
- lamports: await provider.connection.getMinimumBalanceForRentExemption(0),
- space: 0,
- programId: program.programId, // Our program
- })
- const transaction = new Transaction().add(instruction)
- await sendAndConfirmTransaction(provider.connection, transaction, [
- wallet.payer,
- accountToChange,
- ])
- })
- it("Check accounts", async () => {
- await program.methods
- .checkAccounts()
- .accounts({
- payer: wallet.publicKey,
- accountToCreate: accountToCreate.publicKey,
- accountToChange: accountToChange.publicKey,
- })
- .rpc()
- })
- })
|