Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 44 additions & 29 deletions code/anchor/testing-with-anchor/client/testing-with-anchor.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,41 +3,56 @@ const anchor = require("@project-serum/anchor");
const { SystemProgram } = anchor.web3;

describe("testing-with-anchor", () => {
const provider = anchor.Provider.env();
anchor.setProvider(provider);
const program = anchor.workspace.TestingWithAnchor;
const baseAccount = anchor.web3.Keypair.generate();
let provider;
let program;
let baseAccount;

before(async () => {
provider = anchor.Provider.env();
anchor.setProvider(provider);
program = anchor.workspace.TestingWithAnchor;
baseAccount = anchor.web3.Keypair.generate();
});

it("Is initialized!", async () => {
// call initialize!
let tx = await program.rpc.initialize(provider.wallet.publicKey, {
accounts: {
baseAccount: baseAccount.publicKey,
user: provider.wallet.publicKey,
systemProgram: SystemProgram.programId,
},
signers: [baseAccount],
});
console.log("Your transaction signature", tx);
try {
let tx = await program.rpc.initialize(provider.wallet.publicKey, {
accounts: {
baseAccount: baseAccount.publicKey,
user: provider.wallet.publicKey,
systemProgram: SystemProgram.programId,
},
signers: [baseAccount],
});
console.log("Your transaction signature", tx);
} catch (error) {
console.error("Error initializing:", error);
throw error;
}
});

it("Is incrementing!", async () => {
let account = await program.account.baseAccount.fetch(
baseAccount.publicKey
);
console.log("Count is", account.count.toString());
try {
let account = await program.account.baseAccount.fetch(
baseAccount.publicKey
);
console.log("Count is", account.count.toString());

// Call increment!
await program.rpc.increment({
accounts: {
baseAccount: baseAccount.publicKey,
authority: provider.wallet.publicKey,
},
});
// Call increment!
await program.rpc.increment({
accounts: {
baseAccount: baseAccount.publicKey,
authority: provider.wallet.publicKey,
},
});

let accountAfterIncrement = await program.account.baseAccount.fetch(
baseAccount.publicKey
);
console.log("Count is", accountAfterIncrement.count.toString());
let accountAfterIncrement = await program.account.baseAccount.fetch(
baseAccount.publicKey
);
console.log("Count is", accountAfterIncrement.count.toString());
} catch (error) {
console.error("Error incrementing:", error);
throw error;
}
});
});