Skip to content

Commit

Permalink
fix:ran pnpm fix
Browse files Browse the repository at this point in the history
  • Loading branch information
adpthegreat committed Oct 23, 2024
1 parent d3734fe commit 55d896f
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
// single deploy script that's invoked from the CLI, injecting a provider
// configured from the workspace's Anchor.toml.

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

module.exports = async function (provider) {
module.exports = async (provider) => {
// Configure client to use the provider.
anchor.setProvider(provider);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,33 +1,26 @@
import assert from "node:assert";
import { describe, it } from "node:test";
import * as anchor from "@coral-xyz/anchor";
import { PublicKey } from "@solana/web3.js";
import { BankrunProvider } from "anchor-bankrun";
import { startAnchor } from "solana-bankrun";
import type { CloseAccountProgram } from "../target/types/close_account_program";
import assert from 'node:assert';
import { describe, it } from 'node:test';
import * as anchor from '@coral-xyz/anchor';
import { PublicKey } from '@solana/web3.js';
import { BankrunProvider } from 'anchor-bankrun';
import { startAnchor } from 'solana-bankrun';
import type { CloseAccountProgram } from '../target/types/close_account_program';

const IDL = require("../target/idl/close_account_program.json");
const IDL = require('../target/idl/close_account_program.json');
const PROGRAM_ID = new PublicKey(IDL.address);

describe("Close an account", async () => {
describe('Close an account', async () => {
// Configure the client to use the local cluster.
const context = await startAnchor(
"",
[{ name: "close_account", programId: PROGRAM_ID }],
[]
);
const context = await startAnchor('', [{ name: 'close_account', 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 [userAccountAddress] = PublicKey.findProgramAddressSync([Buffer.from('USER'), payer.publicKey.toBuffer()], program.programId);

it("Can create an account", async () => {
const userId = anchor.BN(76362)
it('Can create an account', async () => {
const userId = anchor.BN(76362);
await program.methods
.createUser(userId)
.accounts({
Expand All @@ -36,13 +29,11 @@ describe("Close an account", async () => {
.rpc();

// Fetch the account data
const userAccount = await program.account.userAccount.fetch(
userAccountAddress
);
assert.notEqual(userAccount, null);
const userAccount = await program.account.userAccount.fetch(userAccountAddress);
assert.notEqual(userAccount, null);
});

it("Can close an Account", async () => {
it('Can close an Account', async () => {
await program.methods
.closeUser()
.accounts({
Expand All @@ -52,9 +43,7 @@ describe("Close an account", async () => {

// The account should no longer exist, returning null.
try {
const userAccount = await program.account.userAccount.fetchNullable(
userAccountAddress
);
const userAccount = await program.account.userAccount.fetchNullable(userAccountAddress);
assert.equal(userAccount, null);
} catch (err) {
// Won't return null and will throw an error in anchor-bankrun'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import assert from "node:assert";
import * as anchor from "@coral-xyz/anchor";
import type { Program } from "@coral-xyz/anchor";
import { PublicKey } from "@solana/web3.js";
import type { CloseAccountProgram } from "../target/types/close_account_program";
import assert from 'node:assert';
import * as anchor from '@coral-xyz/anchor';
import type { Program } from '@coral-xyz/anchor';
import { PublicKey } from '@solana/web3.js';
import type { CloseAccountProgram } from '../target/types/close_account_program';

describe("Close an account", () => {
describe('Close an account', () => {
// Configure the client to use the local cluster.
const provider = anchor.AnchorProvider.env();
anchor.setProvider(provider);
Expand All @@ -13,13 +13,10 @@ describe("Close an account", () => {
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
);
const [userAccountAddress] = PublicKey.findProgramAddressSync([Buffer.from('USER'), payer.publicKey.toBuffer()], program.programId);

it("can create an account", async () => {
const userId = anchor.BN(76362)
it('can create an account', async () => {
const userId = anchor.BN(76362);

await program.methods
.createUser(userId)
Expand All @@ -29,24 +26,20 @@ describe("Close an account", () => {
.rpc();

// Fetch the account data
const userAccount = await program.account.userAccount.fetch(
userAccountAddress
);
assert.notEqual(userAccount, null)
const userAccount = await program.account.userAccount.fetch(userAccountAddress);
assert.notEqual(userAccount, null);
});

it("can close an account", async () => {
it('can close an account', async () => {
await program.methods
.closeUser()
.accounts({
user: payer.publicKey
user: payer.publicKey,
})
.rpc();

// The account should no longer exist, returning null.
const userAccount = await program.account.userAccount.fetchNullable(
userAccountAddress
);
const userAccount = await program.account.userAccount.fetchNullable(userAccountAddress);
assert.equal(userAccount, null);
});
});
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import { Account, Pubkey, Result, u8, Signer, u32 } from "@solanaturbine/poseidon";
import { Account, Pubkey, Result, Signer, u8, u32 } from '@solanaturbine/poseidon';

export default class CloseAccount {
static PROGRAM_ID = new Pubkey(
"2q4uoWExFAbZjeDe4n3miipsT9bX9vLnkSetCfZYF2VT"
);
static PROGRAM_ID = new Pubkey('2q4uoWExFAbZjeDe4n3miipsT9bX9vLnkSetCfZYF2VT');

createUser(user: Signer, userAccount: UserAccount, userId: u32): Result {
userAccount.derive(["USER", user.key]).init();
userAccount.derive(['USER', user.key]).init();

userAccount.userBump = userAccount.getBump();

Expand All @@ -15,7 +13,7 @@ export default class CloseAccount {
userAccount.userId = userId;
}
closeUser(userAccount: UserAccount, user: Signer): Result {
userAccount.derive(["USER", user.key]).close(user);
userAccount.derive(['USER', user.key]).close(user);
}
}

Expand Down

0 comments on commit 55d896f

Please sign in to comment.