2021-12-15 15:11:41 -08:00
|
|
|
const assert = require("assert");
|
2022-12-16 05:21:50 -08:00
|
|
|
const anchor = require("@coral-xyz/anchor");
|
2021-09-02 16:29:25 -07:00
|
|
|
const { SystemProgram } = anchor.web3;
|
2021-04-09 09:34:55 -07:00
|
|
|
|
2021-12-15 15:11:41 -08:00
|
|
|
describe("basic-2", () => {
|
2022-04-11 12:48:58 -07:00
|
|
|
const provider = anchor.AnchorProvider.local();
|
2021-03-01 01:25:59 -08:00
|
|
|
|
|
|
|
// Configure the client to use the local cluster.
|
2021-12-15 15:11:41 -08:00
|
|
|
anchor.setProvider(provider);
|
2021-03-01 01:25:59 -08:00
|
|
|
|
|
|
|
// Counter for the tests.
|
2021-12-15 15:11:41 -08:00
|
|
|
const counter = anchor.web3.Keypair.generate();
|
2021-03-01 01:25:59 -08:00
|
|
|
|
|
|
|
// Program for the tests.
|
2021-12-15 15:11:41 -08:00
|
|
|
const program = anchor.workspace.Basic2;
|
2021-03-01 01:25:59 -08:00
|
|
|
|
2021-12-15 15:11:41 -08:00
|
|
|
it("Creates a counter", async () => {
|
2022-10-28 04:12:38 -07:00
|
|
|
await program.methods
|
|
|
|
.create(provider.wallet.publicKey)
|
|
|
|
.accounts({
|
2021-03-01 01:25:59 -08:00
|
|
|
counter: counter.publicKey,
|
2021-09-02 16:29:25 -07:00
|
|
|
user: provider.wallet.publicKey,
|
|
|
|
systemProgram: SystemProgram.programId,
|
2022-10-28 04:12:38 -07:00
|
|
|
})
|
|
|
|
.signers([counter])
|
|
|
|
.rpc();
|
2021-03-01 01:25:59 -08:00
|
|
|
|
2021-12-15 15:11:41 -08:00
|
|
|
let counterAccount = await program.account.counter.fetch(counter.publicKey);
|
2021-03-01 01:25:59 -08:00
|
|
|
|
2021-12-15 15:11:41 -08:00
|
|
|
assert.ok(counterAccount.authority.equals(provider.wallet.publicKey));
|
|
|
|
assert.ok(counterAccount.count.toNumber() === 0);
|
|
|
|
});
|
2021-03-01 01:25:59 -08:00
|
|
|
|
2021-12-15 15:11:41 -08:00
|
|
|
it("Updates a counter", async () => {
|
2022-10-28 04:12:38 -07:00
|
|
|
await program.methods
|
|
|
|
.increment()
|
|
|
|
.accounts({
|
2021-03-01 01:25:59 -08:00
|
|
|
counter: counter.publicKey,
|
|
|
|
authority: provider.wallet.publicKey,
|
2022-10-28 04:12:38 -07:00
|
|
|
})
|
|
|
|
.rpc();
|
2021-03-01 01:25:59 -08:00
|
|
|
|
2021-12-15 15:11:41 -08:00
|
|
|
const counterAccount = await program.account.counter.fetch(
|
|
|
|
counter.publicKey
|
|
|
|
);
|
2021-03-01 01:25:59 -08:00
|
|
|
|
2021-12-15 15:11:41 -08:00
|
|
|
assert.ok(counterAccount.authority.equals(provider.wallet.publicKey));
|
|
|
|
assert.ok(counterAccount.count.toNumber() == 1);
|
|
|
|
});
|
|
|
|
});
|