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

Commit

Permalink
fix: correct event name (#172)
Browse files Browse the repository at this point in the history
  • Loading branch information
AuHau authored Jun 19, 2020
1 parent 020edf9 commit 29b4d54
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 6 deletions.
6 changes: 3 additions & 3 deletions src/blockchain/confirmator.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import config from 'config'

import Event from './event.model'
import { asyncSplit, setDifference, split } from '../utils'
import { asyncSplit, setDifference } from '../utils'

import type { EventData } from 'web3-eth-contract'
import type { BlockHeader, Eth } from 'web3-eth'
Expand Down Expand Up @@ -50,13 +50,13 @@ export class Confirmator {
})

const [valid, invalid] = await asyncSplit(events, this.eventHasValidReceipt.bind(this))
const [toBeEmitted, toBeConfirmed] = split(valid, isConfirmedClosure(currentBlock.number))
const toBeEmitted = valid.filter(isConfirmedClosure(currentBlock.number))

toBeEmitted.forEach(this.confirmEvent.bind(this))
this.logger.info(`Confirmed ${toBeEmitted.length} events.`)
await Event.update({ emitted: true }, { where: { id: toBeEmitted.map(e => e.id) } }) // Update DB that events were emitted

toBeConfirmed.forEach(this.emitNewConfirmationsClosure(currentBlock.number))
valid.forEach(this.emitNewConfirmationsClosure(currentBlock.number))

if (invalid.length !== 0) {
invalid.forEach(e => this.emitter.emit(INVALID_CONFIRMATION_EVENT_NAME, { transactionHash: e.transactionHash }))
Expand Down
30 changes: 27 additions & 3 deletions test/blockchain/confirmator.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,13 +110,25 @@ describe('Confirmator', function () {
await sleep(10)

expect(invalidEventSpy).to.not.have.been.called()
expect(confirmedEventSpy).to.have.callCount(1)
expect(confirmedEventSpy).to.have.callCount(3)
expect(confirmedEventSpy).to.have.been.calledWithExactly({
confirmations: 3,
event: 'testEvent',
targetConfirmation: 4,
transactionHash: '2'
})
expect(confirmedEventSpy).to.have.been.calledWithExactly({
confirmations: 2,
event: 'otherEvent',
targetConfirmation: 2,
transactionHash: '3'
})
expect(confirmedEventSpy).to.have.been.calledWithExactly({
confirmations: 2,
event: 'otherEvent',
targetConfirmation: 2,
transactionHash: '3'
})

expect(newEventSpy).to.have.callCount(2)
expect(newEventSpy).to.have.been.calledWithExactly({
Expand Down Expand Up @@ -193,7 +205,13 @@ describe('Confirmator', function () {
await sleep(10)

expect(invalidEventSpy).to.not.have.been.called()
expect(confirmedEventSpy).to.have.callCount(1)
expect(confirmedEventSpy).to.have.callCount(2)
expect(confirmedEventSpy).to.have.been.calledWithExactly({
confirmations: 2,
event: 'niceEvent',
targetConfirmation: 2,
transactionHash: '3'
})
expect(confirmedEventSpy).to.have.been.calledWithExactly({
confirmations: 3,
event: 'testEvent',
Expand Down Expand Up @@ -346,7 +364,13 @@ describe('Confirmator', function () {
await confirmator.runConfirmationsRoutine(block)
await sleep(10)

expect(confirmedEventSpy).to.have.callCount(0)
expect(confirmedEventSpy).to.have.callCount(1)
expect(confirmedEventSpy).to.have.been.calledWithExactly({
event: 'completelyDifferentEvent',
transactionHash: '5',
targetConfirmation: 2,
confirmations: 2
})

expect(await Event.count()).to.eql(3)

Expand Down

0 comments on commit 29b4d54

Please sign in to comment.