Skip to content

Commit a2dd74a

Browse files
author
okekefrancis112
committed
fix(sdk): expose poll config in InvokeOptions, rename simulation error helper
1 parent 394c725 commit a2dd74a

2 files changed

Lines changed: 23 additions & 5 deletions

File tree

sdk/src/contract/contract.service.spec.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ describe('ContractService.invoke()', () => {
133133
);
134134
expect(lifecycle.sign).toHaveBeenCalledWith(ASSEMBLED_XDR, Networks.TESTNET);
135135
expect(lifecycle.submit).toHaveBeenCalledWith(SIGNED_XDR);
136-
expect(lifecycle.poll).toHaveBeenCalledWith(TX_HASH);
136+
expect(lifecycle.poll).toHaveBeenCalledWith(TX_HASH, undefined);
137137
expect(result).toEqual({ result: 99, txHash: TX_HASH, ledger: 300 });
138138
});
139139

@@ -171,6 +171,22 @@ describe('ContractService.invoke()', () => {
171171
expect.objectContaining({ memo: { type: 'text', value: 'raffle-ref' } }),
172172
);
173173
});
174+
175+
it('passes poll config through to lifecycle.poll()', async () => {
176+
const { service, lifecycle } = buildService(true);
177+
178+
jest.spyOn(lifecycle, 'simulate').mockResolvedValue(mockSimulateResult as any);
179+
jest.spyOn(lifecycle, 'sign').mockResolvedValue(SIGNED_XDR);
180+
jest.spyOn(lifecycle, 'submit').mockResolvedValue(TX_HASH);
181+
jest.spyOn(lifecycle, 'poll').mockResolvedValue(mockSubmitResult as any);
182+
183+
await service.invoke(ContractFn.BUY_TICKET, [1], {
184+
sourcePublicKey: SOURCE_KEY,
185+
poll: { timeoutMs: 90_000 },
186+
});
187+
188+
expect(lifecycle.poll).toHaveBeenCalledWith(TX_HASH, { timeoutMs: 90_000 });
189+
});
174190
});
175191

176192
describe('ContractService.buildUnsigned()', () => {

sdk/src/contract/contract.service.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import { getRaffleContractId } from './constants';
1717
import { ContractFnName } from './bindings';
1818
import { TikkaSdkError, TikkaSdkErrorCode } from '../utils/errors';
1919
import { TransactionLifecycle } from './lifecycle';
20-
import type { TxMemo } from './lifecycle';
20+
import type { TxMemo, PollConfig } from './lifecycle';
2121
export type { TxMemo } from './lifecycle';
2222

2323
export interface InvokeOptions {
@@ -26,6 +26,8 @@ export interface InvokeOptions {
2626
fee?: string;
2727
/** Optional memo attached to the transaction envelope. */
2828
memo?: TxMemo;
29+
/** Optional polling configuration override. */
30+
poll?: PollConfig;
2931
}
3032

3133
export interface InvokeResult<T = any> {
@@ -63,7 +65,7 @@ export interface SubmitSignedResult<T = any> {
6365
* Detects if an error message indicates a failure in an external contract
6466
* (e.g., a SEP-41 token contract rejecting a transfer).
6567
*/
66-
function isExternalContractFailure(errorMsg: string): boolean {
68+
function isExternalSimulationError(errorMsg: string): boolean {
6769
return /external|token|sep-?41/i.test(errorMsg);
6870
}
6971

@@ -116,7 +118,7 @@ export class ContractService {
116118

117119
if (rpc.Api.isSimulationError(simResponse)) {
118120
const errMsg = (simResponse as any).error ?? '';
119-
const code = isExternalContractFailure(errMsg)
121+
const code = isExternalSimulationError(errMsg)
120122
? TikkaSdkErrorCode.ExternalContractError
121123
: TikkaSdkErrorCode.SimulationFailed;
122124
throw new TikkaSdkError(
@@ -161,7 +163,7 @@ export class ContractService {
161163

162164
const signedXdr = await this.lifecycle.sign(sim.assembledXdr, sim.networkPassphrase);
163165
const txHash = await this.lifecycle.submit(signedXdr);
164-
const polled = await this.lifecycle.poll<T>(txHash);
166+
const polled = await this.lifecycle.poll<T>(txHash, options.poll);
165167
return { result: polled.returnValue as T, txHash: polled.txHash, ledger: polled.ledger };
166168
}
167169

0 commit comments

Comments
 (0)