"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const chai_1 = require("chai");
const src_1 = require("../../src");
const globalSettings_1 = require("../../src/global-settings/globalSettings");
const xrpUtils_1 = require("../../src/utils/xrpUtils");
const testUtils_1 = require("../testUtils");
const sinon_1 = __importDefault(require("sinon"));
// 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 XRPMccConnection = {
    url: process.env.XRP_URL || "",
    username: process.env.XRP_USERNAME || "",
    password: process.env.XRP_PASSWORD || "",
    apiTokenKey: process.env.FLARE_API_PORTAL_KEY || "",
};
describe("Xrpl account test mainnet ", function () {
    let MccClient;
    before(async function () {
        sinon_1.default.stub(console, "error");
        src_1.traceManager.displayRuntimeTrace = false;
        src_1.traceManager.displayStateOnException = false;
        MccClient = new src_1.MCC.XRP(XRPMccConnection);
        globalSettings_1.mccSettings.setLoggingCallback = () => {
            return;
        };
    });
    describe("account info", async () => {
        it(`Should get account info`, async () => {
            const acc = "rG1QQv2nh2gr7RCZ1P8YYcBUKCCN633jCn";
            const info = await MccClient.getAccountInfo(acc);
            // Get the flags
            const flags = (0, xrpUtils_1.processFlags)(info.result.account_data.Flags);
            (0, chai_1.expect)(flags.length).to.eq(1);
            (0, chai_1.expect)(flags[0]).to.eq("lsfDisableMaster");
        });
        it(`Should get account info 2 `, async () => {
            const acc = "rMv1dFonUTJo4qeQDmmCuz3cXPsxy9AiHz";
            const info = await MccClient.getAccountInfo(acc);
            // Get the flags
            const flags = (0, xrpUtils_1.processFlags)(info.result.account_data.Flags);
            (0, chai_1.expect)(flags.length).to.eq(0);
            // get account founding transaction (account create)
            const fTx = "5439BB6872644CE74A09F4654CECFC5F443E9687AD5EF6D119E729898F41A8C5";
            const trans = await MccClient.getTransaction(fTx);
            (0, chai_1.expect)(trans.isAccountCreate).to.eq(true);
        });
        it(`Should not get account info - invalid upper bound`, async () => {
            const acc = "rMv1dFonUTJo4qeQDmmCuz3cXPsxy9AiHz";
            await (0, chai_1.expect)(MccClient.getAccountInfo(acc, "28_014_733")).to.eventually.be.rejected;
        });
        it(`Should get account info 3 `, async () => {
            const acc = "rMv1dFonUTJo4qeQDmmCuz3cXPsxy9AiHz";
            const info = await MccClient.getAccountInfo(acc);
            // Get the flags
            const flags = (0, xrpUtils_1.processFlags)(info.result.account_data.Flags);
            (0, chai_1.expect)(flags.length).to.eq(0);
            // get account founding transaction (account create)
            const fTx = "5439BB6872644CE74A09F4654CECFC5F443E9687AD5EF6D119E729898F41A8C5";
            const trans = await MccClient.getTransaction(fTx, { binary: true, min_block: 1, max_block: 2 });
            (0, chai_1.expect)(trans.isAccountCreate).to.eq(false);
        });
    });
    describe("account transactions", async () => {
        it(`Should get account transactions`, async () => {
            const acc = "r4BhzWSGGjTeSdpcXMPoT1AbiCQm76FQGd";
            // get account transactions
            const tr = await MccClient.getAccountTransactions(acc, 71859000, 71867500);
            (0, chai_1.expect)(tr.result.transactions.length).to.eq(73);
        });
        it(`Should get account transactions`, async () => {
            const acc = "r4BhzWSGGjTeSdpcXMPoT1AbiCQm76FQGd";
            // get account transactions
            const tr = await MccClient.getAccountTransactions(acc);
            (0, chai_1.expect)(tr.result.account).to.equal("r4BhzWSGGjTeSdpcXMPoT1AbiCQm76FQGd");
        });
    });
});
const XRPMccConnectionTest = {
    url: process.env.XRP_URL_TESTNET || "https://s1.ripple.com:51234",
    username: process.env.XRP_USERNAME_TESTNET || "",
    password: process.env.XRP_PASSWORD_TESTNET || "",
};
describe.skip(`Xrpl account test testnet (${(0, testUtils_1.getTestFile)(__filename)})`, function () {
    let MccClient;
    before(async function () {
        MccClient = new src_1.MCC.XRP(XRPMccConnectionTest);
    });
    describe.skip("account info", async () => {
        it(`Should get account info`, async () => {
            var _a, _b;
            const info = await MccClient.getAccountInfo("rBwD7GqAPFoZvzz6YaR5HyJWD8TUoaUbJo");
            // Get the flags
            const flags = (0, xrpUtils_1.processFlags)(info.result.account_data.Flags);
            (0, chai_1.expect)(flags.length).to.eq(3);
            // Regular key
            (0, chai_1.expect)(info.result.account_data.RegularKey).to.eq(src_1.SpecialAddresses.ACCOUNT_ONE);
            // Multisig check
            // TODO ripple has a problem here?
            // eslint-disable-next-line @typescript-eslint/ban-ts-comment
            // @ts-ignore
            if ((_a = info.result.account_data) === null || _a === void 0 ? void 0 : _a.signer_lists) {
                // eslint-disable-next-line @typescript-eslint/ban-ts-comment
                // @ts-ignore
                (0, chai_1.expect)((_b = info.result.account_data) === null || _b === void 0 ? void 0 : _b.signer_lists.length).to.eq(0);
            }
        });
    });
    // Testnet gets reset sometimes
    describe("step by step account info", async () => {
        const acc = "rD8btyHW512KmJdsQEoD9KFTMxfDbpqkkA"; // my acc
        it.skip(`Should get account info at the begging`, async () => {
            const info = await MccClient.getAccountInfo(acc, 28014551);
            const flags = (0, xrpUtils_1.processFlags)(info.result.account_data.Flags);
            (0, chai_1.expect)(flags.length).to.eq(0);
            (0, chai_1.expect)(info.result.account_data.RegularKey).to.not.eq(src_1.SpecialAddresses.ACCOUNT_ONE);
        });
        // set by tx 996CF647C655904730759CE3919E5B4F4AB6E99046EB53DA0457F1956A52B6E3
        it.skip(`Should get account info after setting default rippling`, async () => {
            const info = await MccClient.getAccountInfo(acc, 28014612);
            const flags = (0, xrpUtils_1.processFlags)(info.result.account_data.Flags);
            (0, chai_1.expect)(flags.length).to.eq(1);
            (0, chai_1.expect)(flags.includes("lsfDefaultRipple")).to.eq(true);
            (0, chai_1.expect)(info.result.account_data.RegularKey).to.not.eq(src_1.SpecialAddresses.ACCOUNT_ONE);
        });
        // set by E547D21C4F24FC313F492828730C17B442C37038393705A18C64D400D186319D
        it.skip(`Should get account info after setting regular key to ACCOUNT_ONE`, async () => {
            const info = await MccClient.getAccountInfo(acc, 28014704);
            const flags = (0, xrpUtils_1.processFlags)(info.result.account_data.Flags);
            (0, chai_1.expect)(flags.length).to.eq(2);
            (0, chai_1.expect)(flags.includes("lsfDefaultRipple")).to.eq(true);
            (0, chai_1.expect)(info.result.account_data.RegularKey).to.eq(src_1.SpecialAddresses.ACCOUNT_ONE);
        });
        // set by CA70256B2BC1886C5B6B40DB74C3B6B385013EF6F1C66BB940B8F31CF50D1922
        it.skip(`Should get account info after disabling master key`, async () => {
            const info = await MccClient.getAccountInfo(acc, 28014733);
            const flags = (0, xrpUtils_1.processFlags)(info.result.account_data.Flags);
            (0, chai_1.expect)(flags.length).to.eq(3);
            (0, chai_1.expect)(flags.includes("lsfDefaultRipple")).to.eq(true);
            (0, chai_1.expect)(flags.includes("lsfDisableMaster")).to.eq(true);
            (0, chai_1.expect)(info.result.account_data.RegularKey).to.eq(src_1.SpecialAddresses.ACCOUNT_ONE);
        });
    });
});
// testnet account
// The one rBwD7GqAPFoZvzz6YaR5HyJWD8TUoaUbJo
// my rD8btyHW512KmJdsQEoD9KFTMxfDbpqkkA
//# sourceMappingURL=accountInfo.test.js.map