Skip to content

Commit 204e31b

Browse files
committed
minor console log formatting updates
1 parent 8e79654 commit 204e31b

File tree

6 files changed

+67
-50
lines changed
  • tokens/token-2022/transfer-hook/anchor

6 files changed

+67
-50
lines changed

tokens/token-2022/transfer-hook/anchor/TransferHookCounter/programs/transfer-hook/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ pub mod transfer_hook {
2727
ctx: Context<InitializeExtraAccountMetaList>,
2828
) -> Result<()> {
2929

30-
// The `addExtraAccountsToInstruction` JS helper function resolving incorrectly
3130
let account_metas = vec![
3231
ExtraAccountMeta::new_with_seeds(
3332
&[Seed::Literal {

tokens/token-2022/transfer-hook/anchor/TransferHookCounter/tests/transfer-hook.ts

+26-22
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import {
1818
createAssociatedTokenAccountInstruction,
1919
createMintToInstruction,
2020
getAssociatedTokenAddressSync,
21-
createTransferCheckedWithTransferHookInstruction
21+
createTransferCheckedWithTransferHookInstruction,
2222
} from "@solana/spl-token";
2323

2424
describe("transfer-hook", () => {
@@ -59,7 +59,7 @@ describe("transfer-hook", () => {
5959
[Buffer.from("extra-account-metas"), mint.publicKey.toBuffer()],
6060
program.programId
6161
);
62-
62+
6363
const [counterPDA] = PublicKey.findProgramAddressSync(
6464
[Buffer.from("counter")],
6565
program.programId
@@ -98,13 +98,15 @@ describe("transfer-hook", () => {
9898
provider.connection,
9999
transaction,
100100
[wallet.payer, mint],
101-
{ skipPreflight: true, commitment: "finalized"}
101+
{ skipPreflight: true, commitment: "finalized" }
102102
);
103103

104-
const txDetails = await program.provider.connection.getTransaction(txSig, { maxSupportedTransactionVersion: 0, commitment: 'confirmed'});
104+
const txDetails = await program.provider.connection.getTransaction(txSig, {
105+
maxSupportedTransactionVersion: 0,
106+
commitment: "confirmed",
107+
});
105108
console.log(txDetails.meta.logMessages);
106109

107-
108110
console.log(`Transaction Signature: ${txSig}`);
109111
});
110112

@@ -170,7 +172,7 @@ describe("transfer-hook", () => {
170172
provider.connection,
171173
transaction,
172174
[wallet.payer],
173-
{ skipPreflight: true, commitment: "confirmed"}
175+
{ skipPreflight: true, commitment: "confirmed" }
174176
);
175177
console.log("Transaction Signature:", txSig);
176178
});
@@ -180,27 +182,29 @@ describe("transfer-hook", () => {
180182
const amount = 1 * 10 ** decimals;
181183
const amountBigInt = BigInt(amount);
182184

183-
let transferInstructionWithHelper = await createTransferCheckedWithTransferHookInstruction(
184-
connection,
185-
sourceTokenAccount,
186-
mint.publicKey,
187-
destinationTokenAccount,
188-
wallet.publicKey,
189-
amountBigInt,
190-
decimals,
191-
[],
192-
"confirmed",
193-
TOKEN_2022_PROGRAM_ID,
194-
);
185+
let transferInstructionWithHelper =
186+
await createTransferCheckedWithTransferHookInstruction(
187+
connection,
188+
sourceTokenAccount,
189+
mint.publicKey,
190+
destinationTokenAccount,
191+
wallet.publicKey,
192+
amountBigInt,
193+
decimals,
194+
[],
195+
"confirmed",
196+
TOKEN_2022_PROGRAM_ID
197+
);
195198

196199
console.log("Extra accounts meta: " + extraAccountMetaListPDA);
197200
console.log("Counter PDa: " + counterPDA);
198-
console.log("Transfer Instruction: " + JSON.stringify(transferInstructionWithHelper));
199-
200-
const transaction = new Transaction().add(
201-
transferInstructionWithHelper
201+
console.log(
202+
"Transfer Instruction: " +
203+
JSON.stringify(transferInstructionWithHelper, null, 2)
202204
);
203205

206+
const transaction = new Transaction().add(transferInstructionWithHelper);
207+
204208
const txSig = await sendAndConfirmTransaction(
205209
connection,
206210
transaction,

tokens/token-2022/transfer-hook/anchor/TransferHookHelloWorld/programs/transfer-hook/src/lib.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,7 @@ pub mod transfer_hook {
2121
ctx: Context<InitializeExtraAccountMetaList>,
2222
) -> Result<()> {
2323

24-
// The `addExtraAccountsToInstruction` JS helper function resolving incorrectly
25-
let account_metas = vec![
26-
27-
];
24+
let account_metas = vec![];
2825

2926
// calculate account size
3027
let account_size = ExtraAccountMetaList::size_of(account_metas.len())? as u64;

tokens/token-2022/transfer-hook/anchor/TransferHookTransferCost/programs/transfer-hook/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ pub mod transfer_hook {
3131
) -> Result<()> {
3232
// index 0-3 are the accounts required for token transfer (source, mint, destination, owner)
3333
// index 4 is address of ExtraAccountMetaList account
34-
// The `addExtraAccountsToInstruction` JS helper function resolving incorrectly
3534
let account_metas = vec![
3635
// index 5, wrapped SOL mint
3736
ExtraAccountMeta::new_with_pubkey(&ctx.accounts.wsol_mint.key(), false, false)?,

tokens/token-2022/transfer-hook/anchor/TransferHookTransferCost/tests/transfer-hook.ts

+40-21
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ describe("transfer-hook", () => {
218218
provider.connection,
219219
transaction,
220220
[wallet.payer],
221-
{ skipPreflight: true, commitment : "confirmed"}
221+
{ skipPreflight: true, commitment: "confirmed" }
222222
);
223223
console.log("Transaction Signature:", txSig);
224224
});
@@ -250,43 +250,62 @@ describe("transfer-hook", () => {
250250
senderWSolTokenAccount
251251
);
252252

253-
const mintInfo = await getMint(connection, mint.publicKey, "confirmed", TOKEN_2022_PROGRAM_ID);
253+
const mintInfo = await getMint(
254+
connection,
255+
mint.publicKey,
256+
"confirmed",
257+
TOKEN_2022_PROGRAM_ID
258+
);
254259
const transferHook = getTransferHook(mintInfo);
255260
if (transferHook != null) {
256-
console.log("Transfer hook not found" + JSON.stringify(transferHook));
261+
console.log(
262+
"Transfer hook program found: " + JSON.stringify(transferHook, null, 2)
263+
);
257264
}
258265

259-
const extraAccountsAccount = getExtraAccountMetaAddress(mint.publicKey, transferHook.programId);
260-
const extraAccountsInfo = await connection.getAccountInfo(extraAccountsAccount, "confirmed");
266+
const extraAccountsAccount = getExtraAccountMetaAddress(
267+
mint.publicKey,
268+
transferHook.programId
269+
);
270+
const extraAccountsInfo = await connection.getAccountInfo(
271+
extraAccountsAccount,
272+
"confirmed"
273+
);
261274
const extraAccountMetas = getExtraAccountMetas(extraAccountsInfo);
262275

263276
for (const extraAccountMeta of extraAccountMetas) {
264-
console.log("Extra account meta: " + JSON.stringify(extraAccountMeta));
277+
console.log(
278+
"Extra account meta: " + JSON.stringify(extraAccountMeta, null, 2)
279+
);
265280
}
266281

267282
// Standard token transfer instruction
268-
const transferInstruction = await createTransferCheckedWithTransferHookInstruction(
269-
connection,
270-
sourceTokenAccount,
271-
mint.publicKey,
272-
destinationTokenAccount,
273-
wallet.publicKey,
274-
bigIntAmount,
275-
decimals,
276-
[],
277-
"confirmed",
278-
TOKEN_2022_PROGRAM_ID
279-
);
283+
const transferInstruction =
284+
await createTransferCheckedWithTransferHookInstruction(
285+
connection,
286+
sourceTokenAccount,
287+
mint.publicKey,
288+
destinationTokenAccount,
289+
wallet.publicKey,
290+
bigIntAmount,
291+
decimals,
292+
[],
293+
"confirmed",
294+
TOKEN_2022_PROGRAM_ID
295+
);
280296

281-
console.log("Pushed keys:", JSON.stringify(transferInstruction.keys));
297+
console.log(
298+
"Pushed keys:",
299+
JSON.stringify(transferInstruction.keys, null, 2)
300+
);
282301

283302
const transaction = new Transaction().add(
284303
solTransferInstruction,
285304
syncWrappedSolInstruction,
286305
approveInstruction,
287306
transferInstruction
288307
);
289-
308+
290309
const txSig = await sendAndConfirmTransaction(
291310
connection,
292311
transaction,
@@ -296,7 +315,7 @@ describe("transfer-hook", () => {
296315
console.log("Transfer Signature:", txSig);
297316

298317
const tokenAccount = await getAccount(connection, delegateWSolTokenAccount);
299-
318+
300319
assert.equal(Number(tokenAccount.amount), amount / 2);
301320
});
302321
});

tokens/token-2022/transfer-hook/anchor/TransferHookWhitelist/programs/transfer-hook/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ pub mod transfer_hook {
2121
ctx: Context<InitializeExtraAccountMetaList>,
2222
) -> Result<()> {
2323

24-
// The `addExtraAccountsToInstruction` JS helper function resolving incorrectly
2524
let account_metas = vec![
2625
ExtraAccountMeta::new_with_seeds(
2726
&[Seed::Literal {

0 commit comments

Comments
 (0)