Skip to content

Commit 7aaf3e0

Browse files
author
adpthegreat
committed
fix:ran pnpm fix
1 parent 0da12a7 commit 7aaf3e0

File tree

2 files changed

+37
-80
lines changed

2 files changed

+37
-80
lines changed

basics/pda-rent-payer/poseidon/pda_rent_payer/tests/bankrun.test.ts

Lines changed: 19 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { describe, it } from 'node:test';
22
import * as anchor from '@coral-xyz/anchor';
3-
import { clusterApiUrl, Connection, Keypair, LAMPORTS_PER_SOL, PublicKey } from '@solana/web3.js';
3+
import { Connection, Keypair, LAMPORTS_PER_SOL, PublicKey, clusterApiUrl } from '@solana/web3.js';
44
import { BankrunProvider } from 'anchor-bankrun';
55
import { assert } from 'chai';
66
import { startAnchor } from 'solana-bankrun';
@@ -18,35 +18,24 @@ describe('PDA Rent-Payer', async () => {
1818
const connection = provider.connection;
1919

2020
// PDA for the Rent Vault
21-
const auth = new Keypair()
21+
const auth = new Keypair();
2222

23-
const [authPDA, authBump] = PublicKey.findProgramAddressSync(
24-
[Buffer.from("auth")],
25-
PROGRAM_ID
26-
);
23+
const [authPDA, authBump] = PublicKey.findProgramAddressSync([Buffer.from('auth')], PROGRAM_ID);
2724

28-
const [rentVaultPDA, vaultBump] = PublicKey.findProgramAddressSync(
29-
[Buffer.from("vault"),auth.publicKey.toBuffer()],
30-
PROGRAM_ID
31-
);
32-
33-
const [newAccountPDA, newAccountBump] = PublicKey.findProgramAddressSync(
34-
[Buffer.from("new_account"),],
35-
PROGRAM_ID
36-
);
37-
// const [statePDA, stateBump] = PublicKey.findProgramAddressSync(
38-
// [Buffer.from("state"), wallet.publicKey.toBuffer()],
39-
// PROGRAM_ID
40-
// );
25+
const [rentVaultPDA, vaultBump] = PublicKey.findProgramAddressSync([Buffer.from('vault'), auth.publicKey.toBuffer()], PROGRAM_ID);
4126

27+
const [newAccountPDA, newAccountBump] = PublicKey.findProgramAddressSync([Buffer.from('new_account')], PROGRAM_ID);
28+
// const [statePDA, stateBump] = PublicKey.findProgramAddressSync(
29+
// [Buffer.from("state"), wallet.publicKey.toBuffer()],
30+
// PROGRAM_ID
31+
// );
4232

4333
console.log(rentVaultPDA, 'this is the rent vault pda');
44-
console.log(authPDA, 'this is the auth pda')
45-
console.log(newAccountPDA, 'this is the new account pda')
34+
console.log(authPDA, 'this is the auth pda');
35+
console.log(newAccountPDA, 'this is the new account pda');
4636

4737
it('Initialize the Rent Vault', async () => {
48-
49-
const tx = await program.methods
38+
const tx = await program.methods
5039
.initRentVault()
5140
.accounts({
5241
owner: wallet.publicKey,
@@ -57,14 +46,13 @@ const [rentVaultPDA, vaultBump] = PublicKey.findProgramAddressSync(
5746

5847
const accountInfo = await program.provider.connection.getAccountInfo(rentVaultPDA);
5948

60-
console.log(accountInfo, "this is the account info")
49+
console.log(accountInfo, 'this is the account info');
6150

6251
const lamports = await connection.getMinimumBalanceForRentExemption(8);
6352

6453
assert(accountInfo !== null, 'Rent vault account does not exist');
6554

6655
assert(accountInfo.lamports === lamports, 'Incorrect rent vault balance');
67-
6856
});
6957

7058
it('Deposit to the Rent Vault', async () => {
@@ -103,23 +91,20 @@ const [rentVaultPDA, vaultBump] = PublicKey.findProgramAddressSync(
10391

10492
// Check that the account was created
10593
const accountInfo = await connection.getAccountInfo(newAccountPDA);
106-
94+
10795
// 9 is the space the newAccount occupies, poseidon automatically generates space for you when you initialize a pda
10896
const lamports = await connection.getMinimumBalanceForRentExemption(41);
109-
97+
11098
console.log(lamports);
11199
console.log(accountInfo.lamports);
112100

113-
assert(accountInfo !== null, "Rent vault account does not exist");
101+
assert(accountInfo !== null, 'Rent vault account does not exist');
114102

115-
assert(
116-
accountInfo.lamports === fundAmount.toNumber() + lamports,
117-
"Incorrect rent vault balance"
118-
);
103+
assert(accountInfo.lamports === fundAmount.toNumber() + lamports, 'Incorrect rent vault balance');
119104
});
120105
});
121106

122107
//
123-
//owner == payer, use payer
108+
//owner == payer, use payer
124109

125-
//payer --> rentvault --> newAccount
110+
//payer --> rentvault --> newAccount
Lines changed: 18 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,15 @@
1-
import {
2-
Account,
3-
Mint,
4-
Pubkey,
5-
Result,
6-
Signer,
7-
SystemAccount,
8-
SystemProgram,
9-
u8,
10-
u64,
11-
UncheckedAccount,
12-
} from "@solanaturbine/poseidon";
1+
import { Account, Mint, Pubkey, Result, Signer, SystemAccount, SystemProgram, UncheckedAccount, u8, u64 } from '@solanaturbine/poseidon';
132

143
export default class PdaRentPayer {
15-
static PROGRAM_ID = new Pubkey(
16-
"BYj8GpV9hpv9PAVdwoWFCTMkysJkk5jstYjuCrw4pxem"
17-
);
4+
static PROGRAM_ID = new Pubkey('BYj8GpV9hpv9PAVdwoWFCTMkysJkk5jstYjuCrw4pxem');
185

196
// When lamports are transferred to a new address (without and existing account),
207
// An account owned by the system program is created by default
21-
initRentVault(
22-
owner: Signer,
23-
vault: RentVault,
24-
state: RentAccountState,
25-
auth: UncheckedAccount,
26-
) {
8+
initRentVault(owner: Signer, vault: RentVault, state: RentAccountState, auth: UncheckedAccount) {
279
//Derive the accounts with bump and seeds
28-
vault.derive(["vault", auth.key]).init();
29-
state.derive(["state", owner.key]).init()
30-
auth.derive(["auth", state.key]);
10+
vault.derive(['vault', auth.key]).init();
11+
state.derive(['state', owner.key]).init();
12+
auth.derive(['auth', state.key]);
3113

3214
state.owner = owner.key;
3315

@@ -37,24 +19,17 @@ export default class PdaRentPayer {
3719
state.vaultBump = vault.getBump();
3820
}
3921

40-
41-
depositToRentVault(
42-
owner: Signer,
43-
state: RentAccountState,
44-
auth: UncheckedAccount,
45-
vault: RentVault,
46-
amount: u64
47-
) {
22+
depositToRentVault(owner: Signer, state: RentAccountState, auth: UncheckedAccount, vault: RentVault, amount: u64) {
4823
//Since we have stored bumps in the RentAccountState we can derive PDAs with stored bumps by passing that as the second argument
49-
state.deriveWithBump(["state", owner.key], state.stateBump);
50-
auth.deriveWithBump(["auth", state.key], state.authBump);
51-
vault.deriveWithBump(["vault", auth.key], state.vaultBump);
24+
state.deriveWithBump(['state', owner.key], state.stateBump);
25+
auth.deriveWithBump(['auth', state.key], state.authBump);
26+
vault.deriveWithBump(['vault', auth.key], state.vaultBump);
5227

5328
// Transfer specified lamports from owner to the rent vault
5429
SystemProgram.transfer(
5530
owner, //from
5631
vault, //to
57-
amount //amount to be sent
32+
amount, //amount to be sent
5833
);
5934
}
6035

@@ -65,23 +40,20 @@ export default class PdaRentPayer {
6540
auth: UncheckedAccount,
6641
vault: SystemAccount,
6742
new_account_state: NewAccountState,
68-
amount: u64
43+
amount: u64,
6944
): Result {
70-
new_account_state.derive(["new_account", owner.key]).init();
45+
new_account_state.derive(['new_account', owner.key]).init();
7146

72-
state.deriveWithBump(["state", owner.key], state.stateBump);
73-
auth.deriveWithBump(["auth", state.key], state.authBump);
74-
vault.deriveWithBump(["vault", auth.key], state.vaultBump);
47+
state.deriveWithBump(['state', owner.key], state.stateBump);
48+
auth.deriveWithBump(['auth', state.key], state.authBump);
49+
vault.deriveWithBump(['vault', auth.key], state.vaultBump);
7550

7651
// state.newAccountBump = new_account.getBump(); // we don't need the new_account bump
7752

7853
new_account_state.owner = owner.key;
7954

8055
// We now transfer the lamports from the rent_vault to the new account
81-
SystemProgram.transfer(vault, new_account_state, amount, [
82-
"vault",
83-
auth.key,
84-
]);
56+
SystemProgram.transfer(vault, new_account_state, amount, ['vault', auth.key]);
8557
}
8658
}
8759

@@ -96,6 +68,6 @@ export interface RentAccountState extends Account {
9668
export interface RentVault extends Account {}
9769

9870
export interface NewAccountState extends Account {
99-
owner:Pubkey,
71+
owner: Pubkey;
10072
newAccountBump: u8; // Bump for the newly created account
10173
}

0 commit comments

Comments
 (0)