diff --git a/sdk/src/dev/flags.ts b/sdk/src/dev/flags.ts new file mode 100644 index 000000000..9f441055a --- /dev/null +++ b/sdk/src/dev/flags.ts @@ -0,0 +1,4 @@ +// 🚨 :: These should all always be false in any committed code. +export const DEV_FLAGS = { + TEST_COMPUTE_UNITS_OK_DURING_SIMULATION_BUT_FAIL_AT_RUNTIME: false, // Recreates the edge case where when sending a transaction the CU's are OK during simulation but fail at runtime. +}; \ No newline at end of file diff --git a/sdk/src/tx/txHandler.ts b/sdk/src/tx/txHandler.ts index f1d9f37c6..1216c06fd 100644 --- a/sdk/src/tx/txHandler.ts +++ b/sdk/src/tx/txHandler.ts @@ -29,6 +29,7 @@ import { CachedBlockhashFetcher } from './blockhashFetcher/cachedBlockhashFetche import { BaseBlockhashFetcher } from './blockhashFetcher/baseBlockhashFetcher'; import { BlockhashFetcher } from './blockhashFetcher/types'; import { isVersionedTransaction } from './utils'; +import { DEV_FLAGS } from '../dev/flags'; /** * Explanation for SIGNATURE_BLOCK_AND_EXPIRY: @@ -489,6 +490,10 @@ export class TxHandler { }; } + if (DEV_FLAGS.TEST_COMPUTE_UNITS_OK_DURING_SIMULATION_BUT_FAIL_AT_RUNTIME) { + baseTxParams.computeUnits = 1000; // force low compute units to recreate the edge case where the CU's are OK during simulation but fail at runtime. + } + const instructionsArray = Array.isArray(instructions) ? instructions : [instructions]; diff --git a/sdk/src/tx/whileValidTxSender.ts b/sdk/src/tx/whileValidTxSender.ts index 3d4af1673..6ed8b5be2 100644 --- a/sdk/src/tx/whileValidTxSender.ts +++ b/sdk/src/tx/whileValidTxSender.ts @@ -12,6 +12,7 @@ import { BaseTxSender } from './baseTxSender'; import bs58 from 'bs58'; import { TxHandler } from './txHandler'; import { IWallet } from '../types'; +import { DEV_FLAGS } from '../dev/flags'; const DEFAULT_RETRY = 2000; @@ -174,6 +175,11 @@ export class WhileValidTxSender extends BaseTxSender { rawTransaction: Buffer | Uint8Array, opts: ConfirmOptions ): Promise { + + if (DEV_FLAGS.TEST_COMPUTE_UNITS_OK_DURING_SIMULATION_BUT_FAIL_AT_RUNTIME) { + opts.skipPreflight = true; // Skip preflight to recreate the edge case where the CU's are OK during simulation but fail at runtime. + } + const startTime = this.getTimestamp(); const txid = await this.connection.sendRawTransaction(rawTransaction, opts);