"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
    if (mod && mod.__esModule) return mod;
    var result = {};
    if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
    __setModuleDefault(result, mod);
    return result;
};
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());
    });
};
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const bignumber_js_1 = __importDefault(require("bignumber.js"));
const sinon_1 = __importDefault(require("sinon"));
const internal_1 = require("../../../../internal");
const queries_1 = require("../../../../middleware/queries");
const types_1 = require("../../../../middleware/types");
const mocks_1 = require("../../../../testUtils/mocks");
const types_2 = require("../../../../types");
const utils_1 = require("../../../../types/utils");
const constants_1 = require("../../../../utils/constants");
const utilsConversionModule = __importStar(require("../../../../utils/conversion"));
const utilsInternalModule = __importStar(require("../../../../utils/internal"));
jest.mock('~/api/entities/Identity', require("../../../../testUtils/mocks/entities").mockIdentityModule('~/api/entities/Identity'));
jest.mock('~/base/Procedure', require("../../../../testUtils/mocks/procedure").mockProcedureModule('~/base/Procedure'));
describe('Asset class', () => {
    beforeAll(() => {
        mocks_1.dsMockUtils.initMocks();
        mocks_1.entityMockUtils.initMocks();
        mocks_1.procedureMockUtils.initMocks();
    });
    afterEach(() => {
        mocks_1.dsMockUtils.reset();
        mocks_1.entityMockUtils.reset();
        mocks_1.procedureMockUtils.reset();
    });
    afterAll(() => {
        mocks_1.dsMockUtils.cleanup();
        mocks_1.procedureMockUtils.cleanup();
    });
    test('should extend Entity', () => {
        expect(internal_1.Asset.prototype instanceof internal_1.Entity).toBe(true);
    });
    describe('constructor', () => {
        test('should assign ticker and did to instance', () => {
            const ticker = 'test';
            const context = mocks_1.dsMockUtils.getContextInstance();
            const asset = new internal_1.Asset({ ticker }, context);
            expect(asset.ticker).toBe(ticker);
            expect(asset.did).toBe(utilsConversionModule.tickerToDid(ticker));
        });
    });
    describe('method: isUniqueIdentifiers', () => {
        test('should return true if the object conforms to the interface', () => {
            expect(internal_1.Asset.isUniqueIdentifiers({ ticker: 'someTicker' })).toBe(true);
            expect(internal_1.Asset.isUniqueIdentifiers({})).toBe(false);
            expect(internal_1.Asset.isUniqueIdentifiers({ ticker: 3 })).toBe(false);
        });
    });
    describe('method: details', () => {
        let ticker;
        let name;
        let totalSupply;
        let isDivisible;
        let owner;
        let assetType;
        let iuDisabled;
        let did;
        let rawToken;
        let rawName;
        let rawIuDisabled;
        let context;
        let asset;
        beforeAll(() => {
            ticker = 'FAKE_TICKER';
            name = 'tokenName';
            totalSupply = new bignumber_js_1.default(1000);
            isDivisible = true;
            owner = '0x0wn3r';
            assetType = 'EquityCommon';
            iuDisabled = false;
            did = 'someDid';
        });
        beforeEach(() => {
            rawToken = mocks_1.dsMockUtils.createMockSecurityToken({
                /* eslint-disable @typescript-eslint/naming-convention */
                owner_did: mocks_1.dsMockUtils.createMockIdentityId(owner),
                asset_type: mocks_1.dsMockUtils.createMockAssetType(assetType),
                divisible: mocks_1.dsMockUtils.createMockBool(isDivisible),
                total_supply: mocks_1.dsMockUtils.createMockBalance(totalSupply),
                /* eslint-enable @typescript-eslint/naming-convention */
            });
            rawIuDisabled = mocks_1.dsMockUtils.createMockBool(iuDisabled);
            rawName = mocks_1.dsMockUtils.createMockAssetName(name);
            context = mocks_1.dsMockUtils.getContextInstance();
            asset = new internal_1.Asset({ ticker }, context);
            mocks_1.dsMockUtils.createQueryStub('externalAgents', 'groupOfAgent', {
                entries: [
                    utils_1.tuple([mocks_1.dsMockUtils.createMockTicker(ticker), mocks_1.dsMockUtils.createMockIdentityId(did)], mocks_1.dsMockUtils.createMockOption(mocks_1.dsMockUtils.createMockAgentGroup('PolymeshV1Pia'))),
                    utils_1.tuple([mocks_1.dsMockUtils.createMockTicker(ticker), mocks_1.dsMockUtils.createMockIdentityId(owner)], mocks_1.dsMockUtils.createMockOption(mocks_1.dsMockUtils.createMockAgentGroup('Full'))),
                    utils_1.tuple([mocks_1.dsMockUtils.createMockTicker(ticker), mocks_1.dsMockUtils.createMockIdentityId(did)], mocks_1.dsMockUtils.createMockOption(mocks_1.dsMockUtils.createMockAgentGroup('ExceptMeta'))),
                ],
            });
            mocks_1.dsMockUtils.createQueryStub('asset', 'assetNames', {
                returnValue: rawName,
            });
            mocks_1.dsMockUtils.createQueryStub('asset', 'disableInvestorUniqueness', {
                returnValue: rawIuDisabled,
            });
        });
        test('should return details for an Asset', () => __awaiter(void 0, void 0, void 0, function* () {
            const tokensStub = mocks_1.dsMockUtils.createQueryStub('asset', 'tokens', {
                returnValue: rawToken,
            });
            let details = yield asset.details();
            expect(details.name).toBe(name);
            expect(details.totalSupply).toEqual(utilsConversionModule.balanceToBigNumber(totalSupply));
            expect(details.isDivisible).toBe(isDivisible);
            expect(details.owner.did).toBe(owner);
            expect(details.assetType).toBe(assetType);
            expect(details.primaryIssuanceAgents[0].did).toBe(did);
            expect(details.fullAgents[0].did).toBe(owner);
            expect(details.requiresInvestorUniqueness).toBe(true);
            mocks_1.dsMockUtils.createQueryStub('externalAgents', 'groupOfAgent', {
                entries: [
                    utils_1.tuple([mocks_1.dsMockUtils.createMockTicker(ticker), mocks_1.dsMockUtils.createMockIdentityId(did)], mocks_1.dsMockUtils.createMockOption(mocks_1.dsMockUtils.createMockAgentGroup('Full'))),
                ],
            });
            details = yield asset.details();
            expect(details.primaryIssuanceAgents).toEqual([]);
            expect(details.fullAgents[0].did).toEqual(did);
            tokensStub.resolves(mocks_1.dsMockUtils.createMockSecurityToken({
                /* eslint-disable @typescript-eslint/naming-convention */
                owner_did: mocks_1.dsMockUtils.createMockIdentityId(owner),
                asset_type: mocks_1.dsMockUtils.createMockAssetType({
                    Custom: mocks_1.dsMockUtils.createMockU32(new bignumber_js_1.default(10)),
                }),
                divisible: mocks_1.dsMockUtils.createMockBool(isDivisible),
                total_supply: mocks_1.dsMockUtils.createMockBalance(totalSupply),
                /* eslint-enable @typescript-eslint/naming-convention */
            }));
            const customType = 'something';
            mocks_1.dsMockUtils.createQueryStub('asset', 'customTypes', {
                returnValue: mocks_1.dsMockUtils.createMockBytes(customType),
            });
            details = yield asset.details();
            expect(details.assetType).toEqual(customType);
        }));
        test('should allow subscription', () => __awaiter(void 0, void 0, void 0, function* () {
            const unsubCallback = 'unsubCallBack';
            // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/naming-convention
            rawToken.primary_issuance_agent = mocks_1.dsMockUtils.createMockOption();
            mocks_1.dsMockUtils.createQueryStub('asset', 'tokens').callsFake((_, cbFunc) => __awaiter(void 0, void 0, void 0, function* () {
                cbFunc(rawToken);
                return unsubCallback;
            }));
            const callback = sinon_1.default.stub();
            const result = yield asset.details(callback);
            expect(result).toBe(unsubCallback);
            sinon_1.default.assert.calledWithExactly(callback, sinon_1.default.match({
                assetType,
                isDivisible,
                name,
                owner: sinon_1.default.match({ did: owner }),
                totalSupply: new bignumber_js_1.default(totalSupply).div(Math.pow(10, 6)),
                primaryIssuanceAgents: [sinon_1.default.match({ did })],
                fullAgents: [sinon_1.default.match({ did: owner })],
                requiresInvestorUniqueness: true,
            }));
        }));
    });
    describe('method: transferOwnership', () => {
        test('should prepare the procedure with the correct arguments and context, and return the resulting transaction queue', () => __awaiter(void 0, void 0, void 0, function* () {
            const ticker = 'TEST';
            const context = mocks_1.dsMockUtils.getContextInstance();
            const asset = new internal_1.Asset({ ticker }, context);
            const target = 'someOtherDid';
            const expiry = new Date('10/14/3040');
            const args = {
                target,
                expiry,
            };
            const expectedQueue = 'someQueue';
            mocks_1.procedureMockUtils
                .getPrepareStub()
                .withArgs({ args: Object.assign({ ticker }, args), transformer: undefined }, context)
                .resolves(expectedQueue);
            const queue = yield asset.transferOwnership(args);
            expect(queue).toBe(expectedQueue);
        }));
    });
    describe('method: modify', () => {
        test('should prepare the procedure with the correct arguments and context, and return the resulting transaction queue', () => __awaiter(void 0, void 0, void 0, function* () {
            const ticker = 'TEST';
            const context = mocks_1.dsMockUtils.getContextInstance();
            const asset = new internal_1.Asset({ ticker }, context);
            const makeDivisible = true;
            const args = {
                makeDivisible,
            };
            const expectedQueue = 'someQueue';
            mocks_1.procedureMockUtils
                .getPrepareStub()
                .withArgs({ args: Object.assign({ ticker }, args), transformer: undefined }, context)
                .resolves(expectedQueue);
            const queue = yield asset.modify(args);
            expect(queue).toBe(expectedQueue);
        }));
    });
    describe('method: currentFundingRound', () => {
        let ticker;
        let fundingRound;
        let rawFundingRound;
        let context;
        let asset;
        beforeAll(() => {
            ticker = 'FAKE_TICKER';
            fundingRound = 'Series A';
        });
        beforeEach(() => {
            rawFundingRound = mocks_1.dsMockUtils.createMockFundingRoundName(fundingRound);
            context = mocks_1.dsMockUtils.getContextInstance();
            asset = new internal_1.Asset({ ticker }, context);
        });
        test('should return null if there is no funding round for an Asset', () => __awaiter(void 0, void 0, void 0, function* () {
            mocks_1.dsMockUtils.createQueryStub('asset', 'fundingRound', {
                returnValue: mocks_1.dsMockUtils.createMockFundingRoundName(),
            });
            const result = yield asset.currentFundingRound();
            expect(result).toBeNull();
        }));
        test('should return the funding round for an Asset', () => __awaiter(void 0, void 0, void 0, function* () {
            mocks_1.dsMockUtils.createQueryStub('asset', 'fundingRound', {
                returnValue: rawFundingRound,
            });
            const result = yield asset.currentFundingRound();
            expect(result).toBe(fundingRound);
        }));
        test('should allow subscription', () => __awaiter(void 0, void 0, void 0, function* () {
            const unsubCallback = 'unsubCallBack';
            mocks_1.dsMockUtils.createQueryStub('asset', 'fundingRound').callsFake((_, cbFunc) => __awaiter(void 0, void 0, void 0, function* () {
                cbFunc(rawFundingRound);
                return unsubCallback;
            }));
            const callback = sinon_1.default.stub();
            const result = yield asset.currentFundingRound(callback);
            expect(result).toBe(unsubCallback);
            sinon_1.default.assert.calledWithExactly(callback, fundingRound);
        }));
    });
    describe('method: getIdentifiers', () => {
        let ticker;
        let isinValue;
        let cusipValue;
        let cinsValue;
        let leiValue;
        let isinMock;
        let cusipMock;
        let cinsMock;
        let leiMock;
        let securityIdentifiers;
        let context;
        let asset;
        beforeAll(() => {
            ticker = 'TEST';
            isinValue = 'FAKE ISIN';
            cusipValue = 'FAKE CUSIP';
            cinsValue = 'FAKE CINS';
            leiValue = 'FAKE LEI';
            isinMock = mocks_1.dsMockUtils.createMockAssetIdentifier({
                Isin: mocks_1.dsMockUtils.createMockU8aFixed(isinValue),
            });
            cusipMock = mocks_1.dsMockUtils.createMockAssetIdentifier({
                Cusip: mocks_1.dsMockUtils.createMockU8aFixed(cusipValue),
            });
            cinsMock = mocks_1.dsMockUtils.createMockAssetIdentifier({
                Cins: mocks_1.dsMockUtils.createMockU8aFixed(cinsValue),
            });
            leiMock = mocks_1.dsMockUtils.createMockAssetIdentifier({
                Lei: mocks_1.dsMockUtils.createMockU8aFixed(leiValue),
            });
            securityIdentifiers = [
                {
                    type: types_2.SecurityIdentifierType.Isin,
                    value: isinValue,
                },
                {
                    type: types_2.SecurityIdentifierType.Cusip,
                    value: cusipValue,
                },
                {
                    type: types_2.SecurityIdentifierType.Cins,
                    value: cinsValue,
                },
                {
                    type: types_2.SecurityIdentifierType.Lei,
                    value: leiValue,
                },
            ];
        });
        beforeEach(() => {
            context = mocks_1.dsMockUtils.getContextInstance();
            asset = new internal_1.Asset({ ticker }, context);
        });
        test('should return the list of security identifiers for an Asset', () => __awaiter(void 0, void 0, void 0, function* () {
            mocks_1.dsMockUtils.createQueryStub('asset', 'identifiers', {
                returnValue: [isinMock, cusipMock, cinsMock, leiMock],
            });
            const result = yield asset.getIdentifiers();
            expect(result[0].value).toBe(isinValue);
            expect(result[1].value).toBe(cusipValue);
            expect(result[2].value).toBe(cinsValue);
            expect(result[3].value).toBe(leiValue);
        }));
        test('should allow subscription', () => __awaiter(void 0, void 0, void 0, function* () {
            const unsubCallback = 'unsubCallBack';
            mocks_1.dsMockUtils.createQueryStub('asset', 'identifiers').callsFake((_, cbFunc) => __awaiter(void 0, void 0, void 0, function* () {
                cbFunc([isinMock, cusipMock, cinsMock, leiMock]);
                return unsubCallback;
            }));
            const callback = sinon_1.default.stub();
            const result = yield asset.getIdentifiers(callback);
            expect(result).toBe(unsubCallback);
            sinon_1.default.assert.calledWithExactly(callback, securityIdentifiers);
        }));
    });
    describe('method: createdAt', () => {
        test('should return the event identifier object of the Asset creation', () => __awaiter(void 0, void 0, void 0, function* () {
            const ticker = 'SOME_TICKER';
            const blockNumber = new bignumber_js_1.default(1234);
            const blockDate = new Date('4/14/2020');
            const eventIdx = new bignumber_js_1.default(1);
            const variables = {
                moduleId: types_1.ModuleIdEnum.Asset,
                eventId: types_1.EventIdEnum.AssetCreated,
                eventArg1: utilsInternalModule.padString(ticker, constants_1.MAX_TICKER_LENGTH),
            };
            const fakeResult = { blockNumber, blockDate, eventIndex: eventIdx };
            const context = mocks_1.dsMockUtils.getContextInstance();
            const asset = new internal_1.Asset({ ticker }, context);
            mocks_1.dsMockUtils.createApolloQueryStub(queries_1.eventByIndexedArgs(variables), {
                /* eslint-disable @typescript-eslint/naming-convention */
                eventByIndexedArgs: {
                    block_id: blockNumber.toNumber(),
                    block: { datetime: blockDate },
                    event_idx: eventIdx.toNumber(),
                },
                /* eslint-enable @typescript-eslint/naming-convention */
            });
            const result = yield asset.createdAt();
            expect(result).toEqual(fakeResult);
        }));
        test('should return null if the query result is empty', () => __awaiter(void 0, void 0, void 0, function* () {
            const ticker = 'SOME_TICKER';
            const variables = {
                moduleId: types_1.ModuleIdEnum.Asset,
                eventId: types_1.EventIdEnum.AssetCreated,
                eventArg1: utilsInternalModule.padString(ticker, constants_1.MAX_TICKER_LENGTH),
            };
            const context = mocks_1.dsMockUtils.getContextInstance();
            const asset = new internal_1.Asset({ ticker }, context);
            mocks_1.dsMockUtils.createApolloQueryStub(queries_1.eventByIndexedArgs(variables), {});
            const result = yield asset.createdAt();
            expect(result).toBeNull();
        }));
    });
    describe('method: freeze', () => {
        test('should prepare the procedure and return the resulting transaction queue', () => __awaiter(void 0, void 0, void 0, function* () {
            const ticker = 'TICKER';
            const context = mocks_1.dsMockUtils.getContextInstance();
            const asset = new internal_1.Asset({ ticker }, context);
            const expectedQueue = 'someQueue';
            mocks_1.procedureMockUtils
                .getPrepareStub()
                .withArgs({ args: { ticker, freeze: true }, transformer: undefined }, context)
                .resolves(expectedQueue);
            const queue = yield asset.freeze();
            expect(queue).toBe(expectedQueue);
        }));
    });
    describe('method: unfreeze', () => {
        test('should prepare the procedure and return the resulting transaction queue', () => __awaiter(void 0, void 0, void 0, function* () {
            const ticker = 'TICKER';
            const context = mocks_1.dsMockUtils.getContextInstance();
            const asset = new internal_1.Asset({ ticker }, context);
            const expectedQueue = 'someQueue';
            mocks_1.procedureMockUtils
                .getPrepareStub()
                .withArgs({ args: { ticker, freeze: false }, transformer: undefined }, context)
                .resolves(expectedQueue);
            const queue = yield asset.unfreeze();
            expect(queue).toBe(expectedQueue);
        }));
    });
    describe('method: isFrozen', () => {
        let frozenStub;
        let boolValue;
        let rawBoolValue;
        beforeAll(() => {
            boolValue = true;
            rawBoolValue = mocks_1.dsMockUtils.createMockBool(boolValue);
        });
        beforeEach(() => {
            frozenStub = mocks_1.dsMockUtils.createQueryStub('asset', 'frozen');
        });
        test('should return whether the Asset is frozen or not', () => __awaiter(void 0, void 0, void 0, function* () {
            const ticker = 'TICKER';
            const context = mocks_1.dsMockUtils.getContextInstance();
            const asset = new internal_1.Asset({ ticker }, context);
            frozenStub.resolves(rawBoolValue);
            const result = yield asset.isFrozen();
            expect(result).toBe(boolValue);
        }));
        test('should allow subscription', () => __awaiter(void 0, void 0, void 0, function* () {
            const ticker = 'TICKER';
            const context = mocks_1.dsMockUtils.getContextInstance();
            const asset = new internal_1.Asset({ ticker }, context);
            const unsubCallback = 'unsubCallBack';
            frozenStub.callsFake((_, cbFunc) => __awaiter(void 0, void 0, void 0, function* () {
                cbFunc(rawBoolValue);
                return unsubCallback;
            }));
            const callback = sinon_1.default.stub();
            const result = yield asset.isFrozen(callback);
            expect(result).toBe(unsubCallback);
            sinon_1.default.assert.calledWithExactly(callback, boolValue);
        }));
    });
    describe('method: modifyPrimaryIssuanceAgent', () => {
        test('should prepare the procedure and return the resulting transaction queue', () => __awaiter(void 0, void 0, void 0, function* () {
            const ticker = 'TICKER';
            const target = 'someDid';
            const context = mocks_1.dsMockUtils.getContextInstance();
            const asset = new internal_1.Asset({ ticker }, context);
            const expectedQueue = 'someQueue';
            mocks_1.procedureMockUtils
                .getPrepareStub()
                .withArgs({ args: { ticker, target }, transformer: undefined }, context)
                .resolves(expectedQueue);
            const queue = yield asset.modifyPrimaryIssuanceAgent({ target });
            expect(queue).toBe(expectedQueue);
        }));
    });
    describe('method: removePrimaryIssuanceAgent', () => {
        test('should prepare the procedure and return the resulting transaction queue', () => __awaiter(void 0, void 0, void 0, function* () {
            const ticker = 'TICKER';
            const context = mocks_1.dsMockUtils.getContextInstance();
            const asset = new internal_1.Asset({ ticker }, context);
            const expectedQueue = 'someQueue';
            mocks_1.procedureMockUtils
                .getPrepareStub()
                .withArgs({ args: { ticker }, transformer: undefined }, context)
                .resolves(expectedQueue);
            const queue = yield asset.removePrimaryIssuanceAgent();
            expect(queue).toBe(expectedQueue);
        }));
    });
    describe('method: redeem', () => {
        test('should prepare the procedure and return the resulting transaction queue', () => __awaiter(void 0, void 0, void 0, function* () {
            const ticker = 'TICKER';
            const amount = new bignumber_js_1.default(100);
            const context = mocks_1.dsMockUtils.getContextInstance();
            const asset = new internal_1.Asset({ ticker }, context);
            const expectedQueue = 'someQueue';
            mocks_1.procedureMockUtils
                .getPrepareStub()
                .withArgs({ args: { amount, ticker }, transformer: undefined }, context)
                .resolves(expectedQueue);
            const queue = yield asset.redeem({ amount });
            expect(queue).toBe(expectedQueue);
        }));
    });
    describe('method: investorCount', () => {
        let investorCountPerAssetStub;
        let investorCount;
        let rawInvestorCount;
        beforeAll(() => {
            investorCount = new bignumber_js_1.default(10);
            rawInvestorCount = mocks_1.dsMockUtils.createMockU64(investorCount);
        });
        beforeEach(() => {
            investorCountPerAssetStub = mocks_1.dsMockUtils.createQueryStub('statistics', 'investorCountPerAsset');
        });
        test('should return the amount of unique investors that hold the Asset', () => __awaiter(void 0, void 0, void 0, function* () {
            const ticker = 'TICKER';
            const context = mocks_1.dsMockUtils.getContextInstance();
            const asset = new internal_1.Asset({ ticker }, context);
            investorCountPerAssetStub.resolves(rawInvestorCount);
            const result = yield asset.investorCount();
            expect(result).toEqual(investorCount);
        }));
        test('should allow subscription', () => __awaiter(void 0, void 0, void 0, function* () {
            const ticker = 'TICKER';
            const context = mocks_1.dsMockUtils.getContextInstance();
            const asset = new internal_1.Asset({ ticker }, context);
            const unsubCallback = 'unsubCallBack';
            investorCountPerAssetStub.callsFake((_, cbFunc) => __awaiter(void 0, void 0, void 0, function* () {
                cbFunc(rawInvestorCount);
                return unsubCallback;
            }));
            const callback = sinon_1.default.stub();
            const result = yield asset.investorCount(callback);
            expect(result).toEqual(unsubCallback);
            sinon_1.default.assert.calledWithExactly(callback, investorCount);
        }));
    });
    describe('method: controllerTransfer', () => {
        test('should prepare the procedure and return the resulting transaction queue', () => __awaiter(void 0, void 0, void 0, function* () {
            const ticker = 'TICKER';
            const originPortfolio = 'portfolio';
            const amount = new bignumber_js_1.default(1);
            const context = mocks_1.dsMockUtils.getContextInstance();
            const asset = new internal_1.Asset({ ticker }, context);
            const expectedQueue = 'someQueue';
            mocks_1.procedureMockUtils
                .getPrepareStub()
                .withArgs({ args: { ticker, originPortfolio, amount }, transformer: undefined }, context)
                .resolves(expectedQueue);
            const queue = yield asset.controllerTransfer({ originPortfolio, amount });
            expect(queue).toBe(expectedQueue);
        }));
    });
    describe('method: getOperationHistory', () => {
        test('should return a list of agent operations', () => __awaiter(void 0, void 0, void 0, function* () {
            const ticker = 'TICKER';
            const context = mocks_1.dsMockUtils.getContextInstance();
            const asset = new internal_1.Asset({ ticker }, context);
            const did = 'someDid';
            const blockId = new bignumber_js_1.default(1);
            const blockHash = 'someHash';
            const eventIndex = new bignumber_js_1.default(1);
            const datetime = '2020-10-10';
            mocks_1.dsMockUtils.createQueryStub('system', 'blockHash', {
                multi: [mocks_1.dsMockUtils.createMockHash(blockHash)],
            });
            mocks_1.dsMockUtils.createApolloQueryStub(queries_1.tickerExternalAgentHistory({
                ticker,
            }), {
                tickerExternalAgentHistory: [
                    /* eslint-disable @typescript-eslint/naming-convention */
                    {
                        did,
                        history: [
                            {
                                block_id: blockId.toNumber(),
                                datetime,
                                event_idx: eventIndex.toNumber(),
                            },
                        ],
                    },
                    /* eslint-enable @typescript-eslint/naming-convention */
                ],
            });
            let result = yield asset.getOperationHistory();
            expect(result.length).toEqual(1);
            expect(result[0].identity.did).toEqual(did);
            expect(result[0].history.length).toEqual(1);
            expect(result[0].history[0]).toEqual({
                blockNumber: blockId,
                blockHash,
                blockDate: new Date(`${datetime}Z`),
                eventIndex,
            });
            mocks_1.dsMockUtils.createApolloQueryStub(queries_1.tickerExternalAgentHistory({
                ticker,
            }), {
                tickerExternalAgentHistory: [
                    {
                        did,
                        history: [],
                    },
                ],
            });
            result = yield asset.getOperationHistory();
            expect(result.length).toEqual(1);
            expect(result[0].identity.did).toEqual(did);
            expect(result[0].history.length).toEqual(0);
        }));
    });
    describe('method: exists', () => {
        test('should return whether the Asset exists', () => __awaiter(void 0, void 0, void 0, function* () {
            const ticker = 'TICKER';
            const context = mocks_1.dsMockUtils.getContextInstance();
            const asset = new internal_1.Asset({ ticker }, context);
            mocks_1.dsMockUtils.createQueryStub('asset', 'tokens', {
                size: new bignumber_js_1.default(10),
            });
            let result = yield asset.exists();
            expect(result).toBe(true);
            mocks_1.dsMockUtils.createQueryStub('asset', 'tokens', {
                size: new bignumber_js_1.default(0),
            });
            result = yield asset.exists();
            expect(result).toBe(false);
        }));
    });
    describe('method: toJson', () => {
        test('should return a human readable version of the entity', () => {
            const context = mocks_1.dsMockUtils.getContextInstance();
            const asset = new internal_1.Asset({ ticker: 'SOME_TICKER' }, context);
            expect(asset.toJson()).toBe('SOME_TICKER');
        });
    });
});
//# sourceMappingURL=index.js.map