Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add message events #66

Merged
merged 2 commits into from
Aug 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@

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 @@
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);
});
});
});