Skip to content

Commit

Permalink
lint with prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
shivamSspirit committed Oct 24, 2024
1 parent c7d9c92 commit 699b6be
Show file tree
Hide file tree
Showing 3 changed files with 107 additions and 105 deletions.
90 changes: 45 additions & 45 deletions basics/close-account/poseidon/tests/bankrun.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<CloseAccountProgram>(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<CloseAccountProgram>(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}`);
}
});
});
90 changes: 46 additions & 44 deletions basics/close-account/poseidon/tests/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<CloseAccountProgram>;
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<CloseAccountProgram>;
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);
});
});
Original file line number Diff line number Diff line change
@@ -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)
}

0 comments on commit 699b6be

Please sign in to comment.