Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add /basics/rent/poseidon #184

Merged
merged 5 commits into from
Jan 2, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
chore:ran pnpm fix
adpthegreat committed Oct 20, 2024
commit 6eed1847dd3c6b3d8062ac328093d43c6d124425

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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);

Original file line number Diff line number Diff line change
@@ -1,33 +1,24 @@
import * as anchor from "@coral-xyz/anchor";
import { Keypair, PublicKey, SystemProgram } from "@solana/web3.js";
import { assert } from "chai";
import type { CreateSystemAccountProgram } from "../target/types/create_system_account_program";
import { BankrunProvider } from "anchor-bankrun";
import { startAnchor } from "solana-bankrun";

const IDL = require("../target/idl/create_system_account.json");
import * as anchor from '@coral-xyz/anchor';
import { Keypair, PublicKey, SystemProgram } from '@solana/web3.js';
import { BankrunProvider } from 'anchor-bankrun';
import { assert } from 'chai';
import { startAnchor } from 'solana-bankrun';
import type { CreateSystemAccountProgram } from '../target/types/create_system_account_program';

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


describe("Create a system account", async () => {
const context = await startAnchor(
"",
[{ name: "create_system_account", programId: PROGRAM_ID }],
[]
);
describe('Create a system account', async () => {
const context = await startAnchor('', [{ name: 'create_system_account', programId: PROGRAM_ID }], []);
const provider = new BankrunProvider(context);

const wallet = provider.wallet as anchor.Wallet;
const connection = provider.connection;
const program = anchor.workspace
.CreateSystemAccountProgram as anchor.Program<CreateSystemAccountProgram>;
const program = anchor.workspace.CreateSystemAccountProgram as anchor.Program<CreateSystemAccountProgram>;

it("Create the account", async () => {
it('Create the account', async () => {
// Generate the public key from the seed and the programId
const [accountState, _] = anchor.web3.PublicKey.findProgramAddressSync(
[anchor.utils.bytes.utf8.encode("account")],
program.programId
);
const [accountState, _] = anchor.web3.PublicKey.findProgramAddressSync([anchor.utils.bytes.utf8.encode('account')], program.programId);

await program.methods
.createSystemAccount()
@@ -41,10 +32,7 @@ describe("Create a system account", async () => {

// Check that the account was created
const accountInfo = await connection.getAccountInfo(accountState);
assert.isNotNull(accountInfo, "Account should be created");
assert(
accountInfo.lamports >= lamports,
"Account must have the minimum amount of lamports required for rent"
);
assert.isNotNull(accountInfo, 'Account should be created');
assert(accountInfo.lamports >= lamports, 'Account must have the minimum amount of lamports required for rent');
});
});
Original file line number Diff line number Diff line change
@@ -1,22 +1,18 @@
import * as anchor from "@coral-xyz/anchor";
import { Keypair, SystemProgram } from "@solana/web3.js";
import { assert } from "chai";
import type { CreateSystemAccountProgram } from "../target/types/create_system_account_program";
import * as anchor from '@coral-xyz/anchor';
import { Keypair, SystemProgram } from '@solana/web3.js';
import { assert } from 'chai';
import type { CreateSystemAccountProgram } from '../target/types/create_system_account_program';

describe("Create a system account", () => {
describe('Create a system account', () => {
const provider = anchor.AnchorProvider.env();
anchor.setProvider(provider);
const wallet = provider.wallet as anchor.Wallet;
const connection = provider.connection;
const program = anchor.workspace
.CreateSystemAccountProgram as anchor.Program<CreateSystemAccountProgram>;
const program = anchor.workspace.CreateSystemAccountProgram as anchor.Program<CreateSystemAccountProgram>;

it("Create the account", async () => {
it('Create the account', async () => {
// Generate the public key from the seed and the programId
const [accountState, _] = anchor.web3.PublicKey.findProgramAddressSync(
[anchor.utils.bytes.utf8.encode("account")],
program.programId
);
const [accountState, _] = anchor.web3.PublicKey.findProgramAddressSync([anchor.utils.bytes.utf8.encode('account')], program.programId);

await program.methods
.createSystemAccount()
@@ -30,7 +26,7 @@ describe("Create a system account", () => {

// Check that the account was created
const accountInfo = await connection.getAccountInfo(accountState);
assert.isNotNull(accountInfo, "Account should be created");
assert(accountInfo.lamports >= lamports, "Account must have the minimum amount of lamports required for rent");
assert.isNotNull(accountInfo, 'Account should be created');
assert(accountInfo.lamports >= lamports, 'Account must have the minimum amount of lamports required for rent');
});
});
Original file line number Diff line number Diff line change
@@ -1,20 +1,12 @@
import {
Account,
Pubkey,
Result,
Signer,
u8,
} from "@solanaturbine/poseidon";
import { Account, Pubkey, Result, Signer, u8 } from '@solanaturbine/poseidon';

export default class CreateSystemAccountProgram {
static PROGRAM_ID = new Pubkey(
"2Gs21s6ovwaHddKdPZvGpowpVJJBohdy3DrjoX77rqiY"
);
static PROGRAM_ID = new Pubkey('2Gs21s6ovwaHddKdPZvGpowpVJJBohdy3DrjoX77rqiY');

//Create a new system account
createSystemAccount(account: AccountState, owner: Signer): Result {
//We use derive to define the account and chain the `.init()` at the end for creating the account
account.derive(["account"]).init()
account.derive(['account']).init();
//Set owner of the account
account.owner = owner.key;