Skip to content
This repository has been archived by the owner on Aug 6, 2021. It is now read-only.

Commit

Permalink
cherry picked changes from stale branch into current dev branch
Browse files Browse the repository at this point in the history
  • Loading branch information
joeb000 committed Aug 31, 2020
1 parent f4cbfda commit b7721cb
Show file tree
Hide file tree
Showing 2 changed files with 120 additions and 10 deletions.
40 changes: 39 additions & 1 deletion packages/ap.js/__tests__/Default-Terms.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
"scalingEffect": 0,
"penaltyType": 0,
"feeBasis": 0,
"contractPerformance": 0,
"couponType": 0,
"creditEventTypeCovered": 0,

"currency": "0x0000000000000000000000000000000000000000",
"settlementCurrency": "0x0000000000000000000000000000000000000000",
"marketObjectCodeRateReset": "0x00",
Expand All @@ -17,10 +21,18 @@
"maturityDate": 1388534400,
"purchaseDate": 0,
"capitalizationEndDate": 0,
"nonPerformingDate": 0,
"issueDate": 1356998400,

"cycleAnchorDateOfInterestPayment": 1356998400,
"cycleAnchorDateOfRateReset": 0,
"cycleAnchorDateOfScalingIndex": 0,
"cycleAnchorDateOfFee": 0,
"cycleAnchorDateOfPrincipalRedemption": 1356998400,

"cycleAnchorDateOfRedemption": 1598918400,
"cycleAnchorDateOfTermination": 0,
"cycleAnchorDateOfCoupon": 0,
"notionalPrincipal": "3000000000000000000000",
"nominalInterestRate": "100000000000000000",
"accruedInterest": 0,
Expand All @@ -37,10 +49,36 @@
"lifeFloor": 0,
"periodCap": 0,
"periodFloor": 0,
"nominalPrice": "100000000000000000000",
"issuePrice": "100000000000000000000",
"quantity": "100000000000000000000000",
"denominationRatio": 0,
"couponRate": 0,
"nextPrincipalRedemptionPayment": 0,
"coverageOfCreditEnhancement": 1,
"gracePeriod": { "i": 0, "p": 0, "isSet": false },
"delinquencyPeriod": { "i": 0, "p": 0, "isSet": false },
"settlementPeriod": { "i": "10", "p": 0, "isSet": true },
"fixingPeriod": { "i": "0", "p": 0, "isSet": true },
"exercisePeriod": { "i": "5", "p": 0, "isSet": true },
"cycleOfInterestPayment": { "i": 1, "p": 2, "s": 0, "isSet": true },
"cycleOfRateReset": { "i": 0, "p": 0, "s": 0, "isSet": false },
"cycleOfScalingIndex": { "i": 0, "p": 0, "s": 0, "isSet": false },
"cycleOfFee": { "i": 0, "p": 0, "s": 0, "isSet": false }
"cycleOfFee": { "i": 0, "p": 0, "s": 0, "isSet": false },
"cycleOfRedemption": { "i": "3", "p": 2, "s": 1, "isSet": true },
"cycleOfTermination": { "i": 0, "p": 0, "s": 0, "isSet": false },
"cycleOfCoupon": { "i": 0, "p": 0, "s": 0, "isSet": false },
"cycleOfPrincipalRedemption": { "i": 0, "p": 0, "s": 0, "isSet": false },
"contractReference_1": {
"object": "0x0000000000000000000000000000000000000000000000000000000000000001",
"object2": "0x0000000000000000000000000000000000000000000000000000000000000001",
"_type": 1,
"role": 1
},
"contractReference_2": {
"object": "0x0000000000000000000000000000000000000000000000000000000000000002",
"object2": "0x0000000000000000000000000000000000000000000000000000000000000002",
"_type": 1,
"role": 1
}
}
90 changes: 81 additions & 9 deletions packages/ap.js/__tests__/apis/Utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ import Web3 from 'web3';
import Deployments from '@atpar/ap-contracts/deployments.json';

import { Utils, Contracts } from '../../src/apis';
import { Terms, isPAMTerms, isANNTerms, isCERTFTerms, isCECTerms, isCEGTerms } from '../../src/types';
import { removeNullEvents } from '../../src/utils/Schedule';

import DEFAULT_TERMS from '../Default-Terms.json';


