Page MenuHomePhabricator

[Cashtab] Refactor unit tests for parseChronikTx
ClosedPublic

Authored by bytesofman on Jan 23 2024, 22:13.

Details

Reviewers
Fabien
Group Reviewers
Restricted Project
Commits
rABC7c3c410622a7: [Cashtab] Refactor unit tests for parseChronikTx
Summary

Depends on D15253

Create array of test vectors for parseChronikTx unit tests. Mocks are updated to have tx and parsed keys, and renamed to better reflect test case

Test Plan

npm test

Diff Detail

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

Event Timeline

Fabien added inline comments.
cashtab/src/chronik/fixtures/vectors.js
23 ↗(On Diff #44501)

What's the point of having the inputs in one file and the expected output in another ? This is just making it more difficult to read/change/add a test. Imo you should have the inputs and expected output in the same block, so it's super clear what the inputs you're crafting are expected to produce.

Fabien requested changes to this revision.Jan 24 2024, 09:05

Not really requesting changes but clearing my queue

This revision now requires changes to proceed.Jan 24 2024, 09:05
bytesofman added inline comments.
cashtab/src/chronik/fixtures/vectors.js
23 ↗(On Diff #44501)

In this case I think the test vectors are easier to read and maintain using variables at these keys, because the actual tx objects are quite large and cumbersome. This is why they live in mocks.js -- standard purpose of this file in Cashtab is to abstract away the storage of large / complicated mocks that are for the most part copy pasted chronik output.

To add a test here, we

  1. Add mock of the right shape to mocks.js
  2. Import it here and add vector of this format

We could just keep the mocks here, but I think having large objects inside the vector keys makes them harder to read / understand.

What's the point of having the inputs in one file and the expected output in another ?

In mocks.js, each tx object includes the input at key tx and the output at key parsed. I could move these to live in this array, but then it becomes much harder to see what the vectors are because tx is a big object.

This revision is now accepted and ready to land.Jan 24 2024, 14:32