Skip to content

Conversation

@hiletmis
Copy link
Contributor

Related to #363

There are some limitations testing the CLI command
The child process spawned by execSync:

  • Does not inherit the Jest mocks
  • Loads its own modules (ethers, CLI methods) from scratch
  • Creates real JsonRpcProvider and contract objects inside the child process
  • execSync is synchronous, but many ethers calls are async (await provider.getCode(), readDataFeedWithDapiNameHash)

to test with mocks the code should be refactored so that core logic is a function and can be exported.

@hiletmis hiletmis linked an issue Aug 18, 2025 that may be closed by this pull request
@hiletmis hiletmis marked this pull request as ready for review August 18, 2025 12:22
@hiletmis hiletmis requested a review from bbenligiray as a code owner August 18, 2025 12:22
src/cli.test.ts Outdated
const formattedArgs = args
.map(([c, a]) => {
// if args is array then quote each elem and separate them with space
if (Array.isArray(a)) return `${c} ${a.map((element) => quote(element)).join(' ')}`;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The CommandArg type definition above says a's type can be string | number | boolean. I don't see why we're handling the case where a is an array here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right it is unnecessary. It was checking string[] at first which is not necessary after iterating the code.

src/cli.test.ts Outdated
['--chain-id', '5000'],
['--dapi-name', 'UNSUPPORTED/USD']
);
}).toThrow(/⚠️ Attempted to read the feed and failed/);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This probably shouldn't be a partial match (/ are extra)

src/cli.test.ts Outdated

describe('cli tests', () => {
const execCommand = (command: string, ...args: CommandArg[]) => {
const quote = (val: string) => `"${val}"`;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you should also get rid of quote() considering that we're not recommending the user to enclose argument values in quotation marks anywhere. That was an airnode-admin thing where seed phrases needed to be enclosed because they have spaces in them.

Copy link
Member

@bbenligiray bbenligiray left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@hiletmis hiletmis merged commit 1bbadb1 into main Aug 19, 2025
4 checks passed
@hiletmis hiletmis deleted the test-the-cli-command branch August 19, 2025 08:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Test the CLI command

3 participants