|
1 | | -import * as anchor from "@coral-xyz/anchor"; |
2 | | -import { Program } from "@coral-xyz/anchor"; |
3 | | -import { TransferSolProgram } from "../target/types/transfer_sol_program"; |
4 | | -import { Keypair, LAMPORTS_PER_SOL, type PublicKey } from '@solana/web3.js'; |
5 | | - |
6 | | -describe("transfer-sol", () => { |
7 | | - // Configure the client to use the local cluster. |
8 | | - const provider = anchor.AnchorProvider.env(); |
9 | | - |
10 | | - anchor.setProvider(provider); |
11 | | - |
12 | | - const payer = provider.wallet as anchor.Wallet; |
13 | | - const program = anchor.workspace.CreateAccount as Program<TransferSolProgram>; |
14 | | - const transferAmount = 1 * LAMPORTS_PER_SOL; |
15 | | - const recipient = new Keypair(); |
16 | | - |
17 | | - it("It transfer sol!", async () => { |
18 | | - |
19 | | - await getBalances(payer.publicKey, recipient.publicKey, 'Beginning'); |
20 | | - |
21 | | - // Add your test here. |
22 | | - const tx = await program.methods.initialize(new anchor.BN(transferAmount)).accounts({ |
23 | | - sender: payer.publicKey, |
24 | | - receiver: recipient.publicKey |
25 | | - }).rpc(); |
26 | | - |
27 | | - console.log("Your transaction signature", tx); |
28 | | - |
29 | | - await getBalances(payer.publicKey, recipient.publicKey, 'Resulting'); |
30 | | - |
31 | | - |
32 | | - }); |
33 | | - |
34 | | - async function getBalances(payerPubkey: PublicKey, recipientPubkey: PublicKey, timeframe: string) { |
35 | | - const payerBalance = await provider.connection.getBalance(payerPubkey); |
36 | | - const recipientBalance = await provider.connection.getBalance(recipientPubkey); |
37 | | - console.log(`${timeframe} balances:`); |
38 | | - console.log(` Payer: ${payerBalance / LAMPORTS_PER_SOL}`); |
39 | | - console.log(` Recipient: ${recipientBalance / LAMPORTS_PER_SOL}`); |
40 | | - } |
| 1 | +import * as anchor from '@coral-xyz/anchor'; |
| 2 | +import { Program } from '@coral-xyz/anchor'; |
| 3 | +import { Keypair, LAMPORTS_PER_SOL, type PublicKey } from '@solana/web3.js'; |
| 4 | +import { TransferSolProgram } from '../target/types/transfer_sol_program'; |
| 5 | + |
| 6 | +describe('transfer-sol', () => { |
| 7 | + // Configure the client to use the local cluster. |
| 8 | + const provider = anchor.AnchorProvider.env(); |
| 9 | + |
| 10 | + anchor.setProvider(provider); |
| 11 | + |
| 12 | + const payer = provider.wallet as anchor.Wallet; |
| 13 | + const program = anchor.workspace.CreateAccount as Program<TransferSolProgram>; |
| 14 | + const transferAmount = 1 * LAMPORTS_PER_SOL; |
| 15 | + const recipient = new Keypair(); |
| 16 | + |
| 17 | + it('It transfer sol!', async () => { |
| 18 | + await getBalances(payer.publicKey, recipient.publicKey, 'Beginning'); |
| 19 | + |
| 20 | + // Add your test here. |
| 21 | + const tx = await program.methods |
| 22 | + .initialize(new anchor.BN(transferAmount)) |
| 23 | + .accounts({ |
| 24 | + sender: payer.publicKey, |
| 25 | + receiver: recipient.publicKey, |
| 26 | + }) |
| 27 | + .rpc(); |
| 28 | + |
| 29 | + console.log('Your transaction signature', tx); |
| 30 | + |
| 31 | + await getBalances(payer.publicKey, recipient.publicKey, 'Resulting'); |
| 32 | + }); |
| 33 | + |
| 34 | + async function getBalances(payerPubkey: PublicKey, recipientPubkey: PublicKey, timeframe: string) { |
| 35 | + const payerBalance = await provider.connection.getBalance(payerPubkey); |
| 36 | + const recipientBalance = await provider.connection.getBalance(recipientPubkey); |
| 37 | + console.log(`${timeframe} balances:`); |
| 38 | + console.log(` Payer: ${payerBalance / LAMPORTS_PER_SOL}`); |
| 39 | + console.log(` Recipient: ${recipientBalance / LAMPORTS_PER_SOL}`); |
| 40 | + } |
41 | 41 | }); |
42 | | - |
0 commit comments