|
@@ -2,21 +2,46 @@ import * as anchor from "@project-serum/anchor";
|
|
|
import { AnchorProgramExample } from "../target/types/anchor_program_example";
|
|
|
|
|
|
describe("Anchor example", () => {
|
|
|
-
|
|
|
- // Configure the Anchor provider & load the program IDL
|
|
|
- // The IDL gives you a typescript module
|
|
|
- //
|
|
|
+
|
|
|
const provider = anchor.AnchorProvider.env();
|
|
|
anchor.setProvider(provider);
|
|
|
const program = anchor.workspace.AnchorProgramExample as anchor.Program<AnchorProgramExample>;
|
|
|
+ const payer = provider.wallet as anchor.Wallet;
|
|
|
+
|
|
|
+ // We'll create this ahead of time.
|
|
|
+ // Our program will try to modify it.
|
|
|
+ const accountToChange = anchor.web3.Keypair.generate();
|
|
|
+ // Our program will create this.
|
|
|
+ const accountToCreate = anchor.web3.Keypair.generate();
|
|
|
+
|
|
|
+ it("Create an account owned by our program", async () => {
|
|
|
+
|
|
|
+ let ix = anchor.web3.SystemProgram.createAccount({
|
|
|
+ fromPubkey: provider.wallet.publicKey,
|
|
|
+ newAccountPubkey: accountToChange.publicKey,
|
|
|
+ lamports: await provider.connection.getMinimumBalanceForRentExemption(0),
|
|
|
+ space: 0,
|
|
|
+ programId: program.programId, // Our program
|
|
|
+ });
|
|
|
+
|
|
|
+ await anchor.web3.sendAndConfirmTransaction(
|
|
|
+ provider.connection,
|
|
|
+ new anchor.web3.Transaction().add(ix),
|
|
|
+ [payer.payer, accountToChange]
|
|
|
+ );
|
|
|
+ });
|
|
|
|
|
|
- it("Test our example", async () => {
|
|
|
+ it("Check accounts", async () => {
|
|
|
|
|
|
- // Just run Anchor's IDL method to build a transaction!
|
|
|
- //
|
|
|
- await program.methods.hello()
|
|
|
- .accounts({})
|
|
|
- .rpc();
|
|
|
+ await program.methods.checkAccounts()
|
|
|
+ .accounts({
|
|
|
+ payer: provider.wallet.publicKey,
|
|
|
+ accountToCreate: accountToCreate.publicKey,
|
|
|
+ accountToChange: accountToChange.publicKey,
|
|
|
+ systemProgram: anchor.web3.SystemProgram.programId,
|
|
|
+ })
|
|
|
+ .signers([payer.payer])
|
|
|
+ .rpc();
|
|
|
|
|
|
});
|
|
|
});
|