@algorandfoundation/algokit-utils 1.0.0-beta.8 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (141) hide show
  1. package/account.d.ts +91 -0
  2. package/account.d.ts.map +1 -0
  3. package/account.js +158 -0
  4. package/account.js.map +1 -0
  5. package/amount.d.ts +8 -0
  6. package/amount.d.ts.map +1 -0
  7. package/amount.js +24 -0
  8. package/amount.js.map +1 -0
  9. package/app.d.ts +108 -0
  10. package/app.d.ts.map +1 -0
  11. package/app.js +423 -0
  12. package/app.js.map +1 -0
  13. package/application-client.d.ts +10 -0
  14. package/application-client.d.ts.map +1 -0
  15. package/application-client.js +15 -0
  16. package/application-client.js.map +1 -0
  17. package/deploy-app.d.ts +93 -0
  18. package/deploy-app.d.ts.map +1 -0
  19. package/deploy-app.js +410 -0
  20. package/deploy-app.js.map +1 -0
  21. package/index.d.ts +14 -0
  22. package/index.d.ts.map +1 -0
  23. package/index.js +5 -2
  24. package/index.js.map +1 -0
  25. package/indexer-lookup.d.ts +31 -0
  26. package/indexer-lookup.d.ts.map +1 -0
  27. package/indexer-lookup.js +96 -0
  28. package/indexer-lookup.js.map +1 -0
  29. package/localnet.d.ts +54 -0
  30. package/localnet.d.ts.map +1 -0
  31. package/localnet.js +121 -0
  32. package/localnet.js.map +1 -0
  33. package/network-client.d.ts +93 -0
  34. package/network-client.d.ts.map +1 -0
  35. package/network-client.js +182 -0
  36. package/network-client.js.map +1 -0
  37. package/package.json +3 -3
  38. package/testing/account.d.ts +14 -0
  39. package/testing/account.d.ts.map +1 -0
  40. package/testing/account.js +31 -0
  41. package/testing/account.js.map +1 -0
  42. package/testing/fixtures/algokit-log-capture-fixture.d.ts +19 -0
  43. package/testing/fixtures/algokit-log-capture-fixture.d.ts.map +1 -0
  44. package/testing/fixtures/algokit-log-capture-fixture.js +43 -0
  45. package/testing/fixtures/algokit-log-capture-fixture.js.map +1 -0
  46. package/testing/fixtures/algorand-fixture.d.ts +20 -0
  47. package/testing/fixtures/algorand-fixture.d.ts.map +1 -0
  48. package/testing/fixtures/algorand-fixture.js +49 -0
  49. package/testing/fixtures/algorand-fixture.js.map +1 -0
  50. package/testing/fixtures/index.d.ts +3 -0
  51. package/testing/fixtures/index.d.ts.map +1 -0
  52. package/testing/fixtures/index.js +19 -0
  53. package/testing/fixtures/index.js.map +1 -0
  54. package/testing/index.d.ts +6 -0
  55. package/testing/index.d.ts.map +1 -0
  56. package/testing/index.js +22 -0
  57. package/testing/index.js.map +1 -0
  58. package/testing/indexer.d.ts +12 -0
  59. package/testing/indexer.d.ts.map +1 -0
  60. package/testing/indexer.js +39 -0
  61. package/testing/indexer.js.map +1 -0
  62. package/testing/test-logger.d.ts +39 -0
  63. package/testing/test-logger.d.ts.map +1 -0
  64. package/testing/test-logger.js +69 -0
  65. package/testing/test-logger.js.map +1 -0
  66. package/testing/transaction-logger.d.ts +29 -0
  67. package/testing/transaction-logger.d.ts.map +1 -0
  68. package/testing/transaction-logger.js +71 -0
  69. package/testing/transaction-logger.js.map +1 -0
  70. package/transaction.d.ts +80 -0
  71. package/transaction.d.ts.map +1 -0
  72. package/transaction.js +256 -0
  73. package/transaction.js.map +1 -0
  74. package/transfer.d.ts +21 -0
  75. package/transfer.d.ts.map +1 -0
  76. package/transfer.js +65 -0
  77. package/transfer.js.map +1 -0
  78. package/types/account.d.ts +52 -0
  79. package/types/account.d.ts.map +1 -0
  80. package/types/account.js +86 -0
  81. package/types/account.js.map +1 -0
  82. package/types/algo-http-client-with-retry.d.ts +14 -0
  83. package/types/algo-http-client-with-retry.d.ts.map +1 -0
  84. package/types/algo-http-client-with-retry.js +62 -0
  85. package/types/algo-http-client-with-retry.js.map +1 -0
  86. package/types/algod.d.ts +137 -0
  87. package/types/algod.d.ts.map +1 -0
  88. package/types/algod.js +3 -0
  89. package/types/algod.js.map +1 -0
  90. package/types/amount.d.ts +20 -0
  91. package/types/amount.d.ts.map +1 -0
  92. package/types/amount.js +37 -0
  93. package/types/amount.js.map +1 -0
  94. package/types/app.d.ts +279 -0
  95. package/types/app.d.ts.map +1 -0
  96. package/types/app.js +32 -0
  97. package/types/app.js.map +1 -0
  98. package/types/application-client.d.ts +229 -0
  99. package/types/application-client.d.ts.map +1 -0
  100. package/types/application-client.js +470 -0
  101. package/types/application-client.js.map +1 -0
  102. package/types/appspec.d.ts +77 -0
  103. package/types/appspec.d.ts.map +1 -0
  104. package/types/appspec.js +15 -0
  105. package/types/appspec.js.map +1 -0
  106. package/types/config.d.ts +15 -0
  107. package/types/config.d.ts.map +1 -0
  108. package/types/config.js +27 -0
  109. package/types/config.js.map +1 -0
  110. package/types/indexer.d.ts +313 -0
  111. package/types/indexer.d.ts.map +1 -0
  112. package/types/indexer.js +25 -0
  113. package/types/indexer.js.map +1 -0
  114. package/types/logging.d.ts +13 -0
  115. package/types/logging.d.ts.map +1 -0
  116. package/types/logging.js +27 -0
  117. package/types/logging.js.map +1 -0
  118. package/types/logic-error.d.ts +33 -0
  119. package/types/logic-error.d.ts.map +1 -0
  120. package/types/logic-error.js +46 -0
  121. package/types/logic-error.js.map +1 -0
  122. package/types/network-client.d.ts +11 -0
  123. package/types/network-client.d.ts.map +1 -0
  124. package/types/network-client.js +3 -0
  125. package/types/network-client.js.map +1 -0
  126. package/types/testing.d.ts +89 -0
  127. package/types/testing.d.ts.map +1 -0
  128. package/types/testing.js +3 -0
  129. package/types/testing.js.map +1 -0
  130. package/types/transaction.d.ts +67 -0
  131. package/types/transaction.d.ts.map +1 -0
  132. package/types/transaction.js +3 -0
  133. package/types/transaction.js.map +1 -0
  134. package/types/transfer.d.ts +32 -0
  135. package/types/transfer.d.ts.map +1 -0
  136. package/types/transfer.js +3 -0
  137. package/types/transfer.js.map +1 -0
  138. package/types/urlTokenBaseHTTPClient.d.ts +41 -0
  139. package/types/urlTokenBaseHTTPClient.d.ts.map +1 -0
  140. package/types/urlTokenBaseHTTPClient.js +151 -0
  141. package/types/urlTokenBaseHTTPClient.js.map +1 -0
