From 75bff6c367ff8182f543134822a17122aaf58bec Mon Sep 17 00:00:00 2001 From: Memewtoo Date: Mon, 25 Nov 2024 11:55:09 +0800 Subject: [PATCH] chore: format fixes --- basics/counter/poseidon/package.json | 2 +- basics/counter/poseidon/tests/counter.ts | 65 +++++++------------ .../poseidon/ts-programs/src/counter.ts | 57 ++++++++-------- 3 files changed, 54 insertions(+), 70 deletions(-) diff --git a/basics/counter/poseidon/package.json b/basics/counter/poseidon/package.json index 04daffe1b..b036f2ff6 100644 --- a/basics/counter/poseidon/package.json +++ b/basics/counter/poseidon/package.json @@ -1,5 +1,5 @@ { - "license": "ISC", + "license": "ISC", "scripts": { "lint:fix": "prettier */*.js \"*/**/*{.js,.ts}\" -w", "lint": "prettier */*.js \"*/**/*{.js,.ts}\" --check" diff --git a/basics/counter/poseidon/tests/counter.ts b/basics/counter/poseidon/tests/counter.ts index bf2764b46..da278374b 100644 --- a/basics/counter/poseidon/tests/counter.ts +++ b/basics/counter/poseidon/tests/counter.ts @@ -1,10 +1,10 @@ -import * as anchor from "@coral-xyz/anchor"; -import { Program } from "@coral-xyz/anchor"; -import { Counter } from "../target/types/counter"; -import { Keypair, LAMPORTS_PER_SOL, PublicKey } from "@solana/web3.js"; -import { assert } from "chai"; +import * as anchor from '@coral-xyz/anchor'; +import { Program } from '@coral-xyz/anchor'; +import { Keypair, LAMPORTS_PER_SOL, PublicKey } from '@solana/web3.js'; +import { assert } from 'chai'; +import { Counter } from '../target/types/counter'; -describe("counter", () => { +describe('counter', () => { // Configure the client to use the local cluster. const provider = anchor.AnchorProvider.env(); anchor.setProvider(provider); @@ -21,10 +21,7 @@ describe("counter", () => { const latestBlockHash = await provider.connection.getLatestBlockhash(); // Airdrop 1 SOL to the user - const airdropUser = await provider.connection.requestAirdrop( - user.publicKey, - 1 * LAMPORTS_PER_SOL - ); + const airdropUser = await provider.connection.requestAirdrop(user.publicKey, 1 * LAMPORTS_PER_SOL); await provider.connection.confirmTransaction({ blockhash: latestBlockHash.blockhash, lastValidBlockHeight: latestBlockHash.lastValidBlockHeight, @@ -32,72 +29,60 @@ describe("counter", () => { }); // Derive PDA for the counter account - [counterPDA, counterBump] = PublicKey.findProgramAddressSync( - [Buffer.from("counter")], - program.programId - ); + [counterPDA, counterBump] = PublicKey.findProgramAddressSync([Buffer.from('counter')], program.programId); }); - it("Initializes a counter account", async () => { - + it('Initializes a counter account', async () => { // Invoke the Initialize Counter instruction from the program await program.methods .initializeCounter() .accountsPartial({ payer: user.publicKey, - counter: counterPDA + counter: counterPDA, }) .signers([user]) - .rpc() + .rpc(); // Fetch the counter account info const currentCounter = await program.account.counterAccount.fetch(counterPDA); - + // Assert and compare the account data - assert.equal(currentCounter.count.toNumber(), 0, "Expected count to be 0"); + assert.equal(currentCounter.count.toNumber(), 0, 'Expected count to be 0'); }); - it("Increments the counter account", async () => { - + it('Increments the counter account', async () => { // Invoke the Increment Counter instruction from the program await program.methods .incrementCounter() .accountsPartial({ payer: user.publicKey, - counter: counterPDA + counter: counterPDA, }) .signers([user]) - .rpc() - + .rpc(); + // Fetch the counter account info const currentCounter = await program.account.counterAccount.fetch(counterPDA); - + // Assert and compare the account data - assert.equal(currentCounter.count.toNumber(), 1, "Expected count to be 1"); + assert.equal(currentCounter.count.toNumber(), 1, 'Expected count to be 1'); }); - it("Increments the counter account again", async () => { - + it('Increments the counter account again', async () => { // Invoke the Increment Counter instruction from the program await program.methods .incrementCounter() .accountsPartial({ payer: user.publicKey, - counter: counterPDA + counter: counterPDA, }) .signers([user]) - .rpc() - + .rpc(); + // Fetch the counter account info const currentCounter = await program.account.counterAccount.fetch(counterPDA); - + // Assert and compare the account data - assert.equal(currentCounter.count.toNumber(), 2, "Expected count to be 2"); + assert.equal(currentCounter.count.toNumber(), 2, 'Expected count to be 2'); }); }); - - - - - - diff --git a/basics/counter/poseidon/ts-programs/src/counter.ts b/basics/counter/poseidon/ts-programs/src/counter.ts index 9f3433fa8..a2f6f17ca 100644 --- a/basics/counter/poseidon/ts-programs/src/counter.ts +++ b/basics/counter/poseidon/ts-programs/src/counter.ts @@ -1,43 +1,42 @@ -import { Account, Pubkey, Signer, u64, type Result } from "@solanaturbine/poseidon"; - +import { Account, Pubkey, type Result, Signer, u64 } from '@solanaturbine/poseidon'; export default class Counter { - static PROGRAM_ID = new Pubkey("GnL9WWgvnFbhvNedx6LTdPt4QeWXM4XdAtnRE4uToXdV"); + static PROGRAM_ID = new Pubkey('GnL9WWgvnFbhvNedx6LTdPt4QeWXM4XdAtnRE4uToXdV'); - // Initialize Counter instruction - initializeCounter( - // ACCOUNTS + // Initialize Counter instruction + initializeCounter( + // ACCOUNTS - payer: Signer, // user paying for the counter account creation - counter: CounterAccount, - ): Result { - // CONTEXT + payer: Signer, // user paying for the counter account creation + counter: CounterAccount, + ): Result { + // CONTEXT - // .derive([]) ensures that account is a PDA with the as the parameters - // .init() ensures that the account will have the init constraint when transpiled - counter.derive(["counter"]).init(); + // .derive([]) ensures that account is a PDA with the as the parameters + // .init() ensures that the account will have the init constraint when transpiled + counter.derive(['counter']).init(); - // Assign the initial value of the counter to 0 - counter.count = new u64(0); - } + // Assign the initial value of the counter to 0 + counter.count = new u64(0); + } - // Increment Counter Instruction - incrementCounter( - // ACCOUNTS + // Increment Counter Instruction + incrementCounter( + // ACCOUNTS - payer: Signer, // user payingfor incrementing the counter account - counter: CounterAccount, - ): Result { - // CONTEXT + payer: Signer, // user payingfor incrementing the counter account + counter: CounterAccount, + ): Result { + // CONTEXT - counter.derive(["counter"]); + counter.derive(['counter']); - // Increment the counter by 1 - counter.count = counter.count.add(1); - } + // Increment the counter by 1 + counter.count = counter.count.add(1); + } } // STATE export interface CounterAccount extends Account { - count: u64 -} \ No newline at end of file + count: u64; +}