Skip to content
This repository has been archived by the owner on Jul 16, 2024. It is now read-only.

Commit

Permalink
Checkpoint (WIP)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tzal3x committed Oct 20, 2023
1 parent 9d0aa61 commit 3aac8b6
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
12 changes: 6 additions & 6 deletions src/executorServiceHandler.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -34,7 +34,7 @@ export class ExecutorServiceHandler {
txb: TransactionBlock,
client: SuiClient,
splitStrategy: SplitStrategy,
retries: number = 1,
retries = 3,
) {
let res;
do {
Expand All @@ -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,
Expand All @@ -67,11 +67,11 @@ export class ExecutorServiceHandler {

if (result.effects!.status.status === 'failure') {

Check warning on line 68 in src/executorServiceHandler.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

Forbidden non-null assertion

Check warning on line 68 in src/executorServiceHandler.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

Forbidden non-null assertion
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;
}
}
Expand Down
16 changes: 10 additions & 6 deletions test/unit/executorServiceHandler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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");
});

});
Expand Down

0 comments on commit 3aac8b6

Please sign in to comment.