Skip to content

Commit cff4153

Browse files
committed
remove unnecessary subscription
1 parent 4892604 commit cff4153

File tree

2 files changed

+22
-13
lines changed

2 files changed

+22
-13
lines changed

evm-tests/src/config.ts

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
export const ETH_LOCAL_URL = 'http://localhost:9944'
22
export const SUB_LOCAL_URL = 'ws://localhost:9944'
33
export const SS58_PREFIX = 42;
4+
// set the tx timeout as 2 second when eable the fast-blocks feature.
5+
export const TX_TIMEOUT = 2000;
46

57
export const IED25519VERIFY_ADDRESS = "0x0000000000000000000000000000000000000402";
68
export const IEd25519VerifyABI = [

evm-tests/src/substrate.ts

+20-13
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { DEV_PHRASE, entropyToMiniSecret, mnemonicToEntropy, KeyPair } from "@po
88
import { getPolkadotSigner } from "polkadot-api/signer"
99
import { randomBytes } from 'crypto';
1010
import { Keyring } from '@polkadot/keyring';
11-
import { SS58_PREFIX } from "./config";
11+
import { SS58_PREFIX, TX_TIMEOUT } from "./config";
1212

1313
let api: TypedApi<typeof devnet> | undefined = undefined
1414

@@ -111,7 +111,7 @@ export async function getNonceChangePromise(api: TypedApi<typeof devnet>, ss58Ad
111111
subscription.unsubscribe();
112112
console.log('unsubscribed!');
113113
resolve()
114-
}, 2000);
114+
}, TX_TIMEOUT);
115115

116116
})
117117
}
@@ -129,21 +129,28 @@ export function convertPublicKeyToMultiAddress(publicKey: Uint8Array, ss58Format
129129

130130
export async function waitForTransactionCompletion(api: TypedApi<typeof devnet>, tx: Transaction<{}, string, string, void>, signer: PolkadotSigner,) {
131131
const transactionPromise = await getTransactionWatchPromise(tx, signer)
132-
const ss58Address = convertPublicKeyToSs58(signer.publicKey)
133-
const noncePromise = await getNonceChangePromise(api, ss58Address)
134-
135-
return new Promise<void>((resolve, reject) => {
136-
Promise.race([transactionPromise, noncePromise])
137-
.then(resolve)
138-
.catch(reject);
139-
})
132+
return transactionPromise
133+
134+
// If we can't always get the finalized event, then add nonce subscribe as other evidence for tx is finalized.
135+
// Don't need it based on current testing.
136+
// const ss58Address = convertPublicKeyToSs58(signer.publicKey)
137+
// const noncePromise = await getNonceChangePromise(api, ss58Address)
138+
139+
// return new Promise<void>((resolve, reject) => {
140+
// Promise.race([transactionPromise, noncePromise])
141+
// .then(resolve)
142+
// .catch(reject);
143+
// })
140144
}
141145

142146
export async function getTransactionWatchPromise(tx: Transaction<{}, string, string, void>, signer: PolkadotSigner,) {
143147
return new Promise<void>((resolve, reject) => {
148+
// store the txHash, then use it in timeout. easier to know which tx is not finalized in time
149+
let txHash = ""
144150
const subscription = tx.signSubmitAndWatch(signer).subscribe({
145151
next(value) {
146152
console.log("Event:", value);
153+
txHash = value.txHash
147154

148155
// TODO investigate why finalized not for each extrinsic
149156
if (value.type === "finalized") {
@@ -168,9 +175,9 @@ export async function getTransactionWatchPromise(tx: Transaction<{}, string, str
168175

169176
setTimeout(() => {
170177
subscription.unsubscribe();
171-
console.log('unsubscribed!');
172-
resolve()
173-
}, 2000);
178+
console.log('unsubscribed because of timeout for tx {}', txHash);
179+
reject()
180+
}, TX_TIMEOUT);
174181
});
175182
}
176183

0 commit comments

Comments
 (0)