UNPKG

@melonproject/protocol

Version:

Technology Regulated and Operated Investment Funds

84 lines (83 loc) 4.59 kB
"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 Contracts_1 = require("../../../../Contracts"); 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 emptyAddress_1 = require("../../../../utils/constants/emptyAddress"); const randomAddress_1 = require("../../../../utils/helpers/randomAddress"); const FunctionSignatures_1 = require("../utils/FunctionSignatures"); describe('tradingCallbacks', () => { let shared = {}; const mockExchange = randomAddress_1.randomAddress().toString(); beforeAll(() => __awaiter(this, void 0, void 0, function* () { shared.env = yield initTestEnvironment_1.initTestEnvironment(); shared = yield Object.assign(shared, yield deployMockSystem_1.deployMockSystem(shared.env)); shared.user = shared.env.wallet.address; const mockAdapter = yield getContract_1.getContract(shared.env, Contracts_1.Contracts.MockAdapter, yield deployContract_1.deployContract(shared.env, Contracts_1.Contracts.MockAdapter)); yield shared.registry.methods .registerExchangeAdapter(mockExchange, mockAdapter.options.address) .send({ from: shared.user }); shared.trading = yield getContract_1.getContract(shared.env, Contracts_1.Contracts.Trading, yield deployContract_1.deployContract(shared.env, Contracts_1.Contracts.Trading, [ shared.user, [mockExchange], [mockAdapter.options.address], shared.registry.options.address, ])); yield shared.trading.methods .initialize([ shared.accounting.options.address, emptyAddress_1.emptyAddress, emptyAddress_1.emptyAddress, shared.policyManager.options.address, emptyAddress_1.emptyAddress, emptyAddress_1.emptyAddress, emptyAddress_1.emptyAddress, emptyAddress_1.emptyAddress, shared.registry.options.address, emptyAddress_1.emptyAddress, emptyAddress_1.emptyAddress, emptyAddress_1.emptyAddress, ]) .send({ from: shared.user, gas: 8000000 }); })); it('Make order associated callbacks add data to Trading spoke', () => __awaiter(this, void 0, void 0, function* () { const mockOrderId = 42; const makerQuantity = 100; const takerQuantity = 200; yield shared.trading.methods .callOnExchange(0, FunctionSignatures_1.FunctionSignatures.makeOrder, [ emptyAddress_1.emptyAddress, emptyAddress_1.emptyAddress, shared.mln.options.address, shared.weth.options.address, emptyAddress_1.emptyAddress, emptyAddress_1.emptyAddress, ], [makerQuantity, takerQuantity, 0, 0, 0, 0, 0, 0], `0x${Number(mockOrderId) .toString(16) .padStart(64, '0')}`, '0x0', '0x0', '0x0') .send({ from: shared.user, gas: 8000000 }); expect(yield shared.trading.methods .isInOpenMakeOrder(shared.mln.options.address) .call()).toBeTruthy(); const openOrderInfo = yield shared.trading.methods .getOpenOrderInfo(mockExchange, shared.mln.options.address) .call(); expect(Number(openOrderInfo[0])).toBe(mockOrderId); expect(Number(openOrderInfo[2])).toBe(0); const orderDetails = yield shared.trading.methods.getOrderDetails(0).call(); expect(orderDetails[0]).toBe(shared.mln.options.address); expect(orderDetails[1]).toBe(shared.weth.options.address); expect(Number(orderDetails[2])).toBe(makerQuantity); expect(Number(orderDetails[3])).toBe(takerQuantity); })); });