diff --git a/package-lock.json b/package-lock.json index fdcdb61..9ae2a01 100644 --- a/package-lock.json +++ b/package-lock.json @@ -13941,9 +13941,9 @@ } }, "node_modules/vite": { - "version": "7.1.5", - "resolved": "https://registry.npmjs.org/vite/-/vite-7.1.5.tgz", - "integrity": "sha512-4cKBO9wR75r0BeIWWWId9XK9Lj6La5X846Zw9dFfzMRw38IlTk2iCcUt6hsyiDRcPidc55ZParFYDXi0nXOeLQ==", + "version": "7.1.11", + "resolved": "https://registry.npmjs.org/vite/-/vite-7.1.11.tgz", + "integrity": "sha512-uzcxnSDVjAopEUjljkWh8EIrg6tlzrjFUfMcR1EVsRDGwf/ccef0qQPRyOrROwhrTDaApueq+ja+KLPlzR/zdg==", "dev": true, "license": "MIT", "dependencies": { diff --git a/tests/arc4/bool.algo.spec.ts b/tests/arc4/bool.algo.spec.ts index f805c1b..7874345 100644 --- a/tests/arc4/bool.algo.spec.ts +++ b/tests/arc4/bool.algo.spec.ts @@ -1,22 +1,21 @@ import { Bytes } from '@algorandfoundation/algorand-typescript' import { TestExecutionContext } from '@algorandfoundation/algorand-typescript-testing' import { Bool, convertBytes } from '@algorandfoundation/algorand-typescript/arc4' -import { afterEach, beforeAll, describe, expect } from 'vitest' +import { afterEach, describe, expect } from 'vitest' import { ABI_RETURN_VALUE_LOG_PREFIX } from '../../src/constants' import { asUint8Array } from '../../src/util' import { getAvmResult } from '../avm-invoker' import { createArc4TestFixture } from '../test-fixture' describe('arc4.Bool', async () => { - const [test, localnetFixture] = createArc4TestFixture('tests/artifacts/arc4-primitive-ops/contract.algo.ts', { - Arc4PrimitiveOpsContract: { deployParams: { createParams: { extraProgramPages: undefined } } }, + const test = createArc4TestFixture({ + path: 'tests/artifacts/arc4-primitive-ops/contract.algo.ts', + contracts: { + Arc4PrimitiveOpsContract: { deployParams: { createParams: { extraProgramPages: undefined } } }, + }, }) const ctx = new TestExecutionContext() - beforeAll(async () => { - await localnetFixture.newScope() - }) - afterEach(() => { ctx.reset() }) diff --git a/tests/arc4/byte.algo.spec.ts b/tests/arc4/byte.algo.spec.ts index 2b95eab..c284fc8 100644 --- a/tests/arc4/byte.algo.spec.ts +++ b/tests/arc4/byte.algo.spec.ts @@ -3,7 +3,7 @@ import { Bytes } from '@algorandfoundation/algorand-typescript' import { TestExecutionContext } from '@algorandfoundation/algorand-typescript-testing' import { Byte, convertBytes } from '@algorandfoundation/algorand-typescript/arc4' import { encodingUtil } from '@algorandfoundation/puya-ts' -import { afterEach, beforeAll, describe, expect } from 'vitest' +import { afterEach, describe, expect } from 'vitest' import { ABI_RETURN_VALUE_LOG_PREFIX, MAX_UINT64 } from '../../src/constants' import { asBigUintCls, asUint8Array } from '../../src/util' import { getAvmResult } from '../avm-invoker' @@ -11,15 +11,15 @@ import { createArc4TestFixture } from '../test-fixture' const invalidBytesLengthError = 'byte string must be 1 byte long' describe('arc4.Byte', async () => { - const [test, localnetFixture] = createArc4TestFixture('tests/artifacts/arc4-primitive-ops/contract.algo.ts', { - Arc4PrimitiveOpsContract: { deployParams: { createParams: { extraProgramPages: undefined } } }, + const test = createArc4TestFixture({ + path: 'tests/artifacts/arc4-primitive-ops/contract.algo.ts', + contracts: { + Arc4PrimitiveOpsContract: { deployParams: { createParams: { extraProgramPages: undefined } } }, + }, }) const ctx = new TestExecutionContext() - beforeAll(async () => { - await localnetFixture.newScope() - }) afterEach(() => { ctx.reset() }) diff --git a/tests/arc4/circular-reference.algo.spec.ts b/tests/arc4/circular-reference.algo.spec.ts index fa4b847..62029b9 100644 --- a/tests/arc4/circular-reference.algo.spec.ts +++ b/tests/arc4/circular-reference.algo.spec.ts @@ -1,6 +1,6 @@ import { algo } from '@algorandfoundation/algokit-utils' import { methodSelector } from '@algorandfoundation/algorand-typescript/arc4' -import { afterEach, beforeAll, describe, expect } from 'vitest' +import { afterEach, describe, expect } from 'vitest' import { ApplicationSpy } from '../../src/application-spy' import { TestExecutionContext } from '../../src/test-execution-context' import { ContractTwo } from '../artifacts/circurlar-reference/circular-reference-2.algo' @@ -9,13 +9,12 @@ import { createArc4TestFixture } from '../test-fixture' describe('circular reference', () => { const ctx = new TestExecutionContext() - const [test, localnetFixture] = createArc4TestFixture('tests/artifacts/circurlar-reference', { - ContractOne: { funding: algo(1) }, - ContractTwo: { funding: algo(1) }, - }) - - beforeAll(async () => { - await localnetFixture.newScope() + const test = createArc4TestFixture({ + path: 'tests/artifacts/circurlar-reference', + contracts: { + ContractOne: { funding: algo(1) }, + ContractTwo: { funding: algo(1) }, + }, }) afterEach(() => { diff --git a/tests/arc4/emit.algo.spec.ts b/tests/arc4/emit.algo.spec.ts index 28574ce..5a9fa69 100644 --- a/tests/arc4/emit.algo.spec.ts +++ b/tests/arc4/emit.algo.spec.ts @@ -1,7 +1,7 @@ import type { biguint, bytes, uint64 } from '@algorandfoundation/algorand-typescript' import { arc4, BigUint, Bytes, emit, Uint64 } from '@algorandfoundation/algorand-typescript' import { TestExecutionContext } from '@algorandfoundation/algorand-typescript-testing' -import { afterEach, beforeAll, describe, expect } from 'vitest' +import { afterEach, describe, expect } from 'vitest' import { MAX_UINT512, MAX_UINT64 } from '../../src/constants' import { getAvmResultLog } from '../avm-invoker' @@ -41,15 +41,14 @@ class SwappedArc4 extends arc4.Struct<{ }> {} describe('arc4.emit', async () => { - const [test, localnetFixture] = createArc4TestFixture('tests/artifacts/arc4-primitive-ops/contract.algo.ts', { - Arc4PrimitiveOpsContract: { deployParams: { createParams: { extraProgramPages: undefined } } }, + const test = createArc4TestFixture({ + path: 'tests/artifacts/arc4-primitive-ops/contract.algo.ts', + contracts: { + Arc4PrimitiveOpsContract: { deployParams: { createParams: { extraProgramPages: undefined } } }, + }, }) const ctx = new TestExecutionContext() - beforeAll(async () => { - await localnetFixture.newScope() - }) - afterEach(() => { ctx.reset() }) diff --git a/tests/arc4/method-selector.algo.spec.ts b/tests/arc4/method-selector.algo.spec.ts index 9aa0314..94c9c15 100644 --- a/tests/arc4/method-selector.algo.spec.ts +++ b/tests/arc4/method-selector.algo.spec.ts @@ -4,7 +4,7 @@ import { arc4, Bytes, Global, Uint64 } from '@algorandfoundation/algorand-typesc import { TestExecutionContext } from '@algorandfoundation/algorand-typescript-testing' import { DynamicArray, methodSelector } from '@algorandfoundation/algorand-typescript/arc4' import { encodingUtil } from '@algorandfoundation/puya-ts' -import { afterEach, beforeAll, describe, expect } from 'vitest' +import { afterEach, describe, expect } from 'vitest' import { toBytes } from '../../src/impl/encoded-types/encoded-types' import { encodeAddress } from '../../src/impl/reference' import { AnotherStruct, MyStruct, SignaturesContract } from '../artifacts/arc4-abi-method/contract.algo' @@ -15,17 +15,16 @@ const _FUNDED_ACCOUNT_SPENDING = Uint64(1234) describe('methodSelector', async () => { const ctx = new TestExecutionContext() - const [test, localnetFixture] = createArc4TestFixture('tests/artifacts/arc4-abi-method/contract.algo.ts', { - SignaturesContract: { - deployParams: { createParams: { extraProgramPages: undefined, method: 'create' } }, - funding: new AlgoAmount({ microAlgos: Global.minBalance + _FUNDED_ACCOUNT_SPENDING }), + const test = createArc4TestFixture({ + path: 'tests/artifacts/arc4-abi-method/contract.algo.ts', + contracts: { + SignaturesContract: { + deployParams: { createParams: { extraProgramPages: undefined, method: 'create' } }, + funding: new AlgoAmount({ microAlgos: Global.minBalance + _FUNDED_ACCOUNT_SPENDING }), + }, }, }) - beforeAll(async () => { - await localnetFixture.newScope() - }) - afterEach(() => { ctx.reset() }) diff --git a/tests/arc4/resource-encoding.algo.spec.ts b/tests/arc4/resource-encoding.algo.spec.ts index b8868a1..6f03753 100644 --- a/tests/arc4/resource-encoding.algo.spec.ts +++ b/tests/arc4/resource-encoding.algo.spec.ts @@ -1,18 +1,17 @@ import { algo } from '@algorandfoundation/algokit-utils' -import { afterEach, beforeAll, describe, expect } from 'vitest' +import { afterEach, describe, expect } from 'vitest' import { TestExecutionContext } from '../../src/test-execution-context' import { createArc4TestFixture } from '../test-fixture' describe('resource encoding', () => { const ctx = new TestExecutionContext() - const [test, localnetFixture] = createArc4TestFixture('tests/artifacts/resource-encoding/contract.algo.ts', { - ByIndex: {}, - ByValue: {}, - C2C: { funding: algo(1) }, - }) - - beforeAll(async () => { - await localnetFixture.newScope() + const test = createArc4TestFixture({ + path: 'tests/artifacts/resource-encoding/contract.algo.ts', + contracts: { + ByIndex: {}, + ByValue: {}, + C2C: { funding: algo(1) }, + }, }) afterEach(() => { diff --git a/tests/arc4/str.algo.spec.ts b/tests/arc4/str.algo.spec.ts index 26ef037..38352ce 100644 --- a/tests/arc4/str.algo.spec.ts +++ b/tests/arc4/str.algo.spec.ts @@ -2,21 +2,21 @@ import { Bytes } from '@algorandfoundation/algorand-typescript' import { TestExecutionContext } from '@algorandfoundation/algorand-typescript-testing' import { convertBytes, Str } from '@algorandfoundation/algorand-typescript/arc4' import { encodingUtil } from '@algorandfoundation/puya-ts' -import { afterEach, beforeAll, describe, expect } from 'vitest' +import { afterEach, describe, expect } from 'vitest' import { ABI_RETURN_VALUE_LOG_PREFIX, MAX_LOG_SIZE } from '../../src/constants' import { asUint8Array } from '../../src/util' import { getAvmResult } from '../avm-invoker' import { createArc4TestFixture } from '../test-fixture' describe('arc4.Str', async () => { - const [test, localnetFixture] = createArc4TestFixture('tests/artifacts/arc4-primitive-ops/contract.algo.ts', { - Arc4PrimitiveOpsContract: { deployParams: { createParams: { extraProgramPages: undefined } } }, + const test = createArc4TestFixture({ + path: 'tests/artifacts/arc4-primitive-ops/contract.algo.ts', + contracts: { + Arc4PrimitiveOpsContract: { deployParams: { createParams: { extraProgramPages: undefined } } }, + }, }) const ctx = new TestExecutionContext() - beforeAll(async () => { - await localnetFixture.newScope() - }) afterEach(() => { ctx.reset() }) diff --git a/tests/arc4/ufixednxm.algo.spec.ts b/tests/arc4/ufixednxm.algo.spec.ts index fc39d9b..16ec4d1 100644 --- a/tests/arc4/ufixednxm.algo.spec.ts +++ b/tests/arc4/ufixednxm.algo.spec.ts @@ -3,7 +3,7 @@ import { Bytes } from '@algorandfoundation/algorand-typescript' import { TestExecutionContext } from '@algorandfoundation/algorand-typescript-testing' import { convertBytes, UFixed } from '@algorandfoundation/algorand-typescript/arc4' import { encodingUtil } from '@algorandfoundation/puya-ts' -import { afterEach, beforeAll, describe, expect } from 'vitest' +import { afterEach, describe, expect } from 'vitest' import { ABI_RETURN_VALUE_LOG_PREFIX } from '../../src/constants' import { asBigUint, asUint8Array } from '../../src/util' import { getAvmResult } from '../avm-invoker' @@ -11,14 +11,14 @@ import { createArc4TestFixture } from '../test-fixture' const invalidBytesLengthError = (length: number) => `byte string must correspond to a ufixed${length}` describe('arc4.UFixed', async () => { - const [test, localnetFixture] = createArc4TestFixture('tests/artifacts/arc4-primitive-ops/contract.algo.ts', { - Arc4PrimitiveOpsContract: { deployParams: { createParams: { extraProgramPages: undefined } } }, + const test = createArc4TestFixture({ + path: 'tests/artifacts/arc4-primitive-ops/contract.algo.ts', + contracts: { + Arc4PrimitiveOpsContract: { deployParams: { createParams: { extraProgramPages: undefined } } }, + }, }) const ctx = new TestExecutionContext() - beforeAll(async () => { - await localnetFixture.newScope() - }) afterEach(() => { ctx.reset() }) diff --git a/tests/arc4/uintn.algo.spec.ts b/tests/arc4/uintn.algo.spec.ts index 1a76cda..bb346da 100644 --- a/tests/arc4/uintn.algo.spec.ts +++ b/tests/arc4/uintn.algo.spec.ts @@ -4,7 +4,7 @@ import { TestExecutionContext } from '@algorandfoundation/algorand-typescript-te import type { BitSize } from '@algorandfoundation/algorand-typescript/arc4' import { convertBytes, Uint, Uint16, Uint256, Uint32, Uint8 } from '@algorandfoundation/algorand-typescript/arc4' import { encodingUtil } from '@algorandfoundation/puya-ts' -import { afterEach, beforeAll, describe, expect } from 'vitest' +import { afterEach, describe, expect } from 'vitest' import { ABI_RETURN_VALUE_LOG_PREFIX, MAX_UINT512, MAX_UINT64 } from '../../src/constants' import { asBigUintCls, asUint8Array } from '../../src/util' import { getAvmResult } from '../avm-invoker' @@ -12,14 +12,14 @@ import { createArc4TestFixture } from '../test-fixture' const invalidBytesLengthError = (length: number) => `byte string must correspond to a uint${length}` describe('arc4.Uint', async () => { - const [test, localnetFixture] = createArc4TestFixture('tests/artifacts/arc4-primitive-ops/contract.algo.ts', { - Arc4PrimitiveOpsContract: { deployParams: { createParams: { extraProgramPages: undefined } } }, + const test = createArc4TestFixture({ + path: 'tests/artifacts/arc4-primitive-ops/contract.algo.ts', + contracts: { + Arc4PrimitiveOpsContract: { deployParams: { createParams: { extraProgramPages: undefined } } }, + }, }) const ctx = new TestExecutionContext() - beforeAll(async () => { - await localnetFixture.newScope() - }) afterEach(() => { ctx.reset() }) diff --git a/tests/avm12.algo.spec.ts b/tests/avm12.algo.spec.ts index 943fcfc..3bcb758 100644 --- a/tests/avm12.algo.spec.ts +++ b/tests/avm12.algo.spec.ts @@ -1,18 +1,19 @@ import { algos } from '@algorandfoundation/algokit-utils' import { ApplicationSpy, TestExecutionContext } from '@algorandfoundation/algorand-typescript-testing' -import { afterEach, beforeAll, describe, expect } from 'vitest' +import { afterEach, describe, expect } from 'vitest' import { Avm12Contract, ContractV0, ContractV1 } from './artifacts/avm12/contract.algo' import { createArc4TestFixture } from './test-fixture' describe('avm12', () => { - const [test, localnetFixture] = createArc4TestFixture('tests/artifacts/avm12/contract.algo.ts', { - Avm12Contract: { funding: algos(1) }, + const test = createArc4TestFixture({ + path: 'tests/artifacts/avm12/contract.algo.ts', + contracts: { + Avm12Contract: { funding: algos(1) }, + }, }) const ctx = new TestExecutionContext() - beforeAll(async () => { - await localnetFixture.newScope() - }) + afterEach(() => { ctx.reset() }) diff --git a/tests/crypto-op-codes.algo.spec.ts b/tests/crypto-op-codes.algo.spec.ts index cc9c45e..ee1c168 100644 --- a/tests/crypto-op-codes.algo.spec.ts +++ b/tests/crypto-op-codes.algo.spec.ts @@ -7,7 +7,7 @@ import js_sha3 from 'js-sha3' import js_sha512 from 'js-sha512' import nacl from 'tweetnacl' import type { Mock } from 'vitest' -import { afterEach, beforeAll, describe, expect, vi } from 'vitest' +import { afterEach, describe, expect, vi } from 'vitest' import { TestExecutionContext } from '../src' import { LOGIC_DATA_PREFIX, MAX_BYTES_SIZE, PROGRAM_TAG } from '../src/constants' import { BytesCls, Uint64Cls } from '../src/impl/primitives' @@ -35,13 +35,9 @@ vi.mock('../src/impl/crypto', async (importOriginal) => { }) describe('crypto op codes', async () => { - const [test, localnetFixture] = createArc4TestFixture('tests/artifacts/crypto-ops/contract.algo.ts', { CryptoOpsContract: {} }) + const test = createArc4TestFixture({ path: 'tests/artifacts/crypto-ops/contract.algo.ts', contracts: { CryptoOpsContract: {} } }) const ctx = new TestExecutionContext() - beforeAll(async () => { - await localnetFixture.newScope() - }) - afterEach(() => { ctx.reset() }) @@ -125,7 +121,7 @@ describe('crypto op codes', async () => { }) describe('ed25519verify', async () => { - test('should return true for valid signature', async ({ appFactoryCryptoOpsContract }) => { + test('should return true for valid signature', async ({ appFactoryCryptoOpsContract, localnet }) => { const app = await appFactoryCryptoOpsContract.deploy({}) const approval = app.result.compiledApproval! const appCallTxn = ctx.any.txn.applicationCall({ @@ -133,7 +129,7 @@ describe('crypto op codes', async () => { }) const message = Bytes('Test message for ed25519 verification') - const account = await localnetFixture.context.generateAccount({ + const account = await localnet.context.generateAccount({ initialFunds: AlgoAmount.MicroAlgos(INITIAL_BALANCE_MICRO_ALGOS + 100_000), }) diff --git a/tests/global-state-arc4-values.algo.spec.ts b/tests/global-state-arc4-values.algo.spec.ts index 5e9cccf..433662e 100644 --- a/tests/global-state-arc4-values.algo.spec.ts +++ b/tests/global-state-arc4-values.algo.spec.ts @@ -2,7 +2,7 @@ import { Bytes, Uint64 } from '@algorandfoundation/algorand-typescript' import { TestExecutionContext } from '@algorandfoundation/algorand-typescript-testing' import type { ARC4Encoded } from '@algorandfoundation/algorand-typescript/arc4' import { Address, Bool, Byte, DynamicBytes, Str, Uint } from '@algorandfoundation/algorand-typescript/arc4' -import { afterEach, beforeAll, describe, expect } from 'vitest' +import { afterEach, describe, expect } from 'vitest' import type { DeliberateAny, FunctionKeys } from '../src/typescript-helpers' import { asUint8Array } from '../src/util' import { GlobalStateContract } from './artifacts/state-ops/contract.algo' @@ -10,15 +10,14 @@ import { getAvmResult } from './avm-invoker' import { createArc4TestFixture } from './test-fixture' describe('ARC4 AppGlobal values', async () => { - const [test, localnetFixture] = createArc4TestFixture('tests/artifacts/state-ops/contract.algo.ts', { - GlobalStateContract: {}, + const test = createArc4TestFixture({ + path: 'tests/artifacts/state-ops/contract.algo.ts', + contracts: { + GlobalStateContract: {}, + }, }) const ctx = new TestExecutionContext() - beforeAll(async () => { - await localnetFixture.newScope() - }) - afterEach(() => { ctx.reset() }) diff --git a/tests/itxn-compose.algo.spec.ts b/tests/itxn-compose.algo.spec.ts index 6eec7ee..1c2fedc 100644 --- a/tests/itxn-compose.algo.spec.ts +++ b/tests/itxn-compose.algo.spec.ts @@ -2,20 +2,20 @@ import { algos } from '@algorandfoundation/algokit-utils' import { Bytes, TransactionType } from '@algorandfoundation/algorand-typescript' import { TestExecutionContext } from '@algorandfoundation/algorand-typescript-testing' import { Address } from '@algorandfoundation/algorand-typescript/arc4' -import { afterEach, beforeAll, describe, expect } from 'vitest' +import { afterEach, describe, expect } from 'vitest' import { ItxnComposeAlgo, VerifierContract } from './artifacts/itxn-compose/contract.algo' import { createArc4TestFixture } from './test-fixture' describe('itxn compose', async () => { - const [test, localnetFixture] = createArc4TestFixture('tests/artifacts/itxn-compose/contract.algo.ts', { - ItxnComposeAlgo: { funding: algos(5) }, - VerifierContract: {}, + const test = createArc4TestFixture({ + path: 'tests/artifacts/itxn-compose/contract.algo.ts', + contracts: { + ItxnComposeAlgo: { funding: algos(5) }, + VerifierContract: {}, + }, }) const ctx = new TestExecutionContext() - beforeAll(async () => { - await localnetFixture.newScope() - }) afterEach(() => { ctx.reset() }) diff --git a/tests/local-state-arc4-values.algo.spec.ts b/tests/local-state-arc4-values.algo.spec.ts index 3aa893a..a6c2e17 100644 --- a/tests/local-state-arc4-values.algo.spec.ts +++ b/tests/local-state-arc4-values.algo.spec.ts @@ -4,7 +4,7 @@ import { TestExecutionContext } from '@algorandfoundation/algorand-typescript-te import type { ARC4Encoded } from '@algorandfoundation/algorand-typescript/arc4' import { Address, Bool, Byte, DynamicBytes, Str, Uint } from '@algorandfoundation/algorand-typescript/arc4' -import { afterEach, beforeAll, describe, expect } from 'vitest' +import { afterEach, describe, expect } from 'vitest' import { OnApplicationComplete } from '../src/constants' import type { DeliberateAny } from '../src/typescript-helpers' @@ -13,15 +13,14 @@ import { getAvmResult } from './avm-invoker' import { createArc4TestFixture } from './test-fixture' describe('ARC4 AppLocal values', async () => { - const [test, localnetFixture] = createArc4TestFixture('tests/artifacts/state-ops/contract.algo.ts', { - LocalStateContract: {}, + const test = createArc4TestFixture({ + path: 'tests/artifacts/state-ops/contract.algo.ts', + contracts: { + LocalStateContract: {}, + }, }) const ctx = new TestExecutionContext() - beforeAll(async () => { - await localnetFixture.newScope() - }) - afterEach(() => { ctx.reset() }) diff --git a/tests/log.algo.spec.ts b/tests/log.algo.spec.ts index a550771..24bc3a4 100644 --- a/tests/log.algo.spec.ts +++ b/tests/log.algo.spec.ts @@ -12,7 +12,7 @@ import { Uint32, Uint8, } from '@algorandfoundation/algorand-typescript/arc4' -import { afterEach, beforeAll, describe, expect } from 'vitest' +import { afterEach, describe, expect } from 'vitest' import { MAX_UINT512, MAX_UINT64 } from '../src/constants' import type { ApplicationCallTransaction } from '../src/impl/transactions' import { asBigUint, asBigUintCls, asUint8Array } from '../src/util' @@ -21,14 +21,14 @@ import { getAvmResultLog } from './avm-invoker' import { createArc4TestFixture } from './test-fixture' describe('log', async () => { - const [test, localnetFixture] = createArc4TestFixture('tests/artifacts/primitive-ops/contract.algo.ts', { - PrimitiveOpsContract: { deployParams: { createParams: { extraProgramPages: undefined } } }, + const test = createArc4TestFixture({ + path: 'tests/artifacts/primitive-ops/contract.algo.ts', + contracts: { + PrimitiveOpsContract: { deployParams: { createParams: { extraProgramPages: undefined } } }, + }, }) const ctx = new TestExecutionContext() - beforeAll(async () => { - await localnetFixture.newScope() - }) afterEach(() => { ctx.reset() }) diff --git a/tests/multi-inheritance.algo.spec.ts b/tests/multi-inheritance.algo.spec.ts index 186d485..4773d05 100644 --- a/tests/multi-inheritance.algo.spec.ts +++ b/tests/multi-inheritance.algo.spec.ts @@ -1,17 +1,14 @@ import { TestExecutionContext } from '@algorandfoundation/algorand-typescript-testing' import { afterEach } from 'node:test' -import { beforeAll, describe, expect } from 'vitest' +import { describe, expect } from 'vitest' import { MultiBases } from './artifacts/multi-inheritance/contract.algo' import { getAvmResult } from './avm-invoker' import { createArc4TestFixture } from './test-fixture' describe('multi-inheritance', async () => { - const [test, localnetFixture] = createArc4TestFixture('tests/artifacts/multi-inheritance/contract.algo.ts', { MultiBases: {} }) + const test = createArc4TestFixture({ path: 'tests/artifacts/multi-inheritance/contract.algo.ts', contracts: { MultiBases: {} } }) const ctx = new TestExecutionContext() - beforeAll(async () => { - await localnetFixture.newScope() - }) afterEach(() => ctx.reset()) test('should be able to call methods from super classes', async ({ appClientMultiBases: appClient }) => { diff --git a/tests/primitives/biguint.algo.spec.ts b/tests/primitives/biguint.algo.spec.ts index 7ec5562..b002502 100644 --- a/tests/primitives/biguint.algo.spec.ts +++ b/tests/primitives/biguint.algo.spec.ts @@ -3,7 +3,7 @@ import type { biguint } from '@algorandfoundation/algorand-typescript' import { BigUint, Bytes, Uint64 } from '@algorandfoundation/algorand-typescript' import { encodingUtil } from '@algorandfoundation/puya-ts' -import { beforeAll, describe, expect } from 'vitest' +import { describe, expect } from 'vitest' import { BIGUINT_OVERFLOW_UNDERFLOW_MESSAGE, MAX_UINT512, MAX_UINT64 } from '../../src/constants' import { BigUintCls } from '../../src/impl/primitives' @@ -12,11 +12,11 @@ import { getAvmResult, getAvmResultRaw } from '../avm-invoker' import { createArc4TestFixture } from '../test-fixture' describe('BigUint', async () => { - const [test, localnetFixture] = createArc4TestFixture('tests/artifacts/primitive-ops/contract.algo.ts', { - PrimitiveOpsContract: { deployParams: { createParams: { extraProgramPages: undefined } } }, - }) - beforeAll(async () => { - await localnetFixture.newScope() + const test = createArc4TestFixture({ + path: 'tests/artifacts/primitive-ops/contract.algo.ts', + contracts: { + PrimitiveOpsContract: { deployParams: { createParams: { extraProgramPages: undefined } } }, + }, }) describe.each(['eq', 'ne', 'lt', 'le', 'gt', 'ge'])('logical operators', async (op) => { diff --git a/tests/primitives/bytes.algo.spec.ts b/tests/primitives/bytes.algo.spec.ts index d8f8e44..19ab4b3 100644 --- a/tests/primitives/bytes.algo.spec.ts +++ b/tests/primitives/bytes.algo.spec.ts @@ -1,7 +1,7 @@ import type { bytes } from '@algorandfoundation/algorand-typescript' import { Bytes, FixedArray, op } from '@algorandfoundation/algorand-typescript' import { encodingUtil } from '@algorandfoundation/puya-ts' -import { beforeAll, describe, expect, it } from 'vitest' +import { describe, expect, it } from 'vitest' import { MAX_BYTES_SIZE } from '../../src/constants' import type { Byte, StaticArray } from '@algorandfoundation/algorand-typescript/arc4' @@ -14,12 +14,11 @@ import { createArc4TestFixture } from '../test-fixture' import { getSha256Hash, padUint8Array } from '../util' describe('Bytes', async () => { - const [test, localnetFixture] = createArc4TestFixture('tests/artifacts/primitive-ops/contract.algo.ts', { - PrimitiveOpsContract: { deployParams: { createParams: { extraProgramPages: undefined } } }, - }) - - beforeAll(async () => { - await localnetFixture.newScope() + const test = createArc4TestFixture({ + path: 'tests/artifacts/primitive-ops/contract.algo.ts', + contracts: { + PrimitiveOpsContract: { deployParams: { createParams: { extraProgramPages: undefined } } }, + }, }) describe.each([ diff --git a/tests/primitives/uint64.algo.spec.ts b/tests/primitives/uint64.algo.spec.ts index fb205e5..b895266 100644 --- a/tests/primitives/uint64.algo.spec.ts +++ b/tests/primitives/uint64.algo.spec.ts @@ -1,6 +1,6 @@ import type { uint64 } from '@algorandfoundation/algorand-typescript' import { Uint64 } from '@algorandfoundation/algorand-typescript' -import { beforeAll, describe, expect } from 'vitest' +import { describe, expect } from 'vitest' import { MAX_UINT64, UINT64_OVERFLOW_UNDERFLOW_MESSAGE } from '../../src/constants' import { Uint64Cls } from '../../src/impl/primitives' import { asUint64 } from '../../src/util' @@ -8,13 +8,13 @@ import { getAvmResult } from '../avm-invoker' import { createArc4TestFixture } from '../test-fixture' describe('Unit64', async () => { - const [test, localnetFixture] = createArc4TestFixture('tests/artifacts/primitive-ops/contract.algo.ts', { - PrimitiveOpsContract: { deployParams: { createParams: { extraProgramPages: undefined } } }, + const test = createArc4TestFixture({ + path: 'tests/artifacts/primitive-ops/contract.algo.ts', + contracts: { + PrimitiveOpsContract: { deployParams: { createParams: { extraProgramPages: undefined } } }, + }, }) - beforeAll(async () => { - await localnetFixture.newScope() - }) describe.each(['eq', 'ne', 'lt', 'le', 'gt', 'ge'])('logical operators', async (op) => { const operator = (function () { switch (op) { diff --git a/tests/pure-op-codes.algo.spec.ts b/tests/pure-op-codes.algo.spec.ts index 6d5482b..9bc9551 100644 --- a/tests/pure-op-codes.algo.spec.ts +++ b/tests/pure-op-codes.algo.spec.ts @@ -1,7 +1,7 @@ import type { bytes, uint64 } from '@algorandfoundation/algorand-typescript' import { Base64, BigUint, Bytes, err, Uint64 } from '@algorandfoundation/algorand-typescript' import { encodingUtil } from '@algorandfoundation/puya-ts' -import { afterEach, beforeAll, describe, expect } from 'vitest' +import { afterEach, describe, expect } from 'vitest' import { TestExecutionContext } from '../src' import { BIGUINT_OVERFLOW_UNDERFLOW_MESSAGE, @@ -21,15 +21,14 @@ const extractOutOfBoundError = /extraction (start|end) \d+ is beyond length/ const sqrtMaxUint64 = 4294967295n describe('Pure op codes', async () => { - const [test, localnetFixture] = createArc4TestFixture('tests/artifacts/miscellaneous-ops/contract.algo.ts', { - MiscellaneousOpsContract: {}, + const test = createArc4TestFixture({ + path: 'tests/artifacts/miscellaneous-ops/contract.algo.ts', + contracts: { + MiscellaneousOpsContract: {}, + }, }) const ctx = new TestExecutionContext() - beforeAll(async () => { - await localnetFixture.newScope() - }) - afterEach(() => { ctx.reset() }) diff --git a/tests/state-op-codes.algo.spec.ts b/tests/state-op-codes.algo.spec.ts index 158b4dc..4b5441c 100644 --- a/tests/state-op-codes.algo.spec.ts +++ b/tests/state-op-codes.algo.spec.ts @@ -3,7 +3,7 @@ import type { AppClient } from '@algorandfoundation/algokit-utils/types/app-clie import type { bytes, uint64 } from '@algorandfoundation/algorand-typescript' import { Account, arc4, Bytes, Global, OnCompleteAction, op, TransactionType, Uint64 } from '@algorandfoundation/algorand-typescript' import { DynamicBytes } from '@algorandfoundation/algorand-typescript/arc4' -import { afterEach, beforeAll, describe, expect } from 'vitest' +import { afterEach, describe, expect } from 'vitest' import { TestExecutionContext } from '../src' import { ABI_RETURN_VALUE_LOG_PREFIX, MIN_TXN_FEE, OnApplicationComplete, ZERO_ADDRESS } from '../src/constants' import { lazyContext } from '../src/context-helpers/internal-context' @@ -33,23 +33,23 @@ import { generateTestAsset, getAvmResult, INITIAL_BALANCE_MICRO_ALGOS } from './ import { createArc4TestFixture } from './test-fixture' describe('State op codes', async () => { - const [test, localnetFixture] = createArc4TestFixture('tests/artifacts/state-ops/contract.algo.ts', { - ItxnDemoContract: {}, - ITxnOpsContract: {}, - StateAcctParamsGetContract: {}, - StateAppGlobalContract: {}, - StateAppGlobalExContract: {}, - StateAppLocalContract: {}, - StateAppLocalExContract: {}, - StateAppParamsContract: {}, - StateAssetHoldingContract: {}, - StateAssetParamsContract: {}, + const test = createArc4TestFixture({ + path: 'tests/artifacts/state-ops/contract.algo.ts', + contracts: { + ItxnDemoContract: {}, + ITxnOpsContract: {}, + StateAcctParamsGetContract: {}, + StateAppGlobalContract: {}, + StateAppGlobalExContract: {}, + StateAppLocalContract: {}, + StateAppLocalExContract: {}, + StateAppParamsContract: {}, + StateAssetHoldingContract: {}, + StateAssetParamsContract: {}, + }, }) const ctx = new TestExecutionContext() - beforeAll(async () => { - await localnetFixture.newScope() - }) afterEach(() => { ctx.reset() }) @@ -68,8 +68,8 @@ describe('State op codes', async () => { ['verify_acct_total_assets', 0], ['verify_acct_total_boxes', 0], ['verify_acct_total_box_bytes', 0], - ])('%s should return %s', async ([methodName, expectedValue], { appClientStateAcctParamsGetContract: appClient }) => { - const dummyAccountAddress = await localnetFixture.context.generateAccount({ + ])('%s should return %s', async ([methodName, expectedValue], { appClientStateAcctParamsGetContract: appClient, localnet }) => { + const dummyAccountAddress = await localnet.context.generateAccount({ initialFunds: AlgoAmount.MicroAlgos(INITIAL_BALANCE_MICRO_ALGOS + 100_000), }) const dummyAccount = Bytes.fromBase32(dummyAccountAddress.addr.toString()) @@ -102,8 +102,11 @@ describe('State op codes', async () => { expect(mockResult).toEqual(expectedValue) }) - test('should return true when account is eligible for incentive', async ({ appClientStateAcctParamsGetContract: appClient }) => { - const dummyAccountAddress = await localnetFixture.context.generateAccount({ + test('should return true when account is eligible for incentive', async ({ + appClientStateAcctParamsGetContract: appClient, + localnet, + }) => { + const dummyAccountAddress = await localnet.context.generateAccount({ initialFunds: AlgoAmount.MicroAlgos(INITIAL_BALANCE_MICRO_ALGOS), }) const dummyAccount = Bytes.fromBase32(dummyAccountAddress.addr.toString()) @@ -135,8 +138,8 @@ describe('State op codes', async () => { expect(avmResult).toEqual(true) }) - test('should return last round as last proposed and last hearbeat by default', async () => { - const dummyAccountAddress = await localnetFixture.context.generateAccount({ + test('should return last round as last proposed and last hearbeat by default', async ({ localnet }) => { + const dummyAccountAddress = await localnet.context.generateAccount({ initialFunds: AlgoAmount.MicroAlgos(INITIAL_BALANCE_MICRO_ALGOS), }) const dummyAccount = Bytes.fromBase32(dummyAccountAddress.addr.toString()) @@ -152,8 +155,8 @@ describe('State op codes', async () => { expect(lastHeartbeat).toEqual([Global.round, true]) }) - test('should return configured round as last proposed and last hearbeat', async () => { - const dummyAccountAddress = await localnetFixture.context.generateAccount({ + test('should return configured round as last proposed and last hearbeat', async ({ localnet }) => { + const dummyAccountAddress = await localnet.context.generateAccount({ initialFunds: AlgoAmount.MicroAlgos(INITIAL_BALANCE_MICRO_ALGOS), }) const dummyAccount = Bytes.fromBase32(dummyAccountAddress.addr.toString()) diff --git a/tests/switch-statements.algo.spec.ts b/tests/switch-statements.algo.spec.ts index 64aac7c..8cf0333 100644 --- a/tests/switch-statements.algo.spec.ts +++ b/tests/switch-statements.algo.spec.ts @@ -1,11 +1,8 @@ -import { beforeAll, describe } from 'vitest' +import { describe } from 'vitest' import { createArc4TestFixture } from './test-fixture' describe('switch statements', () => { - const [test, localnetFixture] = createArc4TestFixture('tests/artifacts/switch-statements/contract.algo.ts', { DemoContract: {} }) - beforeAll(async () => { - await localnetFixture.newScope() - }) + const test = createArc4TestFixture({ path: 'tests/artifacts/switch-statements/contract.algo.ts', contracts: { DemoContract: {} } }) test('runs', async ({ appClientDemoContract }) => { await appClientDemoContract.send.call({ method: 'run', args: [] }) diff --git a/tests/test-fixture.ts b/tests/test-fixture.ts index e54169f..2406622 100644 --- a/tests/test-fixture.ts +++ b/tests/test-fixture.ts @@ -13,8 +13,8 @@ import { compile, CompileOptions, LoggingContext, processInputPaths } from '@alg import type { Use } from '@vitest/runner/types' import { OnApplicationComplete } from 'algosdk' import fs from 'fs' -import type { ExpectStatic } from 'vitest' -import { test } from 'vitest' +import type { beforeEach, ExpectStatic } from 'vitest' +import { beforeAll, test } from 'vitest' import { invariant } from '../src/errors' import type { DeliberateAny } from '../src/typescript-helpers' import { generateTempDir } from './util' @@ -26,7 +26,7 @@ const algorandTestFixture = (localnetFixture: AlgorandFixture) => testAccount: AlgorandFixture['context']['testAccount'] assetFactory: (assetCreateParams: AssetCreateParams) => Promise }>({ - localnet: async ({ expect: _expect }, use) => { + localnet: async ({ expect: _ }, use) => { await use(localnetFixture) }, testAccount: async ({ localnet }, use) => { @@ -77,7 +77,22 @@ type ProgramInvoker = { type BaseFixtureContextFor = { [key in T as `${key}Invoker`]: ProgramInvoker } -export function createBaseTestFixture(path: string, contracts: TContracts[]) { +/** + * Creates a base test fixture for testing compiled Algorand smart contracts. + * + * @param options - Configuration options for the test fixture + * @param options.path - Path to the TypeScript file containing the contracts + * @param options.contracts - Array of contract names to create fixtures for + * @param options.newScopeAt - When to create a new test scope. Defaults to `beforeAll` for shared state across tests. + * Use `beforeEach` to create a fresh state for each test. + */ +export function createBaseTestFixture(options: { + path: string + contracts: TContracts[] + /** When to create a new test scope. Defaults to `beforeAll`. Use `beforeEach` for fresh state per test. */ + newScopeAt?: typeof beforeAll | typeof beforeEach +}) { + const { path, contracts, newScopeAt = beforeAll } = options const lazyCompile = createLazyCompiler(path, { outputArc56: false, outputBytecode: true }) const localnet = algorandFixture({ testAccountFunding: microAlgos(100_000_000_000), @@ -128,7 +143,8 @@ export function createBaseTestFixture(path: stri } } const extendedTest = algorandTestFixture(localnet).extend>(ctx) - return [extendedTest, localnet] as readonly [typeof extendedTest, AlgorandFixture] + newScopeAt(localnet.newScope) + return extendedTest } type Arc4FixtureContextFor = { @@ -144,10 +160,22 @@ type ContractConfig = { funding?: AlgoAmount } -export function createArc4TestFixture( - path: string, - contracts: Record | TContracts[], -) { +/** + * Creates an ARC-4 test fixture for testing Algorand ARC-4 smart contracts. + * + * @param options - Configuration options for the test fixture + * @param options.path - Path to the TypeScript file containing the ARC-4 contracts + * @param options.contracts - Contract configuration as either an array of names or pairs of name with deployment config + * @param options.newScopeAt - When to create a new` test scope. Defaults to `beforeAll` for shared state across tests. + * Use `beforeEach` to create a fresh state for each test. + */ +export function createArc4TestFixture(options: { + path: string + contracts: Record | TContracts[] + /** When to create a new test scope. Defaults to `beforeAll`. Use `beforeEach` for fresh state per test. */ + newScopeAt?: typeof beforeAll | typeof beforeEach +}) { + const { path, contracts, newScopeAt = beforeAll } = options const lazyCompile = createLazyCompiler(path, { outputArc56: true, outputBytecode: false }) const localnet = algorandFixture({ testAccountFunding: microAlgos(100_000_000_000), @@ -178,7 +206,7 @@ export function createArc4TestFixture( } } - const ctx: DeliberateAny = { localnet } + const ctx: DeliberateAny = {} for (const [contractName, config] of getContracts()) { ctx[`appSpec${contractName}`] = async ({ expect }: { expect: ExpectStatic }, use: Use) => { await use(await getAppSpec(expect, contractName)) @@ -212,7 +240,8 @@ export function createArc4TestFixture( } const extendedTest = algorandTestFixture(localnet).extend>(ctx) - return [extendedTest, localnet] as readonly [typeof extendedTest, AlgorandFixture] + newScopeAt(localnet.newScope) + return extendedTest } type CompilationArtifacts = {