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

Commit

Permalink
Add additional checks to ICT CERTF test case
Browse files Browse the repository at this point in the history
  • Loading branch information
jo-es committed Oct 30, 2020
1 parent 0a2a0e1 commit fb87157
Showing 1 changed file with 53 additions and 49 deletions.
102 changes: 53 additions & 49 deletions packages/protocol/test/ICT/TestICTCERTF.js
Expand Up @@ -16,28 +16,28 @@ describe('ICT', function () {

const computeEventTime = async (scheduleTime) => {
return (await this.CERTFEngineInstance.methods.shiftEventTime(
scheduleTime,
this.terms.businessDayConvention,
this.terms.calendar,
this.terms.maturityDate
scheduleTime,
this.terms.businessDayConvention,
this.terms.calendar,
this.terms.maturityDate
).call());
};

const computeCalcTime = async (scheduleTime) => {
return (await this.CERTFEngineInstance.methods.shiftCalcTime(
scheduleTime,
this.terms.businessDayConvention,
this.terms.calendar,
this.terms.maturityDate
scheduleTime,
this.terms.businessDayConvention,
this.terms.calendar,
this.terms.maturityDate
).call());
};

const encodeNumberAsBytes32 = (number) => {
return web3.utils.padLeft(
web3.utils.numberToHex(
web3.utils.toWei(String(number))
),
64
web3.utils.numberToHex(
web3.utils.toWei(String(number))
),
64
);
};

Expand Down Expand Up @@ -72,34 +72,34 @@ describe('ICT', function () {
};

const { events } = await self.CERTFActorInstance.methods.initialize(
self.terms,
self.schedule,
self.ownership,
self.CERTFEngineInstance.options.address,
ZERO_ADDRESS
self.terms,
self.schedule,
self.ownership,
self.CERTFEngineInstance.options.address,
ZERO_ADDRESS
).send({ from: owner });
expectEvent(events, 'InitializedAsset');

self.assetId = events.InitializedAsset.returnValues.assetId;
self.state = await self.CERTFRegistryInstance.methods.getState(
web3.utils.toHex(self.assetId)
web3.utils.toHex(self.assetId)
).call();

await self.ict.methods.setAssetId(web3.utils.toHex(self.assetId)).send({ from: owner });

await self.DataRegistryInstance.methods.setDataProvider(
self.terms.contractReference_2.object,
self.ict.options.address
self.terms.contractReference_2.object,
self.ict.options.address
).send({ from: deployer });
await self.DataRegistryInstance.methods.setDataProvider(
self.terms.contractReference_1.object,
owner
self.terms.contractReference_1.object,
owner
).send({ from: deployer });

await self.DataRegistryInstance.methods.publishDataPoint(
self.terms.contractReference_1.object,
self.terms.issueDate,
encodeNumberAsBytes32(self.terms.nominalPrice)
self.terms.contractReference_1.object,
self.terms.issueDate,
encodeNumberAsBytes32(self.terms.nominalPrice)
).send({ from: owner });
});

Expand All @@ -110,16 +110,17 @@ describe('ICT', function () {

it('should process the IssueDate event', async () => {
const idEvent = await this.CERTFRegistryInstance.methods.getNextScheduledEvent(
web3.utils.toHex(this.assetId)
web3.utils.toHex(this.assetId)
).call();
const { eventType, scheduleTime } = decodeEvent(idEvent);
assert.strictEqual(eventType, '2'); // #useEventName

// settle and progress asset state
await mineBlock(await computeEventTime(scheduleTime));
await this.CERTFActorInstance.methods.progress(
web3.utils.toHex(this.assetId)
const { events } = await this.CERTFActorInstance.methods.progress(
web3.utils.toHex(this.assetId)
).send({ from: owner });
expectEvent(events, 'ProgressedAsset', { 'eventType': '2' });
});

it('should register investor1 for redemption for the first REF event [ @skip-on-coverage ]', async () => {
Expand All @@ -135,14 +136,14 @@ describe('ICT', function () {
const { scheduleTime: scheduleTimeXD } = decodeEvent(this.schedule[2]);

const exerciseQuantity = (await this.DataRegistryInstance.methods.getDataPoint(
this.terms.contractReference_2.object,
await computeCalcTime(scheduleTimeXD)
this.terms.contractReference_2.object,
await computeCalcTime(scheduleTimeXD)
).call())[0];

const deposit = await this.ict.methods.getDeposit(rfdEvent).call();
const totalSupply = await this.ict.methods.totalSupply().call();
const ratioSignaled = (new BigNumber(deposit.totalAmountSignaled))
.dividedBy(totalSupply).shiftedBy(18).decimalPlaces(0);
.dividedBy(totalSupply).shiftedBy(18).decimalPlaces(0);
const expectedExerciseQuantity = ratioSignaled.multipliedBy(this.terms.quantity).shiftedBy(-18).toFixed();

assert.strictEqual(exerciseQuantity, expectedExerciseQuantity);
Expand All @@ -152,62 +153,65 @@ describe('ICT', function () {

it('should process the first RedemptionFixingDay event', async () => {
const rfdEvent = await this.CERTFRegistryInstance.methods.getNextScheduledEvent(
web3.utils.toHex(this.assetId)
web3.utils.toHex(this.assetId)
).call();
const { eventType, scheduleTime } = decodeEvent(rfdEvent);
assert.strictEqual(eventType, '19'); // #useEventName

await this.DataRegistryInstance.methods.publishDataPoint(
this.terms.contractReference_1.object,
await computeCalcTime(scheduleTime),
encodeNumberAsBytes32(this.terms.nominalPrice)
this.terms.contractReference_1.object,
await computeCalcTime(scheduleTime),
encodeNumberAsBytes32(this.terms.nominalPrice)
).send({ from: owner });

// settle and progress asset state
await mineBlock(await computeEventTime(scheduleTime));
await this.CERTFActorInstance.methods.progress(web3.utils.toHex(this.assetId))
.send({ from: owner });
const { events } = await this.CERTFActorInstance.methods.progress(web3.utils.toHex(this.assetId))
.send({ from: owner });
expectEvent(events, 'ProgressedAsset', { 'eventType': '19' });
await this.CERTFRegistryInstance.methods.getState(web3.utils.toHex(this.assetId)).call();
});

it('should process the first ExecutionDate event', async () => {
const xdEvent = await this.CERTFRegistryInstance.methods
.getNextScheduledEvent(web3.utils.toHex(this.assetId)).call();
.getNextScheduledEvent(web3.utils.toHex(this.assetId)).call();
const { eventType, scheduleTime } = decodeEvent(xdEvent);
assert.strictEqual(eventType, '25'); // #useEventName

// settle and progress asset state
await mineBlock(await computeEventTime(scheduleTime));
await this.CERTFActorInstance.methods.progress(
web3.utils.toHex(this.assetId)
const { events } = await this.CERTFActorInstance.methods.progress(
web3.utils.toHex(this.assetId)
).send({ from: owner });
expectEvent(events, 'ProgressedAsset', { 'eventType': '25' });
});

it('should process the first REP event [ @skip-on-coverage ]', async () => {
const rpdEvent = await this.CERTFRegistryInstance.methods.getNextScheduledEvent(
web3.utils.toHex(this.assetId)
web3.utils.toHex(this.assetId)
).call();
const { eventType, scheduleTime } = decodeEvent(rpdEvent);
assert.strictEqual(eventType, '21'); // #useEventName

// set allowance for CERTFActor
await this.PaymentTokenInstance.methods.approve(
this.CERTFActorInstance.options.address,
(new BigNumber(this.terms.nominalPrice)).multipliedBy(this.terms.quantity).shiftedBy(-18).toFixed(),
this.CERTFActorInstance.options.address,
(new BigNumber(this.terms.nominalPrice)).multipliedBy(this.terms.quantity).shiftedBy(-18).toFixed(),
).send({ from: issuer });

// settle and progress asset state
await mineBlock(await computeEventTime(scheduleTime));
await this.CERTFActorInstance.methods.progress(web3.utils.toHex(
this.assetId)
const { events } = await this.CERTFActorInstance.methods.progress(web3.utils.toHex(
this.assetId)
).send({ from: owner });
expectEvent(events, 'ProgressedAsset', { 'eventType': '21' });
await this.ict.methods.fetchDepositAmountForEvent(this.schedule[1]).send({ from: owner });

const deposit = await this.ict.methods.getDeposit(this.schedule[1]).call();

assert.strictEqual(
deposit.amount,
(new BigNumber(this.terms.nominalPrice)).multipliedBy(this.exerciseQuantity).shiftedBy(-18).toFixed()
deposit.amount,
(new BigNumber(this.terms.nominalPrice)).multipliedBy(this.exerciseQuantity).shiftedBy(-18).toFixed()
);
});

Expand All @@ -217,8 +221,8 @@ describe('ICT', function () {
const deposit = await this.ict.methods.getDeposit(this.schedule[1]).call();

assert.strictEqual(
deposit.claimedAmount,
(new BigNumber(this.terms.nominalPrice)).multipliedBy(this.exerciseQuantity).shiftedBy(-18).toFixed()
deposit.claimedAmount,
(new BigNumber(this.terms.nominalPrice)).multipliedBy(this.exerciseQuantity).shiftedBy(-18).toFixed()
);
});
});

0 comments on commit fb87157

Please sign in to comment.