Skip to content
This repository was archived by the owner on Jul 30, 2025. It is now read-only.

Commit 8d9e62e

Browse files
chore: 🤖 increase wait time on middleware sync to 6 secs
1 parent 23af0c8 commit 8d9e62e

File tree

3 files changed

+18
-6
lines changed

3 files changed

+18
-6
lines changed

src/__tests__/rest/compliance/fungible/tradeWithCompliance.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { BigNumber } from '@polymeshassociation/polymesh-sdk';
12
import { ClaimType, InstructionStatus } from '@polymeshassociation/polymesh-sdk/types';
23

34
import { assertTagPresent } from '~/assertions';
@@ -190,9 +191,6 @@ describe('Compliance Requirements for Fungible Assets', () => {
190191
expect(blockedReceiverInstruction).toEqual(
191192
assertTagPresent(expect, 'settlement.addAndAffirmWithMediators')
192193
);
193-
194-
await awaitMiddlewareSyncedForRestApi(investorInstruction, restClient);
195-
await awaitMiddlewareSyncedForRestApi(blockedReceiverInstruction, restClient);
196194
});
197195

198196
it('should be able to call affirm on instruction for both receivers', async () => {
@@ -227,6 +225,11 @@ describe('Compliance Requirements for Fungible Assets', () => {
227225
expect(blockedAffirmResult).toEqual(
228226
assertTagPresent(expect, 'settlement.affirmInstructionWithCount')
229227
);
228+
229+
// we add buffer of 1 block so that middleware can wait until InstructionExecuted event is processed ( which is done on next block where affirmations are received)
230+
await awaitMiddlewareSyncedForRestApi(investorAffirmResult, restClient, new BigNumber(1));
231+
// we add buffer of 1 block so that middleware can wait until FailedToExecuteInstruction event is processed ( which is done on next block where affirmations are received)
232+
await awaitMiddlewareSyncedForRestApi(blockedAffirmResult, restClient, new BigNumber(1));
230233
});
231234

232235
it('should have transferred asset to investor', async () => {

src/sdk/identities/claims.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export const manageClaims = async (
4141
{ signingAccount }
4242
);
4343

44-
const middlewareSynced = () =>
44+
let middlewareSynced = () =>
4545
new Promise((resolve) => addClaimTx.onProcessedByMiddleware(resolve));
4646

4747
await addClaimTx.run();
@@ -66,9 +66,14 @@ export const manageClaims = async (
6666
},
6767
{ signingAccount }
6868
);
69+
70+
middlewareSynced = () => new Promise((resolve) => revokeClaimTx.onProcessedByMiddleware(resolve));
71+
6972
await revokeClaimTx.run();
7073
assert(revokeClaimTx.isSuccess);
7174

75+
await middlewareSynced();
76+
7277
// This following portion demonstrates different ways to fetch claims
7378

7479
// Note, without specifying `target` the signingIdentity claims will be fetched

src/util.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,9 @@ export const awaitMiddlewareSynced = async (
100100
export const awaitMiddlewareSyncedForRestApi = async (
101101
result: PostResult,
102102
restClient: RestClient,
103+
bufferBlocks = new BigNumber(0),
103104
retries = 15,
104-
delay = 2000
105+
delay = 6000
105106
): Promise<void> => {
106107
if (!('transactions' in result)) {
107108
throw new Error('Transaction was not successful or failed');
@@ -117,7 +118,10 @@ export const awaitMiddlewareSyncedForRestApi = async (
117118
const latestBlock = (metadata as { lastProcessedHeight: string })?.lastProcessedHeight;
118119

119120
if (latestBlock && new BigNumber(latestBlock).gte(new BigNumber(txBlock))) {
120-
return;
121+
if (new BigNumber(latestBlock).gte(new BigNumber(txBlock).plus(bufferBlocks)) || i === 5) {
122+
// this is a hacky way to get middleware to wait on syncing instruction execution event for SettleOnAffirmation type instruction
123+
return;
124+
}
121125
}
122126
} catch (err) {
123127
throw new Error(`Error checking middleware sync status: ${err}`);

0 commit comments

Comments
 (0)