Page MenuHomePhabricator

[ecash-herald] Use saved mocks if available
ClosedPublic

Authored by bytesofman on Jul 7 2023, 17:37.

Details

Reviewers
PiRK
Group Reviewers
Restricted Project
Commits
rABC1c058cec5250: [ecash-herald] Use saved mocks if available
Summary

Testing of ecash-herald is complicated by API calls used in the npm run generateMocks script. We aren't really interested in these changing API call results (e.g. the utxo set of tested addresses, crypto prices). Some API calls will never change so we shouldn't be making them all the time (blockDetails).

This diff checks blocks.js for saved mocks for a specific blockhash. If they exist, these saved mocks are used instead of live API calls. If they do not exist, live API calls are used.

Test Plan

npm run generateMocks true and blocks.js does not change

Diff Detail

Repository
rABC Bitcoin ABC
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

Note: I considered adding unit tests to the generateMocks function, but imo it is not worth it...since the goal of modifying the function is to avoid API calls, I don't want to test it by seeing if it does make API calls when expected.

generateMocks is used nowhere in the production of the app and is a developer-only tool. I've added usage documentation in the README.

PiRK added a subscriber: PiRK.
PiRK added inline comments.
apps/ecash-herald/scripts/generateMocks.js
190–210 ↗(On Diff #41322)

This block could probably be deduplicated. Something like

let chronikApi = chronik;          
           
// Mock coingecko price response
// onNoMatch: 'throwException' helps to debug if mock is not being used
const mock = new MockAdapter(axios, {
    onNoMatch: 'throwException',
});

if (thisSavedBlock.length > 0) {    # previously line 135
    ...
    chronikApi = mockedChronik;
}    # line 202
handleBlockConnectedPromises.push(
    returnHandleBlockConnectedPromise(
        chronikApi,
        telegramBot,
        mockChannelId,
        blockhash,
        true,
        blockname,
    ),
);
This revision is now accepted and ready to land.Jul 9 2023, 20:31