From 859244b12a9aba99b21c44de7c6c8f14a3907a9c Mon Sep 17 00:00:00 2001 From: heisenberg Date: Wed, 18 Dec 2024 17:31:37 +0800 Subject: [PATCH] feat: add debug code --- src/ui/utils/sendTransaction.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/ui/utils/sendTransaction.ts b/src/ui/utils/sendTransaction.ts index f4b80a03e10..f56b08086a7 100644 --- a/src/ui/utils/sendTransaction.ts +++ b/src/ui/utils/sendTransaction.ts @@ -256,6 +256,10 @@ export const sendTransaction = async ({ ? (await Browser.storage.local.get('DEBUG_OTHER_CHAIN_GAS_USD_LIMIT')) .DEBUG_OTHER_CHAIN_GAS_USD_LIMIT || 5 : 5; + const DEBUG_SIMULATION_FAILED = process.env.DEBUG + ? (await Browser.storage.local.get('DEBUG_SIMULATION_FAILED')) + .DEBUG_SIMULATION_FAILED + : false; // generate tx with gas const transaction: Tx = { @@ -271,7 +275,10 @@ export const sendTransaction = async ({ let failedCode; let canUseGasAccount: boolean = false; - if (!preExecResult?.balance_change?.success) { + // random simulation failed for test + if (DEBUG_SIMULATION_FAILED && Math.random() > 0.5) { + failedCode = FailedCode.SimulationFailed; + } else if (!preExecResult?.balance_change?.success) { failedCode = FailedCode.SimulationFailed; } else if (isGasNotEnough) { // native gas not enough check gasAccount