Skip to content

Commit

Permalink
Add message events (#66)
Browse files Browse the repository at this point in the history
  • Loading branch information
moisses89 authored Aug 31, 2023
1 parent b112382 commit ce221a9
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 9 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,16 @@ Some parameters are common to every event:
}
```

### Message created/confirmed
```json
{
"address": "<Ethereum checksummed address>",
"type": "MESSAGE_CREATED" | "MESSAGE_CONFIRMATION",
"messageHash": "<0x-prefixed-hex-string>",
"chainId": "<stringified-int>"
}
```

# Developer documentation

## Installation
Expand Down
4 changes: 3 additions & 1 deletion src/routes/events/event.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ export type TxServiceEventType =
| 'SAFE_CREATED'
| 'MODULE_TRANSACTION'
| 'OUTGOING_ETHER'
| 'OUTGOING_TOKEN';
| 'OUTGOING_TOKEN'
| 'MESSAGE_CREATED'
| 'MESSAGE_CONFIRMATION';

export interface TxServiceEvent {
chainId: string;
Expand Down
48 changes: 40 additions & 8 deletions src/routes/events/events.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,33 +6,38 @@ import { TxServiceEventType } from './event.dto';

describe('EventsService', () => {
let eventsService: EventsService;
let webhookService: WebhookService;
const queueProvider = {
/* eslint-disable @typescript-eslint/no-unused-vars */
subscribeToEvents: async (_: (_: string) => Promise<string>) =>
'exampleTag',
};
const webhookService = {
postEveryWebhook: async (_: object) => ({
data: {},
status: 200,
statusText: 'OK',
}),
};

/* eslint-enable @typescript-eslint/no-unused-vars */

beforeEach(async () => {
const webhookServiceMock = {
postEveryWebhook: async (_: object) => ({

Check warning on line 20 in src/routes/events/events.service.spec.ts

View workflow job for this annotation

GitHub Actions / lint

'_' is defined but never used
data: {},
status: 200,
statusText: 'OK',
}),
};
const module = await Test.createTestingModule({
providers: [EventsService, QueueProvider, WebhookService],
})
.overrideProvider(QueueProvider)
.useValue(queueProvider)
.overrideProvider(WebhookService)
.useValue(webhookService)
.useValue(webhookServiceMock)
.compile();

eventsService = module.get<EventsService>(EventsService);
webhookService = module.get<WebhookService>(WebhookService);
});



describe('listenToEvents', () => {
it('should return consumer tag', async () => {
const expected = 'exampleTag';
Expand All @@ -55,4 +60,31 @@ describe('EventsService', () => {
expect(postEveryWebhook).toBeCalledWith(msg);
});
});

describe('processMessageEvents', () => {
it('should post webhooks', async () => {
const postEveryWebhook = jest.spyOn(webhookService, 'postEveryWebhook');
const messageCreated = {
chainId: '1',
type: 'MESSAGE_CREATED' as TxServiceEventType,
messageHash:
'0x47173285a8d7341e5e972fc677286384f802f8ef42a5ec5f03bbfa254cb01fad',
address: '0x0275FC2adfF11270F3EcC4D2F7Aa0a9784601Ca6',
};
const messageConfirmation = {
chainId: '1',
type: 'MESSAGE_CONFIRMATION' as TxServiceEventType,
messageHash:
'0xc9b14f03293f5febf968b2a3dde3e5d373f978ea9e9403881c5abfa68322bea9',
address: '0x0275FC2adfF11270F3EcC4D2F7Aa0a9784601Ca6',
};

await eventsService.processEvent(JSON.stringify(messageCreated));
expect(postEveryWebhook).toBeCalledTimes(1);
expect(postEveryWebhook).toBeCalledWith(messageCreated);
await eventsService.processEvent(JSON.stringify(messageConfirmation));
expect(postEveryWebhook).toBeCalledTimes(2);
expect(postEveryWebhook).toBeCalledWith(messageConfirmation);
});
});
});

0 comments on commit ce221a9

Please sign in to comment.