Page MenuHomePhabricator

[chronik-client] Add support for validate-tx endpoint to ChronikClientNode
ClosedPublic

Authored by bytesofman on Mar 4 2024, 22:40.

Details

Summary

T3441

Support and tests for the validate-tx enpdoint

Test Plan

CI

Event Timeline

Tail of the build log:

/work/modules/chronik-client /work/abc-ci-builds/chronik-client-tests

> chronik-client@0.24.0 prepublish
> npm run build


> chronik-client@0.24.0 build
> tsc

src/ChronikClientNode.ts(85,57): error TS2345: Argument of type '{ rawTx: Uint8Array; }' is not assignable to parameter of type 'BroadcastTxRequest'.
  Property 'skipTokenChecks' is missing in type '{ rawTx: Uint8Array; }' but required in type 'BroadcastTxRequest'.
src/ChronikClientNode.ts(90,9): error TS2740: Type '{ txid: string; }' is missing the following properties from type 'Tx_InNode': version, inputs, outputs, lockTime, and 7 more.
npm ERR! code 2
npm ERR! path /work/modules/chronik-client
npm ERR! command failed
npm ERR! command sh -c npm run build

npm ERR! A complete log of this run can be found in: /root/.npm/_logs/2024-03-04T22_41_04_925Z-debug-0.log
Build chronik-client-tests failed with exit code 2

Tail of the build log:

[515/555] Building CXX object src/qt/CMakeFiles/bitcoin-qt-base.dir/utilitydialog.cpp.o
[516/555] Building CXX object src/qt/CMakeFiles/bitcoin-qt-base.dir/addressbookpage.cpp.o
[517/555] Building CXX object src/qt/CMakeFiles/bitcoin-qt-base.dir/trafficgraphwidget.cpp.o
[518/555] Building CXX object src/qt/CMakeFiles/bitcoin-qt-base.dir/splashscreen.cpp.o
[519/555] Building CXX object src/qt/CMakeFiles/bitcoin-qt-base.dir/coincontroltreewidget.cpp.o
[520/555] Building CXX object src/qt/CMakeFiles/bitcoin-qt-base.dir/rpcconsole.cpp.o
[521/555] Building CXX object src/qt/CMakeFiles/bitcoin-qt-base.dir/createwalletdialog.cpp.o
[522/555] Building CXX object src/qt/CMakeFiles/bitcoin-qt-base.dir/addresstablemodel.cpp.o
[523/555] Building CXX object src/qt/CMakeFiles/bitcoin-qt-base.dir/askpassphrasedialog.cpp.o
[524/555] Building CXX object src/qt/CMakeFiles/bitcoin-qt-base.dir/editaddressdialog.cpp.o
[525/555] Building CXX object src/qt/CMakeFiles/bitcoin-qt-base.dir/openuridialog.cpp.o
[526/555] Building CXX object src/qt/CMakeFiles/bitcoin-qt-base.dir/qrimagewidget.cpp.o
[527/555] Building CXX object src/qt/CMakeFiles/bitcoin-qt-base.dir/coincontroldialog.cpp.o
[528/555] Building CXX object src/qt/CMakeFiles/bitcoin-qt-base.dir/overviewpage.cpp.o
[529/555] Building CXX object src/qt/CMakeFiles/bitcoin-qt-base.dir/receivecoinsdialog.cpp.o
[530/555] Building CXX object src/qt/CMakeFiles/bitcoin-qt-base.dir/receiverequestdialog.cpp.o
[531/555] Building CXX object src/qt/CMakeFiles/bitcoin-qt-base.dir/recentrequeststablemodel.cpp.o
[532/555] Building CXX object src/qt/CMakeFiles/bitcoin-qt-base.dir/paymentserver.cpp.o
[533/555] Building CXX object src/qt/CMakeFiles/bitcoin-qt-base.dir/sendcoinsentry.cpp.o
[534/555] Building CXX object src/qt/CMakeFiles/bitcoin-qt-base.dir/signverifymessagedialog.cpp.o
[535/555] Building CXX object src/qt/CMakeFiles/bitcoin-qt-base.dir/transactiondescdialog.cpp.o
[536/555] Building CXX object src/qt/CMakeFiles/bitcoin-qt-base.dir/transactionfilterproxy.cpp.o
[537/555] Building CXX object src/qt/CMakeFiles/bitcoin-qt-base.dir/sendcoinsdialog.cpp.o
[538/555] Building CXX object src/qt/CMakeFiles/bitcoin-qt-base.dir/transactiondesc.cpp.o
[539/555] Building CXX object src/qt/CMakeFiles/bitcoin-qt-base.dir/transactionrecord.cpp.o
[540/555] Building CXX object src/qt/CMakeFiles/bitcoin-qt-base.dir/transactiontablemodel.cpp.o
[541/555] Building CXX object src/qt/CMakeFiles/bitcoin-qt-base.dir/transactionview.cpp.o
[542/555] Building CXX object src/qt/CMakeFiles/bitcoin-qt-base.dir/walletframe.cpp.o
[543/555] Building CXX object src/qt/CMakeFiles/bitcoin-qt-base.dir/walletmodeltransaction.cpp.o
[544/555] Building CXX object src/qt/CMakeFiles/bitcoin-qt-base.dir/paymentrequestplus.cpp.o
[545/555] Building CXX object src/qt/CMakeFiles/bitcoin-qt-base.dir/walletcontroller.cpp.o
[546/555] Building CXX object src/qt/CMakeFiles/bitcoin-qt-base.dir/walletmodel.cpp.o
[547/555] Building CXX object src/qt/CMakeFiles/bitcoin-qt-base.dir/walletview.cpp.o
[548/555] Linking CXX executable src/bitcoind
[549/555] Building CXX object src/qt/CMakeFiles/bitcoin-qt-base.dir/qrc_bitcoin.cpp.o
[550/555] Linking CXX executable src/bench/bitcoin-bench
[551/555] Linking CXX static library src/qt/libbitcoin-qt-base.a
[552/555] Automatic MOC for target bitcoin-qt
[553/555] Building CXX object src/qt/CMakeFiles/bitcoin-qt.dir/bitcoin-qt_autogen/mocs_compilation.cpp.o
[554/555] Building CXX object src/qt/CMakeFiles/bitcoin-qt.dir/main.cpp.o
[555/555] Linking CXX executable src/qt/bitcoin-qt
/work/modules/chronik-client /work/abc-ci-builds/chronik-client-integration-tests

