Skip to content

Commit

Permalink
chore: ran pnpm fix
Browse files Browse the repository at this point in the history
  • Loading branch information
adpthegreat committed Oct 20, 2024
1 parent 6ed9dcb commit d291364
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 173 deletions.
4 changes: 2 additions & 2 deletions basics/counter/poseidon/counter_program/migrations/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
// single deploy script that's invoked from the CLI, injecting a provider
// configured from the workspace's Anchor.toml.

const anchor = require("@coral-xyz/anchor");
const anchor = require('@coral-xyz/anchor');

module.exports = async function (provider) {
module.exports = async (provider) => {
// Configure client to use the provider.
anchor.setProvider(provider);

Expand Down
70 changes: 24 additions & 46 deletions basics/counter/poseidon/counter_program/tests/bankrun.test.ts
Original file line number Diff line number Diff line change
@@ -1,33 +1,26 @@
import * as anchor from "@coral-xyz/anchor";
import { Keypair, PublicKey } from "@solana/web3.js";
import { BankrunProvider } from "anchor-bankrun";
import { assert } from "chai";
import { startAnchor } from "solana-bankrun";
import type { CounterProgram } from "../target/types/counter_program";

const IDL = require("../target/idl/counter_program.json");
import * as anchor from '@coral-xyz/anchor';
import { Keypair, PublicKey } from '@solana/web3.js';
import { BankrunProvider } from 'anchor-bankrun';
import { assert } from 'chai';
import { startAnchor } from 'solana-bankrun';
import type { CounterProgram } from '../target/types/counter_program';

const IDL = require('../target/idl/counter_program.json');
const PROGRAM_ID = new PublicKey(IDL.address);

describe("counter_program", async () => {
describe('counter_program', async () => {
// Configure the client to use the anchor-bankrun
const context = await startAnchor(
"",
[{ name: "counter_program", programId: PROGRAM_ID }],
[]
);
const context = await startAnchor('', [{ name: 'counter_program', programId: PROGRAM_ID }], []);

const provider = new BankrunProvider(context);

const payer = provider.wallet as anchor.Wallet;

const program = new anchor.Program<CounterProgram>(IDL, provider);

const [counterState, _] = anchor.web3.PublicKey.findProgramAddressSync(
[anchor.utils.bytes.utf8.encode("count")],
program.programId
);
const [counterState, _] = anchor.web3.PublicKey.findProgramAddressSync([anchor.utils.bytes.utf8.encode('count')], program.programId);

it("Initialize Counter", async () => {
it('Initialize Counter', async () => {
await program.methods
.initializeCounter()
.accounts({
Expand All @@ -37,68 +30,53 @@ describe("counter_program", async () => {

const currentCount = await program.account.counter.fetch(counterState);

assert(
currentCount.count.toNumber() === 0,
"Expected initialized count to be 0"
);
assert(currentCount.count.toNumber() === 0, 'Expected initialized count to be 0');
});

it("Increment Counter", async () => {
it('Increment Counter', async () => {
await program.methods.increment().accounts({}).rpc();

const currentCount = await program.account.counter.fetch(counterState);

assert(currentCount.count.toNumber() === 1, "Expected count to be 1");
assert(currentCount.count.toNumber() === 1, 'Expected count to be 1');
});

it("Increment Counter Again", async () => {
it('Increment Counter Again', async () => {
await program.methods.increment().accounts({ counter: counterState }).rpc();

const currentCount = await program.account.counter.fetch(counterState);

assert(currentCount.count.toNumber() === 2, "Expected count to be 2");
assert(currentCount.count.toNumber() === 2, 'Expected count to be 2');
});
it("Decrement counter", async () => {
it('Decrement counter', async () => {
await program.methods.decrement().accounts({}).rpc();

const currentCount = await program.account.counter.fetch(counterState);
assert(currentCount.count.toNumber() === 1, "Expected count to be 1");
assert(currentCount.count.toNumber() === 1, 'Expected count to be 1');
});
it("Increment and decrement multiple times", async () => {
it('Increment and decrement multiple times', async () => {
// Increment the counter 5 times
for (let i = 0; i < 5; i++) {
await program.methods.increment().accounts({}).rpc();
}

let currentCount = await program.account.counter.fetch(counterState);
assert.strictEqual(
currentCount.count.toNumber(),
6,
"Expected count to be 6 after 5 increments"
);
assert.strictEqual(currentCount.count.toNumber(), 6, 'Expected count to be 6 after 5 increments');

// Decrement the counter 4 times
for (let i = 0; i < 4; i++) {
await program.methods.decrement().accounts({}).rpc();
}

currentCount = await program.account.counter.fetch(counterState);
assert.strictEqual(
currentCount.count.toNumber(),
2,
"Expected count to be 2 after 4 decrements"
);
assert.strictEqual(currentCount.count.toNumber(), 2, 'Expected count to be 2 after 4 decrements');
});

it("Cannot decrement below 0", async () => {
it('Cannot decrement below 0', async () => {
// Decrement the counter to 0
await program.methods.decrement().accounts({}).rpc();
await program.methods.decrement().accounts({}).rpc();
const currentCount = await program.account.counter.fetch(counterState);
assert.strictEqual(
currentCount.count.toNumber(),
0,
"Expected count to be 0 after multiple decrements"
);
assert.strictEqual(currentCount.count.toNumber(), 0, 'Expected count to be 0 after multiple decrements');
});
});
152 changes: 49 additions & 103 deletions basics/counter/poseidon/counter_program/tests/counter_program.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import * as anchor from "@coral-xyz/anchor";
import { Program } from "@coral-xyz/anchor";
import { Keypair } from "@solana/web3.js";
import { assert } from "chai";
import { CounterProgram } from "../target/types/counter_program";
import * as anchor from '@coral-xyz/anchor';
import { Program } from '@coral-xyz/anchor';
import { Keypair } from '@solana/web3.js';
import { assert } from 'chai';
import { CounterProgram } from '../target/types/counter_program';

describe("counter_program", () => {
describe('counter_program', () => {
// Configure the client to use the local cluster.

const provider = anchor.AnchorProvider.env();
Expand All @@ -14,119 +14,65 @@ describe("counter_program", () => {

const program = anchor.workspace.CounterProgram as Program<CounterProgram>;

const [counterState, _] = anchor.web3.PublicKey.findProgramAddressSync(
[anchor.utils.bytes.utf8.encode("count")],
program.programId
);
const [counterState, _] = anchor.web3.PublicKey.findProgramAddressSync([anchor.utils.bytes.utf8.encode('count')], program.programId);

it("Initialize Counter", async () => {
it('Initialize Counter', async () => {
await program.methods
.initializeCounter()
.accounts({
payer: payer.publicKey,
})
.rpc();

const currentCount = await program.account.counter.fetch(
counterState
);
const currentCount = await program.account.counter.fetch(counterState);

assert(
currentCount.count.toNumber() === 0,
"Expected initialized count to be 0"
);
assert(currentCount.count.toNumber() === 0, 'Expected initialized count to be 0');
});

it('Increment Counter', async () => {
await program.methods.increment().accounts({}).rpc();

it("Increment Counter", async () => {
await program.methods
.increment()
.accounts({})
.rpc();

const currentCount = await program.account.counter.fetch(
counterState
);
const currentCount = await program.account.counter.fetch(counterState);

assert(currentCount.count.toNumber() === 1, "Expected count to be 1");
assert(currentCount.count.toNumber() === 1, 'Expected count to be 1');
});

it("Increment Counter Again", async () => {
await program.methods
.increment()
.accounts({ counter: counterState })
.rpc();
it('Increment Counter Again', async () => {
await program.methods.increment().accounts({ counter: counterState }).rpc();

const currentCount = await program.account.counter.fetch(
counterState
);
const currentCount = await program.account.counter.fetch(counterState);

assert(currentCount.count.toNumber() === 2, 'Expected count to be 2');
});
it('Decrement counter', async () => {
await program.methods.decrement().accounts({}).rpc();

const currentCount = await program.account.counter.fetch(counterState);
assert(currentCount.count.toNumber() === 1, 'Expected count to be 1');
});
it('Increment and decrement multiple times', async () => {
// Increment the counter 5 times
for (let i = 0; i < 5; i++) {
await program.methods.increment().accounts({}).rpc();
}

let currentCount = await program.account.counter.fetch(counterState);
assert.strictEqual(currentCount.count.toNumber(), 6, 'Expected count to be 6 after 5 increments');

// Decrement the counter 4 times
for (let i = 0; i < 4; i++) {
await program.methods.decrement().accounts({}).rpc();
}

currentCount = await program.account.counter.fetch(counterState);
assert.strictEqual(currentCount.count.toNumber(), 2, 'Expected count to be 2 after 4 decrements');
});

assert(currentCount.count.toNumber() === 2, "Expected count to be 2");
it('Cannot decrement below 0', async () => {
// Decrement the counter to 0
await program.methods.decrement().accounts({}).rpc();
await program.methods.decrement().accounts({}).rpc();
const currentCount = await program.account.counter.fetch(counterState);
assert.strictEqual(currentCount.count.toNumber(), 0, 'Expected count to be 0 after multiple decrements');
});
it("Decrement counter", async () => {
await program.methods
.decrement()
.accounts({})
.rpc();

const currentCount = await program.account.counter.fetch(
counterState
);
assert(currentCount.count.toNumber() === 1, "Expected count to be 1");
});
it("Increment and decrement multiple times", async () => {
// Increment the counter 5 times
for (let i = 0; i < 5; i++) {
await program.methods
.increment()
.accounts({})
.rpc();
}

let currentCount = await program.account.counter.fetch(
counterState
);
assert.strictEqual(
currentCount.count.toNumber(),
6,
"Expected count to be 6 after 5 increments"
);

// Decrement the counter 4 times
for (let i = 0; i < 4; i++) {
await program.methods
.decrement()
.accounts({})
.rpc();
}

currentCount = await program.account.counter.fetch(
counterState
);
assert.strictEqual(
currentCount.count.toNumber(),
2,
"Expected count to be 2 after 4 decrements"
);
});

it("Cannot decrement below 0", async () => {
// Decrement the counter to 0
await program.methods
.decrement()
.accounts({})
.rpc();
await program.methods
.decrement()
.accounts({})
.rpc();
const currentCount = await program.account.counter.fetch(
counterState
);
assert.strictEqual(
currentCount.count.toNumber(),
0,
"Expected count to be 0 after multiple decrements"
);
});
});
Original file line number Diff line number Diff line change
@@ -1,26 +1,23 @@
import { Account, Pubkey, Signer, u8, u64 } from '@solanaturbine/poseidon';

export interface Counter extends Account {
count: u64;
bump: u8;
}
export interface Counter extends Account {
count: u64;
bump: u8;
}

export default class counter_program {
static PROGRAM_ID = new Pubkey(
"EvcknV23Y3dkbSa4afZNGw2PgoowcfxCy4qvP8Ghogwu"
);
export default class counter_program {
static PROGRAM_ID = new Pubkey('EvcknV23Y3dkbSa4afZNGw2PgoowcfxCy4qvP8Ghogwu');

initializeCounter(counter: Counter, payer: Signer) {
counter.derive(["count"]).init();
counter.count = new u64(0);
}
increment(counter: Counter) {
counter.derive(["count"]);
counter.count = counter.count.add(1);
}
decrement(counter: Counter) {
counter.derive(["count"]);
counter.count = counter.count.sub(1);
}
}

initializeCounter(counter: Counter, payer: Signer) {
counter.derive(['count']).init();
counter.count = new u64(0);
}
increment(counter: Counter) {
counter.derive(['count']);
counter.count = counter.count.add(1);
}
decrement(counter: Counter) {
counter.derive(['count']);
counter.count = counter.count.sub(1);
}
}

0 comments on commit d291364

Please sign in to comment.