@melonproject/protocol
Version:
Technology Regulated and Operated Investment Funds
74 lines (73 loc) • 4.59 kB
JavaScript
;
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 Environment_1 = require("../../../utils/environment/Environment");
const deployAndInitTestEnv_1 = require("../../utils/deployAndInitTestEnv");
const setupInvestedTestFund_1 = require("../../utils/setupInvestedTestFund");
const getTokenBySymbol_1 = require("../../../utils/environment/getTokenBySymbol");
const toBeTrueWith_1 = require("../../utils/toBeTrueWith");
const FunctionSignatures_1 = require("../../../contracts/fund/trading/utils/FunctionSignatures");
const register_1 = require("../../../contracts/fund/policies/transactions/register");
const requestInvestment_1 = require("../../../contracts/fund/participation/transactions/requestInvestment");
const approve_1 = require("../../../contracts/dependencies/token/transactions/approve");
const getToken_1 = require("../../../contracts/dependencies/token/calls/getToken");
const withDifferentAccount_1 = require("../../../utils/environment/withDifferentAccount");
const transfer_1 = require("../../../contracts/dependencies/token/transactions/transfer");
const deployUserWhitelist_1 = require("../../../contracts/fund/policies/compliance/transactions/deployUserWhitelist");
expect.extend({ toBeTrueWith: toBeTrueWith_1.toBeTrueWith });
describe('Happy Path', () => {
const shared = {};
beforeAll(() => __awaiter(this, void 0, void 0, function* () {
shared.env = yield deployAndInitTestEnv_1.deployAndInitTestEnv();
expect(shared.env.track).toBe(Environment_1.Tracks.TESTING);
shared.accounts = yield shared.env.eth.getAccounts();
shared.anotherAccount = withDifferentAccount_1.withDifferentAccount(shared.env, shared.accounts[1]);
shared.engine = shared.env.deployment.melonContracts.engine;
shared.routes = yield setupInvestedTestFund_1.setupInvestedTestFund(shared.env);
shared.weth = getTokenBySymbol_1.getTokenBySymbol(shared.env, 'WETH');
shared.mln = getTokenBySymbol_1.getTokenBySymbol(shared.env, 'MLN');
const userWhitelist = yield deployUserWhitelist_1.deployUserWhitelist(shared.env, [
shared.accounts[0],
]);
yield register_1.register(shared.env, shared.routes.policyManagerAddress, {
method: FunctionSignatures_1.FunctionSignatures.requestInvestment,
policy: userWhitelist,
});
}));
test('Request investment fails if user is not whitelisted', () => __awaiter(this, void 0, void 0, function* () {
const investmentAmount = token_math_1.createQuantity(shared.weth, 1);
const fundToken = yield getToken_1.getToken(shared.env, shared.routes.sharesAddress);
yield transfer_1.transfer(shared.env, {
howMuch: investmentAmount,
to: shared.accounts[1],
});
yield approve_1.approve(shared.anotherAccount, {
howMuch: investmentAmount,
spender: shared.routes.participationAddress,
});
yield expect(requestInvestment_1.requestInvestment(shared.anotherAccount, shared.routes.participationAddress, {
investmentAmount,
requestedShares: token_math_1.createQuantity(fundToken, 1),
})).rejects.toThrow();
}));
test('Request investment passes if user is whitelisted', () => __awaiter(this, void 0, void 0, function* () {
const investmentAmount = token_math_1.createQuantity(shared.weth, 1);
const fundToken = yield getToken_1.getToken(shared.env, shared.routes.sharesAddress);
yield approve_1.approve(shared.env, {
howMuch: investmentAmount,
spender: shared.routes.participationAddress,
});
yield expect(requestInvestment_1.requestInvestment(shared.env, shared.routes.participationAddress, {
investmentAmount,
requestedShares: token_math_1.createQuantity(fundToken, 1),
})).resolves.not.toThrow();
}));
});