import assert from "node:assert/strict";
import test from "node:test";
import { type Address, type Hex } from "viem";
import { buildLaunchContractArgs, launchPreparationSchema } from "../src/launch.js";

const feeWallet = `0x${"11".repeat(20)}` as Address;
const salt = `0x${"22".repeat(32)}` as Hex;
const input = {
  name: "Signal",
  symbol: "sgnl",
  logo: "https://ponsagent.com/api/token-assets/signal",
  description: "A fixed launch input",
  socials: { twitter: "https://x.com/signal", website: "https://signal.example" },
};

test("prepared launch data reuses the exact logo, metadata, fee wallet, and salt", () => {
  const first = buildLaunchContractArgs(input, feeWallet, salt);
  const second = buildLaunchContractArgs(input, feeWallet, salt);
  assert.deepEqual(first, second);
  assert.equal(first[0].symbol, "SGNL");
  assert.equal(first[0].logo, input.logo);
  assert.equal(first[0].feeWallet, feeWallet);
  assert.equal(first[3], salt);
});

test("a prepared prediction requires a 32-byte salt, CA, and fixed launch fee", () => {
  const prepared = launchPreparationSchema.parse({
    salt,
    expectedTokenAddress: `0x${"33".repeat(20)}`,
    expectedLaunchFeeWei: "5000000000000000",
  });
  assert.equal(prepared.salt, salt);
  assert.throws(() => launchPreparationSchema.parse({
    salt: "0x1234",
    expectedTokenAddress: `0x${"33".repeat(20)}`,
    expectedLaunchFeeWei: "1",
  }));
});
