"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
/* eslint-disable @typescript-eslint/no-non-null-assertion */
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(`Transaction Btc test ,(${(0, testUtils_1.getTestFile)(__filename)})`, function () {
    let MccClient;
    before(async function () {
        MccClient = new src_1.MCC.BTC(BtcMccConnection);
    });
    describe("Transaction full processed ", function () {
        const txid = "0x4d58bd737d87eb2011ba7e0d33d3a0c8f94f13020dd096f8d1b96849c9660a53";
        let transaction;
        before(async () => {
            transaction = await MccClient.getTransaction(txid);
            await transaction.makeFullPayment(MccClient);
        });
        it("Should get transaction txid ", async function () {
            (0, chai_1.expect)(transaction.txid).to.eq("4d58bd737d87eb2011ba7e0d33d3a0c8f94f13020dd096f8d1b96849c9660a53");
        });
        it("Should get standardized txid ", async function () {
            (0, chai_1.expect)(transaction.stdTxid).to.eq("4d58bd737d87eb2011ba7e0d33d3a0c8f94f13020dd096f8d1b96849c9660a53");
        });
        it("Should get transaction hash ", async function () {
            (0, chai_1.expect)(transaction.hash).to.eq("c16f1d89e5e82ecfebe57f3ff5fc1c7a6144964a133da24ec3216965cf787cfd");
        });
        it("Should get transaction reference array ", async function () {
            (0, chai_1.expect)(transaction.reference.length).to.eq(0);
        });
        it("Should get standardized transaction reference ", async function () {
            (0, chai_1.expect)(transaction.stdPaymentReference).to.eq("0x0000000000000000000000000000000000000000000000000000000000000000");
        });
        it("Should get transaction timestamp ", async function () {
            // From https://blockstream.info/tx/4d58bd737d87eb2011ba7e0d33d3a0c8f94f13020dd096f8d1b96849c9660a53
            (0, chai_1.expect)(transaction.unixTimestamp).to.eq(1650342330);
        });
        it("Should get source address ", async function () {
            (0, chai_1.expect)(transaction.sourceAddresses.length).to.eq(2);
            (0, chai_1.expect)(transaction.sourceAddresses[0]).to.eq("bc1qdl753ur9ucwa3cgfrud2nqvu7k69dykk3cwwx6g64a5szn3xw92sp8mc7a");
            (0, chai_1.expect)(transaction.sourceAddresses[1]).to.eq("bc1qdl753ur9ucwa3cgfrud2nqvu7k69dykk3cwwx6g64a5szn3xw92sp8mc7a");
        });
        it("Should get receiving address ", async function () {
            (0, chai_1.expect)(transaction.receivingAddresses.length).to.eq(2);
            (0, chai_1.expect)(transaction.receivingAddresses[0]).to.eq("1KiJkugknjgW6AHXNgVQgNuo3b5DqsVFmk");
            (0, chai_1.expect)(transaction.receivingAddresses[1]).to.eq("bc1qwqdg6squsna38e46795at95yu9atm8azzmyvckulcc7kytlcckxswvvzej");
        });
        it("Should get fee ", async function () {
            (0, chai_1.expect)(transaction.fee.toNumber()).to.eq(40000);
        });
        it("Should spend amount ", async function () {
            (0, chai_1.expect)(transaction.spentAmounts.length).to.eq(2);
            (0, chai_1.expect)(transaction.spentAmounts[0].address).to.eq("bc1qdl753ur9ucwa3cgfrud2nqvu7k69dykk3cwwx6g64a5szn3xw92sp8mc7a");
            (0, chai_1.expect)(transaction.spentAmounts[0].amount.toNumber()).to.eq(400000000);
            (0, chai_1.expect)(transaction.spentAmounts[1].address).to.eq("bc1qdl753ur9ucwa3cgfrud2nqvu7k69dykk3cwwx6g64a5szn3xw92sp8mc7a");
            (0, chai_1.expect)(transaction.spentAmounts[1].amount.toNumber()).to.eq(400000000);
        });
        it("Should received amount ", async function () {
            (0, chai_1.expect)(transaction.receivedAmounts.length).to.eq(2);
            (0, chai_1.expect)(transaction.receivedAmounts[0].address).to.eq("1KiJkugknjgW6AHXNgVQgNuo3b5DqsVFmk");
            (0, chai_1.expect)(transaction.receivedAmounts[0].amount.toNumber()).to.eq(494000000);
            (0, chai_1.expect)(transaction.receivedAmounts[1].address).to.eq("bc1qwqdg6squsna38e46795at95yu9atm8azzmyvckulcc7kytlcckxswvvzej");
            (0, chai_1.expect)(transaction.receivedAmounts[1].amount.toNumber()).to.eq(305960000);
        });
        it("Should get type ", async function () {
            (0, chai_1.expect)(transaction.type).to.eq("full_payment");
        });
        it("Should check if native payment ", async function () {
            (0, chai_1.expect)(transaction.isNativePayment).to.eq(true);
        });
        it("Should get currency name ", async function () {
            (0, chai_1.expect)(transaction.currencyName).to.eq("BTC");
        });
        it("Should get elementary unit ", async function () {
            (0, chai_1.expect)(transaction.elementaryUnits.toNumber()).to.eq(100000000);
        });
        it("Should get success status ", async function () {
            (0, chai_1.expect)(transaction.successStatus).to.eq(0);
        });
        it("Should get payment summary from utxo 0 to utxo 0", async function () {
            var _a, _b;
            const summary = await transaction.paymentSummary({ client: MccClient, inUtxo: 0, outUtxo: 0 });
            (0, chai_1.expect)(summary.status).to.eq(src_1.PaymentSummaryStatus.Success);
            (0, chai_1.expect)(summary.response).to.exist;
            (0, chai_1.expect)(summary.response.sourceAddress).to.eq("bc1qdl753ur9ucwa3cgfrud2nqvu7k69dykk3cwwx6g64a5szn3xw92sp8mc7a");
            (0, chai_1.expect)(summary.response.receivingAddress).to.eq("1KiJkugknjgW6AHXNgVQgNuo3b5DqsVFmk");
            (0, chai_1.expect)((_a = summary.response.spentAmount) === null || _a === void 0 ? void 0 : _a.toNumber()).to.eq(800000000);
            (0, chai_1.expect)((_b = summary.response.receivedAmount) === null || _b === void 0 ? void 0 : _b.toNumber()).to.eq(494000000);
            (0, chai_1.expect)(summary.response.paymentReference).to.eq("0x0000000000000000000000000000000000000000000000000000000000000000");
            (0, chai_1.expect)(summary.response.oneToOne).to.eq(false);
            (0, chai_1.expect)(summary.response.isFull).to.eq(true);
        });
        it("Should get payment summary from utxo 0 to utxo 1", async function () {
            var _a, _b;
            const summary = await transaction.paymentSummary({ client: MccClient, inUtxo: 0, outUtxo: 1 });
            (0, chai_1.expect)(summary.status).to.eq(src_1.PaymentSummaryStatus.Success);
            (0, chai_1.expect)(summary.response).to.exist;
            (0, chai_1.expect)(summary.response.sourceAddress).to.eq("bc1qdl753ur9ucwa3cgfrud2nqvu7k69dykk3cwwx6g64a5szn3xw92sp8mc7a");
            (0, chai_1.expect)(summary.response.receivingAddress).to.eq("bc1qwqdg6squsna38e46795at95yu9atm8azzmyvckulcc7kytlcckxswvvzej");
            (0, chai_1.expect)((_a = summary.response.spentAmount) === null || _a === void 0 ? void 0 : _a.toNumber()).to.eq(800000000);
            (0, chai_1.expect)((_b = summary.response.receivedAmount) === null || _b === void 0 ? void 0 : _b.toNumber()).to.eq(305960000);
            (0, chai_1.expect)(summary.response.paymentReference).to.eq("0x0000000000000000000000000000000000000000000000000000000000000000");
            (0, chai_1.expect)(summary.response.oneToOne).to.eq(false);
            (0, chai_1.expect)(summary.response.isFull).to.eq(true);
        });
        it("Should get payment summary from utxo 1 to utxo 0", async function () {
            var _a, _b;
            const summary = await transaction.paymentSummary({ client: MccClient, inUtxo: 1, outUtxo: 0 });
            (0, chai_1.expect)(summary.status).to.eq(src_1.PaymentSummaryStatus.Success);
            (0, chai_1.expect)(summary.response).to.exist;
            (0, chai_1.expect)(summary.response.sourceAddress).to.eq("bc1qdl753ur9ucwa3cgfrud2nqvu7k69dykk3cwwx6g64a5szn3xw92sp8mc7a");
            (0, chai_1.expect)(summary.response.receivingAddress).to.eq("1KiJkugknjgW6AHXNgVQgNuo3b5DqsVFmk");
            (0, chai_1.expect)((_a = summary.response.spentAmount) === null || _a === void 0 ? void 0 : _a.toNumber()).to.eq(800000000);
            (0, chai_1.expect)((_b = summary.response.receivedAmount) === null || _b === void 0 ? void 0 : _b.toNumber()).to.eq(494000000);
            (0, chai_1.expect)(summary.response.paymentReference).to.eq("0x0000000000000000000000000000000000000000000000000000000000000000");
            (0, chai_1.expect)(summary.response.oneToOne).to.eq(false);
            (0, chai_1.expect)(summary.response.isFull).to.eq(true);
        });
        it("Should get payment summary from utxo 1 to utxo 1", async function () {
            var _a, _b;
            const summary = await transaction.paymentSummary({ client: MccClient, inUtxo: 1, outUtxo: 1 });
            (0, chai_1.expect)(summary.status).to.eq(src_1.PaymentSummaryStatus.Success);
            (0, chai_1.expect)(summary.response).to.exist;
            (0, chai_1.expect)(summary.response.sourceAddress).to.eq("bc1qdl753ur9ucwa3cgfrud2nqvu7k69dykk3cwwx6g64a5szn3xw92sp8mc7a");
            (0, chai_1.expect)(summary.response.receivingAddress).to.eq("bc1qwqdg6squsna38e46795at95yu9atm8azzmyvckulcc7kytlcckxswvvzej");
            (0, chai_1.expect)((_a = summary.response.spentAmount) === null || _a === void 0 ? void 0 : _a.toNumber()).to.eq(800000000);
            (0, chai_1.expect)((_b = summary.response.receivedAmount) === null || _b === void 0 ? void 0 : _b.toNumber()).to.eq(305960000);
            (0, chai_1.expect)(summary.response.paymentReference).to.eq("0x0000000000000000000000000000000000000000000000000000000000000000");
            (0, chai_1.expect)(summary.response.oneToOne).to.eq(false);
            (0, chai_1.expect)(summary.response.isFull).to.eq(true);
        });
    });
});
//# sourceMappingURL=transactionObject.test.js.map