Skip to content
This repository has been archived by the owner on May 19, 2023. It is now read-only.

Commit

Permalink
feat: add agreement exceed limit notification to provider (#407)
Browse files Browse the repository at this point in the history
  • Loading branch information
nduchak authored Nov 20, 2020
1 parent 0490340 commit 3d092b7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
5 changes: 4 additions & 1 deletion src/communication/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,19 +44,22 @@ function buildNotification (agreement: Agreement, message: CommsMessage<CommsPay
payload: { ...message.payload, code: message.code, timestamp: message.timestamp }
}
switch (message.code) {
// Provider
case MessageCodesEnum.I_AGREEMENT_NEW:
return {
accounts: [agreement.offerId],
...notification
}
// Provider and Consumer
case MessageCodesEnum.E_GENERAL:
case MessageCodesEnum.E_AGREEMENT_SIZE_LIMIT_EXCEEDED:
case MessageCodesEnum.I_AGREEMENT_EXPIRED:
return {
accounts: [agreement.consumer, agreement.offerId],
...notification
}
// Consumer
case MessageCodesEnum.I_HASH_PINNED:
case MessageCodesEnum.E_AGREEMENT_SIZE_LIMIT_EXCEEDED:
return {
accounts: [agreement.consumer],
...notification
Expand Down
10 changes: 8 additions & 2 deletions test/integration/services/storage/storage-manger.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -407,15 +407,17 @@ describe('Storage service', function () {
await roomPinner.broadcast({ code: MessageCodesEnum.I_HASH_PINNED, payload: { agreementReference: agreement.agreementReference, hash: agreementData.cid } })
await roomPinner.broadcast({ code: MessageCodesEnum.I_AGREEMENT_EXPIRED, payload: { agreementReference: agreement.agreementReference, hash: agreementData.cid } })
await roomPinner.broadcast({ code: MessageCodesEnum.E_AGREEMENT_SIZE_LIMIT_EXCEEDED, payload: { agreementReference: agreement.agreementReference, hash: agreementData.cid } })
await roomPinner.broadcast({ code: MessageCodesEnum.E_GENERAL, payload: { agreementReference: agreement.agreementReference, hash: agreementData.cid, error: 'Error' } })
await sleep(2000)

const notifications = await NotificationModel.findAll()

expect(notifications.length).to.be.eql(4)
expect(notifications.length).to.be.eql(5)
const newAgreement = notifications.find(n => n.payload.code === MessageCodesEnum.I_AGREEMENT_NEW)
const agrExpired = notifications.find(n => n.payload.code === MessageCodesEnum.I_AGREEMENT_EXPIRED)
const hashStop = notifications.find(n => n.payload.code === MessageCodesEnum.I_HASH_PINNED)
const sizeLimit = notifications.find(n => n.payload.code === MessageCodesEnum.E_AGREEMENT_SIZE_LIMIT_EXCEEDED)
const errorGeneral = notifications.find(n => n.payload.code === MessageCodesEnum.E_GENERAL)

expect(newAgreement?.accounts).to.be.eql([app.providerAddress])
expect(newAgreement?.type).to.be.eql(NotificationType.STORAGE)
Expand All @@ -425,10 +427,14 @@ describe('Storage service', function () {
expect(agrExpired?.type).to.be.eql(NotificationType.STORAGE)
expect(agrExpired?.payload).to.be.eql({ agreementReference: agreement.agreementReference, hash: agreementData.cid, code: MessageCodesEnum.I_AGREEMENT_EXPIRED })

expect(sizeLimit?.accounts).to.be.eql([app.consumerAddress])
expect(sizeLimit?.accounts).to.be.eql([app.consumerAddress, app.providerAddress])
expect(sizeLimit?.type).to.be.eql(NotificationType.STORAGE)
expect(sizeLimit?.payload).to.be.eql({ agreementReference: agreement.agreementReference, hash: agreementData.cid, code: MessageCodesEnum.E_AGREEMENT_SIZE_LIMIT_EXCEEDED })

expect(errorGeneral?.accounts).to.be.eql([app.consumerAddress, app.providerAddress])
expect(errorGeneral?.type).to.be.eql(NotificationType.STORAGE)
expect(errorGeneral?.payload).to.be.eql({ agreementReference: agreement.agreementReference, hash: agreementData.cid, code: MessageCodesEnum.E_GENERAL, error: 'Error' })

expect(hashStop?.accounts).to.be.eql([app.consumerAddress])
expect(hashStop?.type).to.be.eql(NotificationType.STORAGE)
expect(hashStop?.payload).to.be.eql({ agreementReference: agreement.agreementReference, hash: agreementData.cid, code: MessageCodesEnum.I_HASH_PINNED })
Expand Down

0 comments on commit 3d092b7

Please sign in to comment.