Skip to content

Commit 6aa0b88

Browse files
committed
format code
1 parent 48b4ca5 commit 6aa0b88

File tree

3 files changed

+62
-104
lines changed

3 files changed

+62
-104
lines changed
Lines changed: 22 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,16 @@
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 { CounterProgramPoseidon } from "../target/types/counter_program_poseidon";
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 { CounterProgramPoseidon } from '../target/types/counter_program_poseidon';
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

@@ -25,7 +21,7 @@ describe("counter_program", async () => {
2521
// Generate a new keypair for the counter account
2622
const counterKeypair = new Keypair();
2723

28-
it("Initialize Counter", async () => {
24+
it('Initialize Counter', async () => {
2925
await program.methods
3026
.initializeCounter()
3127
.accounts({
@@ -35,44 +31,24 @@ describe("counter_program", async () => {
3531
})
3632
.rpc();
3733

38-
const currentCount = await program.account.counterState.fetch(
39-
counterKeypair.publicKey
40-
);
34+
const currentCount = await program.account.counterState.fetch(counterKeypair.publicKey);
4135

42-
assert(
43-
currentCount.count.toNumber() === 0,
44-
"Expected initialized count to be 0"
45-
);
36+
assert(currentCount.count.toNumber() === 0, 'Expected initialized count to be 0');
4637
});
4738

48-
it("Increment Counter", async () => {
49-
await program.methods
50-
.incrementCounter()
51-
.accounts({ counter: counterKeypair.publicKey })
52-
.rpc();
39+
it('Increment Counter', async () => {
40+
await program.methods.incrementCounter().accounts({ counter: counterKeypair.publicKey }).rpc();
5341

54-
const currentCount = await program.account.counterState.fetch(
55-
counterKeypair.publicKey
56-
);
42+
const currentCount = await program.account.counterState.fetch(counterKeypair.publicKey);
5743

58-
assert(currentCount.count.toNumber() === 1, "Expected count to be 1");
44+
assert(currentCount.count.toNumber() === 1, 'Expected count to be 1');
5945
});
6046

61-
it("Decrement Counter", async () => {
62-
await program.methods
63-
.decrementCounter()
64-
.accounts({ counter: counterKeypair.publicKey })
65-
.rpc();
47+
it('Decrement Counter', async () => {
48+
await program.methods.decrementCounter().accounts({ counter: counterKeypair.publicKey }).rpc();
6649

67-
const currentCount = await program.account.counterState.fetch(
68-
counterKeypair.publicKey
69-
);
50+
const currentCount = await program.account.counterState.fetch(counterKeypair.publicKey);
7051

71-
assert(
72-
currentCount.count.toNumber() === 0,
73-
"Expected count to be 0 after decrement"
74-
);
52+
assert(currentCount.count.toNumber() === 0, 'Expected count to be 0 after decrement');
7553
});
76-
77-
78-
});
54+
});
Lines changed: 20 additions & 33 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 { CounterProgramPoseidon } from "../target/types/counter_program_poseidon";
4-
import { Keypair } from "@solana/web3.js";
5-
import { assert } from "chai";
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 { CounterProgramPoseidon } from '../target/types/counter_program_poseidon';
66

7-
describe("counter", () => {
7+
describe('counter', () => {
88
// Configure the client to use the local cluster.
99
const provider = anchor.AnchorProvider.env();
1010
anchor.setProvider(provider);
@@ -14,7 +14,7 @@ describe("counter", () => {
1414
// Generate a new keypair for the counter account
1515
const counterKeypair = new Keypair();
1616

17-
it("Initializes the Counter", async () => {
17+
it('Initializes the Counter', async () => {
1818
// Initialize the counter state
1919
await program.methods
2020
.initializeCounter()
@@ -26,54 +26,41 @@ describe("counter", () => {
2626
.rpc();
2727

2828
// Fetch the current state of the counter
29-
const currentCount = await program.account.counterState.fetch(
30-
counterKeypair.publicKey
31-
);
29+
const currentCount = await program.account.counterState.fetch(counterKeypair.publicKey);
3230

33-
// Assert that the counter was initialized to 0
34-
assert(
35-
currentCount.count.toNumber() === 0,
36-
"Expected initialized count to be 0"
37-
);
31+
// Assert that the counter was initialized to 0
32+
assert(currentCount.count.toNumber() === 0, 'Expected initialized count to be 0');
3833
});
3934

40-
it("Increments the Counter", async () => {
35+
it('Increments the Counter', async () => {
4136
// Call the increment method
4237
await program.methods
4338
.incrementCounter()
4439
.accounts({
45-
counter: counterKeypair.publicKey
40+
counter: counterKeypair.publicKey,
4641
})
4742
.rpc();
4843

4944
// Fetch the updated counter state
50-
const currentCount = await program.account.counterState.fetch(
51-
counterKeypair.publicKey
52-
);
45+
const currentCount = await program.account.counterState.fetch(counterKeypair.publicKey);
5346

54-
// // Assert that the counter was incremented to 1
55-
assert(currentCount.count.toNumber() === 1, "Expected count to be 1");
56-
});
47+
// // Assert that the counter was incremented to 1
48+
assert(currentCount.count.toNumber() === 1, 'Expected count to be 1');
49+
});
5750

58-
it("Decrements the Counter", async () => {
51+
it('Decrements the Counter', async () => {
5952
// Decrement the counter
6053
await program.methods
6154
.decrementCounter()
6255
.accounts({
63-
counter: counterKeypair.publicKey
56+
counter: counterKeypair.publicKey,
6457
})
6558
.rpc();
6659

6760
// Fetch the updated counter state
68-
const currentCount = await program.account.counterState.fetch(
69-
counterKeypair.publicKey
70-
);
61+
const currentCount = await program.account.counterState.fetch(counterKeypair.publicKey);
7162

7263
// Assert that the counter was decremented to 1
73-
assert(
74-
currentCount.count.toNumber() === 1,
75-
"Expected count to be 1 after decrement"
76-
);
64+
assert(currentCount.count.toNumber() === 1, 'Expected count to be 1 after decrement');
7765
});
78-
7966
});
Lines changed: 20 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,26 @@
1-
import { Account, Pubkey, Result, i64, u8, Signer } from "@solanaturbine/poseidon";
1+
import { Account, Pubkey, Result, Signer, i64, u8 } from '@solanaturbine/poseidon';
22

33
export default class CounterProgramPoseidon {
4-
static PROGRAM_ID = new Pubkey("D5GsmVgazEnZ657NZJS4L6RcmnM8FkhR2qxyxcB4Whb3");
5-
6-
initializeCounter(counter: CounterState, user: Signer): Result {
7-
counter.derive(["count"])
8-
.init();
9-
// Set the initial value to the `count` field of the account
10-
counter.count = new i64(0);
11-
}
12-
13-
incrementCounter(counter: CounterState): Result {
14-
counter.derive(["count"]);
15-
counter.count = counter.count.add(1);
16-
}
17-
18-
decrementCounter(counter: CounterState): Result {
19-
counter.derive(["count"]);
20-
counter.count = counter.count.sub(1);
21-
}
4+
static PROGRAM_ID = new Pubkey('D5GsmVgazEnZ657NZJS4L6RcmnM8FkhR2qxyxcB4Whb3');
5+
6+
initializeCounter(counter: CounterState, user: Signer): Result {
7+
counter.derive(['count']).init();
8+
// Set the initial value to the `count` field of the account
9+
counter.count = new i64(0);
10+
}
11+
12+
incrementCounter(counter: CounterState): Result {
13+
counter.derive(['count']);
14+
counter.count = counter.count.add(1);
15+
}
16+
17+
decrementCounter(counter: CounterState): Result {
18+
counter.derive(['count']);
19+
counter.count = counter.count.sub(1);
20+
}
2221
}
2322

2423
export interface CounterState extends Account {
25-
count: i64; // This field store the counter result
26-
bump: u8; // bump is for PDA (program derieved account, a special type of account which controlled by program on Solana)
24+
count: i64; // This field store the counter result
25+
bump: u8; // bump is for PDA (program derieved account, a special type of account which controlled by program on Solana)
2726
}
28-
29-
30-
31-

0 commit comments

Comments
 (0)