Skip to content

Commit d291364

Browse files
author
adpthegreat
committed
chore: ran pnpm fix
1 parent 6ed9dcb commit d291364

File tree

4 files changed

+94
-173
lines changed

4 files changed

+94
-173
lines changed

basics/counter/poseidon/counter_program/migrations/deploy.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
// single deploy script that's invoked from the CLI, injecting a provider
33
// configured from the workspace's Anchor.toml.
44

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

7-
module.exports = async function (provider) {
7+
module.exports = async (provider) => {
88
// Configure client to use the provider.
99
anchor.setProvider(provider);
1010

Lines changed: 24 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,26 @@
1-
import * as anchor from "@coral-xyz/anchor";
2-
import { Keypair, PublicKey } from "@solana/web3.js";
3-
import { BankrunProvider } from "anchor-bankrun";
4-
import { assert } from "chai";
5-
import { startAnchor } from "solana-bankrun";
6-
import type { CounterProgram } from "../target/types/counter_program";
7-
8-
const IDL = require("../target/idl/counter_program.json");
1+
import * as anchor from '@coral-xyz/anchor';
2+
import { Keypair, PublicKey } from '@solana/web3.js';
3+
import { BankrunProvider } from 'anchor-bankrun';
4+
import { assert } from 'chai';
5+
import { startAnchor } from 'solana-bankrun';
6+
import type { CounterProgram } from '../target/types/counter_program';
7+
8+
const IDL = require('../target/idl/counter_program.json');
99
const PROGRAM_ID = new PublicKey(IDL.address);
1010

11-
describe("counter_program", async () => {
11+
describe('counter_program', async () => {
1212
// Configure the client to use the anchor-bankrun
13-
const context = await startAnchor(
14-
"",
15-
[{ name: "counter_program", programId: PROGRAM_ID }],
16-
[]
17-
);
13+
const context = await startAnchor('', [{ name: 'counter_program', programId: PROGRAM_ID }], []);
1814

1915
const provider = new BankrunProvider(context);
2016

2117
const payer = provider.wallet as anchor.Wallet;
2218

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

25-
const [counterState, _] = anchor.web3.PublicKey.findProgramAddressSync(
26-
[anchor.utils.bytes.utf8.encode("count")],
27-
program.programId
28-
);
21+
const [counterState, _] = anchor.web3.PublicKey.findProgramAddressSync([anchor.utils.bytes.utf8.encode('count')], program.programId);
2922

30-
it("Initialize Counter", async () => {
23+
it('Initialize Counter', async () => {
3124
await program.methods
3225
.initializeCounter()
3326
.accounts({
@@ -37,68 +30,53 @@ describe("counter_program", async () => {
3730

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

40-
assert(
41-
currentCount.count.toNumber() === 0,
42-
"Expected initialized count to be 0"
43-
);
33+
assert(currentCount.count.toNumber() === 0, 'Expected initialized count to be 0');
4434
});
4535

46-
it("Increment Counter", async () => {
36+
it('Increment Counter', async () => {
4737
await program.methods.increment().accounts({}).rpc();
4838

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

51-
assert(currentCount.count.toNumber() === 1, "Expected count to be 1");
41+
assert(currentCount.count.toNumber() === 1, 'Expected count to be 1');
5242
});
5343

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

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

59-
assert(currentCount.count.toNumber() === 2, "Expected count to be 2");
49+
assert(currentCount.count.toNumber() === 2, 'Expected count to be 2');
6050
});
61-
it("Decrement counter", async () => {
51+
it('Decrement counter', async () => {
6252
await program.methods.decrement().accounts({}).rpc();
6353

6454
const currentCount = await program.account.counter.fetch(counterState);
65-
assert(currentCount.count.toNumber() === 1, "Expected count to be 1");
55+
assert(currentCount.count.toNumber() === 1, 'Expected count to be 1');
6656
});
67-
it("Increment and decrement multiple times", async () => {
57+
it('Increment and decrement multiple times', async () => {
6858
// Increment the counter 5 times
6959
for (let i = 0; i < 5; i++) {
7060
await program.methods.increment().accounts({}).rpc();
7161
}
7262

7363
let currentCount = await program.account.counter.fetch(counterState);
74-
assert.strictEqual(
75-
currentCount.count.toNumber(),
76-
6,
77-
"Expected count to be 6 after 5 increments"
78-
);
64+
assert.strictEqual(currentCount.count.toNumber(), 6, 'Expected count to be 6 after 5 increments');
7965

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

8571
currentCount = await program.account.counter.fetch(counterState);
86-
assert.strictEqual(
87-
currentCount.count.toNumber(),
88-
2,
89-
"Expected count to be 2 after 4 decrements"
90-
);
72+
assert.strictEqual(currentCount.count.toNumber(), 2, 'Expected count to be 2 after 4 decrements');
9173
});
9274

93-
it("Cannot decrement below 0", async () => {
75+
it('Cannot decrement below 0', async () => {
9476
// Decrement the counter to 0
9577
await program.methods.decrement().accounts({}).rpc();
9678
await program.methods.decrement().accounts({}).rpc();
9779
const currentCount = await program.account.counter.fetch(counterState);
98-
assert.strictEqual(
99-
currentCount.count.toNumber(),
100-
0,
101-
"Expected count to be 0 after multiple decrements"
102-
);
80+
assert.strictEqual(currentCount.count.toNumber(), 0, 'Expected count to be 0 after multiple decrements');
10381
});
10482
});
Lines changed: 49 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import * as anchor from "@coral-xyz/anchor";
2-
import { Program } from "@coral-xyz/anchor";
3-
import { Keypair } from "@solana/web3.js";
4-
import { assert } from "chai";
5-
import { CounterProgram } from "../target/types/counter_program";
1+
import * as anchor from '@coral-xyz/anchor';
2+
import { Program } from '@coral-xyz/anchor';
3+
import { Keypair } from '@solana/web3.js';
4+
import { assert } from 'chai';
5+
import { CounterProgram } from '../target/types/counter_program';
66

7-
describe("counter_program", () => {
7+
describe('counter_program', () => {
88
// Configure the client to use the local cluster.
99

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

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

17-
const [counterState, _] = anchor.web3.PublicKey.findProgramAddressSync(
18-
[anchor.utils.bytes.utf8.encode("count")],
19-
program.programId
20-
);
17+
const [counterState, _] = anchor.web3.PublicKey.findProgramAddressSync([anchor.utils.bytes.utf8.encode('count')], program.programId);
2118

22-
it("Initialize Counter", async () => {
19+
it('Initialize Counter', async () => {
2320
await program.methods
2421
.initializeCounter()
2522
.accounts({
2623
payer: payer.publicKey,
2724
})
2825
.rpc();
2926

30-
const currentCount = await program.account.counter.fetch(
31-
counterState
32-
);
27+
const currentCount = await program.account.counter.fetch(counterState);
3328

34-
assert(
35-
currentCount.count.toNumber() === 0,
36-
"Expected initialized count to be 0"
37-
);
29+
assert(currentCount.count.toNumber() === 0, 'Expected initialized count to be 0');
3830
});
3931

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

41-
it("Increment Counter", async () => {
42-
await program.methods
43-
.increment()
44-
.accounts({})
45-
.rpc();
46-
47-
const currentCount = await program.account.counter.fetch(
48-
counterState
49-
);
35+
const currentCount = await program.account.counter.fetch(counterState);
5036

51-
assert(currentCount.count.toNumber() === 1, "Expected count to be 1");
37+
assert(currentCount.count.toNumber() === 1, 'Expected count to be 1');
5238
});
5339

54-
it("Increment Counter Again", async () => {
55-
await program.methods
56-
.increment()
57-
.accounts({ counter: counterState })
58-
.rpc();
40+
it('Increment Counter Again', async () => {
41+
await program.methods.increment().accounts({ counter: counterState }).rpc();
5942

60-
const currentCount = await program.account.counter.fetch(
61-
counterState
62-
);
43+
const currentCount = await program.account.counter.fetch(counterState);
44+
45+
assert(currentCount.count.toNumber() === 2, 'Expected count to be 2');
46+
});
47+
it('Decrement counter', async () => {
48+
await program.methods.decrement().accounts({}).rpc();
49+
50+
const currentCount = await program.account.counter.fetch(counterState);
51+
assert(currentCount.count.toNumber() === 1, 'Expected count to be 1');
52+
});
53+
it('Increment and decrement multiple times', async () => {
54+
// Increment the counter 5 times
55+
for (let i = 0; i < 5; i++) {
56+
await program.methods.increment().accounts({}).rpc();
57+
}
58+
59+
let currentCount = await program.account.counter.fetch(counterState);
60+
assert.strictEqual(currentCount.count.toNumber(), 6, 'Expected count to be 6 after 5 increments');
61+
62+
// Decrement the counter 4 times
63+
for (let i = 0; i < 4; i++) {
64+
await program.methods.decrement().accounts({}).rpc();
65+
}
66+
67+
currentCount = await program.account.counter.fetch(counterState);
68+
assert.strictEqual(currentCount.count.toNumber(), 2, 'Expected count to be 2 after 4 decrements');
69+
});
6370

64-
assert(currentCount.count.toNumber() === 2, "Expected count to be 2");
71+
it('Cannot decrement below 0', async () => {
72+
// Decrement the counter to 0
73+
await program.methods.decrement().accounts({}).rpc();
74+
await program.methods.decrement().accounts({}).rpc();
75+
const currentCount = await program.account.counter.fetch(counterState);
76+
assert.strictEqual(currentCount.count.toNumber(), 0, 'Expected count to be 0 after multiple decrements');
6577
});
66-
it("Decrement counter", async () => {
67-
await program.methods
68-
.decrement()
69-
.accounts({})
70-
.rpc();
71-
72-
const currentCount = await program.account.counter.fetch(
73-
counterState
74-
);
75-
assert(currentCount.count.toNumber() === 1, "Expected count to be 1");
76-
});
77-
it("Increment and decrement multiple times", async () => {
78-
// Increment the counter 5 times
79-
for (let i = 0; i < 5; i++) {
80-
await program.methods
81-
.increment()
82-
.accounts({})
83-
.rpc();
84-
}
85-
86-
let currentCount = await program.account.counter.fetch(
87-
counterState
88-
);
89-
assert.strictEqual(
90-
currentCount.count.toNumber(),
91-
6,
92-
"Expected count to be 6 after 5 increments"
93-
);
94-
95-
// Decrement the counter 4 times
96-
for (let i = 0; i < 4; i++) {
97-
await program.methods
98-
.decrement()
99-
.accounts({})
100-
.rpc();
101-
}
102-
103-
currentCount = await program.account.counter.fetch(
104-
counterState
105-
);
106-
assert.strictEqual(
107-
currentCount.count.toNumber(),
108-
2,
109-
"Expected count to be 2 after 4 decrements"
110-
);
111-
});
112-
113-
it("Cannot decrement below 0", async () => {
114-
// Decrement the counter to 0
115-
await program.methods
116-
.decrement()
117-
.accounts({})
118-
.rpc();
119-
await program.methods
120-
.decrement()
121-
.accounts({})
122-
.rpc();
123-
const currentCount = await program.account.counter.fetch(
124-
counterState
125-
);
126-
assert.strictEqual(
127-
currentCount.count.toNumber(),
128-
0,
129-
"Expected count to be 0 after multiple decrements"
130-
);
131-
});
13278
});
Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,23 @@
11
import { Account, Pubkey, Signer, u8, u64 } from '@solanaturbine/poseidon';
22

3-
export interface Counter extends Account {
4-
count: u64;
5-
bump: u8;
6-
}
3+
export interface Counter extends Account {
4+
count: u64;
5+
bump: u8;
6+
}
77

8-
export default class counter_program {
9-
static PROGRAM_ID = new Pubkey(
10-
"EvcknV23Y3dkbSa4afZNGw2PgoowcfxCy4qvP8Ghogwu"
11-
);
8+
export default class counter_program {
9+
static PROGRAM_ID = new Pubkey('EvcknV23Y3dkbSa4afZNGw2PgoowcfxCy4qvP8Ghogwu');
1210

13-
initializeCounter(counter: Counter, payer: Signer) {
14-
counter.derive(["count"]).init();
15-
counter.count = new u64(0);
16-
}
17-
increment(counter: Counter) {
18-
counter.derive(["count"]);
19-
counter.count = counter.count.add(1);
20-
}
21-
decrement(counter: Counter) {
22-
counter.derive(["count"]);
23-
counter.count = counter.count.sub(1);
24-
}
25-
}
26-
11+
initializeCounter(counter: Counter, payer: Signer) {
12+
counter.derive(['count']).init();
13+
counter.count = new u64(0);
14+
}
15+
increment(counter: Counter) {
16+
counter.derive(['count']);
17+
counter.count = counter.count.add(1);
18+
}
19+
decrement(counter: Counter) {
20+
counter.derive(['count']);
21+
counter.count = counter.count.sub(1);
22+
}
23+
}

0 commit comments

Comments
 (0)