Browse Source

minor console log formatting updates

John 1 year ago
parent
commit
204e31bc2a

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

@@ -27,7 +27,6 @@ pub mod transfer_hook {
         ctx: Context<InitializeExtraAccountMetaList>,
     ) -> Result<()> {
 
-        // The `addExtraAccountsToInstruction` JS helper function resolving incorrectly
         let account_metas = vec![
             ExtraAccountMeta::new_with_seeds(
                 &[Seed::Literal {

+ 26 - 22
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,

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

@@ -21,10 +21,7 @@ pub mod transfer_hook {
         ctx: Context<InitializeExtraAccountMetaList>,
     ) -> 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;

+ 0 - 1
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)?,

+ 40 - 21
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);
   });
 });

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

@@ -21,7 +21,6 @@ pub mod transfer_hook {
         ctx: Context<InitializeExtraAccountMetaList>,
     ) -> Result<()> {
 
-        // The `addExtraAccountsToInstruction` JS helper function resolving incorrectly
         let account_metas = vec![
             ExtraAccountMeta::new_with_seeds(
                 &[Seed::Literal {