Differential D18385 Diff 54907 modules/chronik-client/test/integration/broadcast_txs_and_validate_rawtx.ts
Changeset View
Changeset View
Standalone View
Standalone View
modules/chronik-client/test/integration/broadcast_txs_and_validate_rawtx.ts
| Show First 20 Lines • Show All 239 Lines • ▼ Show 20 Lines | it('New regtest chain. Behavior of broadcastTx and validateRawTx.', async () => { | ||||
| // We can also preview okRawTx before it is broadcast | // We can also preview okRawTx before it is broadcast | ||||
| const okPreview = await chronik.validateRawTx(okRawTx); | const okPreview = await chronik.validateRawTx(okRawTx); | ||||
| // We can broadcast multiple txs including a burn if we set skipTokenChecks | // We can broadcast multiple txs including a burn if we set skipTokenChecks | ||||
| expect( | expect( | ||||
| await chronik.broadcastTxs([okRawTx, alpBurnRawTx], true), | await chronik.broadcastTxs([okRawTx, alpBurnRawTx], true), | ||||
| ).to.deep.equal({ txids: [okTxid, alpBurnTxid] }); | ).to.deep.equal({ txids: [okTxid, alpBurnTxid] }); | ||||
| await expect( | |||||
| chronik.broadcastTxs(okRawTx as unknown as string[]), | |||||
| ).to.be.rejectedWith( | |||||
| Error, | |||||
| `broadcastTxs expects an array of rawTxs, not a single rawTx. Use broadcastTx for a single rawTx.`, | |||||
| ); | |||||
| // We can broadcast an ALP burn tx if we set skipTokenChecks | // We can broadcast an ALP burn tx if we set skipTokenChecks | ||||
| const alpBurnTwoRawTx = await get_alp_burn_2_rawtx; | const alpBurnTwoRawTx = await get_alp_burn_2_rawtx; | ||||
| const alpBurnTwoTxid = await get_alp_burn_2_txid; | const alpBurnTwoTxid = await get_alp_burn_2_txid; | ||||
| // And we can preview it before it is broadcast | // And we can preview it before it is broadcast | ||||
| const alpBurnTwoPreview = await chronik.validateRawTx(alpBurnTwoRawTx); | const alpBurnTwoPreview = await chronik.validateRawTx(alpBurnTwoRawTx); | ||||
| expect(await chronik.broadcastTx(alpBurnTwoRawTx, true)).to.deep.equal({ | expect(await chronik.broadcastTx(alpBurnTwoRawTx, true)).to.deep.equal({ | ||||
| ▲ Show 20 Lines • Show All 44 Lines • ▼ Show 20 Lines | it('New regtest chain. Behavior of broadcastTx and validateRawTx.', async () => { | ||||
| ); | ); | ||||
| // We can't broadcast a rawtx that conflicts with the mempool | // We can't broadcast a rawtx that conflicts with the mempool | ||||
| await expect(chronik.broadcastTx(BAD_RAW_TX)).to.be.rejectedWith( | await expect(chronik.broadcastTx(BAD_RAW_TX)).to.be.rejectedWith( | ||||
| Error, | Error, | ||||
| `Failed getting /broadcast-tx: 400: Broadcast failed: Transaction rejected by mempool: txn-mempool-conflict`, | `Failed getting /broadcast-tx: 400: Broadcast failed: Transaction rejected by mempool: txn-mempool-conflict`, | ||||
| ); | ); | ||||
| // If we broadcast a tx already in the mempool, we get a normal response | // We can broadcast a tx as a Uint8Array without hitting the broadcastTxs array check | ||||
| expect(await chronik.broadcastTx(alpGenesisRawTx)).to.deep.equal({ | expect( | ||||
| await chronik.broadcastTx(fromHex(alpGenesisRawTx)), | |||||
| ).to.deep.equal({ | |||||
| txid: alpGenesisTxid, | txid: alpGenesisTxid, | ||||
| }); | }); | ||||
| // We can't broadcast a tx if its inputs do not exist in mempool or blockchain | // We can't broadcast a tx if its inputs do not exist in mempool or blockchain | ||||
| // 16fb49b12c7bcafd997040be7ceb9eb72d8624285aae5b13bd3d86e21dea4a93, just taken from mainnet | // 16fb49b12c7bcafd997040be7ceb9eb72d8624285aae5b13bd3d86e21dea4a93, just taken from mainnet | ||||
| // We do not have mainnet history in regtest, so invalid | // We do not have mainnet history in regtest, so invalid | ||||
| const INPUTS_DO_NOT_EXIST_RAWTX = | const INPUTS_DO_NOT_EXIST_RAWTX = | ||||
| '0200000002549194ec103e460d67f530737518f13f6fe30a2882c387c25ba719a2b5a63f1a020000006a47304402204b14aba87bab02e88a19f0303c7d3a6d86583abd99ff1bab2ee185b6499d26c202205e893212af1f5b9a63ab3c0eb6b9432c8d483fbc163fd86ffa7e8711d50eed4a4121037b40772a921c6add3c283037a8784c68378883dcb05b85c1eddfce9b55783027ffffffff42f3c77adfe2d84c2230b8cebc358819538d19075adaa35f09402254d92d7801030000006b483045022100f1fdd68b241be27066b0e0fa673a075e1630677c70c31af62848c658da452a0402205c0274b0ac8a481d03cb75fea6563752dff3bd7f897a5f8278b4a4ee6527a4744121037b40772a921c6add3c283037a8784c68378883dcb05b85c1eddfce9b55783027ffffffff040000000000000000406a04534c500001010453454e4420fb4233e8a568993976ed38a81c2671587c5ad09552dedefa78760deed6ff87aa080000000005f5e1000800000008bb2c970022020000000000001976a91404577f22113160825ce6a2d3ad6696527ee9bdf288ac22020000000000001976a91479557c1fec4f44c688b993feed5cd7a8900d5d6188ac60880d00000000001976a91479557c1fec4f44c688b993feed5cd7a8900d5d6188ac00000000'; | '0200000002549194ec103e460d67f530737518f13f6fe30a2882c387c25ba719a2b5a63f1a020000006a47304402204b14aba87bab02e88a19f0303c7d3a6d86583abd99ff1bab2ee185b6499d26c202205e893212af1f5b9a63ab3c0eb6b9432c8d483fbc163fd86ffa7e8711d50eed4a4121037b40772a921c6add3c283037a8784c68378883dcb05b85c1eddfce9b55783027ffffffff42f3c77adfe2d84c2230b8cebc358819538d19075adaa35f09402254d92d7801030000006b483045022100f1fdd68b241be27066b0e0fa673a075e1630677c70c31af62848c658da452a0402205c0274b0ac8a481d03cb75fea6563752dff3bd7f897a5f8278b4a4ee6527a4744121037b40772a921c6add3c283037a8784c68378883dcb05b85c1eddfce9b55783027ffffffff040000000000000000406a04534c500001010453454e4420fb4233e8a568993976ed38a81c2671587c5ad09552dedefa78760deed6ff87aa080000000005f5e1000800000008bb2c970022020000000000001976a91404577f22113160825ce6a2d3ad6696527ee9bdf288ac22020000000000001976a91479557c1fec4f44c688b993feed5cd7a8900d5d6188ac60880d00000000001976a91479557c1fec4f44c688b993feed5cd7a8900d5d6188ac00000000'; | ||||
| await expect( | await expect( | ||||
| chronik.broadcastTx(INPUTS_DO_NOT_EXIST_RAWTX), | chronik.broadcastTx(INPUTS_DO_NOT_EXIST_RAWTX), | ||||
| ).to.be.rejectedWith( | ).to.be.rejectedWith( | ||||
| Error, | Error, | ||||
| `Failed getting /broadcast-tx: 400: Failed indexing mempool token tx: Tx is spending 1a3fa6b5a219a75bc287c382280ae36f3ff118757330f5670d463e10ec949154 which is found neither in the mempool nor DB`, | `Failed getting /broadcast-tx: 400: Failed indexing mempool token tx: Tx is spending 1a3fa6b5a219a75bc287c382280ae36f3ff118757330f5670d463e10ec949154 which is found neither in the mempool nor DB`, | ||||
| ); | ); | ||||
| // We get a helpful error if we try to broadcast a rawtx with an array | |||||
| await expect( | |||||
| chronik.broadcastTx([alpGenesisRawTx] as unknown as string), | |||||
| ).to.be.rejectedWith( | |||||
| Error, | |||||
| `broadcastTx expects a single rawTx, not an array. Use broadcastTxs for multiple rawTxs.`, | |||||
| ); | |||||
| }); | }); | ||||
| it('After broadcastTxs are mined', async () => { | it('After broadcastTxs are mined', async () => { | ||||
| const chronik = new ChronikClient(chronikUrl); | const chronik = new ChronikClient(chronikUrl); | ||||
| const alpGenesisRawTx = await get_alp_genesis_rawtx; | const alpGenesisRawTx = await get_alp_genesis_rawtx; | ||||
| // We can't broadcast a rawtx if it is already in a block | // We can't broadcast a rawtx if it is already in a block | ||||
| await expect(chronik.broadcastTx(alpGenesisRawTx)).to.be.rejectedWith( | await expect(chronik.broadcastTx(alpGenesisRawTx)).to.be.rejectedWith( | ||||
| Show All 22 Lines | |||||