From 82e98bbe06f85b720e84c9d44608336dd18b12c6 Mon Sep 17 00:00:00 2001 From: Loris Leiva Date: Fri, 23 Jan 2026 09:01:11 +0000 Subject: [PATCH] Use SolanaError instance as CU simulation failure cause --- clients/js/src/estimateComputeLimitInternal.ts | 3 ++- clients/js/test/estimateComputeLimitInternal.test.ts | 5 +++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/clients/js/src/estimateComputeLimitInternal.ts b/clients/js/src/estimateComputeLimitInternal.ts index 9b1c398..0b0e01c 100644 --- a/clients/js/src/estimateComputeLimitInternal.ts +++ b/clients/js/src/estimateComputeLimitInternal.ts @@ -3,6 +3,7 @@ import { Commitment, compileTransaction, getBase64EncodedWireTransaction, + getSolanaErrorFromTransactionError, isSolanaError, isTransactionMessageWithDurableNonceLifetime, pipe, @@ -158,7 +159,7 @@ async function simulateTransactionAndGetConsumedUnits({ const downcastUnitsConsumed = unitsConsumed > 4_294_967_295n ? 4_294_967_295 : Number(unitsConsumed); if (transactionError) { throw new SolanaError(SOLANA_ERROR__TRANSACTION__FAILED_WHEN_SIMULATING_TO_ESTIMATE_COMPUTE_LIMIT, { - cause: transactionError, + cause: getSolanaErrorFromTransactionError(transactionError), unitsConsumed: downcastUnitsConsumed, }); } diff --git a/clients/js/test/estimateComputeLimitInternal.test.ts b/clients/js/test/estimateComputeLimitInternal.test.ts index 886eaf6..62c8967 100644 --- a/clients/js/test/estimateComputeLimitInternal.test.ts +++ b/clients/js/test/estimateComputeLimitInternal.test.ts @@ -10,6 +10,7 @@ import { SOLANA_ERROR__INSTRUCTION_ERROR__INSUFFICIENT_FUNDS, SOLANA_ERROR__TRANSACTION__FAILED_TO_ESTIMATE_COMPUTE_LIMIT, SOLANA_ERROR__TRANSACTION__FAILED_WHEN_SIMULATING_TO_ESTIMATE_COMPUTE_LIMIT, + SOLANA_ERROR__TRANSACTION_ERROR__ACCOUNT_NOT_FOUND, SolanaError, TransactionError, TransactionMessageWithFeePayer, @@ -235,7 +236,7 @@ describe('estimateComputeUnitLimit', () => { await expect(estimatePromise).resolves.toBe(1400000); }); - it('throws with the transaction error as cause when the transaction fails in simulation', async () => { + it('throws with the transaction SolanaError as cause when the transaction fails in simulation', async () => { expect.assertions(1); const transactionError: TransactionError = 'AccountNotFound'; sendSimulateTransactionRequest.mockResolvedValue({ @@ -249,7 +250,7 @@ describe('estimateComputeUnitLimit', () => { await expect(estimatePromise).rejects.toThrow( new SolanaError(SOLANA_ERROR__TRANSACTION__FAILED_WHEN_SIMULATING_TO_ESTIMATE_COMPUTE_LIMIT, { - cause: transactionError, + cause: new SolanaError(SOLANA_ERROR__TRANSACTION_ERROR__ACCOUNT_NOT_FOUND), unitsConsumed: 42, }), );