"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 initTestEnvironment_1 = require("../../../../../tests/utils/initTestEnvironment");
const withPrivateKeySigner_1 = require("../../../../../utils/environment/withPrivateKeySigner");
const getToken_1 = require("../../../../dependencies/token/calls/getToken");
const deploy_1 = require("../../../../dependencies/token/transactions/deploy");
const deploy0xExchange_1 = require("../../../transactions/deploy0xExchange");
const createOrder_1 = require("./createOrder");
const signOrder_1 = require("./signOrder");
const isValidSignature_1 = require("../calls/isValidSignature");
describe('signOrder', () => {
    const shared = {};
    beforeAll(() => __awaiter(this, void 0, void 0, function* () {
        shared.env = yield initTestEnvironment_1.initTestEnvironment();
        shared.withPK = yield withPrivateKeySigner_1.withPrivateKeySigner(shared.env, initTestEnvironment_1.keyPairs.get(shared.env.wallet.address.toLowerCase()));
        shared.weth = yield getToken_1.getToken(shared.env, yield deploy_1.deployToken(shared.env, 'WETH'));
        shared.mln = yield getToken_1.getToken(shared.env, yield deploy_1.deployToken(shared.env, 'MLN'));
        shared.zrx = yield getToken_1.getToken(shared.env, yield deploy_1.deployToken(shared.env, 'ZRX'));
        shared.zeroEx = yield deploy0xExchange_1.deploy0xExchange(shared.env, {
            zrxToken: shared.zrx,
        });
    }));
    it('is same signature with both signing strategies', () => __awaiter(this, void 0, void 0, function* () {
        const makerQuantity = token_math_1.createQuantity(shared.mln, 1);
        const takerQuantity = token_math_1.createQuantity(shared.weth, 0.05);
        const unsignedOrder = yield createOrder_1.createOrder(shared.env, shared.zeroEx, {
            makerQuantity,
            takerQuantity,
        });
        const signedDefault = yield signOrder_1.signOrder(shared.env, unsignedOrder);
        const signedPk = yield signOrder_1.signOrder(shared.withPK, unsignedOrder);
        expect(yield isValidSignature_1.isValidSignature(shared.env, shared.zeroEx, {
            signedOrder: signedDefault,
        })).toBe(true);
        expect(yield isValidSignature_1.isValidSignature(shared.env, shared.zeroEx, {
            signedOrder: signedPk,
        })).toBe(true);
    }));
});
