Skip to content

Commit 650c762

Browse files
committed
Fix linting
1 parent 4a1d038 commit 650c762

File tree

2 files changed

+92
-187
lines changed

2 files changed

+92
-187
lines changed
Lines changed: 52 additions & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import * as anchor from "@coral-xyz/anchor";
2-
import type { Program } from "@coral-xyz/anchor";
1+
import * as anchor from '@coral-xyz/anchor';
2+
import type { Program } from '@coral-xyz/anchor';
33
import {
44
ASSOCIATED_TOKEN_PROGRAM_ID,
55
ExtensionType,
@@ -11,24 +11,17 @@ import {
1111
createTransferCheckedWithTransferHookInstruction,
1212
getAssociatedTokenAddressSync,
1313
getMintLen,
14-
} from "@solana/spl-token";
15-
import {
16-
Keypair,
17-
PublicKey,
18-
SendTransactionError,
19-
SystemProgram,
20-
Transaction,
21-
sendAndConfirmTransaction,
22-
} from "@solana/web3.js";
23-
import type { TransferHook } from "../target/types/transfer_hook";
24-
import { BN } from "bn.js";
25-
import { expect } from "chai";
26-
import chai from "chai";
27-
import chaiAsPromised from "chai-as-promised";
14+
} from '@solana/spl-token';
15+
import { Keypair, PublicKey, SendTransactionError, SystemProgram, Transaction, sendAndConfirmTransaction } from '@solana/web3.js';
16+
import { BN } from 'bn.js';
17+
import { expect } from 'chai';
18+
import chai from 'chai';
19+
import chaiAsPromised from 'chai-as-promised';
20+
import type { TransferHook } from '../target/types/transfer_hook';
2821

2922
chai.use(chaiAsPromised);
3023

