|
1 | | -import * as anchor from "@coral-xyz/anchor"; |
2 | | -import { AnchorProgramExample } from "../target/types/anchor_program_example"; |
| 1 | +import * as anchor from "@coral-xyz/anchor" |
| 2 | +import { AnchorProgramExample } from "../target/types/anchor_program_example" |
| 3 | +import { |
| 4 | + Keypair, |
| 5 | + SystemProgram, |
| 6 | + Transaction, |
| 7 | + sendAndConfirmTransaction, |
| 8 | +} from "@solana/web3.js" |
3 | 9 |
|
4 | 10 | describe("Anchor example", () => { |
5 | | - const provider = anchor.AnchorProvider.env(); |
6 | | - anchor.setProvider(provider); |
| 11 | + const provider = anchor.AnchorProvider.env() |
| 12 | + anchor.setProvider(provider) |
7 | 13 | const program = anchor.workspace |
8 | | - .AnchorProgramExample as anchor.Program<AnchorProgramExample>; |
9 | | - const payer = provider.wallet as anchor.Wallet; |
| 14 | + .AnchorProgramExample as anchor.Program<AnchorProgramExample> |
| 15 | + const wallet = provider.wallet as anchor.Wallet |
10 | 16 |
|
11 | 17 | // We'll create this ahead of time. |
12 | 18 | // Our program will try to modify it. |
13 | | - const accountToChange = anchor.web3.Keypair.generate(); |
| 19 | + const accountToChange = new Keypair() |
14 | 20 | // Our program will create this. |
15 | | - const accountToCreate = anchor.web3.Keypair.generate(); |
| 21 | + const accountToCreate = new Keypair() |
16 | 22 |
|
17 | 23 | it("Create an account owned by our program", async () => { |
18 | | - let ix = anchor.web3.SystemProgram.createAccount({ |
| 24 | + let instruction = SystemProgram.createAccount({ |
19 | 25 | fromPubkey: provider.wallet.publicKey, |
20 | 26 | newAccountPubkey: accountToChange.publicKey, |
21 | 27 | lamports: await provider.connection.getMinimumBalanceForRentExemption(0), |
22 | 28 | space: 0, |
23 | 29 | programId: program.programId, // Our program |
24 | | - }); |
| 30 | + }) |
25 | 31 |
|
26 | | - await anchor.web3.sendAndConfirmTransaction( |
27 | | - provider.connection, |
28 | | - new anchor.web3.Transaction().add(ix), |
29 | | - [payer.payer, accountToChange] |
30 | | - ); |
31 | | - }); |
| 32 | + const transaction = new Transaction().add(instruction) |
| 33 | + |
| 34 | + await sendAndConfirmTransaction(provider.connection, transaction, [ |
| 35 | + wallet.payer, |
| 36 | + accountToChange, |
| 37 | + ]) |
| 38 | + }) |
32 | 39 |
|
33 | 40 | it("Check accounts", async () => { |
34 | 41 | await program.methods |
35 | 42 | .checkAccounts() |
36 | 43 | .accounts({ |
37 | | - payer: provider.wallet.publicKey, |
| 44 | + payer: wallet.publicKey, |
38 | 45 | accountToCreate: accountToCreate.publicKey, |
39 | 46 | accountToChange: accountToChange.publicKey, |
40 | | - systemProgram: anchor.web3.SystemProgram.programId, |
41 | 47 | }) |
42 | | - .signers([payer.payer]) |
43 | | - .rpc(); |
44 | | - }); |
45 | | -}); |
| 48 | + .rpc() |
| 49 | + }) |
| 50 | +}) |
0 commit comments