diff --git a/src/executorServiceHandler.ts b/src/executorServiceHandler.ts index d860279..846bbff 100644 --- a/src/executorServiceHandler.ts +++ b/src/executorServiceHandler.ts @@ -1,4 +1,4 @@ -import { SuiClient, CoinStruct } from '@mysten/sui.js/client'; +import { CoinStruct, SuiClient } from '@mysten/sui.js/client'; import { Keypair } from '@mysten/sui.js/src/cryptography'; import { SuiObjectRef } from '@mysten/sui.js/src/types/objects'; import { TransactionBlock } from '@mysten/sui.js/transactions'; @@ -34,7 +34,7 @@ export class ExecutorServiceHandler { txb: TransactionBlock, client: SuiClient, splitStrategy: SplitStrategy, - retries: number = 1, + retries = 3, ) { let res; do { @@ -55,10 +55,10 @@ export class ExecutorServiceHandler { const noWorkerAvailable = worker === undefined; if (noWorkerAvailable) { this.addWorker(splitStrategy); - return + return; } else { // An available worker is found! Assign to it the task of executing the txb. - worker.status = 'busy'; // Worker is now busy + worker.status = 'busy'; // Worker is now busy const result = await worker.pool.signAndExecuteTransactionBlock({ transactionBlock: txb, @@ -67,11 +67,11 @@ export class ExecutorServiceHandler { if (result.effects!.status.status === 'failure') { this.removeWorker(worker); - return + return; } console.log('TXB execution completed!'); - worker.status = 'available'; // Execution finished, the worker is now available again. + worker.status = 'available'; // Execution finished, the worker is now available again. return result; } } diff --git a/test/unit/executorServiceHandler.test.ts b/test/unit/executorServiceHandler.test.ts index 1d241c1..2041eee 100644 --- a/test/unit/executorServiceHandler.test.ts +++ b/test/unit/executorServiceHandler.test.ts @@ -34,13 +34,12 @@ function createPaymentTxb(recipient: string): TransactionBlock { describe('Test pool adaptability to requests with ExecutorServiceHandler', () => { it('executes a txb', async () => { /* - WARNING! - YOU NEED TO HAVE AT LEAST X COINS IN YOUR ACCOUNTS TO RUN THIS TEST. + WARNING! - YOU NEED TO HAVE AT LEAST X COIN OBJECTS IN YOUR ACCOUNTS TO RUN THIS TEST. X = NUMBER_OF_TRANSACTION_TO_EXECUTE */ - const NUMBER_OF_TRANSACTION_TO_EXECUTE = 3; + const NUMBER_OF_TRANSACTION_TO_EXECUTE = 2; - const txb = createPaymentTxb(process.env.TEST_USER_ADDRESS!); // Pass this transaction to the ExecutorServiceHandler. The ExecutorServiceHandler will // forward the transaction to a worker pool, which will sign and execute the transaction. @@ -55,13 +54,18 @@ describe('Test pool adaptability to requests with ExecutorServiceHandler', () => }, } - const results = []; + const promises = []; + let txb: TransactionBlock; for (let i = 0; i < NUMBER_OF_TRANSACTION_TO_EXECUTE; i++) { - results.push(await eshandler.execute(txb, client, splitStrategy)); + txb = createPaymentTxb(process.env.TEST_USER_ADDRESS!); + promises.push( + eshandler.execute(txb, client, splitStrategy) + ); } + const results = await Promise.allSettled(promises); results.forEach((result) => { - expect(result.effects?.status.status).toEqual('success'); + expect(result.status).toEqual("fulfilled"); }); });