import { describe, it } from "mocha";

import {
	createAssociatedTokenAccountInstruction,
	getAssociatedTokenAddressSync,
} from "@solana/spl-token";
import { PublicKey, Transaction } from "@solana/web3.js";

import { getConnection, getProviders } from "../shared";

describe("claimTokens()", () => {
	const connection = getConnection("mainnet-beta");
	const provider = getProviders(connection)[0];

	it("fetch auction info", async () => {
		const mint = new PublicKey("A1AaPuUirJaCkidfntEPBSgYzg91mPBFeKjrrx342Yux");
		const pda = new PublicKey("CmvD6UdEznUGty1tkPxxsnyTFTkb5mg2vhRYbPaxG7x8");

		const tx = new Transaction();

		const ata = getAssociatedTokenAddressSync(mint, pda, true);

		tx.add(createAssociatedTokenAccountInstruction(provider.publicKey, ata, pda, mint));

		const { blockhash, lastValidBlockHeight } = await connection.getLatestBlockhash();

		tx.feePayer = provider.publicKey;
		tx.recentBlockhash = blockhash;
		tx.lastValidBlockHeight = lastValidBlockHeight;

		const signed = await provider.wallet.signTransaction(tx);
		const signature = await connection.sendRawTransaction(signed.serialize());

		console.log({ signature });
		await connection.confirmTransaction({ signature, blockhash, lastValidBlockHeight });
	});
});
