Skip to content

Commit

Permalink
Merge main into release
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions[bot] authored Mar 22, 2024
2 parents 2f97657 + 5c2f221 commit e3c71df
Show file tree
Hide file tree
Showing 9 changed files with 82 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Testing framework agnostic handler method to run after each test to reset the lo

#### Defined in

[src/types/testing.ts:100](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/testing.ts#L100)
[src/types/testing.ts:104](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/testing.ts#L104)

___

Expand All @@ -53,7 +53,7 @@ Testing framework agnostic handler method to run before each test to prepare the

#### Defined in

[src/types/testing.ts:96](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/testing.ts#L96)
[src/types/testing.ts:100](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/testing.ts#L100)

## Accessors

Expand All @@ -69,4 +69,4 @@ The test logger instance for the current test

#### Defined in

[src/types/testing.ts:92](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/testing.ts#L92)
[src/types/testing.ts:96](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/testing.ts#L96)
4 changes: 2 additions & 2 deletions docs/code/interfaces/types_testing.AlgorandFixture.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Testing framework agnostic handler method to run before each test to prepare the

#### Defined in

[src/types/testing.ts:74](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/testing.ts#L74)
[src/types/testing.ts:78](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/testing.ts#L78)

## Accessors

Expand All @@ -59,4 +59,4 @@ test('My test', () => {

#### Defined in

[src/types/testing.ts:69](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/testing.ts#L69)
[src/types/testing.ts:73](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/testing.ts#L73)
36 changes: 32 additions & 4 deletions docs/code/interfaces/types_testing.AlgorandFixtureConfig.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,41 @@ Configuration for creating an Algorand testing fixture.

### Properties

- [accountGetter](types_testing.AlgorandFixtureConfig.md#accountgetter)
- [algod](types_testing.AlgorandFixtureConfig.md#algod)
- [indexer](types_testing.AlgorandFixtureConfig.md#indexer)
- [kmd](types_testing.AlgorandFixtureConfig.md#kmd)
- [testAccountFunding](types_testing.AlgorandFixtureConfig.md#testaccountfunding)

## Properties

### accountGetter

`Optional` **accountGetter**: (`algod`: `default`, `kmd?`: `default`) => `Promise`\<`default`\>

Optional override for how to get an account; this allows you to retrieve accounts from a known or cached list of accounts.

#### Type declaration

▸ (`algod`, `kmd?`): `Promise`\<`default`\>

##### Parameters

| Name | Type |
| :------ | :------ |
| `algod` | `default` |
| `kmd?` | `default` |

##### Returns

`Promise`\<`default`\>

#### Defined in

[src/types/testing.ts:58](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/testing.ts#L58)

___

### algod

`Optional` **algod**: `default`
Expand All @@ -25,7 +53,7 @@ An optional algod client, if not specified then it will create one against envir

#### Defined in

[src/types/testing.ts:48](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/testing.ts#L48)
[src/types/testing.ts:50](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/testing.ts#L50)

___

Expand All @@ -37,7 +65,7 @@ An optional indexer client, if not specified then it will create one against env

#### Defined in

[src/types/testing.ts:50](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/testing.ts#L50)
[src/types/testing.ts:52](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/testing.ts#L52)

___

Expand All @@ -49,7 +77,7 @@ An optional kmd client, if not specified then it will create one against environ

#### Defined in

[src/types/testing.ts:52](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/testing.ts#L52)
[src/types/testing.ts:54](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/testing.ts#L54)

___

Expand All @@ -61,4 +89,4 @@ The amount of funds to allocate to the default testing account, if not specified

#### Defined in

[src/types/testing.ts:54](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/testing.ts#L54)
[src/types/testing.ts:56](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/testing.ts#L56)
28 changes: 28 additions & 0 deletions docs/code/interfaces/types_testing.GetTestAccountParams.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,39 @@ Parameters for the `getTestAccount` function.

### Properties

- [accountGetter](types_testing.GetTestAccountParams.md#accountgetter)
- [initialFunds](types_testing.GetTestAccountParams.md#initialfunds)
- [suppressLog](types_testing.GetTestAccountParams.md#suppresslog)

## Properties

### accountGetter

`Optional` **accountGetter**: (`algod`: `default`, `kmd?`: `default`) => `Promise`\<`default`\>

Optional override for how to get an account; this allows you to retrieve accounts from a known or cached list of accounts.

#### Type declaration

▸ (`algod`, `kmd?`): `Promise`\<`default`\>

##### Parameters

| Name | Type |
| :------ | :------ |
| `algod` | `default` |
| `kmd?` | `default` |

##### Returns

`Promise`\<`default`\>

#### Defined in

[src/types/testing.ts:44](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/testing.ts#L44)

___

### initialFunds

**initialFunds**: [`AlgoAmount`](../classes/types_amount.AlgoAmount.md)
Expand Down
6 changes: 3 additions & 3 deletions docs/code/interfaces/types_testing.LogSnapshotConfig.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Any accounts/addresses to replace the address for predictably

#### Defined in

[src/types/testing.ts:85](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/testing.ts#L85)
[src/types/testing.ts:89](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/testing.ts#L89)

___

Expand All @@ -38,7 +38,7 @@ Any app IDs to replace predictably

#### Defined in

[src/types/testing.ts:87](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/testing.ts#L87)
[src/types/testing.ts:91](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/testing.ts#L91)

___

Expand All @@ -50,4 +50,4 @@ Any transaction IDs or transactions to replace the ID for predictably

#### Defined in

[src/types/testing.ts:83](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/testing.ts#L83)
[src/types/testing.ts:87](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/testing.ts#L87)
2 changes: 1 addition & 1 deletion jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const config: Config.InitialOptions = {
preset: 'ts-jest',
testEnvironment: 'node',
testMatch: ['**/*.spec.ts'],
testTimeout: 10000,
testTimeout: 20000,
bail: 1,
setupFiles: ['<rootDir>/tests/setup.ts'],
moduleDirectories: ['node_modules', 'src'],
Expand Down
8 changes: 6 additions & 2 deletions src/testing/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,12 @@ import Kmd = algosdk.Kmd
* @param kmd A KMD client, if not specified then a default KMD client will be loaded from environment variables
* @returns The account, with private key loaded
*/
export async function getTestAccount({ suppressLog, initialFunds }: GetTestAccountParams, algod: Algodv2, kmd?: Kmd): Promise<Account> {
const account = algosdk.generateAccount()
export async function getTestAccount(
{ suppressLog, initialFunds, accountGetter }: GetTestAccountParams,
algod: Algodv2,
kmd?: Kmd,
): Promise<Account> {
const account = accountGetter ? await accountGetter(algod, kmd) : algosdk.generateAccount()

Config.getLogger(suppressLog).info(
`New test account created with address '${account.addr}' and mnemonic '${algosdk.secretKeyToMnemonic(account.sk)}'.`,
Expand Down
5 changes: 3 additions & 2 deletions src/testing/fixtures/algorand-fixture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,12 @@ export function algorandFixture(fixtureConfig?: AlgorandFixtureConfig, config?:
indexer: indexer,
kmd: kmd,
testAccount: await getTestAccount(
{ initialFunds: fixtureConfig?.testAccountFunding ?? algos(10), suppressLog: true },
{ initialFunds: fixtureConfig?.testAccountFunding ?? algos(10), suppressLog: true, accountGetter: fixtureConfig?.accountGetter },
transactionLoggerAlgod,
kmd,
),
generateAccount: (params: GetTestAccountParams) => getTestAccount(params, transactionLoggerAlgod, kmd),
generateAccount: (params: GetTestAccountParams) =>
getTestAccount({ accountGetter: fixtureConfig?.accountGetter, ...params }, transactionLoggerAlgod, kmd),
transactionLogger: transactionLogger,
waitForIndexer: () => transactionLogger.waitForIndexer(indexer),
waitForIndexerTransaction: (transactionId: string) => runWhenIndexerCaughtUp(() => lookupTransactionById(transactionId, indexer)),
Expand Down
4 changes: 4 additions & 0 deletions src/types/testing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ export interface GetTestAccountParams {
initialFunds: AlgoAmount
/** Whether to suppress the log (which includes a mnemonic) or not (default: do not suppress the log) */
suppressLog?: boolean
/** Optional override for how to get an account; this allows you to retrieve accounts from a known or cached list of accounts. */
accountGetter?: (algod: Algodv2, kmd?: Kmd) => Promise<Account>
}

/** Configuration for creating an Algorand testing fixture. */
Expand All @@ -52,6 +54,8 @@ export interface AlgorandFixtureConfig {
kmd?: Kmd
/** The amount of funds to allocate to the default testing account, if not specified then it will get 10 ALGOs. */
testAccountFunding?: AlgoAmount
/** Optional override for how to get an account; this allows you to retrieve accounts from a known or cached list of accounts. */
accountGetter?: (algod: Algodv2, kmd?: Kmd) => Promise<Account>
}

/** An Algorand automated testing fixture */
Expand Down

0 comments on commit e3c71df

Please sign in to comment.