From eb2f69d6e1f82c10c5092a5deba3be691ef384b1 Mon Sep 17 00:00:00 2001 From: Martynas Kazlauskas Date: Mon, 16 Dec 2024 14:15:48 +0200 Subject: [PATCH] fix(cardano-services-client): correct blockfrost tx submit request body it has to be binary, otherwise Blockfrost responds with 400 this bug wasn't caught initially because we're not using BlockfrostTxSubmitProvider in our e2e test suite --- .../src/TxSubmitProvider/BlockfrostTxSubmitProvider.ts | 2 +- .../test/TxSubmitProvider/BlockfrostTxSubmitProvider.test.ts | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/cardano-services-client/src/TxSubmitProvider/BlockfrostTxSubmitProvider.ts b/packages/cardano-services-client/src/TxSubmitProvider/BlockfrostTxSubmitProvider.ts index 8c964a85849..4f0a2a6a1e3 100644 --- a/packages/cardano-services-client/src/TxSubmitProvider/BlockfrostTxSubmitProvider.ts +++ b/packages/cardano-services-client/src/TxSubmitProvider/BlockfrostTxSubmitProvider.ts @@ -10,7 +10,7 @@ export class BlockfrostTxSubmitProvider extends BlockfrostProvider implements Tx async submitTx({ signedTransaction }: SubmitTxArgs): Promise { // @ todo handle context and resolutions await this.request('tx/submit', { - body: signedTransaction, + body: Buffer.from(signedTransaction, 'hex'), headers: { 'Content-Type': 'application/cbor' }, method: 'POST' }); diff --git a/packages/cardano-services-client/test/TxSubmitProvider/BlockfrostTxSubmitProvider.test.ts b/packages/cardano-services-client/test/TxSubmitProvider/BlockfrostTxSubmitProvider.test.ts index 92bca225185..578cfd62693 100644 --- a/packages/cardano-services-client/test/TxSubmitProvider/BlockfrostTxSubmitProvider.test.ts +++ b/packages/cardano-services-client/test/TxSubmitProvider/BlockfrostTxSubmitProvider.test.ts @@ -1,5 +1,6 @@ /* eslint-disable @typescript-eslint/no-explicit-any */ import { BlockfrostClient, BlockfrostTxSubmitProvider } from '../../src'; +import { HexBlob } from '@cardano-sdk/util'; import { ProviderError } from '@cardano-sdk/core'; import { logger } from '@cardano-sdk/util-dev'; import { mockResponses } from '../util'; @@ -17,7 +18,7 @@ describe('blockfrostTxSubmitProvider', () => { describe('submitTx', () => { it('wraps error in UnknownTxSubmissionError', async () => { mockResponses(request, [['tx/submit', new Error('some error')]]); - await expect(provider.submitTx({ signedTransaction: null as any })).rejects.toThrowError(ProviderError); + await expect(provider.submitTx({ signedTransaction: HexBlob('abc') })).rejects.toThrowError(ProviderError); }); }); });