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

Trigger cache invalidation tests by queue #2215

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Conversation

iamacook
Copy link
Member

@iamacook iamacook commented Dec 19, 2024

Summary

Our cache is invalidated in accordance with queue events. Most of the test coverage was linked to our previous POST hooks, and therefore skipped.

This converts the tests to trigger via queue instead of POST calls, unskipping them.

Changes

  • Unskip cache invalidation tests
  • Modify tests to trigger via queue

@iamacook iamacook self-assigned this Dec 19, 2024
Comment on lines -101 to -251
txHash: faker.string.hexadecimal({ length: 32 }),
},
{
type: 'MESSAGE_CREATED',
address: faker.finance.ethereumAddress(),
messageHash: faker.string.hexadecimal({ length: 32 }),
},
{
type: 'MESSAGE_CONFIRMATION',
address: faker.finance.ethereumAddress(),
messageHash: faker.string.hexadecimal({ length: 32 }),
},
{
type: 'CHAIN_UPDATE',
},
{
type: 'REORG_DETECTED',
chainId: faker.string.numeric(),
blockNumber: faker.number.int(),
},
{
type: 'SAFE_APPS_UPDATE',
},
{
type: 'SAFE_CREATED',
address: faker.finance.ethereumAddress(),
blockNumber: faker.number.int(),
},
])('accepts $type', async (payload) => {
const chainId = faker.string.numeric();
const data = {
chainId: chainId,
...payload,
};
networkService.get.mockImplementation(({ url }) => {
switch (url) {
case `${safeConfigUrl}/api/v1/chains/${chainId}`:
return Promise.resolve({
data: rawify(chainBuilder().with('chainId', chainId).build()),
status: 200,
});
default:
return Promise.reject(new Error(`Could not match ${url}`));
}
});

await request(app.getHttpServer())
.post(`/hooks/events`)
.set('Authorization', `Basic ${authToken}`)
.send(data)
.expect(202);
});

it('returns 400 (Bad Request) on unknown payload', async () => {
const data = {
type: 'SOME_TEST_TYPE_THAT_WE_DO_NOT_SUPPORT',
safeTxHash: 'some-safe-tx-hash',
};
networkService.get.mockImplementation(({ url }) => {
switch (url) {
case `${safeConfigUrl}/api/v1/chains/1`:
return Promise.resolve({
data: rawify(chainBuilder().with('chainId', '1').build()),
status: 200,
});
default:
return Promise.reject(new Error(`Could not match ${url}`));
}
});

await request(app.getHttpServer())
.post(`/hooks/events`)
.set('Authorization', `Basic ${authToken}`)
.send(data)
.expect(422)
.expect({
statusCode: 422,
code: 'invalid_union_discriminator',
options: [
'CHAIN_UPDATE',
'DELETED_MULTISIG_TRANSACTION',
'EXECUTED_MULTISIG_TRANSACTION',
'INCOMING_ETHER',
'INCOMING_TOKEN',
'MESSAGE_CREATED',
'MODULE_TRANSACTION',
'NEW_CONFIRMATION',
'MESSAGE_CONFIRMATION',
'OUTGOING_ETHER',
'OUTGOING_TOKEN',
'PENDING_MULTISIG_TRANSACTION',
'REORG_DETECTED',
'SAFE_APPS_UPDATE',
'SAFE_CREATED',
],
path: ['type'],
message:
"Invalid discriminator value. Expected 'CHAIN_UPDATE' | 'DELETED_MULTISIG_TRANSACTION' | 'EXECUTED_MULTISIG_TRANSACTION' | 'INCOMING_ETHER' | 'INCOMING_TOKEN' | 'MESSAGE_CREATED' | 'MODULE_TRANSACTION' | 'NEW_CONFIRMATION' | 'MESSAGE_CONFIRMATION' | 'OUTGOING_ETHER' | 'OUTGOING_TOKEN' | 'PENDING_MULTISIG_TRANSACTION' | 'REORG_DETECTED' | 'SAFE_APPS_UPDATE' | 'SAFE_CREATED'",
});
});
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These were removed as we receive no response. If we want to check this, however, we could check whether an error is logged.

Comment on lines +936 to +942
it.each(
[
newDelegateEventBuilder().build(),
updatedDelegateEventBuilder().build(),
deletedDelegateEventBuilder().build(),
].map((event) => [event.type, event]),
)('%s clears delegates', async (_, event) => {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These were added as they were missing - initially marked with a TODO at the top.

@iamacook iamacook marked this pull request as ready for review December 19, 2024 14:51
@iamacook iamacook requested a review from a team as a code owner December 19, 2024 14:51
@iamacook iamacook enabled auto-merge (squash) December 19, 2024 15:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant