"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
Object.defineProperty(exports, "__esModule", { value: true });
const api_1 = require("@polkadot/api");
const chai_1 = require("../../../chai");
const src_1 = require("../../../../src");
const SingleAccountSigner_1 = require("../../../utils/SingleAccountSigner");
const config_1 = require("../../../config");
describe("InterBtcApi", () => {
    const keyring = new api_1.Keyring();
    const keyringPair = keyring.addFromUri(config_1.ORACLE_URI);
    let interBTC;
    const registry = src_1.createAPIRegistry();
    let api;
    before(() => __awaiter(void 0, void 0, void 0, function* () {
        api = yield src_1.createSubstrateAPI(config_1.PARACHAIN_ENDPOINT);
        interBTC = new src_1.DefaultInterBtcApi(api);
    }));
    after(() => __awaiter(void 0, void 0, void 0, function* () {
        yield api.disconnect();
    }));
    describe("setAccount", () => {
        it("should succeed to set KeyringPair", () => {
            interBTC.setAccount(keyringPair);
            chai_1.assert.isDefined(interBTC.account);
        });
        it("should succeed to set address with signer", () => {
            const signer = new SingleAccountSigner_1.SingleAccountSigner(registry, keyringPair);
            interBTC.setAccount(keyringPair, signer);
            chai_1.assert.isDefined(interBTC.account);
        });
        it("should fail to set address without signer", () => {
            chai_1.assert.throw(() => interBTC.setAccount(keyringPair.address));
        });
    });
    describe("removeAccount", () => {
        it("should remove account after it was set", () => {
            interBTC.setAccount(keyringPair);
            interBTC.removeAccount();
            chai_1.assert.isUndefined(interBTC.account);
        });
        it("should fail to send transaction after account removal", () => __awaiter(void 0, void 0, void 0, function* () {
            interBTC.setAccount(keyringPair);
            interBTC.removeAccount();
            const governanceCurrency = interBTC.getGovernanceCurrency();
            const amount = src_1.newMonetaryAmount(1, governanceCurrency, true);
            const aliceAddress = keyring.addFromUri("//Alice").address;
            const tx = interBTC.tokens.transfer(aliceAddress, amount);
            // Transfer to Alice should be rejected, since Bob's account was removed.
            yield chai_1.assert.isRejected(tx);
        }));
    });
});
//# sourceMappingURL=interbtc-api.test.js.map