Skip to content

Commit 0c4e375

Browse files
committed
improve evm test stability
1 parent ffa23bc commit 0c4e375

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

evm-tests/src/substrate.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -168,30 +168,31 @@ export async function waitForTransactionCompletion(api: TypedApi<typeof devnet>,
168168
// })
169169
}
170170

171+
171172
export async function getTransactionWatchPromise(tx: Transaction<{}, string, string, void>, signer: PolkadotSigner,) {
172173
return new Promise<void>((resolve, reject) => {
173174
// store the txHash, then use it in timeout. easier to know which tx is not finalized in time
174175
let txHash = ""
175176
const subscription = tx.signSubmitAndWatch(signer).subscribe({
176177
next(value) {
177-
console.log("Event:", value);
178178
txHash = value.txHash
179179

180180
// TODO investigate why finalized not for each extrinsic
181181
if (value.type === "finalized") {
182182
console.log("Transaction is finalized in block:", value.txHash);
183183
subscription.unsubscribe();
184+
clearTimeout(timeoutId);
184185
if (!value.ok) {
185186
console.log("Transaction threw an error:", value.dispatchError)
186187
}
187188
// Resolve the promise when the transaction is finalized
188189
resolve();
189-
190190
}
191191
},
192192
error(err) {
193193
console.error("Transaction failed:", err);
194194
subscription.unsubscribe();
195+
clearTimeout(timeoutId);
195196
// Reject the promise in case of an error
196197
reject(err);
197198

@@ -201,7 +202,7 @@ export async function getTransactionWatchPromise(tx: Transaction<{}, string, str
201202
}
202203
});
203204

204-
setTimeout(() => {
205+
const timeoutId = setTimeout(() => {
205206
subscription.unsubscribe();
206207
console.log('unsubscribed because of timeout for tx {}', txHash);
207208
reject()

0 commit comments

Comments
 (0)