fix: [BUG] - readStateBatch returns null for contract with no interactions #495
This commit is contained in:
@@ -254,22 +254,23 @@ export class HandlerBasedContract<State> implements Contract<State> {
|
||||
let batchesLoaded = 0;
|
||||
do {
|
||||
const batchBenchmark = Benchmark.measure();
|
||||
this.logger.debug(`Loading ${++batchesLoaded}`, evaluationOptions);
|
||||
this.logger.debug(`Loading ${batchesLoaded + 1} batch`, evaluationOptions);
|
||||
interactions = await interactionsLoader.load(contractTxId, cachedState?.sortKey, sortKey, evaluationOptions);
|
||||
if (signal?.aborted) {
|
||||
throw new AbortError('readStateBatch aborted');
|
||||
}
|
||||
if (interactions.length == 0) {
|
||||
if (interactions.length == 0 && batchesLoaded > 0) {
|
||||
break;
|
||||
}
|
||||
this.logger.debug(`Evaluating ${interactions.length} in ${batchesLoaded}`);
|
||||
this.logger.debug(`Evaluating ${interactions.length} in ${batchesLoaded + 1} batch`);
|
||||
cachedState = await this.readStateFor(cachedState?.sortKey || genesisSortKey, interactions, signal);
|
||||
if (signal?.aborted) {
|
||||
throw new AbortError('readStateBatch aborted');
|
||||
}
|
||||
this.logger.debug(
|
||||
`Batch ${batchesLoaded} evaluated in ${batchBenchmark.elapsed()} at sortKey ${cachedState.sortKey}`
|
||||
`Batch ${batchesLoaded + 1} evaluated in ${batchBenchmark.elapsed()} at sortKey ${cachedState.sortKey}`
|
||||
);
|
||||
batchesLoaded++;
|
||||
} while (interactions.length > 0);
|
||||
|
||||
return cachedState;
|
||||
|
||||
@@ -18,7 +18,7 @@ async function main() {
|
||||
|
||||
try {
|
||||
|
||||
const signal = AbortSignal.timeout(2000);
|
||||
const signal = AbortSignal.timeout(10000);
|
||||
const contract = warp
|
||||
.contract("Daj-MNSnH55TDfxqC7v4eq0lKzVIwh98srUaWqyuZtY")
|
||||
.setEvaluationOptions({
|
||||
@@ -27,7 +27,7 @@ async function main() {
|
||||
allowBigInt: true,
|
||||
unsafeClient: 'skip',
|
||||
});
|
||||
const result = await contract.readStateBatch(1, signal);
|
||||
const result = await contract.readStateBatch(1, undefined, signal);
|
||||
console.dir(result.cachedValue.state, {depth: null});
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
|
||||
Reference in New Issue
Block a user