"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const chai_1 = require("chai");
const src_1 = require("../../src");
const testUtils_1 = require("../testUtils");
const BtcMccConnection = {
    url: process.env.BTC_URL || "",
    username: process.env.BTC_USERNAME || "",
    password: process.env.BTC_PASSWORD || "",
    apiTokenKey: process.env.FLARE_API_PORTAL_KEY || "",
};
describe(`Balance decrease test for BTC, (${(0, testUtils_1.getTestFile)(__filename)})`, function () {
    let MccClient;
    before(async function () {
        MccClient = new src_1.MCC.BTC(BtcMccConnection);
        src_1.traceManager.displayStateOnException = false;
        src_1.traceManager.displayRuntimeTrace = false;
    });
    it("Should detect balance decreasing for 8bae12b5f4c088d940733dcd1455efc6a3a69cf9340e17a981286d3778615684", async function () {
        const transaction = await MccClient.getTransaction("8bae12b5f4c088d940733dcd1455efc6a3a69cf9340e17a981286d3778615684");
        const dec = await transaction.balanceDecreasingSummary({
            sourceAddressIndicator: (0, src_1.toHex32Bytes)(0),
            client: MccClient,
        });
        // console.dir(dec, { depth: null });
        (0, chai_1.expect)(dec.status).to.eq(src_1.BalanceDecreasingSummaryStatus.Success);
        if (dec.response) {
            const decRes = dec.response;
            (0, chai_1.expect)(decRes.blockTimestamp).to.eq(1404107109);
            (0, chai_1.expect)(decRes.transactionHash).to.eq("8bae12b5f4c088d940733dcd1455efc6a3a69cf9340e17a981286d3778615684");
            (0, chai_1.expect)(decRes.sourceAddressHash).to.eq((0, src_1.standardAddressHash)("1HnhWpkMHMjgt167kvgcPyurMmsCQ2WPgg"));
            (0, chai_1.expect)(decRes.sourceAddress).to.eq("1HnhWpkMHMjgt167kvgcPyurMmsCQ2WPgg");
            (0, chai_1.expect)(decRes.spentAmount.toString()).to.eq("220000");
            (0, chai_1.expect)(decRes.isFull).to.eq(true);
            (0, chai_1.expect)(decRes.paymentReference).to.eq(src_1.ZERO_BYTES_32);
        }
    });
    it("Should detect balance decreasing for 5e245d1c690b9a5686414b3c486500c6bd1ddbc6a37eb70be2cf81639b39c1d4", async function () {
        const transaction = await MccClient.getTransaction("5e245d1c690b9a5686414b3c486500c6bd1ddbc6a37eb70be2cf81639b39c1d4");
        const dec = await transaction.balanceDecreasingSummary({ sourceAddressIndicator: (0, src_1.toHex32Bytes)(2), client: MccClient });
        // console.dir(dec, { depth: null });
        (0, chai_1.expect)(dec.status).to.eq(src_1.BalanceDecreasingSummaryStatus.Success);
        if (dec.response) {
            const decRes = dec.response;
            (0, chai_1.expect)(decRes.blockTimestamp).to.eq(1682056438);
            (0, chai_1.expect)(decRes.transactionHash).to.eq("5e245d1c690b9a5686414b3c486500c6bd1ddbc6a37eb70be2cf81639b39c1d4");
            (0, chai_1.expect)(decRes.sourceAddressHash).to.eq((0, src_1.standardAddressHash)("1Lm4XEmHNsNCeKdPS7bc4RGHdAAtBjBjtF"));
            (0, chai_1.expect)(decRes.sourceAddress).to.eq("1Lm4XEmHNsNCeKdPS7bc4RGHdAAtBjBjtF");
            (0, chai_1.expect)(decRes.spentAmount.toString()).to.eq("3526751");
            (0, chai_1.expect)(decRes.isFull).to.eq(true);
            (0, chai_1.expect)(decRes.paymentReference).to.eq(src_1.ZERO_BYTES_32);
        }
    });
    it("Should detect balance decreasing for 64238c5599bf0bda690db001172a9e142e8b2b9a542e747570c191788a585d1e", async function () {
        const transaction = await MccClient.getTransaction("64238c5599bf0bda690db001172a9e142e8b2b9a542e747570c191788a585d1e");
        const dec = await transaction.balanceDecreasingSummary({ sourceAddressIndicator: (0, src_1.toHex32Bytes)(0), client: MccClient });
        // console.dir(dec, { depth: null });
        (0, chai_1.expect)(dec.status).to.eq(src_1.BalanceDecreasingSummaryStatus.Success);
        if (dec.response) {
            const decRes = dec.response;
            (0, chai_1.expect)(decRes.blockTimestamp).to.eq(1682063799);
            (0, chai_1.expect)(decRes.transactionHash).to.eq("64238c5599bf0bda690db001172a9e142e8b2b9a542e747570c191788a585d1e");
            (0, chai_1.expect)(decRes.sourceAddressHash).to.eq((0, src_1.standardAddressHash)("bc1q32sxnq5hecdurfzgzp5x0zh8du86v9x84wdqdx"));
            (0, chai_1.expect)(decRes.sourceAddress).to.eq("bc1q32sxnq5hecdurfzgzp5x0zh8du86v9x84wdqdx");
            (0, chai_1.expect)(decRes.spentAmount.toString()).to.eq("3388240291");
            (0, chai_1.expect)(decRes.isFull).to.eq(true);
            (0, chai_1.expect)(decRes.paymentReference).to.eq(src_1.ZERO_BYTES_32);
        }
    });
    it("Should detect balance decreasing for 2765f45b93095878a5b48f6726b13d622a7f6135aafdc34e88d05865cd60e68c", async function () {
        const transaction = await MccClient.getTransaction("2765f45b93095878a5b48f6726b13d622a7f6135aafdc34e88d05865cd60e68c");
        const dec = await transaction.balanceDecreasingSummary({ sourceAddressIndicator: (0, src_1.toHex32Bytes)(2), client: MccClient });
        (0, chai_1.expect)(dec.status).to.eq(src_1.BalanceDecreasingSummaryStatus.InvalidInUtxo);
    });
    it("Should detect balance decreasing for 2765f45b93095878a5b48f6726b13d622a7f6135aafdc34e88d05865cd60e68c", async function () {
        const transaction = await MccClient.getTransaction("2765f45b93095878a5b48f6726b13d622a7f6135aafdc34e88d05865cd60e68c");
        const dec = await transaction.balanceDecreasingSummary({ sourceAddressIndicator: "0x", client: MccClient });
        (0, chai_1.expect)(dec.status).to.eq(src_1.BalanceDecreasingSummaryStatus.NotValidSourceAddressFormat);
    });
});
//# sourceMappingURL=balanceDecreasing.test.js.map