Skip to content

Commit 0cd3b5c

Browse files
author
Antoine de Chevigné
committed
tests + cleanup
1 parent 9877128 commit 0cd3b5c

File tree

7 files changed

+933
-23
lines changed

7 files changed

+933
-23
lines changed

run/jobs/backfillOrbitMessageDeliveredLogs.js

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ module.exports = async (job) => {
1010
const data = job.data;
1111

1212
const orbitConfig = await OrbitChainConfig.findByPk(data.orbitChainConfigId);
13+
if (!orbitConfig)
14+
throw new Error('OrbitChainConfig not found');
15+
1316
const parentWorkspace = await orbitConfig.getParentWorkspace();
1417
const bridgeContract = orbitConfig.bridgeContract;
1518
let fromBlock = data.fromBlock;
@@ -39,21 +42,21 @@ module.exports = async (job) => {
3942
});
4043

4144
const logs = await client.getFilterLogs({ filter });
45+
const deposits = [];
4246
for (const log of logs) {
4347
if ([3, 7, 9, 12].includes(log.args.kind)) {
4448
logger.info(`Found deposit #${parseInt(log.args.messageIndex)}`)
45-
await OrbitDeposit.bulkCreate([
46-
{
47-
workspaceId: orbitConfig.workspaceId,
48-
l1Block: parseInt(log.blockNumber),
49-
l1TransactionHash: log.transactionHash,
50-
messageIndex: parseInt(log.args.messageIndex),
51-
timestamp: String(log.args.timestamp),
52-
sender: log.args.sender
53-
}
54-
], { ignoreDuplicates: true });
49+
deposits.push({
50+
workspaceId: orbitConfig.workspaceId,
51+
l1Block: parseInt(log.blockNumber),
52+
l1TransactionHash: log.transactionHash,
53+
messageIndex: parseInt(log.args.messageIndex),
54+
timestamp: String(log.args.timestamp),
55+
sender: log.args.sender
56+
});
5557
}
5658
}
59+
await OrbitDeposit.bulkCreate(deposits, { ignoreDuplicates: true });
5760

5861
const newFromBlock = fromBlock - SCAN_RANGE;
5962
return enqueue('backfillOrbitMessageDeliveredLogs', `backfillOrbitMessageDeliveredLogs-${orbitConfig.id}-${newFromBlock}-${fromBlock - 2 * SCAN_RANGE}`, {

run/jobs/blockSync.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ module.exports = async job => {
5050
if (!workspace.explorer)
5151
return 'No active explorer for this workspace';
5252

53-
// if (!workspace.explorer.shouldSync)
54-
// return 'Sync is disabled';
53+
if (!workspace.explorer.shouldSync)
54+
return 'Sync is disabled';
5555

5656
if (workspace.rpcHealthCheckEnabled && workspace.rpcHealthCheck && !workspace.rpcHealthCheck.isReachable)
5757
return 'RPC is not reachable';

run/jobs/checkOrbitMessageDeliveredLogs.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ module.exports = async () => {
1616
const newProcesses = [];
1717
const existingProcesses = [];
1818
for (const orbitConfig of orbitConfigs) {
19+
// Additional safety check to ensure parentWorkspaceId is valid
20+
if (!orbitConfig.parentWorkspaceId) {
21+
continue;
22+
}
23+
1924
const pm2 = new PM2(getPm2Host(), getPm2Secret());
2025
const { data: existingProcess } = await pm2.find(`logListener-${orbitConfig.parentWorkspaceId}`);
2126

@@ -24,7 +29,6 @@ module.exports = async () => {
2429
continue;
2530
}
2631

27-
console.log(`Listening address ${orbitConfig.bridgeContract} on ${orbitConfig.parentWorkspaceId}`);
2832
await pm2.startLogListener(`logListener-${orbitConfig.parentWorkspaceId}`,
2933
JSON.stringify({
3034
parentWorkspaceId: orbitConfig.parentWorkspaceId,

run/tests/.cursor/rules/backend-tests.mdc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,5 @@ description: |
1313
- Assuming you're in the "run/" or "pm2-server" directory, run tests with `npm run test`. You can pass a file path as an argument to only run tests in this file.
1414
- All functions in run/lib/firebase.js are automatically mocked to a jest.fn(), you don't need to setup a mock again for those.
1515
- As a general rule, do not setup mocks for files that are under run/lib in a test file, they should have their own mocking file. You can create it if it doesn't exist. However, feel free to override the mocks using mockImplementation, mockResolvedValue, etc...based on individual tests.
16-
- 500 are unexpected and thus shouldn't be tested, if you deem that a 500 scenario is likely to happen often enough so that it should be tested, fix the code so that it returns a 400, then test it.
16+
- 500 are unexpected and thus shouldn't be tested, if you deem that a 500 scenario is likely to happen often enough so that it should be tested, fix the code so that it returns a 400, then test it.
17+
- More generally, do not write tests for unhandled unexpected values, but try to handle it in the code and then write a test to make sure it's handled properly

0 commit comments

Comments
 (0)