Skip to content

Commit f843c6e

Browse files
committed
fix: move invariant function from tests folder to fix combuild error
1 parent 6bb3957 commit f843c6e

File tree

8 files changed

+15
-26
lines changed

8 files changed

+15
-26
lines changed

examples/precompiled/precompiled-typed.spec.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -138,11 +138,6 @@ describe('pre compiled typed app calls', () => {
138138
itxnContext.setReturnValue(1)
139139
}
140140
})
141-
spy.on.receivesAssetConfig((itxnContext) => {
142-
if (itxnContext.appId === receivesTxnsApp) {
143-
itxnContext.setReturnValue(ctx.any.bytes(64))
144-
}
145-
})
146141

147142
ctx.addApplicationSpy(spy)
148143

src/errors.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export class NotImplementedError extends Error {
4949
}
5050
}
5151

52-
export function testInvariant(condition: unknown, message: string): asserts condition {
52+
export function invariant(condition: unknown, message: string): asserts condition {
5353
if (!condition) {
5454
throw new InternalError(message)
5555
}

src/impl/inner-transactions.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,9 @@ import type {
77
} from '@algorandfoundation/algorand-typescript'
88
import { TransactionType } from '@algorandfoundation/algorand-typescript'
99
import type { BareCreateApplicationCallFields, TypedApplicationCallFields } from '@algorandfoundation/algorand-typescript/arc4'
10-
import { invariant } from '../../tests/util'
1110
import { ABI_RETURN_VALUE_LOG_PREFIX } from '../constants'
1211
import { lazyContext } from '../context-helpers/internal-context'
13-
import { InternalError } from '../errors'
12+
import { InternalError, invariant } from '../errors'
1413
import { extractArraysFromArgs } from '../subcontexts/contract-context'
1514
import type { DeliberateAny } from '../typescript-helpers'
1615
import { asBytes, asNumber, asUint8Array } from '../util'
@@ -297,7 +296,7 @@ export class ApplicationCallInnerTxnContext<TReturn = unknown> extends Applicati
297296
setReturnValue(value: TReturn) {
298297
// Ignore undefined (void) values
299298
if (value === undefined) return
300-
super.appendLog(ABI_RETURN_VALUE_LOG_PREFIX.concat(encodeArc4Impl(undefined, value)))
299+
this.appendLog(ABI_RETURN_VALUE_LOG_PREFIX.concat(encodeArc4Impl(undefined, value)))
301300
this.#returnValue = value
302301
}
303302
/* @internal */

src/impl/pure.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { biguint, bytes, op, uint64 } from '@algorandfoundation/algorand-typescript'
22
import { Base64 } from '@algorandfoundation/algorand-typescript'
33
import { BITS_IN_BYTE, MAX_BYTES_SIZE, MAX_UINT64, MAX_UINT8, UINT64_SIZE } from '../constants'
4-
import { AvmError, CodeError, NotImplementedError, testInvariant } from '../errors'
4+
import { AvmError, CodeError, invariant, NotImplementedError } from '../errors'
55
import { asBigUint, asBytes, asBytesCls, asMaybeBytesCls, asMaybeUint64Cls, asUint64Cls, binaryStringToBytes } from '../util'
66
import type { StubBigUintCompat, StubBytesCompat, StubUint64Compat } from './primitives'
77
import { BigUintCls, Bytes, BytesCls, checkBigUint, isUint64, Uint64, Uint64Cls } from './primitives'
@@ -222,7 +222,7 @@ export const setBit = ((a: StubUint64Compat | StubBytesCompat, b: StubUint64Comp
222222
return newBytes.toUint64().asAlgoTs()
223223
} else {
224224
const bytesCls = asMaybeBytesCls(a)
225-
testInvariant(bytesCls, 'a must be uint64 or bytes')
225+
invariant(bytesCls, 'a must be uint64 or bytes')
226226
const binaryString = toBinaryString(bytesCls.asAlgoTs())
227227
const newBytes = doSetBit(binaryString, indexParam, bit)
228228
return newBytes.asAlgoTs()

src/subcontexts/transaction-context.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { checkRoutingConditions } from '../context-helpers/context-util'
66
import { lazyContext } from '../context-helpers/internal-context'
77
import type { DecodedLogs, LogDecoding } from '../decode-logs'
88
import { decodeLogs } from '../decode-logs'
9-
import { InternalError, testInvariant } from '../errors'
9+
import { InternalError, invariant } from '../errors'
1010
import type {
1111
ApplicationCallInnerTxn,
1212
AssetConfigInnerTxn,
@@ -265,7 +265,7 @@ export class TransactionGroup {
265265
if (this.transactions.length === 0) {
266266
throw new InternalError('No transactions in the group')
267267
}
268-
testInvariant(this.activeTransaction.type === TransactionType.ApplicationCall, 'No app_id found in the active transaction')
268+
invariant(this.activeTransaction.type === TransactionType.ApplicationCall, 'No app_id found in the active transaction')
269269
return (this.activeTransaction as ApplicationCallTransaction).backingAppId.id
270270
}
271271

@@ -322,7 +322,7 @@ export class TransactionGroup {
322322
if (this.constructingItxnGroup.length) {
323323
throw new InternalError('itxn begin without itxn submit')
324324
}
325-
testInvariant(this.activeTransaction.type === TransactionType.ApplicationCall, 'No active application call transaction')
325+
invariant(this.activeTransaction.type === TransactionType.ApplicationCall, 'No active application call transaction')
326326
if (this.activeTransaction.onCompletion === OnCompleteAction.ClearState) {
327327
throw new InternalError('Cannot begin inner transaction group in a clear state call')
328328
}
@@ -376,12 +376,12 @@ export class TransactionGroup {
376376
getItxnGroup(index?: StubUint64Compat): ItxnGroup {
377377
const i = index !== undefined ? asNumber(index) : undefined
378378

379-
testInvariant(this.itxnGroups.length > 0, 'no previous inner transactions')
379+
invariant(this.itxnGroups.length > 0, 'no previous inner transactions')
380380
if (i !== undefined && i >= this.itxnGroups.length) {
381381
throw new InternalError('Invalid group index')
382382
}
383383
const group = i !== undefined ? this.itxnGroups[i] : this.itxnGroups.at(-1)!
384-
testInvariant(group.itxns.length > 0, 'no previous inner transactions')
384+
invariant(group.itxns.length > 0, 'no previous inner transactions')
385385

386386
return group
387387
}
@@ -552,7 +552,7 @@ export class ItxnGroup {
552552
}
553553

554554
private getInnerTxnImpl({ type, index }: { type?: TransactionType; index?: StubUint64Compat }) {
555-
testInvariant(this.itxns.length > 0, 'no previous inner transactions')
555+
invariant(this.itxns.length > 0, 'no previous inner transactions')
556556
const i = index !== undefined ? asNumber(index) : undefined
557557
if (i !== undefined && i >= this.itxns.length) {
558558
throw new InternalError('Invalid group index')

tests/state-op-codes.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { afterEach, beforeAll, describe, expect } from 'vitest'
77
import { TestExecutionContext } from '../src'
88
import { ABI_RETURN_VALUE_LOG_PREFIX, MIN_TXN_FEE, OnApplicationComplete, ZERO_ADDRESS } from '../src/constants'
99
import { lazyContext } from '../src/context-helpers/internal-context'
10-
import { testInvariant } from '../src/errors'
10+
import { invariant } from '../src/errors'
1111
import { Block, gloadBytes, gloadUint64 } from '../src/impl'
1212
import type { InnerTxn } from '../src/impl/itxn'
1313
import { BytesCls, Uint64Cls } from '../src/impl/primitives'
@@ -93,7 +93,7 @@ describe('State op codes', async () => {
9393
methodName as string,
9494
asUint8Array(mockAccount.bytes),
9595
)
96-
testInvariant(avmResult !== undefined, 'There must be an AVM result')
96+
invariant(avmResult !== undefined, 'There must be an AVM result')
9797
const mockContract = ctx.contract.create(StateAcctParamsGetContract)
9898
const mockResult = mockContract[methodName as keyof StateAcctParamsGetContract](mockAccount)
9999

tests/test-fixture.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@ import { OnApplicationComplete } from 'algosdk'
1515
import fs from 'fs'
1616
import type { ExpectStatic } from 'vitest'
1717
import { test } from 'vitest'
18+
import { invariant } from '../src/errors'
1819
import type { DeliberateAny } from '../src/typescript-helpers'
19-
import { generateTempDir, invariant } from './util'
20+
import { generateTempDir } from './util'
2021

2122
const algorandTestFixture = (localnetFixture: AlgorandFixture) =>
2223
test.extend<{

tests/util.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,6 @@ import type { BytesCls, StubBigUintCompat, StubBytesCompat } from '../src/impl/p
88
import { BigUintCls, Bytes } from '../src/impl/primitives'
99
import { asUint8Array } from '../src/util'
1010

11-
class InvariantError extends Error {}
12-
export function invariant(condition: unknown, message: string): asserts condition {
13-
if (!condition) {
14-
throw new InvariantError(message)
15-
}
16-
}
1711
export const padUint8Array = (arr: Uint8Array, padSize: number): Uint8Array => {
1812
const paddedUint8Array = new Uint8Array(arr.length + padSize)
1913
arr.forEach((v, i) => (paddedUint8Array[padSize + i] = v))

0 commit comments

Comments
 (0)