From 204e31bc2ad68dab67720afa6ce0484ee7f0c0cf Mon Sep 17 00:00:00 2001 From: John Date: Wed, 20 Mar 2024 16:08:26 -0500 Subject: [PATCH] minor console log formatting updates --- .../programs/transfer-hook/src/lib.rs | 1 - .../tests/transfer-hook.ts | 48 ++++++++------- .../programs/transfer-hook/src/lib.rs | 5 +- .../programs/transfer-hook/src/lib.rs | 1 - .../tests/transfer-hook.ts | 61 ++++++++++++------- .../programs/transfer-hook/src/lib.rs | 1 - 6 files changed, 67 insertions(+), 50 deletions(-) diff --git a/tokens/token-2022/transfer-hook/anchor/TransferHookCounter/programs/transfer-hook/src/lib.rs b/tokens/token-2022/transfer-hook/anchor/TransferHookCounter/programs/transfer-hook/src/lib.rs index 04876b8f7..83adfd2a1 100644 --- a/tokens/token-2022/transfer-hook/anchor/TransferHookCounter/programs/transfer-hook/src/lib.rs +++ b/tokens/token-2022/transfer-hook/anchor/TransferHookCounter/programs/transfer-hook/src/lib.rs @@ -27,7 +27,6 @@ pub mod transfer_hook { ctx: Context, ) -> Result<()> { - // The `addExtraAccountsToInstruction` JS helper function resolving incorrectly let account_metas = vec![ ExtraAccountMeta::new_with_seeds( &[Seed::Literal { diff --git a/tokens/token-2022/transfer-hook/anchor/TransferHookCounter/tests/transfer-hook.ts b/tokens/token-2022/transfer-hook/anchor/TransferHookCounter/tests/transfer-hook.ts index 05e739397..1fdce7c2c 100644 --- a/tokens/token-2022/transfer-hook/anchor/TransferHookCounter/tests/transfer-hook.ts +++ b/tokens/token-2022/transfer-hook/anchor/TransferHookCounter/tests/transfer-hook.ts @@ -18,7 +18,7 @@ import { createAssociatedTokenAccountInstruction, createMintToInstruction, getAssociatedTokenAddressSync, - createTransferCheckedWithTransferHookInstruction + createTransferCheckedWithTransferHookInstruction, } from "@solana/spl-token"; describe("transfer-hook", () => { @@ -59,7 +59,7 @@ describe("transfer-hook", () => { [Buffer.from("extra-account-metas"), mint.publicKey.toBuffer()], program.programId ); - + const [counterPDA] = PublicKey.findProgramAddressSync( [Buffer.from("counter")], program.programId @@ -98,13 +98,15 @@ describe("transfer-hook", () => { provider.connection, transaction, [wallet.payer, mint], - { skipPreflight: true, commitment: "finalized"} + { skipPreflight: true, commitment: "finalized" } ); - const txDetails = await program.provider.connection.getTransaction(txSig, { maxSupportedTransactionVersion: 0, commitment: 'confirmed'}); + const txDetails = await program.provider.connection.getTransaction(txSig, { + maxSupportedTransactionVersion: 0, + commitment: "confirmed", + }); console.log(txDetails.meta.logMessages); - console.log(`Transaction Signature: ${txSig}`); }); @@ -170,7 +172,7 @@ describe("transfer-hook", () => { provider.connection, transaction, [wallet.payer], - { skipPreflight: true, commitment: "confirmed"} + { skipPreflight: true, commitment: "confirmed" } ); console.log("Transaction Signature:", txSig); }); @@ -180,27 +182,29 @@ describe("transfer-hook", () => { const amount = 1 * 10 ** decimals; const amountBigInt = BigInt(amount); - let transferInstructionWithHelper = await createTransferCheckedWithTransferHookInstruction( - connection, - sourceTokenAccount, - mint.publicKey, - destinationTokenAccount, - wallet.publicKey, - amountBigInt, - decimals, - [], - "confirmed", - TOKEN_2022_PROGRAM_ID, - ); + let transferInstructionWithHelper = + await createTransferCheckedWithTransferHookInstruction( + connection, + sourceTokenAccount, + mint.publicKey, + destinationTokenAccount, + wallet.publicKey, + amountBigInt, + decimals, + [], + "confirmed", + TOKEN_2022_PROGRAM_ID + ); console.log("Extra accounts meta: " + extraAccountMetaListPDA); console.log("Counter PDa: " + counterPDA); - console.log("Transfer Instruction: " + JSON.stringify(transferInstructionWithHelper)); - - const transaction = new Transaction().add( - transferInstructionWithHelper + console.log( + "Transfer Instruction: " + + JSON.stringify(transferInstructionWithHelper, null, 2) ); + const transaction = new Transaction().add(transferInstructionWithHelper); + const txSig = await sendAndConfirmTransaction( connection, transaction, diff --git a/tokens/token-2022/transfer-hook/anchor/TransferHookHelloWorld/programs/transfer-hook/src/lib.rs b/tokens/token-2022/transfer-hook/anchor/TransferHookHelloWorld/programs/transfer-hook/src/lib.rs index 09f5c8fe1..df9b4d676 100644 --- a/tokens/token-2022/transfer-hook/anchor/TransferHookHelloWorld/programs/transfer-hook/src/lib.rs +++ b/tokens/token-2022/transfer-hook/anchor/TransferHookHelloWorld/programs/transfer-hook/src/lib.rs @@ -21,10 +21,7 @@ pub mod transfer_hook { ctx: Context, ) -> Result<()> { - // The `addExtraAccountsToInstruction` JS helper function resolving incorrectly - let account_metas = vec![ - - ]; + let account_metas = vec![]; // calculate account size let account_size = ExtraAccountMetaList::size_of(account_metas.len())? as u64; diff --git a/tokens/token-2022/transfer-hook/anchor/TransferHookTransferCost/programs/transfer-hook/src/lib.rs b/tokens/token-2022/transfer-hook/anchor/TransferHookTransferCost/programs/transfer-hook/src/lib.rs index c42841a7f..1097d455c 100644 --- a/tokens/token-2022/transfer-hook/anchor/TransferHookTransferCost/programs/transfer-hook/src/lib.rs +++ b/tokens/token-2022/transfer-hook/anchor/TransferHookTransferCost/programs/transfer-hook/src/lib.rs @@ -31,7 +31,6 @@ pub mod transfer_hook { ) -> Result<()> { // index 0-3 are the accounts required for token transfer (source, mint, destination, owner) // index 4 is address of ExtraAccountMetaList account - // The `addExtraAccountsToInstruction` JS helper function resolving incorrectly let account_metas = vec![ // index 5, wrapped SOL mint ExtraAccountMeta::new_with_pubkey(&ctx.accounts.wsol_mint.key(), false, false)?, diff --git a/tokens/token-2022/transfer-hook/anchor/TransferHookTransferCost/tests/transfer-hook.ts b/tokens/token-2022/transfer-hook/anchor/TransferHookTransferCost/tests/transfer-hook.ts index 62bc9e54a..fd8795140 100644 --- a/tokens/token-2022/transfer-hook/anchor/TransferHookTransferCost/tests/transfer-hook.ts +++ b/tokens/token-2022/transfer-hook/anchor/TransferHookTransferCost/tests/transfer-hook.ts @@ -218,7 +218,7 @@ describe("transfer-hook", () => { provider.connection, transaction, [wallet.payer], - { skipPreflight: true, commitment : "confirmed"} + { skipPreflight: true, commitment: "confirmed" } ); console.log("Transaction Signature:", txSig); }); @@ -250,35 +250,54 @@ describe("transfer-hook", () => { senderWSolTokenAccount ); - const mintInfo = await getMint(connection, mint.publicKey, "confirmed", TOKEN_2022_PROGRAM_ID); + const mintInfo = await getMint( + connection, + mint.publicKey, + "confirmed", + TOKEN_2022_PROGRAM_ID + ); const transferHook = getTransferHook(mintInfo); if (transferHook != null) { - console.log("Transfer hook not found" + JSON.stringify(transferHook)); + console.log( + "Transfer hook program found: " + JSON.stringify(transferHook, null, 2) + ); } - const extraAccountsAccount = getExtraAccountMetaAddress(mint.publicKey, transferHook.programId); - const extraAccountsInfo = await connection.getAccountInfo(extraAccountsAccount, "confirmed"); + const extraAccountsAccount = getExtraAccountMetaAddress( + mint.publicKey, + transferHook.programId + ); + const extraAccountsInfo = await connection.getAccountInfo( + extraAccountsAccount, + "confirmed" + ); const extraAccountMetas = getExtraAccountMetas(extraAccountsInfo); for (const extraAccountMeta of extraAccountMetas) { - console.log("Extra account meta: " + JSON.stringify(extraAccountMeta)); + console.log( + "Extra account meta: " + JSON.stringify(extraAccountMeta, null, 2) + ); } // Standard token transfer instruction - const transferInstruction = await createTransferCheckedWithTransferHookInstruction( - connection, - sourceTokenAccount, - mint.publicKey, - destinationTokenAccount, - wallet.publicKey, - bigIntAmount, - decimals, - [], - "confirmed", - TOKEN_2022_PROGRAM_ID - ); + const transferInstruction = + await createTransferCheckedWithTransferHookInstruction( + connection, + sourceTokenAccount, + mint.publicKey, + destinationTokenAccount, + wallet.publicKey, + bigIntAmount, + decimals, + [], + "confirmed", + TOKEN_2022_PROGRAM_ID + ); - console.log("Pushed keys:", JSON.stringify(transferInstruction.keys)); + console.log( + "Pushed keys:", + JSON.stringify(transferInstruction.keys, null, 2) + ); const transaction = new Transaction().add( solTransferInstruction, @@ -286,7 +305,7 @@ describe("transfer-hook", () => { approveInstruction, transferInstruction ); - + const txSig = await sendAndConfirmTransaction( connection, transaction, @@ -296,7 +315,7 @@ describe("transfer-hook", () => { console.log("Transfer Signature:", txSig); const tokenAccount = await getAccount(connection, delegateWSolTokenAccount); - + assert.equal(Number(tokenAccount.amount), amount / 2); }); }); diff --git a/tokens/token-2022/transfer-hook/anchor/TransferHookWhitelist/programs/transfer-hook/src/lib.rs b/tokens/token-2022/transfer-hook/anchor/TransferHookWhitelist/programs/transfer-hook/src/lib.rs index 991dc8845..4df876488 100644 --- a/tokens/token-2022/transfer-hook/anchor/TransferHookWhitelist/programs/transfer-hook/src/lib.rs +++ b/tokens/token-2022/transfer-hook/anchor/TransferHookWhitelist/programs/transfer-hook/src/lib.rs @@ -21,7 +21,6 @@ pub mod transfer_hook { ctx: Context, ) -> Result<()> { - // The `addExtraAccountsToInstruction` JS helper function resolving incorrectly let account_metas = vec![ ExtraAccountMeta::new_with_seeds( &[Seed::Literal {