"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const chai_1 = require("chai");
const src_1 = require("../../src");
// eslint-disable-next-line @typescript-eslint/no-var-requires
const chai = require("chai");
// eslint-disable-next-line @typescript-eslint/no-var-requires
chai.use(require("chai-as-promised"));
const DogeMccConnection = {
    url: process.env.DOGE_URL || "",
    username: process.env.DOGE_USERNAME || "",
    password: process.env.DOGE_PASSWORD || "",
    apiTokenKey: process.env.FLARE_API_PORTAL_KEY || "",
};
describe("Transaction DOGE base test ", function () {
    let MccClient;
    before(async function () {
        src_1.traceManager.displayStateOnException = false;
        MccClient = new src_1.MCC.DOGE(DogeMccConnection);
    });
    describe("Transaction does not exist ", function () {
        const txid = "8bae12b5f4c088d940733dcd1455efc6a3a69cf9340e17a981286d37786156ff";
        it("Should get transaction does not exist ", async function () {
            const transaction = MccClient.getTransaction(txid);
            await (0, chai_1.expect)(transaction).to.be.rejectedWith("InvalidTransaction");
        });
    });
    const TransactionsToTest = [
        {
            description: "Transaction 1 ",
            txid: "de07c395ab9e3d987f13f72ee71f0b3ba4217c3b4df6f9dd928fe579c014b90e",
            expect: {
                txid: "de07c395ab9e3d987f13f72ee71f0b3ba4217c3b4df6f9dd928fe579c014b90e",
                stdTxid: "de07c395ab9e3d987f13f72ee71f0b3ba4217c3b4df6f9dd928fe579c014b90e",
                hash: "de07c395ab9e3d987f13f72ee71f0b3ba4217c3b4df6f9dd928fe579c014b90e",
                reference: [],
                stdPaymentReference: "0x0000000000000000000000000000000000000000000000000000000000000000",
                unixTimestamp: 1647899747,
                sourceAddresses: [undefined],
                receivingAddresses: ["DPcBYzf5vGemYGtWK6BZbvHqvCSAzwpscv", "9theYDTPbCniM4Rdnza3RdeCw4d1H68sDz"],
                isFeeError: true,
                fee: "InvalidResponse",
                spentAmounts: [
                    {
                        address: undefined,
                        amount: (0, src_1.toBN)(0),
                    },
                ],
                receivedAmounts: [
                    {
                        address: "DPcBYzf5vGemYGtWK6BZbvHqvCSAzwpscv",
                        amount: (0, src_1.toBN)(27791743986),
                    },
                    {
                        address: "9theYDTPbCniM4Rdnza3RdeCw4d1H68sDz",
                        amount: (0, src_1.toBN)(1677708425369),
                    },
                ],
                type: "payment",
                isNativePayment: true,
                currencyName: "DOGE",
                elementaryUnits: "100000000",
                successStatus: src_1.TransactionSuccessStatus.SUCCESS,
            },
            summary: {
                status: src_1.PaymentSummaryStatus.Success,
            },
        },
        {
            description: "Coinbase Transaction",
            txid: "9d863418ef3761eb45fd38eea5074965efa1266694a8b2826d5ce148aa564095",
            expect: {
                txid: "9d863418ef3761eb45fd38eea5074965efa1266694a8b2826d5ce148aa564095",
                stdTxid: "9d863418ef3761eb45fd38eea5074965efa1266694a8b2826d5ce148aa564095",
                hash: "9d863418ef3761eb45fd38eea5074965efa1266694a8b2826d5ce148aa564095",
                reference: [],
                stdPaymentReference: "0x0000000000000000000000000000000000000000000000000000000000000000",
                unixTimestamp: 1647899747,
                sourceAddresses: [undefined],
                receivingAddresses: ["DMr3fEiVrPWFpoCWS958zNtqgnFb7QWn9D"],
                isFeeError: false,
                fee: "0",
                spentAmounts: [
                    {
                        address: undefined,
                        amount: (0, src_1.toBN)(0),
                    },
                ],
                receivedAmounts: [
                    {
                        address: "DMr3fEiVrPWFpoCWS958zNtqgnFb7QWn9D",
                        amount: (0, src_1.toBN)(1001181448000),
                    },
                ],
                type: "coinbase",
                isNativePayment: true,
                currencyName: "DOGE",
                elementaryUnits: "100000000",
                successStatus: src_1.TransactionSuccessStatus.SUCCESS,
            },
            summary: {
                status: src_1.PaymentSummaryStatus.Success,
            },
        },
    ];
    for (const transData of TransactionsToTest) {
        describe(transData.description, function () {
            let transaction;
            before(async function () {
                transaction = await MccClient.getTransaction(transData.txid);
            });
            it("Should find transaction in block ", function () {
                (0, chai_1.expect)(transaction).to.not.eq(undefined);
            });
            it("Should get transaction txid ", async function () {
                (0, chai_1.expect)(transaction.txid).to.eq(transData.expect.txid);
            });
            it("Should get standardized txid ", async function () {
                (0, chai_1.expect)(transaction.stdTxid).to.eq(transData.expect.stdTxid);
            });
            it("Should get transaction hash ", async function () {
                (0, chai_1.expect)(transaction.hash).to.eq(transData.expect.hash);
            });
            it("Should get transaction reference array ", async function () {
                (0, chai_1.expect)(transaction.reference.length).to.eq(transData.expect.reference.length);
                const a = transaction.reference.sort();
                const b = transData.expect.reference.sort();
                for (let i = 0; i < a.length; i++) {
                    (0, chai_1.expect)(a[i]).to.eq(b[i]);
                }
            });
            it("Should get standardized transaction reference ", async function () {
                (0, chai_1.expect)(transaction.stdPaymentReference).to.eq(transData.expect.stdPaymentReference);
            });
            it("Should get transaction timestamp ", async function () {
                (0, chai_1.expect)(transaction.unixTimestamp).to.eq(transData.expect.unixTimestamp);
            });
            it("Should get source address ", async function () {
                (0, chai_1.expect)(transaction.sourceAddresses.length).to.eq(transData.expect.sourceAddresses.length);
                const a = transaction.sourceAddresses.sort();
                const b = transData.expect.sourceAddresses.sort();
                for (let i = 0; i < a.length; i++) {
                    (0, chai_1.expect)(a[i]).to.eq(b[i]);
                }
            });
            it("Should get receiving address ", async function () {
                (0, chai_1.expect)(transaction.receivingAddresses.length).to.eq(transData.expect.receivingAddresses.length);
                const a = transaction.receivingAddresses.sort();
                const b = transData.expect.receivingAddresses.sort();
                for (let i = 0; i < a.length; i++) {
                    (0, chai_1.expect)(a[i]).to.eq(b[i]);
                }
            });
            it("Should get fee ", async function () {
                if (transData.expect.isFeeError) {
                    (0, chai_1.expect)(function () {
                        transaction.fee;
                    }).to.throw(transData.expect.fee);
                }
                else {
                    (0, chai_1.expect)(transaction.fee.toString()).to.eq(transData.expect.fee);
                }
            });
            it("Should spend amount ", async function () {
                (0, chai_1.expect)(transaction.spentAmounts.length).to.eq(transData.expect.spentAmounts.length);
                const a = transaction.spentAmounts.sort();
                const b = transData.expect.spentAmounts.sort();
                for (let i = 0; i < a.length; i++) {
                    (0, chai_1.expect)(a[i].address).to.eq(b[i].address);
                    (0, chai_1.expect)(a[i].amount.toString()).to.eq(b[i].amount.toString());
                }
            });
            it("Should received amount ", async function () {
                (0, chai_1.expect)(transaction.receivedAmounts.length).to.eq(transData.expect.receivedAmounts.length);
                const a = transaction.receivedAmounts.sort();
                const b = transData.expect.receivedAmounts.sort();
                for (let i = 0; i < a.length; i++) {
                    (0, chai_1.expect)(a[i].address).to.eq(b[i].address);
                    (0, chai_1.expect)(a[i].amount.toString()).to.eq(b[i].amount.toString());
                }
            });
            it("Should get type ", async function () {
                (0, chai_1.expect)(transaction.type).to.eq(transData.expect.type);
            });
            it("Should check if native payment ", async function () {
                (0, chai_1.expect)(transaction.isNativePayment).to.eq(transData.expect.isNativePayment);
            });
            it("Should get currency name ", async function () {
                (0, chai_1.expect)(transaction.currencyName).to.eq(transData.expect.currencyName);
            });
            it("Should get elementary unit ", async function () {
                (0, chai_1.expect)(transaction.elementaryUnits.toString()).to.eq(transData.expect.elementaryUnits);
            });
            it("Should get success status ", async function () {
                (0, chai_1.expect)(transaction.successStatus).to.eq(transData.expect.successStatus);
            });
            it("should validate pkscripts", function () {
                for (let index = 0; index < transaction["data"].vout.length; index++) {
                    (0, chai_1.assert)(transaction.isValidPkscript(index));
                }
            });
        });
    }
});
//# sourceMappingURL=transaction.test.js.map