From 699b6be3e05ccb8757475023aca288795c2519e6 Mon Sep 17 00:00:00 2001 From: shivam Date: Thu, 24 Oct 2024 20:21:31 +0530 Subject: [PATCH] lint with prettier --- .../poseidon/tests/bankrun.test.ts | 90 +++++++++---------- basics/close-account/poseidon/tests/test.ts | 90 ++++++++++--------- .../ts-programs/src/closeAccountProgram.ts | 32 +++---- 3 files changed, 107 insertions(+), 105 deletions(-) diff --git a/basics/close-account/poseidon/tests/bankrun.test.ts b/basics/close-account/poseidon/tests/bankrun.test.ts index 9137e8034..aa37b23ee 100644 --- a/basics/close-account/poseidon/tests/bankrun.test.ts +++ b/basics/close-account/poseidon/tests/bankrun.test.ts @@ -10,54 +10,54 @@ const IDL = require("../target/idl/close_account_program.json"); const PROGRAM_ID = new PublicKey(IDL.address); describe("close-account", async () => { - // Configure the client to use the local cluster. - const context = await startAnchor( - "", - [{ name: "close_account_program", programId: PROGRAM_ID }], - [], - ); - const provider = new BankrunProvider(context); + // Configure the client to use the local cluster. + const context = await startAnchor( + "", + [{ name: "close_account_program", programId: PROGRAM_ID }], + [] + ); + const provider = new BankrunProvider(context); - const payer = provider.wallet as anchor.Wallet; - const program = new anchor.Program(IDL, provider); - // Derive the PDA for the user's account. - const [userAccountAddress] = PublicKey.findProgramAddressSync( - [Buffer.from("user"), payer.publicKey.toBuffer()], - program.programId, - ); + const payer = provider.wallet as anchor.Wallet; + const program = new anchor.Program(IDL, provider); + // Derive the PDA for the user's account. + const [userAccountAddress] = PublicKey.findProgramAddressSync( + [Buffer.from("user"), payer.publicKey.toBuffer()], + program.programId + ); - it("Create Account", async () => { - await program.methods - .createUser() - .accounts({ - user: payer.publicKey, - }) - .rpc(); + it("Create Account", async () => { + await program.methods + .createUser() + .accounts({ + user: payer.publicKey, + }) + .rpc(); - // Fetch the account data - const userAccount = - await program.account.closeAccountState.fetch(userAccountAddress); - assert.equal(userAccount.user.toBase58(), payer.publicKey.toBase58()); - }); + // Fetch the account data + const userAccount = await program.account.closeAccountState.fetch( + userAccountAddress + ); + assert.equal(userAccount.user.toBase58(), payer.publicKey.toBase58()); + }); - it("Close Account", async () => { - await program.methods - .closeUser() - .accounts({ - user: payer.publicKey, - }) - .rpc(); + it("Close Account", async () => { + await program.methods + .closeUser() + .accounts({ + user: payer.publicKey, + }) + .rpc(); - // The account should no longer exist, returning null. - try { - const userAccount = - await program.account.closeAccountState.fetchNullable( - userAccountAddress, - ); - assert.equal(userAccount, null); - } catch (err) { - // Won't return null and will throw an error in anchor-bankrun' - assert.equal(err.message, `Could not find ${userAccountAddress}`); - } - }); + // The account should no longer exist, returning null. + try { + const userAccount = await program.account.closeAccountState.fetchNullable( + userAccountAddress + ); + assert.equal(userAccount, null); + } catch (err) { + // Won't return null and will throw an error in anchor-bankrun' + assert.equal(err.message, `Could not find ${userAccountAddress}`); + } + }); }); diff --git a/basics/close-account/poseidon/tests/test.ts b/basics/close-account/poseidon/tests/test.ts index 709848e18..18e68888f 100644 --- a/basics/close-account/poseidon/tests/test.ts +++ b/basics/close-account/poseidon/tests/test.ts @@ -5,48 +5,50 @@ import { PublicKey } from "@solana/web3.js"; import { CloseAccountProgram } from "../target/types/close_account_program"; describe("close_account", () => { - // Configure the client to use the local cluster. - - const provider = anchor.AnchorProvider.env(); - anchor.setProvider(provider); - - const program = anchor.workspace - .CloseAccountProgram as Program; - const payer = provider.wallet as anchor.Wallet; - - // Derive the PDA for the user's account. - const [userAccountAddress] = PublicKey.findProgramAddressSync( - [Buffer.from("user"), payer.publicKey.toBuffer()], - program.programId, - ); - - it("Create Account", async () => { - await program.methods - .createUser() - .accounts({ - user: payer.publicKey, - userAccount: userAccountAddress, - }) - .rpc(); - - // Fetch the account data - const userAccount = - await program.account.closeAccountState.fetch(userAccountAddress); - assert.equal(userAccount.user.toBase58(), payer.publicKey.toBase58()); - }); - - it("Close Account", async () => { - await program.methods - .closeUser() - .accounts({ - user: payer.publicKey, - userAccount: userAccountAddress, - }) - .rpc(); - - // The account should no longer exist, returning null. - const userAccount = - await program.account.closeAccountState.fetchNullable(userAccountAddress); - assert.equal(userAccount, null); - }); + // Configure the client to use the local cluster. + + const provider = anchor.AnchorProvider.env(); + anchor.setProvider(provider); + + const program = anchor.workspace + .CloseAccountProgram as Program; + const payer = provider.wallet as anchor.Wallet; + + // Derive the PDA for the user's account. + const [userAccountAddress] = PublicKey.findProgramAddressSync( + [Buffer.from("user"), payer.publicKey.toBuffer()], + program.programId + ); + + it("Create Account", async () => { + await program.methods + .createUser() + .accounts({ + user: payer.publicKey, + userAccount: userAccountAddress, + }) + .rpc(); + + // Fetch the account data + const userAccount = await program.account.closeAccountState.fetch( + userAccountAddress + ); + assert.equal(userAccount.user.toBase58(), payer.publicKey.toBase58()); + }); + + it("Close Account", async () => { + await program.methods + .closeUser() + .accounts({ + user: payer.publicKey, + userAccount: userAccountAddress, + }) + .rpc(); + + // The account should no longer exist, returning null. + const userAccount = await program.account.closeAccountState.fetchNullable( + userAccountAddress + ); + assert.equal(userAccount, null); + }); }); diff --git a/basics/close-account/poseidon/ts-programs/src/closeAccountProgram.ts b/basics/close-account/poseidon/ts-programs/src/closeAccountProgram.ts index b764a01f1..28d987cad 100644 --- a/basics/close-account/poseidon/ts-programs/src/closeAccountProgram.ts +++ b/basics/close-account/poseidon/ts-programs/src/closeAccountProgram.ts @@ -1,30 +1,30 @@ import { Account, Pubkey, Result, u8, Signer } from "@solanaturbine/poseidon"; export default class closeAccountProgram { - static PROGRAM_ID = new Pubkey( - "7U4SZvsUMjGYCwnzqGGE9enJactKhVPF2EaE7VHtBLTd", - ); + static PROGRAM_ID = new Pubkey( + "7U4SZvsUMjGYCwnzqGGE9enJactKhVPF2EaE7VHtBLTd" + ); - // create user account + // create user account - create_user(user_account: closeAccountState, user: Signer): Result { - user_account.derive(["user", user.key]).init(); + create_user(user_account: closeAccountState, user: Signer): Result { + user_account.derive(["user", user.key]).init(); - // Set the initial value to the `user_account` fields - user_account.user = user.key; - user_account.bump = user_account.getBump(); - } + // Set the initial value to the `user_account` fields + user_account.user = user.key; + user_account.bump = user_account.getBump(); + } - // close user account + // close user account - close_user(user_account: closeAccountState, user: Signer): Result { - user_account.close(user); - } + close_user(user_account: closeAccountState, user: Signer): Result { + user_account.close(user); + } } // setup the state export interface closeAccountState extends Account { - user: Pubkey; // This field store the user pub key - bump: u8; // bump is for PDA (program derieved account, a special type of account which controlled by program on Solana) + user: Pubkey; // This field store the user pub key + bump: u8; // bump is for PDA (program derieved account, a special type of account which controlled by program on Solana) }