> chronik-client@0.24.0 prepublish
> npm run build


> chronik-client@0.24.0 build
> tsc

src/ChronikClientNode.ts(85,57): error TS2345: Argument of type '{ rawTx: Uint8Array; }' is not assignable to parameter of type 'BroadcastTxRequest'.
  Property 'skipTokenChecks' is missing in type '{ rawTx: Uint8Array; }' but required in type 'BroadcastTxRequest'.
src/ChronikClientNode.ts(90,9): error TS2740: Type '{ txid: string; }' is missing the following properties from type 'Tx_InNode': version, inputs, outputs, lockTime, and 7 more.
npm ERR! code 2
npm ERR! path /work/modules/chronik-client
npm ERR! command failed
npm ERR! command sh -c npm run build

npm ERR! A complete log of this run can be found in: /root/.npm/_logs/2024-03-04T22_43_47_824Z-debug-0.log
Build chronik-client-integration-tests failed with exit code 2

Add function, tests, changelog, version bump

remove test file, remove debug log

bytesofman added inline comments.
modules/chronik-client/test/integration/broadcast_txs_and_validate_rawtx.ts
337 ↗(On Diff #45917)

@tobias_ruck I'm not sure what's going on here.

Is the preview from validateRawTx expected to change after a tx is mined?

Tail of the build log:

/work/modules/chronik-client /work/abc-ci-builds/chronik-client-tests

> chronik-client@0.25.0 prepublish
> npm run build


> chronik-client@0.25.0 build
> tsc

test/validateTx.ts(27,17): error TS2741: Property 'outputScript' is missing in type '{ prevOut: { txid: string; outIdx: number; }; inputScript: string; value: number; sequenceNo: number; token: { tokenId: string; tokenType: { protocol: "SLP"; type: "SLP_TOKEN_TYPE_FUNGIBLE"; number: number; }; amount: string; isMintBaton: false; entryIdx: number; }; }' but required in type 'TxInput_InNode'.
test/validateTx.ts(49,17): error TS2741: Property 'outputScript' is missing in type '{ prevOut: { txid: string; outIdx: number; }; inputScript: string; value: number; sequenceNo: number; }' but required in type 'TxInput_InNode'.
test/validateTx.ts(61,17): error TS2741: Property 'spentBy' is missing in type '{ value: number; outputScript: string; }' but required in type 'TxOutput_InNode'.
test/validateTx.ts(66,17): error TS2741: Property 'spentBy' is missing in type '{ value: number; outputScript: string; token: { tokenId: string; tokenType: { protocol: "SLP"; type: "SLP_TOKEN_TYPE_FUNGIBLE"; number: number; }; amount: string; isMintBaton: false; entryIdx: number; }; }' but required in type 'TxOutput_InNode'.
test/validateTx.ts(83,17): error TS2741: Property 'spentBy' is missing in type '{ value: number; outputScript: string; token: { tokenId: string; tokenType: { protocol: "SLP"; type: "SLP_TOKEN_TYPE_FUNGIBLE"; number: number; }; amount: string; isMintBaton: false; entryIdx: number; }; }' but required in type 'TxOutput_InNode'.
test/validateTx.ts(100,17): error TS2741: Property 'spentBy' is missing in type '{ value: number; outputScript: string; }' but required in type 'TxOutput_InNode'.
test/validateTx.ts(138,15): error TS1155: 'const' declarations must be initialized.
test/validateTx.ts(138,15): error TS7005: Variable 'nod' implicitly has an 'any' type.
test/validateTx.ts(141,20): error TS2304: Cannot find name 'isValidWsSubscription'.
npm ERR! code 2
npm ERR! path /work/modules/chronik-client
npm ERR! command failed
npm ERR! command sh -c npm run build

npm ERR! A complete log of this run can be found in: /root/.npm/_logs/2024-03-05T00_01_58_905Z-debug-0.log
Build chronik-client-tests failed with exit code 2

Tail of the build log:

[521/555] Building CXX object src/qt/CMakeFiles/bitcoin-qt-base.dir/splashscreen.cpp.o
[522/555] Building CXX object src/qt/CMakeFiles/bitcoin-qt-base.dir/createwalletdialog.cpp.o
[523/555] Building CXX object src/qt/CMakeFiles/bitcoin-qt-base.dir/rpcconsole.cpp.o
[524/555] Building CXX object src/qt/CMakeFiles/bitcoin-qt-base.dir/editaddressdialog.cpp.o
[525/555] Building CXX object src/qt/CMakeFiles/bitcoin-qt-base.dir/addresstablemodel.cpp.o
[526/555] Building CXX object src/qt/CMakeFiles/bitcoin-qt-base.dir/openuridialog.cpp.o
[527/555] Building CXX object src/qt/CMakeFiles/bitcoin-qt-base.dir/qrimagewidget.cpp.o
[528/555] Building CXX object src/qt/CMakeFiles/bitcoin-qt-base.dir/coincontroldialog.cpp.o
[529/555] Building CXX object src/qt/CMakeFiles/bitcoin-qt-base.dir/overviewpage.cpp.o
[530/555] Building CXX object src/qt/CMakeFiles/bitcoin-qt-base.dir/receiverequestdialog.cpp.o
[531/555] Building CXX object src/qt/CMakeFiles/bitcoin-qt-base.dir/receivecoinsdialog.cpp.o
[532/555] Building CXX object src/qt/CMakeFiles/bitcoin-qt-base.dir/recentrequeststablemodel.cpp.o
[533/555] Building CXX object src/qt/CMakeFiles/bitcoin-qt-base.dir/sendcoinsentry.cpp.o
[534/555] Building CXX object src/qt/CMakeFiles/bitcoin-qt-base.dir/transactiondescdialog.cpp.o
[535/555] Building CXX object src/qt/CMakeFiles/bitcoin-qt-base.dir/transactionfilterproxy.cpp.o
[536/555] Building CXX object src/qt/CMakeFiles/bitcoin-qt-base.dir/paymentserver.cpp.o
[537/555] Building CXX object src/qt/CMakeFiles/bitcoin-qt-base.dir/signverifymessagedialog.cpp.o
[538/555] Building CXX object src/qt/CMakeFiles/bitcoin-qt-base.dir/transactiondesc.cpp.o
[539/555] Building CXX object src/qt/CMakeFiles/bitcoin-qt-base.dir/sendcoinsdialog.cpp.o
[540/555] Building CXX object src/qt/CMakeFiles/bitcoin-qt-base.dir/transactionrecord.cpp.o
[541/555] Building CXX object src/qt/CMakeFiles/bitcoin-qt-base.dir/walletmodeltransaction.cpp.o
[542/555] Building CXX object src/qt/CMakeFiles/bitcoin-qt-base.dir/transactiontablemodel.cpp.o
[543/555] Building CXX object src/qt/CMakeFiles/bitcoin-qt-base.dir/transactionview.cpp.o
[544/555] Building CXX object src/qt/CMakeFiles/bitcoin-qt-base.dir/walletframe.cpp.o
[545/555] Building CXX object src/qt/CMakeFiles/bitcoin-qt-base.dir/walletcontroller.cpp.o
[546/555] Building CXX object src/qt/CMakeFiles/bitcoin-qt-base.dir/paymentrequestplus.cpp.o
[547/555] Building CXX object src/qt/CMakeFiles/bitcoin-qt-base.dir/walletmodel.cpp.o
[548/555] Building CXX object src/qt/CMakeFiles/bitcoin-qt-base.dir/walletview.cpp.o
[549/555] Building CXX object src/qt/CMakeFiles/bitcoin-qt-base.dir/qrc_bitcoin.cpp.o
[550/555] Linking CXX executable src/bench/bitcoin-bench
[551/555] Linking CXX static library src/qt/libbitcoin-qt-base.a
[552/555] Automatic MOC for target bitcoin-qt
[553/555] Building CXX object src/qt/CMakeFiles/bitcoin-qt.dir/bitcoin-qt_autogen/mocs_compilation.cpp.o
[554/555] Building CXX object src/qt/CMakeFiles/bitcoin-qt.dir/main.cpp.o
[555/555] Linking CXX executable src/qt/bitcoin-qt
/work/modules/chronik-client /work/abc-ci-builds/chronik-client-integration-tests

> chronik-client@0.25.0 prepublish
> npm run build


> chronik-client@0.25.0 build
> tsc

test/validateTx.ts(27,17): error TS2741: Property 'outputScript' is missing in type '{ prevOut: { txid: string; outIdx: number; }; inputScript: string; value: number; sequenceNo: number; token: { tokenId: string; tokenType: { protocol: "SLP"; type: "SLP_TOKEN_TYPE_FUNGIBLE"; number: number; }; amount: string; isMintBaton: false; entryIdx: number; }; }' but required in type 'TxInput_InNode'.
test/validateTx.ts(49,17): error TS2741: Property 'outputScript' is missing in type '{ prevOut: { txid: string; outIdx: number; }; inputScript: string; value: number; sequenceNo: number; }' but required in type 'TxInput_InNode'.
test/validateTx.ts(61,17): error TS2741: Property 'spentBy' is missing in type '{ value: number; outputScript: string; }' but required in type 'TxOutput_InNode'.
test/validateTx.ts(66,17): error TS2741: Property 'spentBy' is missing in type '{ value: number; outputScript: string; token: { tokenId: string; tokenType: { protocol: "SLP"; type: "SLP_TOKEN_TYPE_FUNGIBLE"; number: number; }; amount: string; isMintBaton: false; entryIdx: number; }; }' but required in type 'TxOutput_InNode'.
test/validateTx.ts(83,17): error TS2741: Property 'spentBy' is missing in type '{ value: number; outputScript: string; token: { tokenId: string; tokenType: { protocol: "SLP"; type: "SLP_TOKEN_TYPE_FUNGIBLE"; number: number; }; amount: string; isMintBaton: false; entryIdx: number; }; }' but required in type 'TxOutput_InNode'.
test/validateTx.ts(100,17): error TS2741: Property 'spentBy' is missing in type '{ value: number; outputScript: string; }' but required in type 'TxOutput_InNode'.
test/validateTx.ts(138,15): error TS1155: 'const' declarations must be initialized.
test/validateTx.ts(138,15): error TS7005: Variable 'nod' implicitly has an 'any' type.
test/validateTx.ts(141,20): error TS2304: Cannot find name 'isValidWsSubscription'.
npm ERR! code 2
npm ERR! path /work/modules/chronik-client
npm ERR! command failed
npm ERR! command sh -c npm run build

npm ERR! A complete log of this run can be found in: /root/.npm/_logs/2024-03-05T00_04_22_522Z-debug-0.log
Build chronik-client-integration-tests failed with exit code 2
The build failed due to an unexpected infrastructure outage. The administrators have been notified to investigate. Sorry for the inconvenience.

Failed tests logs:

====== Test broadcastTx and broadcastTxs methods from ChronikClient: New regtest chain. Behavior of broadcastTx and validateRawTx..Test broadcastTx and broadcastTxs methods from ChronikClient New regtest chain. Behavior of broadcastTx and validateRawTx. ======
AssertionError: expected promise to be rejected with an error including 'Failed getting /broadcast-tx (): 400:…' but got 'Failed getting /broadcast-tx: 400: Br…'

      + expected - actual

      -Failed getting /broadcast-tx: 400: Broadcast failed: Transaction rejected by mempool: bad-txns-in-belowout, value in (25000000.00) < value out (49999999600.00)
      +Failed getting /broadcast-tx (): 400: Broadcast failed: Transaction rejected by mempool: bad-txns-in-belowout, value in (25000000.00) < value out (49999999600.00)
====== Test broadcastTx and broadcastTxs methods from ChronikClient: After broadcastTxs are mined.Test broadcastTx and broadcastTxs methods from ChronikClient After broadcastTxs are mined ======
AssertionError: expected promise to be rejected with 'Error' but it was fulfilled with { Object (txid) }

      + expected - actual:  failed to generate Mocha diff

Each failure log is accessible here:
Test broadcastTx and broadcastTxs methods from ChronikClient: New regtest chain. Behavior of broadcastTx and validateRawTx..Test broadcastTx and broadcastTxs methods from ChronikClient New regtest chain. Behavior of broadcastTx and validateRawTx.
Test broadcastTx and broadcastTxs methods from ChronikClient: After broadcastTxs are mined.Test broadcastTx and broadcastTxs methods from ChronikClient After broadcastTxs are mined

emack requested changes to this revision.Tue, Dec 10, 08:07
emack added a subscriber: emack.
emack added inline comments.
modules/chronik-client/src/ChronikClient.ts
90

if it's a number it won't be in hex format by the time it gets fed into proto.RawTx.encode()

modules/chronik-client/test/integration/broadcast_txs_and_validate_rawtx.ts
281
This revision now requires changes to proceed.Tue, Dec 10, 08:07

Add input type validation, add test to confirm uint8array input is also supported

bytesofman added inline comments.
modules/chronik-client/src/ChronikClient.ts
90

can't be a number -- can only be Uint8Array | string

But, point taken --- added a check to confirm validation before calling the API

modules/chronik-client/test/integration/broadcast_txs_and_validate_rawtx.ts
281

eh now that we have validation, I don't think we need to show that every invalid type doesn't work. the test added with {obj: 'not valid'} is sufficient.

This revision is now accepted and ready to land.Wed, Dec 11, 01:52