From fb8715791bdd099c19beef24c0d9a65f9a2877c5 Mon Sep 17 00:00:00 2001 From: jo-es Date: Fri, 30 Oct 2020 14:00:29 +0100 Subject: [PATCH] Add additional checks to ICT CERTF test case --- packages/protocol/test/ICT/TestICTCERTF.js | 102 +++++++++++---------- 1 file changed, 53 insertions(+), 49 deletions(-) diff --git a/packages/protocol/test/ICT/TestICTCERTF.js b/packages/protocol/test/ICT/TestICTCERTF.js index b4422454..3cb30cb3 100644 --- a/packages/protocol/test/ICT/TestICTCERTF.js +++ b/packages/protocol/test/ICT/TestICTCERTF.js @@ -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 ); }; @@ -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 }); }); @@ -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 () => { @@ -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); @@ -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() ); }); @@ -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() ); }); });