31-
describe("transfer-hook", () => {
24+
describe('transfer-hook', () => {
3225
// Configure the client to use the local cluster.
3326
const provider = anchor.AnchorProvider.env();
3427
anchor.setProvider(provider);
@@ -47,7 +40,7 @@ describe("transfer-hook", () => {
4740
wallet.publicKey,
4841
false,
4942
TOKEN_2022_PROGRAM_ID,
50-
ASSOCIATED_TOKEN_PROGRAM_ID
43+
ASSOCIATED_TOKEN_PROGRAM_ID,
5144
);
5245

5346
// Recipient token account address
@@ -57,26 +50,22 @@ describe("transfer-hook", () => {
5750
recipient.publicKey,
5851
false,
5952
TOKEN_2022_PROGRAM_ID,
60-
ASSOCIATED_TOKEN_PROGRAM_ID
53+
ASSOCIATED_TOKEN_PROGRAM_ID,
6154
);
6255

6356
// ExtraAccountMetaList address
6457
// Store extra accounts required by the custom transfer hook instruction
6558
const [extraAccountMetaListPDA] = PublicKey.findProgramAddressSync(
66-
[Buffer.from("extra-account-metas"), mint.publicKey.toBuffer()],
67-
program.programId
59+
[Buffer.from('extra-account-metas'), mint.publicKey.toBuffer()],
60+
program.programId,
6861
);
6962

70-
const [counterPDA] = PublicKey.findProgramAddressSync(
71-
[Buffer.from("counter")],
72-
program.programId
73-
);
63+
const [counterPDA] = PublicKey.findProgramAddressSync([Buffer.from('counter')], program.programId);
7464

75-
it("Create Mint Account with Transfer Hook Extension", async () => {
65+
it('Create Mint Account with Transfer Hook Extension', async () => {
7666
const extensions = [ExtensionType.TransferHook];
7767
const mintLen = getMintLen(extensions);
78-
const lamports =
79-
await provider.connection.getMinimumBalanceForRentExemption(mintLen);
68+
const lamports = await provider.connection.getMinimumBalanceForRentExemption(mintLen);
8069

8170
const transaction = new Transaction().add(
8271
SystemProgram.createAccount({
@@ -90,30 +79,19 @@ describe("transfer-hook", () => {
9079
mint.publicKey,
9180
wallet.publicKey,
9281
program.programId, // Transfer Hook Program ID
93-
TOKEN_2022_PROGRAM_ID
82+
TOKEN_2022_PROGRAM_ID,
9483
),
95-
createInitializeMintInstruction(
96-
mint.publicKey,
97-
decimals,
98-
wallet.publicKey,
99-
null,
100-
TOKEN_2022_PROGRAM_ID
101-
)
84+
createInitializeMintInstruction(mint.publicKey, decimals, wallet.publicKey, null, TOKEN_2022_PROGRAM_ID),
10285
);
10386

104-
const txSig = await sendAndConfirmTransaction(
105-
provider.connection,
106-
transaction,
107-
[wallet.payer, mint],
108-
{
109-
skipPreflight: true,
110-
commitment: "finalized",
111-
}
112-
);
87+
const txSig = await sendAndConfirmTransaction(provider.connection, transaction, [wallet.payer, mint], {
88+
skipPreflight: true,
89+
commitment: 'finalized',
90+
});
11391

11492
const txDetails = await program.provider.connection.getTransaction(txSig, {
11593
maxSupportedTransactionVersion: 0,
116-
commitment: "confirmed",
94+
commitment: 'confirmed',
11795
});
11896
console.log(txDetails.meta.logMessages);
11997

@@ -122,7 +100,7 @@ describe("transfer-hook", () => {
122100

123101
// Create the two token accounts for the transfer-hook enabled mint
124102
// Fund the sender token account with 100 tokens
125-
it("Create Token Accounts and Mint Tokens", async () => {
103+
it('Create Token Accounts and Mint Tokens', async () => {
126104
// 100 tokens
127105
const amount = 100 * 10 ** decimals;
128106

@@ -133,95 +111,68 @@ describe("transfer-hook", () => {
133111
wallet.publicKey,
134112
mint.publicKey,
135113
TOKEN_2022_PROGRAM_ID,
136-
ASSOCIATED_TOKEN_PROGRAM_ID
114+
ASSOCIATED_TOKEN_PROGRAM_ID,
137115
),
138116
createAssociatedTokenAccountInstruction(
139117
wallet.publicKey,
140118
destinationTokenAccount,
141119
recipient.publicKey,
142120
mint.publicKey,
143121
TOKEN_2022_PROGRAM_ID,
144-
ASSOCIATED_TOKEN_PROGRAM_ID
122+
ASSOCIATED_TOKEN_PROGRAM_ID,
145123
),
146-
createMintToInstruction(
147-
mint.publicKey,
148-
sourceTokenAccount,
149-
wallet.publicKey,
150-
amount,
151-
[],
152-
TOKEN_2022_PROGRAM_ID
153-
)
124+
createMintToInstruction(mint.publicKey, sourceTokenAccount, wallet.publicKey, amount, [], TOKEN_2022_PROGRAM_ID),
154125
);
155126

156-
const txSig = await sendAndConfirmTransaction(
157-
connection,
158-
transaction,
159-
[wallet.payer],
160-
{ skipPreflight: true }
161-
);
127+
const txSig = await sendAndConfirmTransaction(connection, transaction, [wallet.payer], { skipPreflight: true });
162128

163129
console.log(`Transaction Signature: ${txSig}`);
164130
});
165131

166132
// Account to store extra accounts required by the transfer hook instruction
167-
it("Create ExtraAccountMetaList Account", async () => {
133+
it('Create ExtraAccountMetaList Account', async () => {
168134
const initializeExtraAccountMetaListInstruction = await program.methods
169135
.initializeExtraAccountMetaList()
170136
.accounts({
171137
mint: mint.publicKey,
172138
})
173139
.instruction();
174140

175-
const transaction = new Transaction().add(
176-
initializeExtraAccountMetaListInstruction
177-
);
141+
const transaction = new Transaction().add(initializeExtraAccountMetaListInstruction);
178142

179-
const txSig = await sendAndConfirmTransaction(
180-
provider.connection,
181-
transaction,
182-
[wallet.payer],
183-
{ skipPreflight: true, commitment: "confirmed" }
184-
);
185-
console.log("Transaction Signature:", txSig);
143+
const txSig = await sendAndConfirmTransaction(provider.connection, transaction, [wallet.payer], { skipPreflight: true, commitment: 'confirmed' });
144+
console.log('Transaction Signature:', txSig);
186145
});
187146

188-
it("Transfer Hook with Extra Account Meta", async () => {
147+
it('Transfer Hook with Extra Account Meta', async () => {
189148
// 1 tokens
190149
const amount = 1 * 10 ** decimals;
191150
const amountBigInt = BigInt(amount);
192151

193-
const transferInstructionWithHelper =
194-
await createTransferCheckedWithTransferHookInstruction(
195-
connection,
196-
sourceTokenAccount,
197-
mint.publicKey,
198-
destinationTokenAccount,
199-
wallet.publicKey,
200-
amountBigInt,
201-
decimals,
202-
[],
203-
"confirmed",
204-
TOKEN_2022_PROGRAM_ID
205-
);
152+
const transferInstructionWithHelper = await createTransferCheckedWithTransferHookInstruction(
153+
connection,
154+
sourceTokenAccount,
155+
mint.publicKey,
156+
destinationTokenAccount,
157+
wallet.publicKey,
158+
amountBigInt,
159+
decimals,
160+
[],
161+
'confirmed',
162+
TOKEN_2022_PROGRAM_ID,
163+
);
206164

207165
console.log(`Extra accounts meta: ${extraAccountMetaListPDA}`);
208166
console.log(`Counter PDA: ${counterPDA}`);
209-
console.log(
210-
`Transfer Instruction: ${JSON.stringify(transferInstructionWithHelper)}`
211-
);
167+
console.log(`Transfer Instruction: ${JSON.stringify(transferInstructionWithHelper)}`);
212168

213169
const transaction = new Transaction().add(transferInstructionWithHelper);
214170

215-
const txSig = await sendAndConfirmTransaction(
216-
connection,
217-
transaction,
218-
[wallet.payer],
219-
{ skipPreflight: true }
220-
);
221-
console.log("Transfer Signature:", txSig);
171+
const txSig = await sendAndConfirmTransaction(connection, transaction, [wallet.payer], { skipPreflight: true });
172+
console.log('Transfer Signature:', txSig);
222173
});
223174

224-
it("Try call transfer hook without transfer", async () => {
175+
it('Try call transfer hook without transfer', async () => {
225176
const transferHookIx = await program.methods
226177
.transferHook(new BN(1))
227178
.accounts({
@@ -234,16 +185,8 @@ describe("transfer-hook", () => {
234185

235186
const transaction = new Transaction().add(transferHookIx);
236187

237-
const sendPromise = sendAndConfirmTransaction(
238-
connection,
239-
transaction,
240-
[wallet.payer],
241-
{ skipPreflight: false }
242-
);
188+
const sendPromise = sendAndConfirmTransaction(connection, transaction, [wallet.payer], { skipPreflight: false });
243189

244-
await expect(sendPromise).to.eventually.be.rejectedWith(
245-
SendTransactionError,
246-
program.idl.errors[1].msg
247-
);
190+
await expect(sendPromise).to.eventually.be.rejectedWith(SendTransactionError, program.idl.errors[1].msg);
248191
});
249192
});

0 commit comments

Comments
 (0)