package/localnet.d.ts ADDED
@@ -0,0 +1,54 @@
1
+ import { Account, Algodv2, Kmd } from 'algosdk';
2
+ import { AlgoAmount } from './types/amount';
3
+ /** Returns true if the algod client is pointing to a LocalNet Algorand network */
4
+ export declare function isLocalNet(algod: Algodv2): Promise<boolean>;
5
+ /**
6
+ * Gets an account with private key loaded from a KMD wallet of the given name, or alternatively creates one with funds in it via a KMD wallet of the given name.
7
+ *
8
+ * This is useful to get idempotent accounts from a local sandbox without having to specify the private key (which will change when resetting the sandbox).
9
+ *
10
+ * This significantly speeds up local dev time and improves experience since you can write code that *just works* first go without manual config in a fresh sandbox.
11
+ *
12
+ * If this is used via @see {getAccount}, then you can even use the same code that runs on production without changes for local development!
13
+ *
14
+ * @param walletAccount The wallet details with:
15
+ * * `name`: The name of the wallet to retrieve / create
16
+ * * `fundWith`: The number of Algos to fund the account with it it gets created, if not specified then 1000 Algos will be funded from the dispenser account @see {getDispenserAccount}
17
+ * @param algod An algod client
18
+ * @param kmdClient A KMD client, if not specified then a default KMD client will be loaded from environment variables @see {getAlgoKmdClient}
19
+ *
20
+ * @returns An Algorand account with private key loaded - either one that already existed in the given KMD wallet, or a new one that is funded for you
21
+ */
22
+ export declare function getOrCreateKmdWalletAccount(walletAccount: {
23
+ name: string;
24
+ fundWith?: AlgoAmount;
25
+ }, algod: Algodv2, kmdClient?: Kmd): Promise<Account>;
26
+ /**
27
+ * Returns an Algorand account with private key loaded from the given KMD wallet (identified by name).
28
+ *
29
+ * @param walletAccount The details of the wallet, with:
30
+ * * `name`: The name of the wallet to retrieve an account from
31
+ * * `predicate`: An optional filter to use to find the account (otherwise it will return a random account from the wallet)
32
+ * @param algod An algod client
33
+ * @param kmdClient A KMD client, if not specified then a default KMD client will be loaded from environment variables @see {getAlgoKmdClient}
34
+ * @example Get default funded account in a LocalNet
35
+ *
36
+ * ```typescript
37
+ * const defaultDispenserAccount = await getKmdWalletAccount(algod,
38
+ * 'unencrypted-default-wallet',
39
+ * a => a.status !== 'Offline' && a.amount > 1_000_000_000
40
+ * )
41
+ * ```
42
+ */
43
+ export declare function getKmdWalletAccount(walletAccount: {
44
+ name: string;
45
+ predicate?: (account: Record<string, any>) => boolean;
46
+ }, algod: Algodv2, kmdClient?: Kmd): Promise<Account | undefined>;
47
+ /**
48
+ * Returns an Algorand account with private key loaded for the default LocalNet dispenser account (that can be used to fund other accounts)
49
+ *
50
+ * @param algod An algod client
51
+ * @param kmd A KMD client, if not specified then a default KMD client will be loaded from environment variables @see {getAlgoKmdClient}
52
+ */
53
+ export declare function getLocalNetDispenserAccount(algod: Algodv2, kmd?: Kmd): Promise<Account>;
54
+ //# sourceMappingURL=localnet.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"localnet.d.ts","sourceRoot":"","sources":["../src/localnet.ts"],"names":[],"mappings":"AAAA,OAAgB,EAAE,OAAO,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,SAAS,CAAA;AAKxD,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAE3C,kFAAkF;AAClF,wBAAsB,UAAU,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAIjE;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAsB,2BAA2B,CAC/C,aAAa,EAAE;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,EAAE,UAAU,CAAA;CAAE,EACtD,KAAK,EAAE,OAAO,EACd,SAAS,CAAC,EAAE,GAAG,GACd,OAAO,CAAC,OAAO,CAAC,CAmClB;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAsB,mBAAmB,CACvC,aAAa,EAAE;IACb,IAAI,EAAE,MAAM,CAAA;IAEZ,SAAS,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,KAAK,OAAO,CAAA;CACtD,EACD,KAAK,EAAE,OAAO,EACd,SAAS,CAAC,EAAE,GAAG,GACd,OAAO,CAAC,OAAO,GAAG,SAAS,CAAC,CAmC9B;AAED;;;;;GAKG;AACH,wBAAsB,2BAA2B,CAAC,KAAK,EAAE,OAAO,EAAE,GAAG,CAAC,EAAE,GAAG,GAAG,OAAO,CAAC,OAAO,CAAC,CAW7F"}
package/localnet.js ADDED
@@ -0,0 +1,121 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.getLocalNetDispenserAccount = exports.getKmdWalletAccount = exports.getOrCreateKmdWalletAccount = exports.isLocalNet = void 0;
7
+ const algosdk_1 = __importDefault(require("algosdk"));
8
+ const _1 = require("./");
9
+ const account_1 = require("./account");
10
+ const network_client_1 = require("./network-client");
11
+ const transfer_1 = require("./transfer");
12
+ const amount_1 = require("./types/amount");
13
+ /** Returns true if the algod client is pointing to a LocalNet Algorand network */
14
+ async function isLocalNet(algod) {
15
+ const params = await algod.getTransactionParams().do();
16
+ return params.genesisID === 'devnet-v1' || params.genesisID === 'sandnet-v1';
17
+ }
18
+ exports.isLocalNet = isLocalNet;
19
+ /**
20
+ * Gets an account with private key loaded from a KMD wallet of the given name, or alternatively creates one with funds in it via a KMD wallet of the given name.
21
+ *
22
+ * This is useful to get idempotent accounts from a local sandbox without having to specify the private key (which will change when resetting the sandbox).
23
+ *
24
+ * This significantly speeds up local dev time and improves experience since you can write code that *just works* first go without manual config in a fresh sandbox.
25
+ *
26
+ * If this is used via @see {getAccount}, then you can even use the same code that runs on production without changes for local development!
27
+ *
28
+ * @param walletAccount The wallet details with:
29
+ * * `name`: The name of the wallet to retrieve / create
30
+ * * `fundWith`: The number of Algos to fund the account with it it gets created, if not specified then 1000 Algos will be funded from the dispenser account @see {getDispenserAccount}
31
+ * @param algod An algod client
32
+ * @param kmdClient A KMD client, if not specified then a default KMD client will be loaded from environment variables @see {getAlgoKmdClient}
33
+ *
34
+ * @returns An Algorand account with private key loaded - either one that already existed in the given KMD wallet, or a new one that is funded for you
35
+ */
36
+ async function getOrCreateKmdWalletAccount(walletAccount, algod, kmdClient) {
37
+ const kmd = kmdClient ?? (0, network_client_1.getAlgoKmdClient)();
38
+ // Get an existing account from the KMD wallet
39
+ const existing = await getKmdWalletAccount(walletAccount, algod, kmd);
40
+ if (existing) {
41
+ return existing;
42
+ }
43
+ // None existed: create the KMD wallet instead
44
+ const walletId = (await kmd.createWallet(walletAccount.name, '')).wallet.id;
45
+ const walletHandle = (await kmd.initWalletHandle(walletId, '')).wallet_handle_token;
46
+ await kmd.generateKey(walletHandle);
47
+ // Get the account from the new KMD wallet
48
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
49
+ const account = (await getKmdWalletAccount(walletAccount, algod, kmd));
50
+ _1.Config.logger.info(`LocalNet account '${walletAccount.name}' doesn't yet exist; created account ${account.addr} with keys stored in KMD and funding with ${walletAccount.fundWith?.algos ?? 1000} ALGOs`);
51
+ // Fund the account from the dispenser
52
+ await (0, transfer_1.transferAlgos)({
53
+ amount: walletAccount.fundWith ?? amount_1.AlgoAmount.Algos(1000),
54
+ from: await (0, account_1.getDispenserAccount)(algod, kmd),
55
+ to: account.addr,
56
+ }, algod);
57
+ return account;
58
+ }
59
+ exports.getOrCreateKmdWalletAccount = getOrCreateKmdWalletAccount;
60
+ /**
61
+ * Returns an Algorand account with private key loaded from the given KMD wallet (identified by name).
62
+ *
63
+ * @param walletAccount The details of the wallet, with:
64
+ * * `name`: The name of the wallet to retrieve an account from
65
+ * * `predicate`: An optional filter to use to find the account (otherwise it will return a random account from the wallet)
66
+ * @param algod An algod client
67
+ * @param kmdClient A KMD client, if not specified then a default KMD client will be loaded from environment variables @see {getAlgoKmdClient}
68
+ * @example Get default funded account in a LocalNet
69
+ *
70
+ * ```typescript
71
+ * const defaultDispenserAccount = await getKmdWalletAccount(algod,
72
+ * 'unencrypted-default-wallet',
73
+ * a => a.status !== 'Offline' && a.amount > 1_000_000_000
74
+ * )
75
+ * ```
76
+ */
77
+ async function getKmdWalletAccount(walletAccount, algod, kmdClient) {
78
+ const { name, predicate } = walletAccount;
79
+ const kmd = kmdClient ?? (0, network_client_1.getAlgoKmdClient)();
80
+ const wallets = await kmd.listWallets();
81
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
82
+ const wallet = wallets.wallets.filter((w) => w.name === name);
83
+ if (wallet.length === 0) {
84
+ return undefined;
85
+ }
86
+ const walletId = wallet[0].id;
87
+ const walletHandle = (await kmd.initWalletHandle(walletId, '')).wallet_handle_token;
88
+ const keyIds = (await kmd.listKeys(walletHandle)).addresses;
89
+ let i = 0;
90
+ if (predicate) {
91
+ for (i = 0; i < keyIds.length; i++) {
92
+ const key = keyIds[i];
93
+ const account = await algod.accountInformation(key).do();
94
+ if (predicate(account)) {
95
+ break;
96
+ }
97
+ }
98
+ }
99
+ if (i >= keyIds.length) {
100
+ return undefined;
101
+ }
102
+ const accountKey = (await kmd.exportKey(walletHandle, '', keyIds[i])).private_key;
103
+ const accountMnemonic = algosdk_1.default.secretKeyToMnemonic(accountKey);
104
+ return (0, account_1.mnemonicAccount)(accountMnemonic);
105
+ }
106
+ exports.getKmdWalletAccount = getKmdWalletAccount;
107
+ /**
108
+ * Returns an Algorand account with private key loaded for the default LocalNet dispenser account (that can be used to fund other accounts)
109
+ *
110
+ * @param algod An algod client
111
+ * @param kmd A KMD client, if not specified then a default KMD client will be loaded from environment variables @see {getAlgoKmdClient}
112
+ */
113
+ async function getLocalNetDispenserAccount(algod, kmd) {
114
+ if (!(await isLocalNet(algod))) {
115
+ throw "Can't get default account from non LocalNet network";
116
+ }
117
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
118
+ return (await getKmdWalletAccount({ name: 'unencrypted-default-wallet', predicate: (a) => a.status !== 'Offline' && a.amount > 1000000000 }, algod, kmd));
119
+ }
120
+ exports.getLocalNetDispenserAccount = getLocalNetDispenserAccount;
121
+ //# sourceMappingURL=localnet.js.map
@@ -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rieve the algod configuration from environment variables (expects to be called from a Node.js environment not algod-side) */
4
+ export declare function getAlgodConfigFromEnvironment(): AlgoClientConfig;
5
+ /** Retrieve the indexer configuration from environment variables (expects to be called from a Node.js environment not algod-side) */
6
+ export declare function getIndexerConfigFromEnvironment(): AlgoClientConfig;
7
+ /** Returns the Algorand configuration to point to the AlgoNode service
8
+ *
9
+ * @param network Which network to connect to - TestNet or MainNet
10
+ * @param config Which algod config to return - Algod or Indexer
11
+ */
12
+ export declare function getAlgoNodeConfig(network: 'testnet' | 'mainnet', config: 'algod' | 'indexer'): AlgoClientConfig;
13
+ /** Returns the Algorand configuration to point to the default LocalNet
14
+ *
15
+ * @param configOrPort Which algod config to return - algod, kmd, or indexer OR a port number
16
+ */
17
+ export declare function getDefaultLocalNetConfig(configOrPort: 'algod' | 'indexer' | 'kmd' | number): AlgoClientConfig;
18
+ /** Returns an algod SDK client that automatically retries on idempotent calls
19
+ *
20
+ * @param config The config if you want to override the default (getting config from process.env)
21
+ * @example Default (load from environment variables)
22
+ *
23
+ * ```typescript
24
+ * // Uses process.env.ALGOD_SERVER, process.env.ALGOD_PORT and process.env.ALGOD_TOKEN
25
+ * // Automatically detects if you are using PureStake to switch in the right header name for ALGOD_TOKEN
26
+ * const algod = getAlgoClient()
27
+ * await algod.healthCheck().do()
28
+ * ```
29
+ * @example AlgoNode (testnet)
30
+ * ```typescript
31
+ * const algod = getAlgoClient(getAlgoNodeConfig('testnet', 'algod'))
32
+ * await algod.healthCheck().do()
33
+ * ```
34
+ * @example AlgoNode (mainnet)
35
+ * ```typescript
36
+ * const algod = getAlgoClient(getAlgoNodeConfig('mainnet', 'algod'))
37
+ * await algod.healthCheck().do()
38
+ * ```
39
+ * @example Custom (e.g. default local sandbox, although we recommend loading this into a .env and using the Default option instead)
40
+ * ```typescript
41
+ * const algod = getAlgoClient({server: 'http://localhost', port: '4001', token: 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'})
42
+ * await algod.healthCheck().do()
43
+ * ```
44
+ */
45
+ export declare function getAlgoClient(config?: AlgoClientConfig): Algodv2;
46
+ /** Returns an indexer SDK client that automatically retries on idempotent calls
47
+ *
48
+ * @param config The config if you want to override the default (getting config from process.env)
49
+ * @example Default (load from environment variables)
50
+ *
51
+ * ```typescript
52
+ * // Uses process.env.INDEXER_SERVER, process.env.INDEXER_PORT and process.env.INDEXER_TOKEN
53
+ * // Automatically detects if you are using PureStake to switch in the right header name for INDEXER_TOKEN
54
+ * const indexer = getAlgoIndexerClient()
55
+ * await indexer.makeHealthCheck().do()
56
+ * ```
57
+ * @example AlgoNode (testnet)
58
+ * ```typescript
59
+ * const indexer = getAlgoIndexerClient(getAlgoNodeConfig('testnet', 'indexer'))
60
+ * await indexer.makeHealthCheck().do()
61
+ * ```
62
+ * @example AlgoNode (mainnet)
63
+ * ```typescript
64
+ * const indexer = getAlgoIndexerClient(getAlgoNodeConfig('mainnet', 'indexer'))
65
+ * await indexer.makeHealthCheck().do()
66
+ * ```
67
+ * @example Custom (e.g. default local sandbox, although we recommend loading this into a .env and using the Default option instead)
68
+ * ```typescript
69
+ * const indexer = getAlgoIndexerClient({server: 'http://localhost', port: '8980', token: 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'})
70
+ * await indexer.makeHealthCheck().do()
71
+ * ```
72
+ */
73
+ export declare function getAlgoIndexerClient(config?: AlgoClientConfig): Indexer;
74
+ /**
75
+ * Returns a KMD SDK client that automatically retries on idempotent calls
76
+ *
77
+ * KMD client allows you to export private keys, which is useful to get the default account in a sandbox network.
78
+ *
79
+ * @param config The config if you want to override the default (getting config from process.env)
80
+ * @example Default (load from environment variables)
81
+ *
82
+ * ```typescript
83
+ * // Uses process.env.ALGOD_SERVER, process.env.KMD_PORT (or if not specified: port 4002) and process.env.ALGOD_TOKEN
84
+ * const kmd = getAlgoKmdClient()
85
+ * ```
86
+ * @example Custom (e.g. default local sandbox, although we recommend loading this into a .env and using the Default option instead)
87
+ * ```typescript
88
+ * const kmd = getAlgoKmdClient({server: 'http://localhost', port: '4002', token: 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'})
89
+ * ```
90
+ */
91
+ export declare function getAlgoKmdClient(config?: AlgoClientConfig): Kmd;
92
+ export { isLocalNet } from './localnet';
93
+ //# sourceMappingURL=network-client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"network-client.d.ts","sourceRoot":"","sources":["../src/network-client.ts"],"names":[],"mappings":"AAAA,OAAgB,EAAE,OAAO,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,SAAS,CAAA;AAGxD,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAA;AAEzD,mIAAmI;AACnI,wBAAgB,6BAA6B,IAAI,gBAAgB,CAchE;AAED,qIAAqI;AACrI,wBAAgB,+BAA+B,IAAI,gBAAgB,CAclE;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,SAAS,GAAG,SAAS,EAAE,MAAM,EAAE,OAAO,GAAG,SAAS,GAAG,gBAAgB,CAK/G;AAED;;;GAGG;AACH,wBAAgB,wBAAwB,CAAC,YAAY,EAAE,OAAO,GAAG,SAAS,GAAG,KAAK,GAAG,MAAM,GAAG,gBAAgB,CAM7G;AAUD;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,wBAAgB,aAAa,CAAC,MAAM,CAAC,EAAE,gBAAgB,GAAG,OAAO,CAIhE;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,CAAC,EAAE,gBAAgB,GAAG,OAAO,CAIvE;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,CAAC,EAAE,gBAAgB,GAAG,GAAG,CAK/D;AAED,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA"}
@@ -0,0 +1,182 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.isLocalNet = exports.getAlgoKmdClient = exports.getAlgoIndexerClient = exports.getAlgoClient = exports.getDefaultLocalNetConfig = exports.getAlgoNodeConfig = exports.getIndexerConfigFromEnvironment = exports.getAlgodConfigFromEnvironment = void 0;
27
+ const algosdk_1 = __importStar(require("algosdk"));
28
+ const algo_http_client_with_retry_1 = require("./types/algo-http-client-with-retry");
29
+ /** Retrieve the algod configuration from environment variables (expects to be called from a Node.js environment not algod-side) */
30
+ function getAlgodConfigFromEnvironment() {
31
+ if (!process || !process.env) {
32
+ throw new Error('Attempt to get default algod configuration from a non Node.js context; supply the config instead');
33
+ }
34
+ if (!process.env.ALGOD_SERVER) {
35
+ throw new Error('Attempt to get default algod configuration without specifying ALGOD_SERVER in the environment variables');
36
+ }
37
+ return {
38
+ server: process.env.ALGOD_SERVER,
39
+ port: process.env.ALGOD_PORT,
40
+ token: process.env.ALGOD_TOKEN,
41
+ };
42
+ }
43
+ exports.getAlgodConfigFromEnvironment = getAlgodConfigFromEnvironment;
44
+ /** Retrieve the indexer configuration from environment variables (expects to be called from a Node.js environment not algod-side) */
45
+ function getIndexerConfigFromEnvironment() {
46
+ if (!process || !process.env) {
47
+ throw new Error('Attempt to get default indexer configuration from a non Node.js context; supply the config instead');
48
+ }
49
+ if (!process.env.INDEXER_SERVER) {
50
+ throw new Error('Attempt to get default indexer configuration without specifying INDEXER_SERVER in the environment variables');
51
+ }
52
+ return {
53
+ server: process.env.INDEXER_SERVER,
54
+ port: process.env.INDEXER_PORT,
55
+ token: process.env.INDEXER_TOKEN,
56
+ };
57
+ }
58
+ exports.getIndexerConfigFromEnvironment = getIndexerConfigFromEnvironment;
59
+ /** Returns the Algorand configuration to point to the AlgoNode service
60
+ *
61
+ * @param network Which network to connect to - TestNet or MainNet
62
+ * @param config Which algod config to return - Algod or Indexer
63
+ */
64
+ function getAlgoNodeConfig(network, config) {
65
+ return {
66
+ server: `https://${network}-${config === 'algod' ? 'api' : 'idx'}.algonode.cloud/`,
67
+ port: 443,
68
+ };
69
+ }
70
+ exports.getAlgoNodeConfig = getAlgoNodeConfig;
71
+ /** Returns the Algorand configuration to point to the default LocalNet
72
+ *
73
+ * @param configOrPort Which algod config to return - algod, kmd, or indexer OR a port number
74
+ */
75
+ function getDefaultLocalNetConfig(configOrPort) {
76
+ return {
77
+ server: `http://localhost`,
78
+ port: configOrPort === 'algod' ? 4001 : configOrPort === 'indexer' ? 8980 : configOrPort === 'kmd' ? 4002 : configOrPort,
79
+ token: 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa',
80
+ };
81
+ }
82
+ exports.getDefaultLocalNetConfig = getDefaultLocalNetConfig;
83
+ function getAlgoTokenHeader(server, token, defaultHeader) {
84
+ // Purestake uses a slightly different API key header than the default
85
+ if (server.includes('purestake.io') && typeof token === 'string')
86
+ return { 'X-API-Key': token };
87
+ // Because we override the default HTTP Client construction (to get retries) we need to put a string token into the standard header ourselves
88
+ return typeof token === 'string' ? { [defaultHeader ?? 'X-Algo-API-Token']: token } : token ?? {};
89
+ }
90
+ /** Returns an algod SDK client that automatically retries on idempotent calls
91
+ *
92
+ * @param config The config if you want to override the default (getting config from process.env)
93
+ * @example Default (load from environment variables)
94
+ *
95
+ * ```typescript
96
+ * // Uses process.env.ALGOD_SERVER, process.env.ALGOD_PORT and process.env.ALGOD_TOKEN
97
+ * // Automatically detects if you are using PureStake to switch in the right header name for ALGOD_TOKEN
98
+ * const algod = getAlgoClient()
99
+ * await algod.healthCheck().do()
100
+ * ```
101
+ * @example AlgoNode (testnet)
102
+ * ```typescript
103
+ * const algod = getAlgoClient(getAlgoNodeConfig('testnet', 'algod'))
104
+ * await algod.healthCheck().do()
105
+ * ```
106
+ * @example AlgoNode (mainnet)
107
+ * ```typescript
108
+ * const algod = getAlgoClient(getAlgoNodeConfig('mainnet', 'algod'))
109
+ * await algod.healthCheck().do()
110
+ * ```
111
+ * @example Custom (e.g. default local sandbox, although we recommend loading this into a .env and using the Default option instead)
112
+ * ```typescript
113
+ * const algod = getAlgoClient({server: 'http://localhost', port: '4001', token: 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'})
114
+ * await algod.healthCheck().do()
115
+ * ```
116
+ */
117
+ function getAlgoClient(config) {
118
+ const { token, server, port } = config ?? getAlgodConfigFromEnvironment();
119
+ const httpClientWithRetry = new algo_http_client_with_retry_1.AlgoHttpClientWithRetry(getAlgoTokenHeader(server, token), server, port);
120
+ return new algosdk_1.default.Algodv2(httpClientWithRetry, server);
121
+ }
122
+ exports.getAlgoClient = getAlgoClient;
123
+ /** Returns an indexer SDK client that automatically retries on idempotent calls
124
+ *
125
+ * @param config The config if you want to override the default (getting config from process.env)
126
+ * @example Default (load from environment variables)
127
+ *
128
+ * ```typescript
129
+ * // Uses process.env.INDEXER_SERVER, process.env.INDEXER_PORT and process.env.INDEXER_TOKEN
130
+ * // Automatically detects if you are using PureStake to switch in the right header name for INDEXER_TOKEN
131
+ * const indexer = getAlgoIndexerClient()
132
+ * await indexer.makeHealthCheck().do()
133
+ * ```
134
+ * @example AlgoNode (testnet)
135
+ * ```typescript
136
+ * const indexer = getAlgoIndexerClient(getAlgoNodeConfig('testnet', 'indexer'))
137
+ * await indexer.makeHealthCheck().do()
138
+ * ```
139
+ * @example AlgoNode (mainnet)
140
+ * ```typescript
141
+ * const indexer = getAlgoIndexerClient(getAlgoNodeConfig('mainnet', 'indexer'))
142
+ * await indexer.makeHealthCheck().do()
143
+ * ```
144
+ * @example Custom (e.g. default local sandbox, although we recommend loading this into a .env and using the Default option instead)
145
+ * ```typescript
146
+ * const indexer = getAlgoIndexerClient({server: 'http://localhost', port: '8980', token: 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'})
147
+ * await indexer.makeHealthCheck().do()
148
+ * ```
149
+ */
150
+ function getAlgoIndexerClient(config) {
151
+ const { token, server, port } = config ?? getIndexerConfigFromEnvironment();
152
+ const httpClientWithRetry = new algo_http_client_with_retry_1.AlgoHttpClientWithRetry(getAlgoTokenHeader(server, token, 'X-Indexer-API-Token'), server, port);
153
+ return new algosdk_1.Indexer(httpClientWithRetry);
154
+ }
155
+ exports.getAlgoIndexerClient = getAlgoIndexerClient;
156
+ /**
157
+ * Returns a KMD SDK client that automatically retries on idempotent calls
158
+ *
159
+ * KMD client allows you to export private keys, which is useful to get the default account in a sandbox network.
160
+ *
161
+ * @param config The config if you want to override the default (getting config from process.env)
162
+ * @example Default (load from environment variables)
163
+ *
164
+ * ```typescript
165
+ * // Uses process.env.ALGOD_SERVER, process.env.KMD_PORT (or if not specified: port 4002) and process.env.ALGOD_TOKEN
166
+ * const kmd = getAlgoKmdClient()
167
+ * ```
168
+ * @example Custom (e.g. default local sandbox, although we recommend loading this into a .env and using the Default option instead)
169
+ * ```typescript
170
+ * const kmd = getAlgoKmdClient({server: 'http://localhost', port: '4002', token: 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'})
171
+ * ```
172
+ */
173
+ function getAlgoKmdClient(config) {
174
+ const { token, server } = config ?? getAlgodConfigFromEnvironment();
175
+ // We can only use Kmd on the Sandbox otherwise it's not exposed so this makes some assumptions
176
+ // (e.g. same token and server as algod and port 4002 by default)
177
+ return new algosdk_1.Kmd(token, server, process?.env?.KMD_PORT ?? '4002');
178
+ }
179
+ exports.getAlgoKmdClient = getAlgoKmdClient;
180
+ var localnet_1 = require("./localnet");
181
+ Object.defineProperty(exports, "isLocalNet", { enumerable: true, get: function () { return localnet_1.isLocalNet; } });
182
+ //# sourceMappingURL=network-client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"network-client.js","sourceRoot":"","sources":["../src/network-client.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,mDAAwD;AAExD,qFAA6E;AAG7E,mIAAmI;AACnI,SAAgB,6BAA6B;IAC3C,IAAI,CAAC,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE;QAC5B,MAAM,IAAI,KAAK,CAAC,kGAAkG,CAAC,CAAA;KACpH;IAED,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,YAAY,EAAE;QAC7B,MAAM,IAAI,KAAK,CAAC,yGAAyG,CAAC,CAAA;KAC3H;IAED,OAAO;QACL,MAAM,EAAE,OAAO,CAAC,GAAG,CAAC,YAAY;QAChC,IAAI,EAAE,OAAO,CAAC,GAAG,CAAC,UAAU;QAC5B,KAAK,EAAE,OAAO,CAAC,GAAG,CAAC,WAAW;KAC/B,CAAA;AACH,CAAC;AAdD,sEAcC;AAED,qIAAqI;AACrI,SAAgB,+BAA+B;IAC7C,IAAI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,4CAKC;AAED,uCAAuC;AAA9B,sGAAA,UAAU,OAAA"}
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "main": "index.js",
3
3
  "types": "index.d.ts",
