Module: testing

August 28, 2023 · View on GitHub

@algorandfoundation/algokit-utils / testing

Module: testing

Table of contents

Classes

Functions

Functions

algoKitLogCaptureFixture

algoKitLogCaptureFixture(): AlgoKitLogCaptureFixture

Creates a test fixture for capturing AlgoKit logs.

Returns

AlgoKitLogCaptureFixture

The fixture

Example

const logs = algoKitLogCaptureFixture()

beforeEach(logs.beforeEach)
afterEach(logs.afterEach)

test('My test', () => {
    const capturedLogs = logs.testLogger.capturedLogs
})

Defined in

src/testing/fixtures/algokit-log-capture-fixture.ts:21


algorandFixture

algorandFixture(fixtureConfig?): AlgorandFixture

Creates a test fixture for automated testing against Algorand. By default it tests against an environment variable specified client if the standard environment variables are specified, otherwise against a default LocalNet instance, but you can pass in an algod, indexer and/or kmd if you want to test against an explicitly defined network.

Parameters

NameTypeDescription
fixtureConfig?AlgorandFixtureConfigThe fixture configuration

Returns

AlgorandFixture

The fixture

Example

const algorand = algorandFixture()

beforeEach(algorand.beforeEach, 10_000)

test('My test', async () => {
    const {algod, indexer, testAccount, ...} = algorand.context
    // test things...
})

Defined in

src/testing/fixtures/algorand-fixture.ts:35

algorandFixture(fixtureConfig, config): AlgorandFixture

Creates a test fixture for automated testing against Algorand. By default it tests against an environment variable specified client if the standard environment variables are specified, otherwise against a default LocalNet instance, but you can pass in an algod, indexer and/or kmd if you want to test against an explicitly defined network.

Parameters

NameTypeDescription
fixtureConfigundefined | AlgorandFixtureConfigThe fixture configuration
configAlgoConfigThe algo configuration

Returns

AlgorandFixture

The fixture

Example

const algorand = algorandFixture(undefined, getConfigFromEnvOrDefaults())

beforeEach(algorand.beforeEach, 10_000)

test('My test', async () => {
    const {algod, indexer, testAccount, ...} = algorand.context
    // test things...
})

Defined in

src/testing/fixtures/algorand-fixture.ts:59


getTestAccount

getTestAccount(param0, algod, kmd?): Promise<Account>

Creates an ephemeral Algorand account for the purposes of testing. Returns a newly created random test account that is funded from the dispenser DO NOT USE THIS TO CREATE A MAINNET ACCOUNT! Note: By default this will log the mnemonic of the account.

Parameters

NameTypeDescription
param0GetTestAccountParamsThe config for the test account to generate
algoddefaultAn algod client
kmd?defaultA KMD client, if not specified then a default KMD client will be loaded from environment variables

Returns

Promise<Account>

The account, with private key loaded

Defined in

src/testing/account.ts:17


runWhenIndexerCaughtUp

runWhenIndexerCaughtUp<T>(run): Promise<T>

Runs the given indexer call until a 404 error is no longer returned. Tried every 200ms up to 20 times. Very rudimentary implementation designed for automated testing.

Type parameters

Name
T

Parameters

NameTypeDescription
run() => Promise<T>The code to run

Returns

Promise<T>

The result (as a promise), or throws if the indexer didn't catch up in time

Example

const transaction = await runWhenIndexerCaughtUp(() => indexer.lookupTransactionByID(txnId).do())

Defined in

src/testing/indexer.ts:11