Skip to content

Commit

Permalink
minor console log formatting updates
Browse files Browse the repository at this point in the history
  • Loading branch information
ZYJLiu committed Mar 20, 2024
1 parent 8e79654 commit 204e31b
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
createAssociatedTokenAccountInstruction,
createMintToInstruction,
getAssociatedTokenAddressSync,
createTransferCheckedWithTransferHookInstruction
createTransferCheckedWithTransferHookInstruction,
} from "@solana/spl-token";

describe("transfer-hook", () => {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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}`);
});

Expand Down Expand Up @@ -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);
});
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)?,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Expand Down Expand Up @@ -250,43 +250,62 @@ 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,
syncWrappedSolInstruction,
approveInstruction,
transferInstruction
);

const txSig = await sendAndConfirmTransaction(
connection,
transaction,
Expand All @@ -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);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 204e31b

Please sign in to comment.