4
4
  "name": "@algorandfoundation/algokit-utils",
5
- "version": "1.0.0-beta.8",
5
+ "version": "1.0.0",
6
6
  "private": false,
7
7
  "description": "A set of core Algorand utilities written in TypeScript and released via npm that make it easier to build solutions on Algorand.",
8
8
  "author": "Algorand Foundation",
@@ -11,10 +11,10 @@
11
11
  "node": ">=16.0"
12
12
  },
13
13
  "files": [
14
- "dist/**/*"
14
+ "**/*"
15
15
  ],
16
16
  "dependencies": {
17
- "algosdk": "^2.1.0",
17
+ "algosdk": "^2.2.0",
18
18
  "buffer": "^6.0.3"
19
19
  }
20
20
  }
@@ -0,0 +1,14 @@
1
+ import { Account, Algodv2, Kmd } from 'algosdk';
2
+ import { GetTestAccountParams } from '../types/testing';
3
+ /**
4
+ * Creates an ephemeral Algorand account for the purposes of testing.
5
+ * Returns a newly created random test account that is funded from the dispenser @see {getDispenserAccount}
6
+ * DO NOT USE THIS TO CREATE A MAINNET ACCOUNT!
7
+ * Note: By default this will log the mnemonic of the account.
8
+ * @param param0 The config for the test account to generate
9
+ * @param algod An algod client
10
+ * @param kmd A KMD client, if not specified then a default KMD client will be loaded from environment variables @see {getAlgoKmdClient}
11
+ * @returns The account, with private key loaded
12
+ */
13
+ export declare function getTestAccount({ suppressLog, initialFunds }: GetTestAccountParams, algod: Algodv2, kmd?: Kmd): Promise<Account>;
14
+ //# sourceMappingURL=account.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"account.d.ts","sourceRoot":"","sources":["../../src/testing/account.ts"],"names":[],"mappings":"AAAA,OAAgB,EAAE,OAAO,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,SAAS,CAAA;AAIxD,OAAO,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAA;AAEvD;;;;;;;;;GASG;AACH,wBAAsB,cAAc,CAAC,EAAE,WAAW,EAAE,YAAY,EAAE,EAAE,oBAAoB,EAAE,KAAK,EAAE,OAAO,EAAE,GAAG,CAAC,EAAE,GAAG,GAAG,OAAO,CAAC,OAAO,CAAC,CAgBrI"}
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.getTestAccount = void 0;
7
+ const algosdk_1 = __importDefault(require("algosdk"));
8
+ const __1 = require("../");
9
+ const account_1 = require("../account");
10
+ const transfer_1 = require("../transfer");
11
+ /**
12
+ * Creates an ephemeral Algorand account for the purposes of testing.
13
+ * Returns a newly created random test account that is funded from the dispenser @see {getDispenserAccount}
14
+ * DO NOT USE THIS TO CREATE A MAINNET ACCOUNT!
15
+ * Note: By default this will log the mnemonic of the account.
16
+ * @param param0 The config for the test account to generate
17
+ * @param algod An algod client
18
+ * @param kmd A KMD client, if not specified then a default KMD client will be loaded from environment variables @see {getAlgoKmdClient}
19
+ * @returns The account, with private key loaded
20
+ */
21
+ async function getTestAccount({ suppressLog, initialFunds }, algod, kmd) {
22
+ const account = algosdk_1.default.generateAccount();
23
+ __1.Config.getLogger(suppressLog).info(`New test account created with address '${account.addr}' and mnemonic '${algosdk_1.default.secretKeyToMnemonic(account.sk)}'.`);
24
+ const dispenser = await (0, account_1.getDispenserAccount)(algod, kmd);
25
+ await (0, transfer_1.transferAlgos)({ from: dispenser, to: account.addr, amount: initialFunds, note: 'Funding test account', suppressLog }, algod);
26
+ const accountInfo = await algod.accountInformation(account.addr).do();
27
+ __1.Config.getLogger(suppressLog).info('Test account funded; account balance: %d µAlgos', accountInfo.amount);
28
+ return account;
29
+ }
30
+ exports.getTestAccount = getTestAccount;
31
+ //# sourceMappingURL=account.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"account.js","sourceRoot":"","sources":["../../src/testing/account.ts"],"names":[],"mappings":";;;;;;AAAA,sDAAwD;AACxD,2BAA4B;AAC5B,wCAAgD;AAChD,0CAA2C;AAG3C;;;;;;;;;GASG;AACI,KAAK,UAAU,cAAc,CAAC,EAAE,WAAW,EAAE,YAAY,EAAwB,EAAE,KAAc,EAAE,GAAS;IACjH,MAAM,OAAO,GAAG,iBAAO,CAAC,eAAe,EAAE,CAAA;IAEzC,UAAM,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC,IAAI,CAChC,0CAA0C,OAAO,CAAC,IAAI,mBAAmB,iBAAO,CAAC,mBAAmB,CAAC,OAAO,CAAC,EAAE,CAAC,IAAI,CACrH,CAAA;IAED,MAAM,SAAS,GAAG,MAAM,IAAA,6BAAmB,EAAC,KAAK,EAAE,GAAG,CAAC,CAAA;IAEvD,MAAM,IAAA,wBAAa,EAAC,EAAE,IAAI,EAAE,SAAS,EAAE,EAAE,EAAE,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,YAAY,EAAE,IAAI,EAAE,sBAAsB,EAAE,WAAW,EAAE,EAAE,KAAK,CAAC,CAAA;IAElI,MAAM,WAAW,GAAG,MAAM,KAAK,CAAC,kBAAkB,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,EAAE,EAAE,CAAA;IAErE,UAAM,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC,IAAI,CAAC,iDAAiD,EAAE,WAAW,CAAC,MAAM,CAAC,CAAA;IAEzG,OAAO,OAAO,CAAA;AAChB,CAAC;AAhBD,wCAgBC"}
@@ -0,0 +1,19 @@
1
+ import { AlgoKitLogCaptureFixture } from '../../types/testing';
2
+ /**
3
+ * Creates a test fixture for capturing AlgoKit logs.
4
+ *
5
+ * @example ```typescript
6
+ * const logs = algoKitLogCaptureFixture()
7
+ *
8
+ * beforeEach(logs.beforeEach)
9
+ * afterEach(logs.afterEach)
10
+ *
11
+ * test('My test', () => {
12
+ * const capturedLogs = logs.testLogger.capturedLogs
13
+ * })
14
+ * ```
15
+ *
16
+ * @returns The fixture
17
+ */
18
+ export declare const algoKitLogCaptureFixture: () => AlgoKitLogCaptureFixture;
19
+ //# sourceMappingURL=algokit-log-capture-fixture.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"algokit-log-capture-fixture.d.ts","sourceRoot":"","sources":["../../../src/testing/fixtures/algokit-log-capture-fixture.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,wBAAwB,EAAE,MAAM,qBAAqB,CAAA;AAG9D;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,wBAAwB,EAAE,MAAM,wBAqB5C,CAAA"}
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.algoKitLogCaptureFixture = void 0;
4
+ const __1 = require("../../");
5
+ const test_logger_1 = require("../test-logger");
6
+ /**
7
+ * Creates a test fixture for capturing AlgoKit logs.
8
+ *
9
+ * @example ```typescript
10
+ * const logs = algoKitLogCaptureFixture()
11
+ *
12
+ * beforeEach(logs.beforeEach)
13
+ * afterEach(logs.afterEach)
14
+ *
15
+ * test('My test', () => {
16
+ * const capturedLogs = logs.testLogger.capturedLogs
17
+ * })
18
+ * ```
19
+ *
20
+ * @returns The fixture
21
+ */
22
+ const algoKitLogCaptureFixture = () => {
23
+ const originalLogger = __1.Config.logger;
24
+ let hybridLogger;
25
+ return {
26
+ get testLogger() {
27
+ return hybridLogger;
28
+ },
29
+ beforeEach: () => {
30
+ hybridLogger = new test_logger_1.TestLogger(originalLogger);
31
+ __1.Config.configure({
32
+ logger: hybridLogger,
33
+ });
34
+ },
35
+ afterEach: () => {
36
+ __1.Config.configure({
37
+ logger: originalLogger,
38
+ });
39
+ },
40
+ };
41
+ };
42
+ exports.algoKitLogCaptureFixture = algoKitLogCaptureFixture;
43
+ //# sourceMappingURL=algokit-log-capture-fixture.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"algokit-log-capture-fixture.js","sourceRoot":"","sources":["../../../src/testing/fixtures/algokit-log-capture-fixture.ts"],"names":[],"mappings":";;;AAAA,8BAA+B;AAE/B,gDAA2C;AAE3C;;;;;;;;;;;;;;;GAeG;AACI,MAAM,wBAAwB,GAAmC,GAAG,EAAE;IAC3E,MAAM,cAAc,GAAG,UAAM,CAAC,MAAM,CAAA;IAEpC,IAAI,YAAwB,CAAA;IAE5B,OAAO;QACL,IAAI,UAAU;YACZ,OAAO,YAAY,CAAA;QACrB,CAAC;QACD,UAAU,EAAE,GAAG,EAAE;YACf,YAAY,GAAG,IAAI,wBAAU,CAAC,cAAc,CAAC,CAAA;YAC7C,UAAM,CAAC,SAAS,CAAC;gBACf,MAAM,EAAE,YAAY;aACrB,CAAC,CAAA;QACJ,CAAC;QACD,SAAS,EAAE,GAAG,EAAE;YACd,UAAM,CAAC,SAAS,CAAC;gBACf,MAAM,EAAE,cAAc;aACvB,CAAC,CAAA;QACJ,CAAC;KACF,CAAA;AACH,CAAC,CAAA;AArBY,QAAA,wBAAwB,4BAqBpC"}
@@ -0,0 +1,20 @@
1
+ import { AlgorandFixture, AlgorandFixtureConfig } from '../../types/testing';
2
+ /**
3
+ * Creates a test fixture for automated testing against Algorand.
4
+ * By default it tests against a default LocalNet instance, but you can pass in an algod and indexer if you want to test against, say, TestNet.
5
+ *
6
+ * @example ```typescript
7
+ * const algorand = algorandFixture()
8
+ *
9
+ * beforeEach(algorand.beforeEach, 10_000)
10
+ *
11
+ * test('My test', () => {
12
+ * const {algod, indexer, testAccount, ...} = algorand.context
13
+ * })
14
+ * ```
15
+ *
16
+ * @param fixtureConfig The fixture configuration
17
+ * @returns The fixture
18
+ */
19
+ export declare const algorandFixture: (fixtureConfig?: AlgorandFixtureConfig) => AlgorandFixture;
20
+ //# sourceMappingURL=algorand-fixture.d.ts.map