Skip to content

Commit

Permalink
refactor: make parallel calls to avm in test to reduce wait time in t…
Browse files Browse the repository at this point in the history
…ests
  • Loading branch information
boblat committed Jan 3, 2025
1 parent 3b939fd commit db3c627
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 18 deletions.
6 changes: 2 additions & 4 deletions tests/primitives/uint64.spec.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import { AppSpec } from '@algorandfoundation/algokit-utils/types/app-spec'
import { internal, uint64, Uint64 } from '@algorandfoundation/algorand-typescript'
import { describe, expect, it } from 'vitest'
import { UINT64_OVERFLOW_UNDERFLOW_MESSAGE } from '../../src/constants'
import { MAX_UINT64, UINT64_OVERFLOW_UNDERFLOW_MESSAGE } from '../../src/constants'
import { asUint64 } from '../../src/util'
import appSpecJson from '../artifacts/primitive-ops/data/PrimitiveOpsContract.arc32.json'
import { getAlgorandAppClient, getAvmResult } from '../avm-invoker'

const MAX_UINT64 = 2n ** 64n - 1n
const asUint64 = (val: bigint | number) => (typeof val === 'bigint' ? Uint64(val) : Uint64(val))

describe('Unit64', async () => {
const appClient = await getAlgorandAppClient(appSpecJson as AppSpec)

Expand Down
40 changes: 26 additions & 14 deletions tests/state-op-codes.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@ describe('State op codes', async () => {
})

describe('AcctParams', async () => {
const appClient = await getAlgorandAppClient(acctParamsAppSpecJson as AppSpec)
const dummyAccount = await generateTestAccount()
const [appClient, dummyAccount] = await Promise.all([getAlgorandAppClient(acctParamsAppSpecJson as AppSpec), generateTestAccount()])

test.each([
['verify_acct_balance', INITIAL_BALANCE_MICRO_ALGOS + 100_000],
Expand Down Expand Up @@ -100,8 +99,11 @@ describe('State op codes', async () => {
})

describe('AppParams', async () => {
const [appClient, app] = await getAlgorandAppClientWithApp(appParamsAppSpecJson as AppSpec)
const dummyAccount = await getLocalNetDefaultAccount()
const [[appClient, app], dummyAccount] = await Promise.all([
getAlgorandAppClientWithApp(appParamsAppSpecJson as AppSpec),
getLocalNetDefaultAccount(),
])

test.each([
['verify_app_params_get_approval_program', undefined],
['verify_app_params_get_clear_state_program', undefined],
Expand Down Expand Up @@ -142,8 +144,11 @@ describe('State op codes', async () => {
})

describe('AssetHolding', async () => {
const appClient = await getAlgorandAppClient(assetHoldingAppSpecJson as AppSpec)
const dummyAccount = await getLocalNetDefaultAccount()
const [appClient, dummyAccount] = await Promise.all([
getAlgorandAppClient(assetHoldingAppSpecJson as AppSpec),
getLocalNetDefaultAccount(),
])

test.each([
['verify_asset_holding_get', 100],
['verify_asset_frozen_get', false],
Expand Down Expand Up @@ -174,8 +179,10 @@ describe('State op codes', async () => {
})

describe('AssetParams', async () => {
const appClient = await getAlgorandAppClient(assetParamsAppSpecJson as AppSpec)
const dummyAccount = await getLocalNetDefaultAccount()
const [appClient, dummyAccount] = await Promise.all([
getAlgorandAppClient(assetParamsAppSpecJson as AppSpec),
getLocalNetDefaultAccount(),
])

test.each([
['verify_asset_params_get_total', 100n],
Expand Down Expand Up @@ -437,8 +444,11 @@ describe('State op codes', async () => {
})

describe('AppGlobal', async () => {
const appClient = await getAlgorandAppClient(appGlobalAppSpecJson as AppSpec)
const [_exAppClient, exApp] = await getAlgorandAppClientWithApp(appGlobalExAppSpecJson as AppSpec)
const [appClient, [_exAppClient, exApp]] = await Promise.all([
getAlgorandAppClient(appGlobalAppSpecJson as AppSpec),
getAlgorandAppClientWithApp(appGlobalExAppSpecJson as AppSpec),
])

it('should be able to put, get and delete app global state', async () => {
const bytesKey = 'global_bytes'
const uint64Key = 'global_uint64'
Expand Down Expand Up @@ -510,10 +520,12 @@ describe('State op codes', async () => {
})

describe('AppLocal', async () => {
const appClient = await getAlgorandAppClient(appLocalAppSpecJson as AppSpec)
const [exAppClient, exApp] = await getAlgorandAppClientWithApp(appLocalExAppSpecJson as AppSpec)
await tryOptIn(appClient)
await tryOptIn(exAppClient)
const [appClient, [exAppClient, exApp]] = await Promise.all([
getAlgorandAppClient(appLocalAppSpecJson as AppSpec),
getAlgorandAppClientWithApp(appLocalExAppSpecJson as AppSpec),
])

await Promise.all([tryOptIn(appClient), tryOptIn(exAppClient)])

it('should be able to put, get and delete app local state', async () => {
const localNetAccount = await getLocalNetDefaultAccount()
Expand Down

0 comments on commit db3c627

Please sign in to comment.