Skip to content

Commit 47f69d7

Browse files
authored
Resolve conflicts, pr comments (#90)
1 parent 8da5a55 commit 47f69d7

File tree

9 files changed

+41
-14
lines changed

9 files changed

+41
-14
lines changed

README.md

+4
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,10 @@ The batch size of active dAPIs that are to be fetched in a single RPC call.
185185

186186
The fetch interval in seconds between retrievals of signed API data.
187187

188+
#### `signedApiUrls`
189+
190+
A list of signed API URLs to call along with URLs fetched from the chain.
191+
188192
## Docker
189193

190194
### Build

config/airseeker.example.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,6 @@
2323
}
2424
},
2525
"deviationThresholdCoefficient": 1,
26-
"signedDataFetchInterval": 10
26+
"signedDataFetchInterval": 10,
27+
"signedApiUrls": []
2728
}

jest-e2e.config.js

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ module.exports = {
99
collectCoverage: false, // It doesn't make sense to collect coverage for e2e tests because they target high level features and interaction with other services.
1010
maxWorkers: 1, // We don't want to run tests in parallel because they might interfere with each other. This option is the same as --runInBand. See: https://stackoverflow.com/a/46489246.
1111

12+
mockReset: true,
1213
preset: 'ts-jest',
1314
restoreMocks: true,
1415
setupFiles: [join(__dirname, './jest.setup.js')],

jest-unit.config.js

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ module.exports = {
1111
coveragePathIgnorePatterns: ['node_modules', '<rootDir>/src/typechain-types'], // Coverage is collected for all files imported by the tests. We want to exclude files generated by Typechain.
1212
coverageProvider: 'v8',
1313

14+
mockReset: true,
1415
preset: 'ts-jest',
1516
restoreMocks: true,
1617
setupFiles: [join(__dirname, './jest.setup.js')],

local-test-configuration/airseeker/airseeker.example.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,6 @@
2323
}
2424
},
2525
"deviationThresholdCoefficient": 1,
26-
"signedDataFetchInterval": 10
26+
"signedDataFetchInterval": 10,
27+
"signedApiUrls": []
2728
}

src/config/schema.ts

+1
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ export const configSchema = z
141141
chains: chainsSchema,
142142
signedDataFetchInterval: z.number().positive(),
143143
deviationThresholdCoefficient: deviationThresholdCoefficientSchema,
144+
signedApiUrls: z.array(z.string().url()),
144145
})
145146
.strict();
146147

src/signed-api-fetch/data-fetcher.test.ts

+21-5
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@ import { initializeState } from '../../test/fixtures/mock-config';
44
import * as localDataStore from '../signed-data-store';
55
import { updateState } from '../state';
66

7-
import { runDataFetcher, stopDataFetcher } from './data-fetcher';
7+
import * as dataFetcherModule from './data-fetcher';
88

99
const mockedAxios = axios as jest.MockedFunction<typeof axios>;
1010
jest.mock('axios');
1111

1212
describe('data fetcher', () => {
1313
beforeEach(() => {
14+
jest.resetAllMocks();
1415
initializeState();
1516
localDataStore.clear();
1617
updateState((draft) => {
@@ -63,13 +64,28 @@ describe('data fetcher', () => {
6364
})
6465
);
6566

66-
const dataFetcherPromise = runDataFetcher();
67-
67+
const dataFetcherPromise = dataFetcherModule.runDataFetcher();
6868
await expect(dataFetcherPromise).resolves.toBeDefined();
69-
70-
stopDataFetcher();
69+
dataFetcherModule.stopDataFetcher();
7170

7271
expect(mockedAxios).toHaveBeenCalledTimes(1);
7372
expect(setStoreDataPointSpy).toHaveBeenCalledTimes(3);
7473
});
74+
75+
it('calls signed api urls from config', async () => {
76+
jest.spyOn(dataFetcherModule, 'callSignedDataApi');
77+
78+
const signedApiUrl = 'http://some.url/0xbF3137b0a7574563a23a8fC8badC6537F98197CC';
79+
updateState((draft) => {
80+
draft.config.signedApiUrls = [signedApiUrl];
81+
});
82+
83+
const dataFetcherPromise = dataFetcherModule.runDataFetcher();
84+
85+
await expect(dataFetcherPromise).resolves.toBeDefined();
86+
dataFetcherModule.stopDataFetcher();
87+
88+
expect(mockedAxios).toHaveBeenCalledTimes(2);
89+
expect(dataFetcherModule.callSignedDataApi).toHaveBeenCalledWith(signedApiUrl);
90+
});
7591
});

src/signed-api-fetch/data-fetcher.ts

+8-7
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@ export const stopDataFetcher = () => {
3636
};
3737

3838
/**
39-
* Calls a remote signed data URL and inserts the result into the datastore
39+
* Calls a remote signed data URL.
4040
* @param url
4141
*/
42-
const callSignedDataApi = async (url: string): Promise<SignedData[] | null> => {
42+
export const callSignedDataApi = async (url: string): Promise<SignedData[] | null> => {
4343
const goAxiosCall = await go<Promise<AxiosResponse>, AxiosError>(
4444
async () =>
4545
axios({
@@ -72,7 +72,7 @@ export const runDataFetcher = async () => {
7272
logger.debug('Running data fetcher');
7373
const state = getState();
7474
const {
75-
config: { signedDataFetchInterval },
75+
config: { signedDataFetchInterval, signedApiUrls },
7676
signedApiUrlStore,
7777
dataFetcherInterval,
7878
} = state;
@@ -86,12 +86,13 @@ export const runDataFetcher = async () => {
8686
});
8787
}
8888

89-
const urls = uniq(
90-
Object.values(signedApiUrlStore)
89+
const urls = uniq([
90+
...Object.values(signedApiUrlStore)
9191
.flatMap((urlsPerProvider) => Object.values(urlsPerProvider))
9292
.flatMap((urlsPerAirnode) => Object.values(urlsPerAirnode))
93-
.flat()
94-
);
93+
.flat(),
94+
...signedApiUrls,
95+
]);
9596

9697
logger.debug('Fetching data from signed APIs', { urls });
9798
return Promise.all(

test/fixtures/mock-config.ts

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ export const generateTestConfig = (): Config => ({
2525
},
2626
signedDataFetchInterval: 10,
2727
deviationThresholdCoefficient: 1,
28+
signedApiUrls: [],
2829
});
2930

3031
export const initializeState = (config: Config = generateTestConfig()) => setInitialState(config);

0 commit comments

Comments
 (0)