describe('Utils', (): void => {

let web3: Web3;
Expand All @@ -22,17 +23,88 @@ describe('Utils', (): void => {
contracts = new Contracts(web3, addressBook);
});

it('should return schedule for terms', async (): Promise<void> => {
const terms = DEFAULT_TERMS;
const schedule = await Utils.schedule.computeScheduleFromTerms(contracts.engine(terms.contractType), terms);
describe('Schedule', (): void => {

it('should remove null events', async (): Promise<void> => {
const schedule = [
'0x0200000000000000000000000000000000000000000000000000000050e22700',
'0x1400000000000000000000000000000000000000000000000000000052c35a80',
'0x0000000000000000000000000000000000000000000000000000000000000000'
];
const newSchedule = removeNullEvents(schedule);
expect(newSchedule.length).toBe(2)
});

it('should return schedule for terms', async (): Promise<void> => {
const terms = DEFAULT_TERMS;
const schedule = await Utils.schedule.computeScheduleFromTerms(contracts.engine(terms.contractType), terms);

expect(schedule.length).toBeGreaterThan(0);
});

it('should return schedule for terms - perpetual', async (): Promise<void> => {
const terms = DEFAULT_TERMS;
const schedule = await Utils.schedule.computeScheduleFromTerms(contracts.engine(terms.contractType), terms, true, terms.maturityDate, terms.maturityDate);

expect(schedule.length).toBeGreaterThan(0);
});

expect(schedule.length).toBeGreaterThan(0);
});

describe('Conversion', (): void => {
it('should convert date ISO to Unix', async (): Promise<void> => {
const isoString = '2020-06-06T23:05:30'; //1591484730
const unixDate = Utils.conversion.isoToUnix(isoString);
expect(unixDate).toBe('1591484730');
});

it('should convert date Unix to ISO', async (): Promise<void> => {
const unixString = '1591484730'; // 2020-06-06T23:05:30
const unixNumber = 1591484730; // 2020-06-06T23:05:30
const isoDateFromString = Utils.conversion.unixToISO(unixString);
const isoDateFromNumber = Utils.conversion.unixToISO(unixNumber);
expect(isoDateFromString).toBe('2020-06-06T23:05:30.000Z');
expect(isoDateFromNumber).toBe('2020-06-06T23:05:30.000Z');
});

it('should convert date Unix to ISO', async (): Promise<void> => {
const unixString = '1591484730'; // 2020-06-06T23:05:30
const unixNumber = 1591484730; // 2020-06-06T23:05:30
const isoDateFromString = Utils.conversion.unixToISO(unixString);
const isoDateFromNumber = Utils.conversion.unixToISO(unixNumber);
expect(isoDateFromString).toBe('2020-06-06T23:05:30.000Z');
expect(isoDateFromNumber).toBe('2020-06-06T23:05:30.000Z');
});

it('should return schedule for terms - perpetual', async (): Promise<void> => {
const terms = DEFAULT_TERMS;
const schedule = await Utils.schedule.computeScheduleFromTerms(contracts.engine(terms.contractType), terms, true, terms.maturityDate, terms.maturityDate);
it('should convert full terms to ANNTerms', async (): Promise<void> => {
const terms: Terms = DEFAULT_TERMS;
const annTerms = Utils.conversion.extractANNTerms(terms);
expect(isANNTerms(annTerms))
});

expect(schedule.length).toBeGreaterThan(0);
it('should convert full terms to CECTerms', async (): Promise<void> => {
const terms: Terms = DEFAULT_TERMS;
const cecTerms = Utils.conversion.extractCECTerms(terms);
expect(isCECTerms(cecTerms))
});

it('should convert full terms to CEGTerms', async (): Promise<void> => {
const terms: Terms = DEFAULT_TERMS;
const cegTerms = Utils.conversion.extractCEGTerms(terms);
expect(isCEGTerms(cegTerms))
});

it('should convert full terms to CERTFTerms', async (): Promise<void> => {
const terms: Terms = DEFAULT_TERMS;
const certfTerms = Utils.conversion.extractCERTFTerms(terms);
expect(isCERTFTerms(certfTerms))
});

it('should convert full terms to PAMTerms', async (): Promise<void> => {
const terms: Terms = DEFAULT_TERMS;
const pamTerms = Utils.conversion.extractPAMTerms(terms);
expect(isPAMTerms(pamTerms))
});
});

});

0 comments on commit b7721cb

Please sign in to comment.