Skip to content
This repository was archived by the owner on Jul 9, 2024. It is now read-only.

Commit b415d94

Browse files
authored
Merge branch 'main' into filter-empty-sponsors
2 parents 787a6c8 + 2466c70 commit b415d94

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

src/update-data-feeds.test.ts

+23
Original file line numberDiff line numberDiff line change
@@ -435,4 +435,27 @@ describe('initializeUpdateCycle', () => {
435435
const groups = api.groupDataFeedsByProviderSponsor();
436436
expect(await api.initializeUpdateCycle(groups[0], api.DataFeedType.Beacon, Date.now())).toBeNull();
437437
});
438+
439+
it('returns null if no feeds are found for selected data feed type', async () => {
440+
state.updateState((currentState) => ({
441+
...currentState,
442+
beaconValues: {
443+
'0x2ba0526238b0f2671b7981fd7a263730619c8e849a528088fd4a92350a8c2f2c': validSignedData,
444+
'0xa5ddf304a7dcec62fa55449b7fe66b33339fd8b249db06c18423d5b0da7716c2': undefined as any,
445+
'0x8fa9d00cb8f2d95b1299623d97a97696ed03d0e3350e4ea638f469beabcdabcd': validSignedData,
446+
},
447+
}));
448+
449+
const txCountSpy = jest.spyOn(ethers.providers.StaticJsonRpcProvider.prototype, 'getTransactionCount');
450+
txCountSpy.mockResolvedValueOnce(212);
451+
452+
const groups = api.groupDataFeedsByProviderSponsor();
453+
454+
// Sponsor `0x417B205fEdB1b2352c7996B0F050A7a61544c5e2` on chain `3` have no beacon set
455+
const group = groups.find(
456+
({ sponsorAddress, provider }) =>
457+
sponsorAddress === '0x417B205fEdB1b2352c7996B0F050A7a61544c5e2' && provider.chainId === '3'
458+
);
459+
expect(await api.initializeUpdateCycle(group as any, api.DataFeedType.BeaconSet, Date.now())).toBeNull();
460+
});
438461
});

src/update-data-feeds.ts

+9-1
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,6 @@ export const initializeUpdateCycle = async (
105105
dataFeedType: DataFeedType,
106106
startTime: number
107107
) => {
108-
const { config, beaconValues, sponsorWalletsPrivateKey } = getState();
109108
const { provider, updateInterval, sponsorAddress, beacons, beaconSets } = providerSponsorDataFeeds;
110109
const { rpcProvider, chainId, providerName } = provider;
111110
const logOptions = {
@@ -119,6 +118,15 @@ export const initializeUpdateCycle = async (
119118

120119
logger.debug(`Initializing updates`, logOptions);
121120

121+
if (
122+
(dataFeedType === DataFeedType.Beacon && isEmpty(beacons)) ||
123+
(dataFeedType === DataFeedType.BeaconSet && isEmpty(beaconSets))
124+
) {
125+
logger.debug(`No ${dataFeedType} found, skipping initialization cycle`, logOptions);
126+
return null;
127+
}
128+
129+
const { config, beaconValues, sponsorWalletsPrivateKey } = getState();
122130
// All the beacon updates for given provider & sponsor have up to <updateInterval> seconds to finish
123131
const totalTimeout = updateInterval * 1_000;
124132

0 commit comments

Comments
 (0)