"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const src_1 = require("../../src");
const chai_1 = require("chai");
const testUtils_1 = require("../testUtils");
const xrplJsTransactionTypesCheck_1 = require("./xrplJsTransactionTypesCheck");
describe("Test utils ", function () {
    it("should convert empty address to bytes ", async function () {
        const byts = (0, src_1.rippleAddressToBytes)("");
        (0, chai_1.expect)(byts.length).to.eq(1);
    });
    it("should convert classic account to bytes ", async function () {
        const acc = "r4BhzWSGGjTeSdpcXMPoT1AbiCQm76FQGd";
        const byts = (0, src_1.rippleAddressToBytes)(acc);
        (0, chai_1.expect)(byts.length).to.eq(20);
    });
    it("should convert x-account to bytes ", async function () {
        const acc = "XVLhHMPHU98es4dbozjVtdWzVrDjtV18pX8yuPT7y4xaEHi";
        const byts = (0, src_1.rippleAddressToBytes)(acc);
        (0, chai_1.expect)(byts.length).to.eq(20);
    });
    it("should check that classic and x-account to bytes match ", async function () {
        const acc = "XVLhHMPHU98es4dbozjVtdWzVrDjtV18pX8yuPT7y4xaEHi";
        const classicAcc = "rGWrZyQqhTp9Xu7G5Pkayo7bXjH4k4QYpf";
        const byts = (0, src_1.rippleAddressToBytes)(acc);
        const cByts = (0, src_1.rippleAddressToBytes)(classicAcc);
        (0, chai_1.expect)(byts.length).to.eq(20);
        (0, chai_1.expect)(cByts.length).to.eq(20);
        (0, chai_1.expect)(Buffer.compare(byts, cByts)).to.eq(0);
    });
    it("should encode and decode to same acc string ", async function () {
        const classicAcc = "rGWrZyQqhTp9Xu7G5Pkayo7bXjH4k4QYpf";
        const cByts = (0, src_1.rippleAddressToBytes)(classicAcc);
        const decode = (0, src_1.bytesToRippleAddress)(cByts);
        (0, chai_1.expect)(cByts.length).to.eq(20);
        (0, chai_1.expect)(classicAcc).to.eq(decode);
    });
    it("should not convert from bytes to ripple address", async function () {
        const byts = Buffer.from("0x00");
        const fn = () => {
            return (0, src_1.bytesToRippleAddress)(byts);
        };
        const er = `Not a valid ripple address`;
        (0, chai_1.expect)(fn).to.throw(Error);
        (0, chai_1.expect)(fn).to.throw(er);
    });
    it("should not decode from x-account to bytes ", async function () {
        const acc = "XVLhHMPHU98es4dbozjVtdWzVrDjtV18pX8yuPT7y4xaEHi";
        const classicAcc = "rGWrZyQqhTp9Xu7G5Pkayo7bXjH4k4QYpf";
        const byts = (0, src_1.rippleAddressToBytes)(acc);
        const decode = (0, src_1.bytesToRippleAddress)(byts);
        (0, chai_1.expect)(byts.length).to.eq(20);
        (0, chai_1.expect)(classicAcc).to.eq(decode);
    });
    it("should convert from ripple time to unix epoch", async function () {
        //1.1.2022 in ripple time = 694310400
        //1.1.2022 in unix epoch = 1640995200
        const rt2022 = 694310400;
        const expected = 1640995200;
        const res = (0, src_1.rippleTimeToUnixEpoch)(rt2022);
        (0, chai_1.expect)(res).to.equal(expected);
    });
    it("should convert from unix epoch to ripple time", async function () {
        //1.1.2022 in ripple time = 694310400
        //1.1.2022 in unix epoch = 1640995200
        const ux2022 = 1640995200;
        const expected = 694310400;
        const res = (0, src_1.unixEpochToRippleTime)(ux2022);
        (0, chai_1.expect)(res).to.equal(expected);
    });
    describe("transaction types", function () {
        it("should match xrpl types", async function () {
            const checkPassed = await (0, xrplJsTransactionTypesCheck_1.checkTransactionTypes)();
            (0, chai_1.assert)(checkPassed);
        });
    });
    describe("getters", function () {
        let tx;
        before(async function () {
            const XRPMccConnection = {
                url: process.env.XRP_URL || "",
                username: process.env.XRP_USERNAME || "",
                password: process.env.XRP_PASSWORD || "",
                apiTokenKey: process.env.FLARE_API_PORTAL_KEY || "",
            };
            const client = new src_1.MCC.XRP(XRPMccConnection);
            tx = await client.getTransaction("CFD798AA6AB21AAAF9459A59A7AF4C8A8414374F735D585D605D493317EFCC05");
        });
        for (const getters of [testUtils_1.GETTERS_AMOUNTS, testUtils_1.GETTERS_BASIC, testUtils_1.GETTERS_BN, testUtils_1.GETTERS_LISTS]) {
            for (let getter of getters) {
                it(`should have getter ${getter}`, function () {
                    (0, chai_1.expect)(getter in tx);
                });
            }
        }
    });
});
//# sourceMappingURL=utils.test.js.map