Skip to content
This repository was archived by the owner on Aug 12, 2023. It is now read-only.

Commit 26da541

Browse files
authored
Refactor a few things to shrink another PR (#442)
* Refactor a few things to shrink another PR * Tweak timeouts
1 parent 086e66a commit 26da541

File tree

15 files changed

+185
-177
lines changed

15 files changed

+185
-177
lines changed

src/apps/sync-app-definitions.test.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,16 @@ jest.mock('./get-app-definitions');
77

88
beforeAll(async () => {
99
await testUtils.setupDb();
10-
});
10+
}, 30000);
1111

1212
afterEach(async () => {
1313
await testUtils.resetDb();
1414
jest.resetAllMocks();
15-
});
15+
}, 30000);
1616

17-
afterAll(() => {
18-
testUtils.tearDownDb();
19-
});
17+
afterAll(async () => {
18+
await testUtils.tearDownDb();
19+
}, 30000);
2020

2121
describe('apps/syncAppDefinitions', () => {
2222
it('should create all app documents when none exist', async () => {

src/consumers/convert-relayer-fees/index.test.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@ jest.mock('../../rates/get-conversion-rate');
1010

1111
beforeAll(async () => {
1212
await testUtils.setupDb();
13-
});
13+
}, 30000);
1414

1515
afterEach(async () => {
1616
await testUtils.resetDb();
17-
});
17+
}, 30000);
1818

19-
afterAll(() => {
20-
testUtils.tearDownDb();
21-
});
19+
afterAll(async () => {
20+
await testUtils.tearDownDb();
21+
}, 30000);
2222

2323
describe('consumers/convert-relayer-fees', () => {
2424
it('should throw an error when fillId format is invalid', async () => {

src/consumers/create-token.test.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ beforeAll(async () => {
1616
afterEach(async () => {
1717
jest.resetAllMocks();
1818
await testUtils.resetDb();
19-
});
19+
}, 30000);
2020

21-
afterAll(() => {
22-
testUtils.tearDownDb();
23-
});
21+
afterAll(async () => {
22+
await testUtils.tearDownDb();
23+
}, 30000);
2424

2525
describe('consumers.createToken', () => {
2626
it('should subscribe to token-processing queue and consume create-token jobs', () => {

src/consumers/fetch-transaction/index.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@ beforeEach(() => {
3838
afterEach(async () => {
3939
jest.clearAllMocks();
4040
await resetDb();
41-
});
41+
}, 30000);
4242

4343
afterAll(async () => {
44-
tearDownDb();
44+
await tearDownDb();
4545
}, 30000);
4646

4747
const simpleJob = {

src/events/persist-events.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@ const { getModel } = require('../model');
33
const persistEvents = async (events, options) => {
44
const Event = getModel('Event');
55

6-
await Event.create(events, options);
6+
await Event.create(
7+
events.map(event => ({ ...event, dateIngested: new Date() })),
8+
options,
9+
);
710
};
811

912
module.exports = persistEvents;

src/fills/convert-protocol-fee.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,19 @@ const { JOB, QUEUE } = require('../constants');
22
const { publishJob } = require('../queues');
33

44
const fetchFillStatus = async (fill, delay) => {
5+
const fillId = fill._id.toString();
6+
57
await publishJob(
68
QUEUE.FILL_PROCESSING,
79
JOB.CONVERT_PROTOCOL_FEE,
810
{
9-
fillId: fill._id,
11+
fillId,
1012
fillDate: fill.date,
1113
protocolFee: fill.protocolFee,
1214
},
1315
{
1416
delay,
15-
jobId: `convert-protocol-fee-${fill._id}`,
17+
jobId: `convert-protocol-fee-${fillId}`,
1618
},
1719
);
1820
};

src/index/index-traded-tokens.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ const indexTradedTokens = fill => {
1313
throw new Error(`No traded tokens for fill: ${fill._id}`);
1414
}
1515

16+
const fillId = fill._id.toString();
17+
1618
publishJob(
1719
QUEUE.TRADED_TOKEN_INDEXING,
1820
JOB.INDEX_TRADED_TOKENS,
@@ -22,11 +24,11 @@ const indexTradedTokens = fill => {
2224
type: app.type,
2325
})),
2426
date: fill.date,
25-
fillId: fill._id,
27+
fillId,
2628
relayerId: fill.relayerId,
2729
tradedTokens,
2830
},
29-
{ jobId: `index-traded-tokens-${fill._id}` },
31+
{ jobId: `index-traded-tokens-${fillId}` },
3032
);
3133
};
3234

src/jobs/batch-schedule-transaction-fetch.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
1-
const signale = require('signale');
2-
31
const { JOB, QUEUE } = require('../constants');
42
const { publishJob } = require('../queues');
53
const Event = require('../model/event');
64

7-
const logger = signale.scope('batch schedule transaction fetch');
8-
9-
const batchScheduleTransactionFetch = async ({ batchSize }) => {
5+
const batchScheduleTransactionFetch = async ({ batchSize }, { logger }) => {
106
logger.info(`scheduling transaction fetch for batch of fills: ${batchSize}`);
117

128
// Fetch a batch of unprocessed events

src/jobs/create-fills/persist-fill.test.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@ const testUtils = require('../../test-utils');
66

77
beforeAll(async () => {
88
await testUtils.setupDb();
9-
});
10-
11-
afterAll(() => {
12-
testUtils.tearDownDb();
13-
});
9+
}, 30000);
1410

1511
afterEach(async () => {
1612
await testUtils.resetDb();
17-
});
13+
}, 30000);
14+
15+
afterAll(async () => {
16+
await testUtils.tearDownDb();
17+
}, 30000);
1818

1919
const simpleFill = {
2020
_id: '5bb1f06b62f9ca0004c7cf20',
@@ -127,7 +127,7 @@ it('should persist fill', async () => {
127127
protocolVersion: 3,
128128
relayerId: 15,
129129
senderAddress: '0xd3d0474124c1013ed6bfcfd9a49cfedb8c78fc44',
130-
status: 0,
130+
status: 1,
131131
taker: '0x7447dab10325f902725191a34eb8288abe02c7f4',
132132
transactionHash:
133133
'0x28ffb48f354997d384eee49d326c13a10c4584ca3bced4632053b201d3a0cbbc',

src/model/event.js

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,22 @@ const mongoose = require('mongoose');
22

33
const { Schema } = mongoose;
44

5-
const schema = Schema({
6-
blockNumber: { required: true, type: Number },
7-
data: { required: true, type: Schema.Types.Mixed },
8-
fillCreated: { type: Boolean },
9-
logIndex: { required: true, type: Number },
10-
protocolVersion: { required: true, type: Number },
11-
scheduler: {
12-
transactionFetchScheduled: Boolean,
5+
const schema = Schema(
6+
{
7+
blockNumber: { required: true, type: Number },
8+
dateIngested: { required: true, type: Date },
9+
data: { required: true, type: Schema.Types.Mixed },
10+
fillCreated: { type: Boolean },
11+
logIndex: { required: true, type: Number },
12+
protocolVersion: { required: true, type: Number },
13+
scheduler: {
14+
transactionFetchScheduled: Boolean,
15+
},
16+
transactionHash: { required: true, type: String },
17+
type: { required: true, type: String },
1318
},
14-
transactionHash: { required: true, type: String },
15-
type: { required: true, type: String },
16-
});
19+
{ strict: 'throw' },
20+
);
1721

1822
schema.index({ fillCreated: 1 });
1923
schema.index({ logIndex: 1, transactionHash: 1 }, { unique: true });

0 commit comments

Comments
 (0)