Skip to content

Commit

Permalink
chore: format fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Memewtoo committed Nov 25, 2024
1 parent a6332e1 commit 75bff6c
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 70 deletions.
2 changes: 1 addition & 1 deletion basics/counter/poseidon/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"license": "ISC",
"license": "ISC",
"scripts": {
"lint:fix": "prettier */*.js \"*/**/*{.js,.ts}\" -w",
"lint": "prettier */*.js \"*/**/*{.js,.ts}\" --check"
Expand Down
65 changes: 25 additions & 40 deletions basics/counter/poseidon/tests/counter.ts
Original file line number Diff line number Diff line change
@@ -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);
Expand All @@ -21,83 +21,68 @@ 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,
signature: airdropUser,
});

// 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');
});
});






57 changes: 28 additions & 29 deletions basics/counter/poseidon/ts-programs/src/counter.ts
Original file line number Diff line number Diff line change
@@ -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([<seeds>]) ensures that account is a PDA with the <seeds> as the parameters
// .init() ensures that the account will have the init constraint when transpiled
counter.derive(["counter"]).init();
// .derive([<seeds>]) ensures that account is a PDA with the <seeds> 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
}
count: u64;
}

0 comments on commit 75bff6c

Please sign in to comment.