diff --git a/src/gas-price/index.ts b/src/gas-price/index.ts new file mode 100644 index 00000000..04ea12fa --- /dev/null +++ b/src/gas-price/index.ts @@ -0,0 +1 @@ +export * from './gas-price'; diff --git a/src/update-feeds/dapi-data-registry.test.ts b/src/update-feeds/dapi-data-registry.test.ts index 18986825..79c9cf33 100644 --- a/src/update-feeds/dapi-data-registry.test.ts +++ b/src/update-feeds/dapi-data-registry.test.ts @@ -31,7 +31,7 @@ describe('helper functions', () => { beacons: [ { airnodeAddress: '0xc52EeA00154B4fF1EbbF8Ba39FDe37F1AC3B9Fd4', - dataFeedId: '0xf5c140bcb4814dfec311d38f6293e86c02d32ba1b7da027fe5b5202cae35dbc6', + beaconId: '0xf5c140bcb4814dfec311d38f6293e86c02d32ba1b7da027fe5b5202cae35dbc6', templateId: '0x457a3b3da67e394a895ea49e534a4d91b2d009477bef15eab8cbed313925b010', }, ], @@ -41,12 +41,12 @@ describe('helper functions', () => { beacons: [ { airnodeAddress: '0xc52EeA00154B4fF1EbbF8Ba39FDe37F1AC3B9Fd4', - dataFeedId: '0xf5c140bcb4814dfec311d38f6293e86c02d32ba1b7da027fe5b5202cae35dbc6', + beaconId: '0xf5c140bcb4814dfec311d38f6293e86c02d32ba1b7da027fe5b5202cae35dbc6', templateId: '0x457a3b3da67e394a895ea49e534a4d91b2d009477bef15eab8cbed313925b010', }, { airnodeAddress: '0xc52EeA00154B4fF1EbbF8Ba39FDe37F1AC3B9Fd4', - dataFeedId: '0xf5c140bcb4814dfec311d38f6293e86c02d32ba1b7da027fe5b5202cae35dbc6', + beaconId: '0xf5c140bcb4814dfec311d38f6293e86c02d32ba1b7da027fe5b5202cae35dbc6', templateId: '0x457a3b3da67e394a895ea49e534a4d91b2d009477bef15eab8cbed313925b010', }, ], diff --git a/src/update-feeds/update-feeds.test.ts b/src/update-feeds/update-feeds.test.ts index a38f6a72..531e36b5 100644 --- a/src/update-feeds/update-feeds.test.ts +++ b/src/update-feeds/update-feeds.test.ts @@ -11,6 +11,7 @@ import * as utilsModule from '../utils'; import * as dapiDataRegistryModule from './dapi-data-registry'; import * as updateFeedsModule from './update-feeds'; +import * as updateTransactionModule from './update-transactions'; jest.mock('../state'); @@ -145,8 +146,8 @@ describe(updateFeedsModule.runUpdateFeed.name, () => { it('fetches other batches in a staggered way and logs errors', async () => { // Prepare the mocked contract so it returns three batches (of size 1) of dAPIs and the second batch fails to load. - const firstBatch = generateReadDapiWithIndexResponse(); - const thirdBatch = generateReadDapiWithIndexResponse(); + const firstDapi = generateReadDapiWithIndexResponse(); + const thirdDapi = generateReadDapiWithIndexResponse(); const dapiDataRegistry = generateMockDapiDataRegistry(); jest .spyOn(dapiDataRegistryModule, 'getDapiDataRegistry') @@ -154,10 +155,10 @@ describe(updateFeedsModule.runUpdateFeed.name, () => { dapiDataRegistry.interface.decodeFunctionResult.mockImplementation((_fn, value) => value); dapiDataRegistry.callStatic.tryMulticall.mockResolvedValueOnce({ successes: [true, true], - returndata: [[ethers.BigNumber.from(3)], firstBatch], + returndata: [[ethers.BigNumber.from(3)], firstDapi], }); dapiDataRegistry.callStatic.tryMulticall.mockResolvedValueOnce({ successes: [false], returndata: [] }); - dapiDataRegistry.callStatic.tryMulticall.mockResolvedValueOnce({ successes: [true], returndata: [thirdBatch] }); + dapiDataRegistry.callStatic.tryMulticall.mockResolvedValueOnce({ successes: [true], returndata: [thirdDapi] }); const sleepCalls = [] as number[]; const originalSleep = utilsModule.sleep; jest.spyOn(utilsModule, 'sleep').mockImplementation(async (ms) => { @@ -174,7 +175,7 @@ describe(updateFeedsModule.runUpdateFeed.name, () => { signedApiUrlStore: { '31337': { 'some-test-provider': ['url-one'] } }, signedApiStore: {}, gasPriceStore: { - '123': { + '31337': { 'some-test-provider': { gasPrices: [], sponsorLastUpdateTimestampMs: { @@ -185,7 +186,13 @@ describe(updateFeedsModule.runUpdateFeed.name, () => { }, }) ); - jest.spyOn(updateFeedsModule, 'getFeedsToUpdate').mockImplementation(() => []); + jest + .spyOn(updateFeedsModule, 'getFeedsToUpdate') + .mockImplementation(() => [ + allowPartial({ dapiInfo: firstDapi }), + allowPartial({ dapiInfo: thirdDapi }), + ]); + jest.spyOn(updateTransactionModule, 'updateFeeds').mockResolvedValue([null, null]); await updateFeedsModule.runUpdateFeed( 'provider-name', @@ -197,7 +204,7 @@ describe(updateFeedsModule.runUpdateFeed.name, () => { DapiDataRegistry: '0xDD78254f864F97f65e2d86541BdaEf88A504D2B2', }, }), - '123' + '31337' ); // Expect the contract to fetch the batches to be called with the correct stagger time. @@ -212,7 +219,7 @@ describe(updateFeedsModule.runUpdateFeed.name, () => { 'Failed to get active dAPIs batch', new Error('One of the multicalls failed') ); - expect(logger.debug).toHaveBeenCalledTimes(6); + expect(logger.debug).toHaveBeenCalledTimes(7); expect(logger.debug).toHaveBeenNthCalledWith(1, 'Fetching first batch of dAPIs batches'); expect(logger.debug).toHaveBeenNthCalledWith(2, 'Processing batch of active dAPIs', expect.anything()); expect(logger.debug).toHaveBeenNthCalledWith(3, 'Fetching batches of active dAPIs', { @@ -226,5 +233,10 @@ describe(updateFeedsModule.runUpdateFeed.name, () => { batchIndex: 2, }); expect(logger.debug).toHaveBeenNthCalledWith(6, 'Processing batch of active dAPIs', expect.anything()); + expect(logger.debug).toHaveBeenNthCalledWith(7, 'Finished processing batches of active dAPIs', { + batchesCount: 3, + errorCount: 4, + successCount: 0, + }); }); }); diff --git a/src/update-feeds/update-feeds.ts b/src/update-feeds/update-feeds.ts index c851ff35..e0fce453 100644 --- a/src/update-feeds/update-feeds.ts +++ b/src/update-feeds/update-feeds.ts @@ -5,7 +5,7 @@ import { range, size, zip } from 'lodash'; import { calculateMedian, checkUpdateConditions } from '../condition-check'; import type { Chain } from '../config/schema'; import { INT224_MAX, INT224_MIN } from '../constants'; -import { clearSponsorLastUpdateTimestampMs } from '../gas-price/gas-price'; +import { clearSponsorLastUpdateTimestampMs } from '../gas-price'; import { logger } from '../logger'; import { getStoreDataPoint } from '../signed-data-store'; import { getState, updateState } from '../state'; diff --git a/src/update-feeds/update-transactions.ts b/src/update-feeds/update-transactions.ts index c53e1799..5f8a8b9d 100644 --- a/src/update-feeds/update-transactions.ts +++ b/src/update-feeds/update-transactions.ts @@ -2,7 +2,7 @@ import type { Api3ServerV1 } from '@api3/airnode-protocol-v1'; import { go } from '@api3/promise-utils'; import { ethers } from 'ethers'; -import { getAirseekerRecommendedGasPrice } from '../gas-price/gas-price'; +import { getAirseekerRecommendedGasPrice } from '../gas-price'; import { logger } from '../logger'; import { getState, updateState } from '../state'; import type { SignedData, ChainId, ProviderName } from '../types'; @@ -74,7 +74,7 @@ export const updateFeeds = async ( updateableBeacons.map((beacon) => beacon.beaconId) ); - logger.debug('Deriving sponsor wallet'); + logger.debug('Getting derived sponsor wallet'); const sponsorWallet = getDerivedSponsorWallet(sponsorWalletMnemonic, dapiName); const goGasPrice = await go(async () => diff --git a/test/e2e/gas-price.feature.ts b/test/e2e/gas-price.feature.ts index 12432d78..4cba011c 100644 --- a/test/e2e/gas-price.feature.ts +++ b/test/e2e/gas-price.feature.ts @@ -6,7 +6,7 @@ import { multiplyGasPrice, initializeGasStore, clearExpiredStoreGasPrices, -} from '../../src/gas-price/gas-price'; +} from '../../src/gas-price'; import { getState, updateState } from '../../src/state'; import { init } from '../fixtures/mock-config'; diff --git a/test/e2e/update-feeds.feature.ts b/test/e2e/update-feeds.feature.ts index 1877c74d..b6b3ee65 100644 --- a/test/e2e/update-feeds.feature.ts +++ b/test/e2e/update-feeds.feature.ts @@ -1,7 +1,7 @@ import { ethers } from 'ethers'; import { omit } from 'lodash'; -import { initializeGasStore } from '../../src/gas-price/gas-price'; +import { initializeGasStore } from '../../src/gas-price'; import { logger } from '../../src/logger'; import * as stateModule from '../../src/state'; import { runUpdateFeed } from '../../src/update-feeds'; @@ -82,7 +82,9 @@ it('updates blockchain data', async () => { }, ]); + expect(logger.debug).toHaveBeenCalledTimes(4); expect(logger.debug).toHaveBeenNthCalledWith(1, 'Estimating gas limit'); - expect(logger.debug).toHaveBeenNthCalledWith(2, 'Deriving sponsor wallet'); - expect(logger.debug).toHaveBeenNthCalledWith(5, 'Successfully updated dAPI'); + expect(logger.debug).toHaveBeenNthCalledWith(2, 'Getting derived sponsor wallet'); + expect(logger.debug).toHaveBeenNthCalledWith(3, 'Derived new sponsor wallet', expect.anything()); + expect(logger.debug).toHaveBeenNthCalledWith(4, 'Updating dAPI', expect.anything()); });