"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 token_math_1 = require("@melonproject/token-math");
const deploy_1 = require("../../contracts/dependencies/token/transactions/deploy");
const getToken_1 = require("../../contracts/dependencies/token/calls/getToken");
const transfer_1 = require("../../contracts/dependencies/token/transactions/transfer");
const signTransaction_1 = require("../environment/signTransaction");
const initTestEnvironment_1 = require("../../tests/utils/initTestEnvironment");
describe('transactionFactory', () => {
    const shared = {};
    beforeAll(() => __awaiter(this, void 0, void 0, function* () {
        shared.env = yield initTestEnvironment_1.initTestEnvironment();
        shared.token = yield getToken_1.getToken(shared.env, yield deploy_1.deployToken(shared.env));
        shared.accounts = (yield shared.env.eth.getAccounts()).map(account => new token_math_1.Address(account));
    }));
    it('Skip guards and preflight', () => __awaiter(this, void 0, void 0, function* () {
        const params = {
            howMuch: token_math_1.createQuantity(shared.token, 2000000),
            to: shared.accounts[1],
        };
        yield expect(transfer_1.transfer.prepare(shared.env, params)).rejects.toThrow('Insufficient FIXED');
        yield expect(transfer_1.transfer.prepare(shared.env, params, { skipGuards: true })).rejects.toThrow('Gas estimation (preflight) failed');
        yield expect(transfer_1.transfer.prepare(shared.env, params, {
            skipGasEstimation: true,
            skipGuards: true,
        })).rejects.toThrow('Cannot skip gasEstimation if no options.gas is provided');
        const prepared = yield transfer_1.transfer.prepare(shared.env, params, {
            gas: '8000000',
            skipGasEstimation: true,
            skipGuards: true,
        });
        const signedTransactionData = yield signTransaction_1.signTransaction(shared.env, prepared.rawTransaction);
        yield expect(transfer_1.transfer.send(shared.env, signedTransactionData, params)).rejects.toThrow('VM Exception while processing transaction: revert');
        yield expect(transfer_1.transfer(shared.env, params, {
            gas: '8000000',
            skipGasEstimation: true,
            skipGuards: true,
        })).rejects.toThrow('VM Exception while processing transaction: revert');
    }));
});
