Skip to content

Commit 228d2cb

Browse files
committed
use Record<TK, TV> instead of array type to setup scratch space in tests to simplify the setup
1 parent 627c06e commit 228d2cb

File tree

3 files changed

+5
-8
lines changed

3 files changed

+5
-8
lines changed

src/impl/scratch.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export const gloadUint64: internal.opTypes.GloadUint64Type = (
88
const txn = lazyContext.activeGroup.getTransaction(a)
99
const result = txn.getScratchSlot(b)
1010
if (result instanceof internal.primitives.Uint64Cls) {
11-
return result as uint64
11+
return result.asAlgoTs()
1212
}
1313
throw new internal.errors.InternalError('invalid scratch slot type')
1414
}
@@ -20,7 +20,7 @@ export const gloadBytes: internal.opTypes.GloadBytesType = (
2020
const txn = lazyContext.activeGroup.getTransaction(a)
2121
const result = txn.getScratchSlot(b)
2222
if (result instanceof internal.primitives.BytesCls) {
23-
return result as bytes
23+
return result.asAlgoTs()
2424
}
2525
throw new internal.errors.InternalError('invalid scratch slot type')
2626
}

src/impl/transactions.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ export type ApplicationTransactionFields = TxnFields<gtxn.ApplicationTxn> &
233233
approvalProgramPages: Array<bytes>
234234
clearStateProgramPages: Array<bytes>
235235
appLogs: Array<bytes>
236-
scratchSpace: Array<bytes | uint64>
236+
scratchSpace: Record<number, bytes | uint64>
237237
}>
238238

239239
export class ApplicationTransaction extends TransactionBase implements gtxn.ApplicationTxn {
@@ -266,7 +266,7 @@ export class ApplicationTransaction extends TransactionBase implements gtxn.Appl
266266
this.#apps = fields.apps ?? []
267267
this.#approvalProgramPages = fields.approvalProgramPages ?? (fields.approvalProgram ? [fields.approvalProgram] : [])
268268
this.#clearStateProgramPages = fields.clearStateProgramPages ?? (fields.clearStateProgram ? [fields.clearStateProgram] : [])
269-
fields.scratchSpace?.forEach((v, i) => this.setScratchSlot(i, v))
269+
Object.entries(fields.scratchSpace ?? {}).forEach(([k, v]) => this.setScratchSlot(Number(k), v))
270270
}
271271

272272
readonly appId: Application

tests/state-op-codes.spec.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -367,10 +367,7 @@ describe('State op codes', async () => {
367367
[3, Uint64(42)],
368368
[255, Bytes('max_index')],
369369
])('should return the correct field value of the scratch slot', async (index: number, value: bytes | uint64) => {
370-
const newScratchSpace = Array(256).fill(Uint64(0))
371-
newScratchSpace[index] = value
372-
373-
ctx.txn.createScope([ctx.any.txn.applicationCall({ scratchSpace: newScratchSpace })]).execute(() => {})
370+
ctx.txn.createScope([ctx.any.txn.applicationCall({ scratchSpace: { [index]: value } })]).execute(() => {})
374371

375372
expect(ctx.txn.lastGroup.getScratchSlot(index)).toEqual(value)
376373

0 commit comments

Comments
 (0)