testing
@algorandfoundation/algokit-utils / testing
Table of contents
Section titled “Table of contents”Classes
Section titled “Classes”Functions
Section titled “Functions”Functions
Section titled “Functions”algoKitLogCaptureFixture
Section titled “algoKitLogCaptureFixture”▸ algoKitLogCaptureFixture(): AlgoKitLogCaptureFixture
Creates a test fixture for capturing AlgoKit logs.
Returns
Section titled “Returns”The fixture
Example
const logs = algoKitLogCaptureFixture();
beforeEach(logs.beforeEach);afterEach(logs.afterEach);
test('My test', () => { const capturedLogs = logs.testLogger.capturedLogs;});Defined in
Section titled “Defined in”src/testing/fixtures/algokit-log-capture-fixture.ts:22
algorandFixture
Section titled “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 (or their respective config) if you want to test against an explicitly defined network.
Parameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
fixtureConfig? | AlgorandFixtureConfig | The fixture configuration |
Returns
Section titled “Returns”The fixture
Example
const fixture = algorandFixture()
beforeEach(fixture.newScope, 10_000)
test('My test', async () => { const {algod, indexer, testAccount, ...} = fixture.context // test things...})Example
const fixture = algorandFixture()
beforeAll(fixture.newScope, 10_000)
test('My test', async () => { const {algod, indexer, testAccount, ...} = fixture.context // test things...})Example
const fixture = algorandFixture({ algod: new Algodv2('localhost', 12345, 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'), // ...})
beforeEach(fixture.newScope, 10_000)
test('My test', async () => { const {algod, indexer, testAccount, ...} = fixture.context // test things...})Defined in
Section titled “Defined in”src/testing/fixtures/algorand-fixture.ts:60
▸ algorandFixture(fixtureConfig, config): AlgorandFixture
Parameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
fixtureConfig | undefined | AlgorandFixtureConfig | The fixture configuration |
config | AlgoConfig | The fixture configuration |
Returns
Section titled “Returns”The fixture
Deprecated
Config can be passed in directly to fixture config now.
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.
Defined in
Section titled “Defined in”src/testing/fixtures/algorand-fixture.ts:75
getTestAccount
Section titled “getTestAccount”▸ getTestAccount(params, algod, kmd?): Promise<Address & Account & TransactionSignerAccount>
Parameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
params | GetTestAccountParams | The config for the test account to generate |
algod | AlgodClient | An algod client |
kmd? | KmdClient | A KMD client, if not specified then a default KMD client will be loaded from environment variables and if not found fallback to the default LocalNet KMD client |
Returns
Section titled “Returns”Promise<Address & Account & TransactionSignerAccount>
The account, with private key loaded
Deprecated
Use getTestAccount(params, algorandClient) instead. The algorandClient object can be created using AlgorandClient.fromClients({ algod, kmd }).
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.
Defined in
Section titled “Defined in”▸ getTestAccount(params, algorand): Promise<Address & Account & TransactionSignerAccount>
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
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
params | GetTestAccountParams | The config for the test account to generate |
algorand | AlgorandClient | An AlgorandClient client |
Returns
Section titled “Returns”Promise<Address & Account & TransactionSignerAccount>
The account, with private key loaded
Defined in
Section titled “Defined in”runWhenIndexerCaughtUp
Section titled “runWhenIndexerCaughtUp”▸ runWhenIndexerCaughtUp<T>(run): Promise<T>
Runs the given indexer call until a 404 error is no longer returned. Tried every 200ms up to 100 times. Very rudimentary implementation designed for automated testing.
Type parameters
Section titled “Type parameters”| Name |
|---|
T |
Parameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
run | () => Promise<T> | The code to run |
Returns
Section titled “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());