nac-presale/server/presale.test.ts

86 lines
3.0 KiB
TypeScript

import { describe, expect, it, vi, beforeEach } from "vitest";
import { CONTRACTS, TOKEN_PRICE_USDT, HARD_CAP_USDT, MAX_PURCHASE_USDT } from "./onchain";
describe("Presale Configuration", () => {
it("should have correct BSC presale contract address", () => {
expect(CONTRACTS.BSC.presale).toBe("0xc65e7a2738ed884db8d26a6eb2fecf7daca2e90c");
});
it("should have correct ETH presale contract address", () => {
expect(CONTRACTS.ETH.presale).toBe("0x85AB2F2d9f7ca7ecB272b5E8726c70f3fd45D1E3");
});
it("should have correct XIC token contract address", () => {
expect(CONTRACTS.BSC.token).toBe("0x59ff34dd59680a7125782b1f6df2a86ed46f5a24");
});
it("should have correct TRON receiving address", () => {
expect(CONTRACTS.TRON.receivingWallet).toBe("TWc2ugYBFN5aSoimAh4qGt9oMyket6NYZp");
});
it("should have correct TRON EVM receiving address", () => {
expect(CONTRACTS.TRON.evmReceivingWallet).toBe("0x43DAb577f3279e11D311E7d628C6201d893A9Aa3");
});
it("should have correct token price", () => {
expect(TOKEN_PRICE_USDT).toBe(0.02);
});
it("should have correct hard cap", () => {
expect(HARD_CAP_USDT).toBe(5_000_000);
});
it("should have correct max purchase limit", () => {
expect(MAX_PURCHASE_USDT).toBe(50_000);
});
it("should calculate XIC amount correctly from USDT", () => {
const usdtAmount = 100;
const expectedXic = usdtAmount / TOKEN_PRICE_USDT;
expect(expectedXic).toBe(5000);
});
it("should calculate XIC amount for large purchase", () => {
const usdtAmount = 50000;
const expectedXic = usdtAmount / TOKEN_PRICE_USDT;
expect(expectedXic).toBe(2_500_000);
});
});
describe("TRC20 Monitor Logic", () => {
it("should correctly calculate XIC from USDT amount (6 decimals)", () => {
// USDT on TRON has 6 decimals
const rawValue = "100000000"; // 100 USDT
const usdtAmount = Number(rawValue) / 1_000_000;
const xicAmount = usdtAmount / TOKEN_PRICE_USDT;
expect(usdtAmount).toBe(100);
expect(xicAmount).toBe(5000);
});
it("should skip dust transactions below 0.01 USDT", () => {
const rawValue = "5000"; // 0.005 USDT
const usdtAmount = Number(rawValue) / 1_000_000;
expect(usdtAmount).toBeLessThan(0.01);
});
it("should correctly parse large USDT amounts", () => {
const rawValue = "50000000000"; // 50,000 USDT
const usdtAmount = Number(rawValue) / 1_000_000;
expect(usdtAmount).toBe(50000);
});
});
describe("i18n translations", () => {
it("should have matching keys in EN and ZH", async () => {
const { translations } = await import("../client/src/lib/i18n");
const enKeys = Object.keys(translations.en).filter(k => k !== "faq");
const zhKeys = Object.keys(translations.zh).filter(k => k !== "faq");
expect(enKeys.sort()).toEqual(zhKeys.sort());
});
it("should have same number of FAQ items in EN and ZH", async () => {
const { translations } = await import("../client/src/lib/i18n");
expect(translations.en.faq.length).toBe(translations.zh.faq.length);
});
});