"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    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) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
Object.defineProperty(exports, "__esModule", { value: true });
const initTestEnvironment_1 = require("../../../../tests/utils/initTestEnvironment");
const deployMockSystem_1 = require("../../../../utils/deploy/deployMockSystem");
const deployContract_1 = require("../../../../utils/solidity/deployContract");
const getContract_1 = require("../../../../utils/solidity/getContract");
const randomAddress_1 = require("../../../../utils/helpers/randomAddress");
const Contracts_1 = require("../../../../Contracts");
const token_math_1 = require("@melonproject/token-math");
describe('shares', () => {
    let shared = {};
    beforeAll(() => __awaiter(this, void 0, void 0, function* () {
        shared.env = yield initTestEnvironment_1.initTestEnvironment();
        shared = Object.assign(shared, yield deployMockSystem_1.deployMockSystem(shared.env));
        shared.user = shared.env.wallet.address;
        shared.shares = getContract_1.getContract(shared.env, Contracts_1.Contracts.Shares, yield deployContract_1.deployContract(shared.env, Contracts_1.Contracts.Shares, [
            shared.hub.options.address,
        ]));
    }));
    it('Shares contract is properly initialized', () => __awaiter(this, void 0, void 0, function* () {
        const hubName = yield shared.hub.methods.name().call();
        yield expect(shared.shares.methods.name().call()).resolves.toEqual(hubName);
        yield expect(shared.shares.methods.symbol().call()).resolves.toBe('MLNF');
        yield expect(shared.shares.methods.decimals().call()).resolves.toBe('18');
    }));
    it('Create and destroy shares (auth)', () => __awaiter(this, void 0, void 0, function* () {
        const mockAccount = randomAddress_1.randomAddress().toString();
        const amount = new token_math_1.BigInteger(1000000000);
        yield expect(shared.shares.methods.balanceOf(mockAccount).call()).resolves.toEqual('0');
        yield shared.shares.methods
            .createFor(mockAccount, `${amount}`)
            .send({ from: shared.user });
        yield expect(shared.shares.methods.balanceOf(mockAccount).call()).resolves.toEqual(amount);
        yield shared.shares.methods
            .destroyFor(mockAccount, `${amount}`)
            .send({ from: shared.user });
        yield expect(shared.shares.methods.balanceOf(mockAccount).call()).resolves.toEqual('0');
    }));
});
