@algorandfoundation/algokit-utils 8.1.0-beta.1 → 8.1.0-beta.3
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.
- package/index.js +1 -0
- package/index.js.map +1 -1
- package/index.mjs +1 -1
- package/package.json +1 -1
- package/testing/fixtures/algorand-fixture.d.ts +19 -19
- package/testing/fixtures/algorand-fixture.js +7 -5
- package/testing/fixtures/algorand-fixture.js.map +1 -1
- package/testing/fixtures/algorand-fixture.mjs +7 -5
- package/testing/fixtures/algorand-fixture.mjs.map +1 -1
- package/testing/test-logger.js +1 -1
- package/testing/test-logger.js.map +1 -1
- package/testing/test-logger.mjs +1 -1
- package/testing/test-logger.mjs.map +1 -1
- package/testing/transaction-logger.js +4 -1
- package/testing/transaction-logger.js.map +1 -1
- package/testing/transaction-logger.mjs +4 -1
- package/testing/transaction-logger.mjs.map +1 -1
- package/transaction/transaction.d.ts +18 -3
- package/transaction/transaction.js +356 -215
- package/transaction/transaction.js.map +1 -1
- package/transaction/transaction.mjs +356 -216
- package/transaction/transaction.mjs.map +1 -1
- package/types/app-client.d.ts +5 -1
- package/types/app-deployer.js +1 -1
- package/types/app-deployer.js.map +1 -1
- package/types/app-deployer.mjs +1 -1
- package/types/app-deployer.mjs.map +1 -1
- package/types/composer.d.ts +5 -3
- package/types/composer.js +96 -24
- package/types/composer.js.map +1 -1
- package/types/composer.mjs +96 -24
- package/types/composer.mjs.map +1 -1
- package/types/testing.d.ts +46 -2
- package/types/transaction.d.ts +13 -0
package/index.js
CHANGED
|
@@ -136,6 +136,7 @@ exports.getSenderTransactionSigner = transaction.getSenderTransactionSigner;
|
|
|
136
136
|
exports.getTransactionParams = transaction.getTransactionParams;
|
|
137
137
|
exports.getTransactionWithSigner = transaction.getTransactionWithSigner;
|
|
138
138
|
exports.populateAppCallResources = transaction.populateAppCallResources;
|
|
139
|
+
exports.prepareGroupForSending = transaction.prepareGroupForSending;
|
|
139
140
|
exports.sendAtomicTransactionComposer = transaction.sendAtomicTransactionComposer;
|
|
140
141
|
exports.sendGroupOfTransactions = transaction.sendGroupOfTransactions;
|
|
141
142
|
exports.sendTransaction = transaction.sendTransaction;
|
package/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
package/index.mjs
CHANGED
|
@@ -25,5 +25,5 @@ export { ensureFunded, rekeyAccount, transferAsset } from './transfer/transfer.m
|
|
|
25
25
|
export { transferAlgos } from './transfer/transfer-algos.mjs';
|
|
26
26
|
export { persistSourceMaps } from './debugging/debugging.mjs';
|
|
27
27
|
export { performAtomicTransactionComposerSimulate } from './transaction/perform-atomic-transaction-composer-simulate.mjs';
|
|
28
|
-
export { MAX_APP_CALL_ACCOUNT_REFERENCES, MAX_APP_CALL_FOREIGN_REFERENCES, MAX_TRANSACTION_GROUP_SIZE, capTransactionFee, controlFees, encodeLease, encodeTransactionNote, getABIReturnValue, getAtomicTransactionComposerTransactions, getSenderAddress, getSenderTransactionSigner, getTransactionParams, getTransactionWithSigner, populateAppCallResources, sendAtomicTransactionComposer, sendGroupOfTransactions, sendTransaction, signTransaction, waitForConfirmation } from './transaction/transaction.mjs';
|
|
28
|
+
export { MAX_APP_CALL_ACCOUNT_REFERENCES, MAX_APP_CALL_FOREIGN_REFERENCES, MAX_TRANSACTION_GROUP_SIZE, capTransactionFee, controlFees, encodeLease, encodeTransactionNote, getABIReturnValue, getAtomicTransactionComposerTransactions, getSenderAddress, getSenderTransactionSigner, getTransactionParams, getTransactionWithSigner, populateAppCallResources, prepareGroupForSending, sendAtomicTransactionComposer, sendGroupOfTransactions, sendTransaction, signTransaction, waitForConfirmation } from './transaction/transaction.mjs';
|
|
29
29
|
//# sourceMappingURL=index.mjs.map
|
package/package.json
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
"**"
|
|
7
7
|
],
|
|
8
8
|
"name": "@algorandfoundation/algokit-utils",
|
|
9
|
-
"version": "8.1.0-beta.
|
|
9
|
+
"version": "8.1.0-beta.3",
|
|
10
10
|
"private": false,
|
|
11
11
|
"description": "A set of core Algorand utilities written in TypeScript and released via npm that make it easier to build solutions on Algorand.",
|
|
12
12
|
"author": "Algorand Foundation",
|
|
@@ -8,29 +8,41 @@ import { AlgorandFixture, AlgorandFixtureConfig } from '../../types/testing';
|
|
|
8
8
|
* and/or kmd (or their respective config) if you want to test against
|
|
9
9
|
* an explicitly defined network.
|
|
10
10
|
*
|
|
11
|
-
* @example No config
|
|
11
|
+
* @example No config (per-test isolation)
|
|
12
12
|
* ```typescript
|
|
13
|
-
* const
|
|
13
|
+
* const fixture = algorandFixture()
|
|
14
14
|
*
|
|
15
|
-
* beforeEach(
|
|
15
|
+
* beforeEach(fixture.newScope, 10_000)
|
|
16
16
|
*
|
|
17
17
|
* test('My test', async () => {
|
|
18
|
-
* const {algod, indexer, testAccount, ...} =
|
|
18
|
+
* const {algod, indexer, testAccount, ...} = fixture.context
|
|
19
|
+
* // test things...
|
|
20
|
+
* })
|
|
21
|
+
* ```
|
|
22
|
+
*
|
|
23
|
+
* @example No config (test suite isolation)
|
|
24
|
+
* ```typescript
|
|
25
|
+
* const fixture = algorandFixture()
|
|
26
|
+
*
|
|
27
|
+
* beforeAll(fixture.newScope, 10_000)
|
|
28
|
+
*
|
|
29
|
+
* test('My test', async () => {
|
|
30
|
+
* const {algod, indexer, testAccount, ...} = fixture.context
|
|
19
31
|
* // test things...
|
|
20
32
|
* })
|
|
21
33
|
* ```
|
|
22
34
|
*
|
|
23
35
|
* @example With config
|
|
24
36
|
* ```typescript
|
|
25
|
-
* const
|
|
37
|
+
* const fixture = algorandFixture({
|
|
26
38
|
* algod: new Algodv2('localhost', 12345, 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'),
|
|
27
39
|
* // ...
|
|
28
40
|
* })
|
|
29
41
|
*
|
|
30
|
-
* beforeEach(
|
|
42
|
+
* beforeEach(fixture.newScope, 10_000)
|
|
31
43
|
*
|
|
32
44
|
* test('My test', async () => {
|
|
33
|
-
* const {algod, indexer, testAccount, ...} =
|
|
45
|
+
* const {algod, indexer, testAccount, ...} = fixture.context
|
|
34
46
|
* // test things...
|
|
35
47
|
* })
|
|
36
48
|
* ```
|
|
@@ -48,18 +60,6 @@ export declare function algorandFixture(fixtureConfig?: AlgorandFixtureConfig):
|
|
|
48
60
|
* a default LocalNet instance, but you can pass in an algod, indexer
|
|
49
61
|
* and/or kmd if you want to test against an explicitly defined network.
|
|
50
62
|
*
|
|
51
|
-
* @example
|
|
52
|
-
* ```typescript
|
|
53
|
-
* const algorand = algorandFixture(undefined, getConfigFromEnvOrDefaults())
|
|
54
|
-
*
|
|
55
|
-
* beforeEach(algorand.beforeEach, 10_000)
|
|
56
|
-
*
|
|
57
|
-
* test('My test', async () => {
|
|
58
|
-
* const {algod, indexer, testAccount, ...} = algorand.context
|
|
59
|
-
* // test things...
|
|
60
|
-
* })
|
|
61
|
-
* ```
|
|
62
|
-
*
|
|
63
63
|
* @param fixtureConfig The fixture configuration
|
|
64
64
|
* @param config The fixture configuration
|
|
65
65
|
* @returns The fixture
|
|
@@ -18,19 +18,18 @@ function algorandFixture(fixtureConfig, config$1) {
|
|
|
18
18
|
const kmd = fixtureConfig.kmd ?? types_clientManager.ClientManager.getKmdClient(fixtureConfig.kmdConfig);
|
|
19
19
|
let context;
|
|
20
20
|
let algorand;
|
|
21
|
-
const
|
|
21
|
+
const newScope = async () => {
|
|
22
22
|
config.Config.configure({ debug: true });
|
|
23
23
|
const transactionLogger$1 = new transactionLogger.TransactionLogger();
|
|
24
24
|
const transactionLoggerAlgod = transactionLogger$1.capture(algod);
|
|
25
|
-
algorand = types_algorandClient.AlgorandClient.fromClients({ algod: transactionLoggerAlgod, indexer: indexer$1, kmd });
|
|
25
|
+
algorand = types_algorandClient.AlgorandClient.fromClients({ algod: transactionLoggerAlgod, indexer: indexer$1, kmd }).setSuggestedParamsCacheTimeout(0);
|
|
26
26
|
const testAccount = await account.getTestAccount({ initialFunds: fixtureConfig?.testAccountFunding ?? amount.algos(10), suppressLog: true }, algorand);
|
|
27
|
-
algorand.setSignerFromAccount(testAccount)
|
|
27
|
+
algorand.setSignerFromAccount(testAccount);
|
|
28
28
|
// If running against LocalNet we are likely in dev mode and we need to set a much higher validity window
|
|
29
29
|
// otherwise we are more likely to get invalid transactions.
|
|
30
30
|
if (await algorand.client.isLocalNet()) {
|
|
31
31
|
algorand.setDefaultValidityWindow(1000);
|
|
32
32
|
}
|
|
33
|
-
algorand.account.setSignerFromAccount(testAccount);
|
|
34
33
|
context = {
|
|
35
34
|
algorand,
|
|
36
35
|
algod: transactionLoggerAlgod,
|
|
@@ -49,12 +48,15 @@ function algorandFixture(fixtureConfig, config$1) {
|
|
|
49
48
|
};
|
|
50
49
|
return {
|
|
51
50
|
get context() {
|
|
51
|
+
if (!context)
|
|
52
|
+
throw new Error('Context not initialised; make sure to call fixture.newScope() before accessing context.');
|
|
52
53
|
return context;
|
|
53
54
|
},
|
|
54
55
|
get algorand() {
|
|
55
56
|
return algorand;
|
|
56
57
|
},
|
|
57
|
-
beforeEach,
|
|
58
|
+
beforeEach: newScope,
|
|
59
|
+
newScope,
|
|
58
60
|
};
|
|
59
61
|
}
|
|
60
62
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"algorand-fixture.js","sources":["../../../src/testing/fixtures/algorand-fixture.ts"],"sourcesContent":["import { algos, Config } from '../../'\nimport { AlgorandClient } from '../../types/algorand-client'\nimport { ClientManager } from '../../types/client-manager'\nimport { AlgoConfig } from '../../types/network-client'\nimport { AlgorandFixture, AlgorandFixtureConfig, AlgorandTestAutomationContext, GetTestAccountParams } from '../../types/testing'\nimport { getTestAccount } from '../account'\nimport { runWhenIndexerCaughtUp } from '../indexer'\nimport { TransactionLogger } from '../transaction-logger'\n\n/**\n * Creates a test fixture for automated testing against Algorand.\n * By default it tests against an environment variable specified client\n * if the standard environment variables are specified, otherwise against\n * a default LocalNet instance, but you can pass in an algod, indexer\n * and/or kmd (or their respective config) if you want to test against\n * an explicitly defined network.\n *\n * @example No config\n * ```typescript\n * const
|
|
1
|
+
{"version":3,"file":"algorand-fixture.js","sources":["../../../src/testing/fixtures/algorand-fixture.ts"],"sourcesContent":["import { algos, Config } from '../../'\nimport { AlgorandClient } from '../../types/algorand-client'\nimport { ClientManager } from '../../types/client-manager'\nimport { AlgoConfig } from '../../types/network-client'\nimport { AlgorandFixture, AlgorandFixtureConfig, AlgorandTestAutomationContext, GetTestAccountParams } from '../../types/testing'\nimport { getTestAccount } from '../account'\nimport { runWhenIndexerCaughtUp } from '../indexer'\nimport { TransactionLogger } from '../transaction-logger'\n\n/**\n * Creates a test fixture for automated testing against Algorand.\n * By default it tests against an environment variable specified client\n * if the standard environment variables are specified, otherwise against\n * a default LocalNet instance, but you can pass in an algod, indexer\n * and/or kmd (or their respective config) if you want to test against\n * an explicitly defined network.\n *\n * @example No config (per-test isolation)\n * ```typescript\n * const fixture = algorandFixture()\n *\n * beforeEach(fixture.newScope, 10_000)\n *\n * test('My test', async () => {\n * const {algod, indexer, testAccount, ...} = fixture.context\n * // test things...\n * })\n * ```\n *\n * @example No config (test suite isolation)\n * ```typescript\n * const fixture = algorandFixture()\n *\n * beforeAll(fixture.newScope, 10_000)\n *\n * test('My test', async () => {\n * const {algod, indexer, testAccount, ...} = fixture.context\n * // test things...\n * })\n * ```\n *\n * @example With config\n * ```typescript\n * const fixture = algorandFixture({\n * algod: new Algodv2('localhost', 12345, 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'),\n * // ...\n * })\n *\n * beforeEach(fixture.newScope, 10_000)\n *\n * test('My test', async () => {\n * const {algod, indexer, testAccount, ...} = fixture.context\n * // test things...\n * })\n * ```\n *\n * @param fixtureConfig The fixture configuration\n * @returns The fixture\n */\nexport function algorandFixture(fixtureConfig?: AlgorandFixtureConfig): AlgorandFixture\n\n/**\n * @deprecated Config can be passed in directly to fixture config now.\n *\n * Creates a test fixture for automated testing against Algorand.\n * By default it tests against an environment variable specified client\n * if the standard environment variables are specified, otherwise against\n * a default LocalNet instance, but you can pass in an algod, indexer\n * and/or kmd if you want to test against an explicitly defined network.\n *\n * @param fixtureConfig The fixture configuration\n * @param config The fixture configuration\n * @returns The fixture\n */\nexport function algorandFixture(fixtureConfig: AlgorandFixtureConfig | undefined, config: AlgoConfig): AlgorandFixture\n\nexport function algorandFixture(fixtureConfig?: AlgorandFixtureConfig, config?: AlgoConfig): AlgorandFixture {\n fixtureConfig = { ...fixtureConfig, ...config }\n if (!fixtureConfig.algod || !fixtureConfig.indexer || !fixtureConfig.kmd) {\n fixtureConfig = { ...ClientManager.getConfigFromEnvironmentOrLocalNet(), ...fixtureConfig }\n }\n\n const algod = fixtureConfig.algod ?? ClientManager.getAlgodClient(fixtureConfig.algodConfig!)\n const indexer = fixtureConfig.indexer ?? ClientManager.getIndexerClient(fixtureConfig.indexerConfig!)\n const kmd = fixtureConfig.kmd ?? ClientManager.getKmdClient(fixtureConfig.kmdConfig!)\n let context: AlgorandTestAutomationContext\n let algorand: AlgorandClient\n\n const newScope = async () => {\n Config.configure({ debug: true })\n const transactionLogger = new TransactionLogger()\n const transactionLoggerAlgod = transactionLogger.capture(algod)\n\n algorand = AlgorandClient.fromClients({ algod: transactionLoggerAlgod, indexer, kmd }).setSuggestedParamsCacheTimeout(0)\n\n const testAccount = await getTestAccount({ initialFunds: fixtureConfig?.testAccountFunding ?? algos(10), suppressLog: true }, algorand)\n algorand.setSignerFromAccount(testAccount)\n\n // If running against LocalNet we are likely in dev mode and we need to set a much higher validity window\n // otherwise we are more likely to get invalid transactions.\n if (await algorand.client.isLocalNet()) {\n algorand.setDefaultValidityWindow(1000)\n }\n context = {\n algorand,\n algod: transactionLoggerAlgod,\n indexer: indexer,\n kmd: kmd,\n testAccount,\n generateAccount: async (params: GetTestAccountParams) => {\n const account = await getTestAccount(params, algorand)\n algorand.setSignerFromAccount(account)\n return account\n },\n transactionLogger: transactionLogger,\n waitForIndexer: () => transactionLogger.waitForIndexer(indexer),\n waitForIndexerTransaction: (transactionId: string) => runWhenIndexerCaughtUp(() => indexer.lookupTransactionByID(transactionId).do()),\n }\n }\n\n return {\n get context() {\n if (!context) throw new Error('Context not initialised; make sure to call fixture.newScope() before accessing context.')\n return context\n },\n get algorand() {\n return algorand\n },\n beforeEach: newScope,\n newScope,\n }\n}\n"],"names":["config","ClientManager","indexer","Config","transactionLogger","TransactionLogger","AlgorandClient","getTestAccount","algos","account","runWhenIndexerCaughtUp"],"mappings":";;;;;;;;;;AA4EgB,SAAA,eAAe,CAAC,aAAqC,EAAEA,QAAmB,EAAA;IACxF,aAAa,GAAG,EAAE,GAAG,aAAa,EAAE,GAAGA,QAAM,EAAE;AAC/C,IAAA,IAAI,CAAC,aAAa,CAAC,KAAK,IAAI,CAAC,aAAa,CAAC,OAAO,IAAI,CAAC,aAAa,CAAC,GAAG,EAAE;QACxE,aAAa,GAAG,EAAE,GAAGC,iCAAa,CAAC,kCAAkC,EAAE,EAAE,GAAG,aAAa,EAAE;;AAG7F,IAAA,MAAM,KAAK,GAAG,aAAa,CAAC,KAAK,IAAIA,iCAAa,CAAC,cAAc,CAAC,aAAa,CAAC,WAAY,CAAC;AAC7F,IAAA,MAAMC,SAAO,GAAG,aAAa,CAAC,OAAO,IAAID,iCAAa,CAAC,gBAAgB,CAAC,aAAa,CAAC,aAAc,CAAC;AACrG,IAAA,MAAM,GAAG,GAAG,aAAa,CAAC,GAAG,IAA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CAACF,SAAO,CAAC;YAC/D,yBAAyB,EAAE,CAAC,aAAqB,KAAKQ,8BAAsB,CAAC,MAAMR,SAAO,CAAC,qBAAqB,CAAC,aAAa,CAAC,CAAC,EAAE,EAAE,CAAC;SACtI;AACH,KAAC;IAED,OAAO;AACL,QAAA,IAAI,OAAO,GAAA;AACT,YAAA,IAAI,CAAC,OAAO;AAAE,gBAAA,MAAM,IAAI,KAAK,CAAC,yFAAyF,CAAC;AACxH,YAAA,OAAO,OAAO;SACf;AACD,QAAA,IAAI,QAAQ,GAAA;AACV,YAAA,OAAO,QAAQ;SAChB;AACD,QAAA,UAAU,EAAE,QAAQ;QACpB,QAAQ;KACT;AACH;;;;"}
|
|
@@ -16,19 +16,18 @@ function algorandFixture(fixtureConfig, config) {
|
|
|
16
16
|
const kmd = fixtureConfig.kmd ?? ClientManager.getKmdClient(fixtureConfig.kmdConfig);
|
|
17
17
|
let context;
|
|
18
18
|
let algorand;
|
|
19
|
-
const
|
|
19
|
+
const newScope = async () => {
|
|
20
20
|
Config.configure({ debug: true });
|
|
21
21
|
const transactionLogger = new TransactionLogger();
|
|
22
22
|
const transactionLoggerAlgod = transactionLogger.capture(algod);
|
|
23
|
-
algorand = AlgorandClient.fromClients({ algod: transactionLoggerAlgod, indexer, kmd });
|
|
23
|
+
algorand = AlgorandClient.fromClients({ algod: transactionLoggerAlgod, indexer, kmd }).setSuggestedParamsCacheTimeout(0);
|
|
24
24
|
const testAccount = await getTestAccount({ initialFunds: fixtureConfig?.testAccountFunding ?? algos(10), suppressLog: true }, algorand);
|
|
25
|
-
algorand.setSignerFromAccount(testAccount)
|
|
25
|
+
algorand.setSignerFromAccount(testAccount);
|
|
26
26
|
// If running against LocalNet we are likely in dev mode and we need to set a much higher validity window
|
|
27
27
|
// otherwise we are more likely to get invalid transactions.
|
|
28
28
|
if (await algorand.client.isLocalNet()) {
|
|
29
29
|
algorand.setDefaultValidityWindow(1000);
|
|
30
30
|
}
|
|
31
|
-
algorand.account.setSignerFromAccount(testAccount);
|
|
32
31
|
context = {
|
|
33
32
|
algorand,
|
|
34
33
|
algod: transactionLoggerAlgod,
|
|
@@ -47,12 +46,15 @@ function algorandFixture(fixtureConfig, config) {
|
|
|
47
46
|
};
|
|
48
47
|
return {
|
|
49
48
|
get context() {
|
|
49
|
+
if (!context)
|
|
50
|
+
throw new Error('Context not initialised; make sure to call fixture.newScope() before accessing context.');
|
|
50
51
|
return context;
|
|
51
52
|
},
|
|
52
53
|
get algorand() {
|
|
53
54
|
return algorand;
|
|
54
55
|
},
|
|
55
|
-
beforeEach,
|
|
56
|
+
beforeEach: newScope,
|
|
57
|
+
newScope,
|
|
56
58
|
};
|
|
57
59
|
}
|
|
58
60
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"algorand-fixture.mjs","sources":["../../../src/testing/fixtures/algorand-fixture.ts"],"sourcesContent":["import { algos, Config } from '../../'\nimport { AlgorandClient } from '../../types/algorand-client'\nimport { ClientManager } from '../../types/client-manager'\nimport { AlgoConfig } from '../../types/network-client'\nimport { AlgorandFixture, AlgorandFixtureConfig, AlgorandTestAutomationContext, GetTestAccountParams } from '../../types/testing'\nimport { getTestAccount } from '../account'\nimport { runWhenIndexerCaughtUp } from '../indexer'\nimport { TransactionLogger } from '../transaction-logger'\n\n/**\n * Creates a test fixture for automated testing against Algorand.\n * By default it tests against an environment variable specified client\n * if the standard environment variables are specified, otherwise against\n * a default LocalNet instance, but you can pass in an algod, indexer\n * and/or kmd (or their respective config) if you want to test against\n * an explicitly defined network.\n *\n * @example No config\n * ```typescript\n * const
|
|
1
|
+
{"version":3,"file":"algorand-fixture.mjs","sources":["../../../src/testing/fixtures/algorand-fixture.ts"],"sourcesContent":["import { algos, Config } from '../../'\nimport { AlgorandClient } from '../../types/algorand-client'\nimport { ClientManager } from '../../types/client-manager'\nimport { AlgoConfig } from '../../types/network-client'\nimport { AlgorandFixture, AlgorandFixtureConfig, AlgorandTestAutomationContext, GetTestAccountParams } from '../../types/testing'\nimport { getTestAccount } from '../account'\nimport { runWhenIndexerCaughtUp } from '../indexer'\nimport { TransactionLogger } from '../transaction-logger'\n\n/**\n * Creates a test fixture for automated testing against Algorand.\n * By default it tests against an environment variable specified client\n * if the standard environment variables are specified, otherwise against\n * a default LocalNet instance, but you can pass in an algod, indexer\n * and/or kmd (or their respective config) if you want to test against\n * an explicitly defined network.\n *\n * @example No config (per-test isolation)\n * ```typescript\n * const fixture = algorandFixture()\n *\n * beforeEach(fixture.newScope, 10_000)\n *\n * test('My test', async () => {\n * const {algod, indexer, testAccount, ...} = fixture.context\n * // test things...\n * })\n * ```\n *\n * @example No config (test suite isolation)\n * ```typescript\n * const fixture = algorandFixture()\n *\n * beforeAll(fixture.newScope, 10_000)\n *\n * test('My test', async () => {\n * const {algod, indexer, testAccount, ...} = fixture.context\n * // test things...\n * })\n * ```\n *\n * @example With config\n * ```typescript\n * const fixture = algorandFixture({\n * algod: new Algodv2('localhost', 12345, 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'),\n * // ...\n * })\n *\n * beforeEach(fixture.newScope, 10_000)\n *\n * test('My test', async () => {\n * const {algod, indexer, testAccount, ...} = fixture.context\n * // test things...\n * })\n * ```\n *\n * @param fixtureConfig The fixture configuration\n * @returns The fixture\n */\nexport function algorandFixture(fixtureConfig?: AlgorandFixtureConfig): AlgorandFixture\n\n/**\n * @deprecated Config can be passed in directly to fixture config now.\n *\n * Creates a test fixture for automated testing against Algorand.\n * By default it tests against an environment variable specified client\n * if the standard environment variables are specified, otherwise against\n * a default LocalNet instance, but you can pass in an algod, indexer\n * and/or kmd if you want to test against an explicitly defined network.\n *\n * @param fixtureConfig The fixture configuration\n * @param config The fixture configuration\n * @returns The fixture\n */\nexport function algorandFixture(fixtureConfig: AlgorandFixtureConfig | undefined, config: AlgoConfig): AlgorandFixture\n\nexport function algorandFixture(fixtureConfig?: AlgorandFixtureConfig, config?: AlgoConfig): AlgorandFixture {\n fixtureConfig = { ...fixtureConfig, ...config }\n if (!fixtureConfig.algod || !fixtureConfig.indexer || !fixtureConfig.kmd) {\n fixtureConfig = { ...ClientManager.getConfigFromEnvironmentOrLocalNet(), ...fixtureConfig }\n }\n\n const algod = fixtureConfig.algod ?? ClientManager.getAlgodClient(fixtureConfig.algodConfig!)\n const indexer = fixtureConfig.indexer ?? ClientManager.getIndexerClient(fixtureConfig.indexerConfig!)\n const kmd = fixtureConfig.kmd ?? ClientManager.getKmdClient(fixtureConfig.kmdConfig!)\n let context: AlgorandTestAutomationContext\n let algorand: AlgorandClient\n\n const newScope = async () => {\n Config.configure({ debug: true })\n const transactionLogger = new TransactionLogger()\n const transactionLoggerAlgod = transactionLogger.capture(algod)\n\n algorand = AlgorandClient.fromClients({ algod: transactionLoggerAlgod, indexer, kmd }).setSuggestedParamsCacheTimeout(0)\n\n const testAccount = await getTestAccount({ initialFunds: fixtureConfig?.testAccountFunding ?? algos(10), suppressLog: true }, algorand)\n algorand.setSignerFromAccount(testAccount)\n\n // If running against LocalNet we are likely in dev mode and we need to set a much higher validity window\n // otherwise we are more likely to get invalid transactions.\n if (await algorand.client.isLocalNet()) {\n algorand.setDefaultValidityWindow(1000)\n }\n context = {\n algorand,\n algod: transactionLoggerAlgod,\n indexer: indexer,\n kmd: kmd,\n testAccount,\n generateAccount: async (params: GetTestAccountParams) => {\n const account = await getTestAccount(params, algorand)\n algorand.setSignerFromAccount(account)\n return account\n },\n transactionLogger: transactionLogger,\n waitForIndexer: () => transactionLogger.waitForIndexer(indexer),\n waitForIndexerTransaction: (transactionId: string) => runWhenIndexerCaughtUp(() => indexer.lookupTransactionByID(transactionId).do()),\n }\n }\n\n return {\n get context() {\n if (!context) throw new Error('Context not initialised; make sure to call fixture.newScope() before accessing context.')\n return context\n },\n get algorand() {\n return algorand\n },\n beforeEach: newScope,\n newScope,\n }\n}\n"],"names":[],"mappings":";;;;;;;;AA4EgB,SAAA,eAAe,CAAC,aAAqC,EAA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,CAAC,MAAM,CAAC,UAAU,EAAE,EAAE;AACtC,YAAA,QAAQ,CAAC,wBAAwB,CAAC,IAAI,CAAC;;AAEzC,QAAA,OAAO,GAAG;YACR,QAAQ;AACR,YAAA,KAAK,EAAE,sBAAsB;AAC7B,YAAA,OAAO,EAAE,OAAO;AAChB,YAAA,GAAG,EAAE,GAAG;YACR,WAAW;AACX,YAAA,eAAe,EAAE,OAAO,MAA4B,KAAI;gBACtD,MAAM,OAAO,GAAG,MAAM,cAAc,CAAC,MAAM,EAAE,QAAQ,CAAC;AACtD,gBAAA,QAAQ,CAAC,oBAAoB,CAAC,OAAO,CAAC;AACtC,gBAAA,OAAO,OAAO;aACf;AACD,YAAA,iBAAiB,EAAE,iBAAiB;YACpC,cAAc,EAAE,MAAM,iBAAiB,CAAC,cAAc,CAAC,OAAO,CAAC;YAC/D,yBAAyB,EAAE,CAAC,aAAqB,KAAK,sBAAsB,CAAC,MAAM,OAAO,CAAC,qBAAqB,CAAC,aAAa,CAAC,CAAC,EAAE,EAAE,CAAC;SACtI;AACH,KAAC;IAED,OAAO;AACL,QAAA,IAAI,OAAO,GAAA;AACT,YAAA,IAAI,CAAC,OAAO;AAAE,gBAAA,MAAM,IAAI,KAAK,CAAC,yFAAyF,CAAC;AACxH,YAAA,OAAO,OAAO;SACf;AACD,QAAA,IAAI,QAAQ,GAAA;AACV,YAAA,OAAO,QAAQ;SAChB;AACD,QAAA,UAAU,EAAE,QAAQ;QACpB,QAAQ;KACT;AACH;;;;"}
|
package/testing/test-logger.js
CHANGED
|
@@ -40,7 +40,7 @@ class TestLogger {
|
|
|
40
40
|
*/
|
|
41
41
|
getLogSnapshot(config) {
|
|
42
42
|
const { transactions: transactionIds, accounts, apps } = config ?? {};
|
|
43
|
-
let snapshot = this.capturedLogs.join('\n');
|
|
43
|
+
let snapshot = this.capturedLogs.filter(config?.filterPredicate ?? (() => true)).join('\n');
|
|
44
44
|
transactionIds?.forEach((txn, id) => (snapshot = snapshot.replace(new RegExp(typeof txn === 'string' ? txn : txn.txID(), 'g'), `TXID_${id + 1}`)));
|
|
45
45
|
accounts?.forEach((sender, id) => (snapshot = snapshot.replace(new RegExp(typeof sender === 'string'
|
|
46
46
|
? sender
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"test-logger.js","sources":["../../src/testing/test-logger.ts"],"sourcesContent":["import { Logger } from '../types/logging'\nimport { LogSnapshotConfig } from '../types/testing'\nimport { asJson } from '../util'\n\n/** Exposes an AlgoKit logger which captures log messages, while wrapping an original logger.\n * This is useful for automated testing.\n */\nexport class TestLogger implements Logger {\n private originalLogger: Logger | undefined\n private logs: string[]\n\n /**\n * Create a new test logger that wraps the given logger if provided.\n * @param originalLogger The optional original logger to wrap.\n */\n constructor(originalLogger?: Logger) {\n this.originalLogger = originalLogger\n this.logs = []\n }\n\n /** Returns all logs captured thus far. */\n get capturedLogs(): string[] {\n return this.logs\n }\n\n /** Clears all logs captured so far. */\n clear() {\n this.logs = []\n }\n\n /**\n * Returns a captured log snapshot.\n * This helps ensure that the provided configuration items won't appear\n * with random values in the log snapshot, but rather will get substituted with predictable ids.\n *\n * https://jestjs.io/docs/snapshot-testing#2-tests-should-be-deterministic\n *\n * @example Jest Example\n * ```typescript\n * const logger = new TestLogger()\n * ...\n * expect(logger.getLogSnapshot()).toMatchSnapshot()\n * ```\n * @param config The snapshot configuration\n * @returns The snapshotted logs.\n */\n getLogSnapshot(config?: LogSnapshotConfig) {\n const { transactions: transactionIds, accounts, apps } = config ?? {}\n let snapshot = this.capturedLogs.join('\\n')\n transactionIds?.forEach(\n (txn, id) => (snapshot = snapshot.replace(new RegExp(typeof txn === 'string' ? txn : txn.txID(), 'g'), `TXID_${id + 1}`)),\n )\n accounts?.forEach(\n (sender, id) =>\n (snapshot = snapshot.replace(\n new RegExp(\n typeof sender === 'string'\n ? sender\n : 'addr' in sender\n ? sender.addr.toString()\n : 'address' in sender\n ? sender.address().toString()\n : sender.toString(),\n 'g',\n ),\n `ACCOUNT_${id + 1}`,\n )),\n )\n apps?.forEach((app, id) => (snapshot = snapshot.replace(new RegExp(`\\\\b${app.toString()}\\\\b(?! bytes)`, 'g'), `APP_${id + 1}`)))\n return snapshot\n }\n\n error(message: string, ...optionalParams: unknown[]): void {\n this.originalLogger?.error(message, ...optionalParams)\n this.logs.push(`ERROR: ${message}${optionalParams.length ? ` | ${asJson(optionalParams)}` : ''}`)\n }\n warn(message: string, ...optionalParams: unknown[]): void {\n this.originalLogger?.warn(message, ...optionalParams)\n this.logs.push(`WARN: ${message}${optionalParams.length ? ` | ${asJson(optionalParams)}` : ''}`)\n }\n info(message: string, ...optionalParams: unknown[]): void {\n this.originalLogger?.info(message, ...optionalParams)\n this.logs.push(`INFO: ${message}${optionalParams.length ? ` | ${asJson(optionalParams)}` : ''}`)\n }\n verbose(message: string, ...optionalParams: unknown[]): void {\n this.originalLogger?.verbose(message, ...optionalParams)\n this.logs.push(`VERBOSE: ${message}${optionalParams.length ? ` | ${asJson(optionalParams)}` : ''}`)\n }\n debug(message: string, ...optionalParams: unknown[]): void {\n this.originalLogger?.debug(message, ...optionalParams)\n this.logs.push(`DEBUG: ${message}${optionalParams.length ? ` | ${asJson(optionalParams)}` : ''}`)\n }\n}\n"],"names":["asJson"],"mappings":";;;;AAIA;;AAEG;MACU,UAAU,CAAA;AAIrB;;;AAGG;AACH,IAAA,WAAA,CAAY,cAAuB,EAAA;AACjC,QAAA,IAAI,CAAC,cAAc,GAAG,cAAc;AACpC,QAAA,IAAI,CAAC,IAAI,GAAG,EAAE;;;AAIhB,IAAA,IAAI,YAAY,GAAA;QACd,OAAO,IAAI,CAAC,IAAI;;;IAIlB,KAAK,GAAA;AACH,QAAA,IAAI,CAAC,IAAI,GAAG,EAAE;;AAGhB;;;;;;;;;;;;;;;AAeG;AACH,IAAA,cAAc,CAAC,MAA0B,EAAA;AACvC,QAAA,MAAM,EAAE,YAAY,EAAE,cAAc,EAAE,QAAQ,EAAE,IAAI,EAAE,GAAG,MAAM,IAAI,EAAE;QACrE,IAAI,QAAQ,GAAG,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC;
|
|
1
|
+
{"version":3,"file":"test-logger.js","sources":["../../src/testing/test-logger.ts"],"sourcesContent":["import { Logger } from '../types/logging'\nimport { LogSnapshotConfig } from '../types/testing'\nimport { asJson } from '../util'\n\n/** Exposes an AlgoKit logger which captures log messages, while wrapping an original logger.\n * This is useful for automated testing.\n */\nexport class TestLogger implements Logger {\n private originalLogger: Logger | undefined\n private logs: string[]\n\n /**\n * Create a new test logger that wraps the given logger if provided.\n * @param originalLogger The optional original logger to wrap.\n */\n constructor(originalLogger?: Logger) {\n this.originalLogger = originalLogger\n this.logs = []\n }\n\n /** Returns all logs captured thus far. */\n get capturedLogs(): string[] {\n return this.logs\n }\n\n /** Clears all logs captured so far. */\n clear() {\n this.logs = []\n }\n\n /**\n * Returns a captured log snapshot.\n * This helps ensure that the provided configuration items won't appear\n * with random values in the log snapshot, but rather will get substituted with predictable ids.\n *\n * https://jestjs.io/docs/snapshot-testing#2-tests-should-be-deterministic\n *\n * @example Jest Example\n * ```typescript\n * const logger = new TestLogger()\n * ...\n * expect(logger.getLogSnapshot()).toMatchSnapshot()\n * ```\n * @param config The snapshot configuration\n * @returns The snapshotted logs.\n */\n getLogSnapshot(config?: LogSnapshotConfig) {\n const { transactions: transactionIds, accounts, apps } = config ?? {}\n let snapshot = this.capturedLogs.filter(config?.filterPredicate ?? (() => true)).join('\\n')\n transactionIds?.forEach(\n (txn, id) => (snapshot = snapshot.replace(new RegExp(typeof txn === 'string' ? txn : txn.txID(), 'g'), `TXID_${id + 1}`)),\n )\n accounts?.forEach(\n (sender, id) =>\n (snapshot = snapshot.replace(\n new RegExp(\n typeof sender === 'string'\n ? sender\n : 'addr' in sender\n ? sender.addr.toString()\n : 'address' in sender\n ? sender.address().toString()\n : sender.toString(),\n 'g',\n ),\n `ACCOUNT_${id + 1}`,\n )),\n )\n apps?.forEach((app, id) => (snapshot = snapshot.replace(new RegExp(`\\\\b${app.toString()}\\\\b(?! bytes)`, 'g'), `APP_${id + 1}`)))\n return snapshot\n }\n\n error(message: string, ...optionalParams: unknown[]): void {\n this.originalLogger?.error(message, ...optionalParams)\n this.logs.push(`ERROR: ${message}${optionalParams.length ? ` | ${asJson(optionalParams)}` : ''}`)\n }\n warn(message: string, ...optionalParams: unknown[]): void {\n this.originalLogger?.warn(message, ...optionalParams)\n this.logs.push(`WARN: ${message}${optionalParams.length ? ` | ${asJson(optionalParams)}` : ''}`)\n }\n info(message: string, ...optionalParams: unknown[]): void {\n this.originalLogger?.info(message, ...optionalParams)\n this.logs.push(`INFO: ${message}${optionalParams.length ? ` | ${asJson(optionalParams)}` : ''}`)\n }\n verbose(message: string, ...optionalParams: unknown[]): void {\n this.originalLogger?.verbose(message, ...optionalParams)\n this.logs.push(`VERBOSE: ${message}${optionalParams.length ? ` | ${asJson(optionalParams)}` : ''}`)\n }\n debug(message: string, ...optionalParams: unknown[]): void {\n this.originalLogger?.debug(message, ...optionalParams)\n this.logs.push(`DEBUG: ${message}${optionalParams.length ? ` | ${asJson(optionalParams)}` : ''}`)\n }\n}\n"],"names":["asJson"],"mappings":";;;;AAIA;;AAEG;MACU,UAAU,CAAA;AAIrB;;;AAGG;AACH,IAAA,WAAA,CAAY,cAAuB,EAAA;AACjC,QAAA,IAAI,CAAC,cAAc,GAAG,cAAc;AACpC,QAAA,IAAI,CAAC,IAAI,GAAG,EAAE;;;AAIhB,IAAA,IAAI,YAAY,GAAA;QACd,OAAO,IAAI,CAAC,IAAI;;;IAIlB,KAAK,GAAA;AACH,QAAA,IAAI,CAAC,IAAI,GAAG,EAAE;;AAGhB;;;;;;;;;;;;;;;AAeG;AACH,IAAA,cAAc,CAAC,MAA0B,EAAA;AACvC,QAAA,MAAM,EAAE,YAAY,EAAE,cAAc,EAAE,QAAQ,EAAE,IAAI,EAAE,GAAG,MAAM,IAAI,EAAE;QACrE,IAAI,QAAQ,GAAG,IAAI,CAAC,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CAAC,IAAI,CAAC,IAAI,CAAC,CAAU,OAAA,EAAA,OAAO,CAAG,EAAA,cAAc,CAAC,MAAM,GAAG,CAAM,GAAA,EAAAA,WAAM,CAAC,cAAc,CAAC,CAAA,CAAE,GAAG,EAAE,CAAE,CAAA,CAAC;;AAEpG;;;;"}
|
package/testing/test-logger.mjs
CHANGED
|
@@ -38,7 +38,7 @@ class TestLogger {
|
|
|
38
38
|
*/
|
|
39
39
|
getLogSnapshot(config) {
|
|
40
40
|
const { transactions: transactionIds, accounts, apps } = config ?? {};
|
|
41
|
-
let snapshot = this.capturedLogs.join('\n');
|
|
41
|
+
let snapshot = this.capturedLogs.filter(config?.filterPredicate ?? (() => true)).join('\n');
|
|
42
42
|
transactionIds?.forEach((txn, id) => (snapshot = snapshot.replace(new RegExp(typeof txn === 'string' ? txn : txn.txID(), 'g'), `TXID_${id + 1}`)));
|
|
43
43
|
accounts?.forEach((sender, id) => (snapshot = snapshot.replace(new RegExp(typeof sender === 'string'
|
|
44
44
|
? sender
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"test-logger.mjs","sources":["../../src/testing/test-logger.ts"],"sourcesContent":["import { Logger } from '../types/logging'\nimport { LogSnapshotConfig } from '../types/testing'\nimport { asJson } from '../util'\n\n/** Exposes an AlgoKit logger which captures log messages, while wrapping an original logger.\n * This is useful for automated testing.\n */\nexport class TestLogger implements Logger {\n private originalLogger: Logger | undefined\n private logs: string[]\n\n /**\n * Create a new test logger that wraps the given logger if provided.\n * @param originalLogger The optional original logger to wrap.\n */\n constructor(originalLogger?: Logger) {\n this.originalLogger = originalLogger\n this.logs = []\n }\n\n /** Returns all logs captured thus far. */\n get capturedLogs(): string[] {\n return this.logs\n }\n\n /** Clears all logs captured so far. */\n clear() {\n this.logs = []\n }\n\n /**\n * Returns a captured log snapshot.\n * This helps ensure that the provided configuration items won't appear\n * with random values in the log snapshot, but rather will get substituted with predictable ids.\n *\n * https://jestjs.io/docs/snapshot-testing#2-tests-should-be-deterministic\n *\n * @example Jest Example\n * ```typescript\n * const logger = new TestLogger()\n * ...\n * expect(logger.getLogSnapshot()).toMatchSnapshot()\n * ```\n * @param config The snapshot configuration\n * @returns The snapshotted logs.\n */\n getLogSnapshot(config?: LogSnapshotConfig) {\n const { transactions: transactionIds, accounts, apps } = config ?? {}\n let snapshot = this.capturedLogs.join('\\n')\n transactionIds?.forEach(\n (txn, id) => (snapshot = snapshot.replace(new RegExp(typeof txn === 'string' ? txn : txn.txID(), 'g'), `TXID_${id + 1}`)),\n )\n accounts?.forEach(\n (sender, id) =>\n (snapshot = snapshot.replace(\n new RegExp(\n typeof sender === 'string'\n ? sender\n : 'addr' in sender\n ? sender.addr.toString()\n : 'address' in sender\n ? sender.address().toString()\n : sender.toString(),\n 'g',\n ),\n `ACCOUNT_${id + 1}`,\n )),\n )\n apps?.forEach((app, id) => (snapshot = snapshot.replace(new RegExp(`\\\\b${app.toString()}\\\\b(?! bytes)`, 'g'), `APP_${id + 1}`)))\n return snapshot\n }\n\n error(message: string, ...optionalParams: unknown[]): void {\n this.originalLogger?.error(message, ...optionalParams)\n this.logs.push(`ERROR: ${message}${optionalParams.length ? ` | ${asJson(optionalParams)}` : ''}`)\n }\n warn(message: string, ...optionalParams: unknown[]): void {\n this.originalLogger?.warn(message, ...optionalParams)\n this.logs.push(`WARN: ${message}${optionalParams.length ? ` | ${asJson(optionalParams)}` : ''}`)\n }\n info(message: string, ...optionalParams: unknown[]): void {\n this.originalLogger?.info(message, ...optionalParams)\n this.logs.push(`INFO: ${message}${optionalParams.length ? ` | ${asJson(optionalParams)}` : ''}`)\n }\n verbose(message: string, ...optionalParams: unknown[]): void {\n this.originalLogger?.verbose(message, ...optionalParams)\n this.logs.push(`VERBOSE: ${message}${optionalParams.length ? ` | ${asJson(optionalParams)}` : ''}`)\n }\n debug(message: string, ...optionalParams: unknown[]): void {\n this.originalLogger?.debug(message, ...optionalParams)\n this.logs.push(`DEBUG: ${message}${optionalParams.length ? ` | ${asJson(optionalParams)}` : ''}`)\n }\n}\n"],"names":[],"mappings":";;AAIA;;AAEG;MACU,UAAU,CAAA;AAIrB;;;AAGG;AACH,IAAA,WAAA,CAAY,cAAuB,EAAA;AACjC,QAAA,IAAI,CAAC,cAAc,GAAG,cAAc;AACpC,QAAA,IAAI,CAAC,IAAI,GAAG,EAAE;;;AAIhB,IAAA,IAAI,YAAY,GAAA;QACd,OAAO,IAAI,CAAC,IAAI;;;IAIlB,KAAK,GAAA;AACH,QAAA,IAAI,CAAC,IAAI,GAAG,EAAE;;AAGhB;;;;;;;;;;;;;;;AAeG;AACH,IAAA,cAAc,CAAC,MAA0B,EAAA;AACvC,QAAA,MAAM,EAAE,YAAY,EAAE,cAAc,EAAE,QAAQ,EAAE,IAAI,EAAE,GAAG,MAAM,IAAI,EAAE;QACrE,IAAI,QAAQ,GAAG,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC;
|
|
1
|
+
{"version":3,"file":"test-logger.mjs","sources":["../../src/testing/test-logger.ts"],"sourcesContent":["import { Logger } from '../types/logging'\nimport { LogSnapshotConfig } from '../types/testing'\nimport { asJson } from '../util'\n\n/** Exposes an AlgoKit logger which captures log messages, while wrapping an original logger.\n * This is useful for automated testing.\n */\nexport class TestLogger implements Logger {\n private originalLogger: Logger | undefined\n private logs: string[]\n\n /**\n * Create a new test logger that wraps the given logger if provided.\n * @param originalLogger The optional original logger to wrap.\n */\n constructor(originalLogger?: Logger) {\n this.originalLogger = originalLogger\n this.logs = []\n }\n\n /** Returns all logs captured thus far. */\n get capturedLogs(): string[] {\n return this.logs\n }\n\n /** Clears all logs captured so far. */\n clear() {\n this.logs = []\n }\n\n /**\n * Returns a captured log snapshot.\n * This helps ensure that the provided configuration items won't appear\n * with random values in the log snapshot, but rather will get substituted with predictable ids.\n *\n * https://jestjs.io/docs/snapshot-testing#2-tests-should-be-deterministic\n *\n * @example Jest Example\n * ```typescript\n * const logger = new TestLogger()\n * ...\n * expect(logger.getLogSnapshot()).toMatchSnapshot()\n * ```\n * @param config The snapshot configuration\n * @returns The snapshotted logs.\n */\n getLogSnapshot(config?: LogSnapshotConfig) {\n const { transactions: transactionIds, accounts, apps } = config ?? {}\n let snapshot = this.capturedLogs.filter(config?.filterPredicate ?? (() => true)).join('\\n')\n transactionIds?.forEach(\n (txn, id) => (snapshot = snapshot.replace(new RegExp(typeof txn === 'string' ? txn : txn.txID(), 'g'), `TXID_${id + 1}`)),\n )\n accounts?.forEach(\n (sender, id) =>\n (snapshot = snapshot.replace(\n new RegExp(\n typeof sender === 'string'\n ? sender\n : 'addr' in sender\n ? sender.addr.toString()\n : 'address' in sender\n ? sender.address().toString()\n : sender.toString(),\n 'g',\n ),\n `ACCOUNT_${id + 1}`,\n )),\n )\n apps?.forEach((app, id) => (snapshot = snapshot.replace(new RegExp(`\\\\b${app.toString()}\\\\b(?! bytes)`, 'g'), `APP_${id + 1}`)))\n return snapshot\n }\n\n error(message: string, ...optionalParams: unknown[]): void {\n this.originalLogger?.error(message, ...optionalParams)\n this.logs.push(`ERROR: ${message}${optionalParams.length ? ` | ${asJson(optionalParams)}` : ''}`)\n }\n warn(message: string, ...optionalParams: unknown[]): void {\n this.originalLogger?.warn(message, ...optionalParams)\n this.logs.push(`WARN: ${message}${optionalParams.length ? ` | ${asJson(optionalParams)}` : ''}`)\n }\n info(message: string, ...optionalParams: unknown[]): void {\n this.originalLogger?.info(message, ...optionalParams)\n this.logs.push(`INFO: ${message}${optionalParams.length ? ` | ${asJson(optionalParams)}` : ''}`)\n }\n verbose(message: string, ...optionalParams: unknown[]): void {\n this.originalLogger?.verbose(message, ...optionalParams)\n this.logs.push(`VERBOSE: ${message}${optionalParams.length ? ` | ${asJson(optionalParams)}` : ''}`)\n }\n debug(message: string, ...optionalParams: unknown[]): void {\n this.originalLogger?.debug(message, ...optionalParams)\n this.logs.push(`DEBUG: ${message}${optionalParams.length ? ` | ${asJson(optionalParams)}` : ''}`)\n }\n}\n"],"names":[],"mappings":";;AAIA;;AA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AAE,CAAE,CAAA,CAAC;;AAElG,IAAA,OAAO,CAAC,OAAe,EAAE,GAAG,cAAyB,EAAA;QACnD,IAAI,CAAC,cAAc,EAAE,OAAO,CAAC,OAAO,EAAE,GAAG,cAAc,CAAC;QACxD,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAY,SAAA,EAAA,OAAO,CAAG,EAAA,cAAc,CAAC,MAAM,GAAG,CAAM,GAAA,EAAA,MAAM,CAAC,cAAc,CAAC,CAAA,CAAE,GAAG,EAAE,CAAE,CAAA,CAAC;;AAErG,IAAA,KAAK,CAAC,OAAe,EAAE,GAAG,cAAyB,EAAA;QACjD,IAAI,CAAC,cAAc,EAAE,KAAK,CAAC,OAAO,EAAE,GAAG,cAAc,CAAC;QACtD,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAU,OAAA,EAAA,OAAO,CAAG,EAAA,cAAc,CAAC,MAAM,GAAG,CAAM,GAAA,EAAA,MAAM,CAAC,cAAc,CAAC,CAAA,CAAE,GAAG,EAAE,CAAE,CAAA,CAAC;;AAEpG;;;;"}
|
|
@@ -49,7 +49,10 @@ class TransactionLogger {
|
|
|
49
49
|
}
|
|
50
50
|
/** Wait until all logged transactions IDs appear in the given `Indexer`. */
|
|
51
51
|
async waitForIndexer(indexer$1) {
|
|
52
|
-
|
|
52
|
+
if (this._sentTransactionIds.length === 0)
|
|
53
|
+
return;
|
|
54
|
+
const lastTxId = this._sentTransactionIds[this._sentTransactionIds.length - 1];
|
|
55
|
+
await indexer.runWhenIndexerCaughtUp(() => indexer$1.lookupTransactionByID(lastTxId).do());
|
|
53
56
|
}
|
|
54
57
|
}
|
|
55
58
|
class TransactionLoggingAlgodv2ProxyHandler {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transaction-logger.js","sources":["../../src/testing/transaction-logger.ts"],"sourcesContent":["import algosdk from 'algosdk'\nimport { runWhenIndexerCaughtUp } from './indexer'\nimport Algodv2 = algosdk.Algodv2\nimport decodeSignedTransaction = algosdk.decodeSignedTransaction\nimport Indexer = algosdk.Indexer\n\n/**\n * Allows you to keep track of Algorand transaction IDs by wrapping an `Algodv2` in a proxy.\n * Useful for automated tests.\n */\nexport class TransactionLogger {\n private _sentTransactionIds: string[] = []\n\n /**\n * The list of transaction IDs that has been logged thus far.\n */\n get sentTransactionIds(): Readonly<string[]> {\n return this._sentTransactionIds\n }\n\n /**\n * Clear all logged IDs.\n */\n clear() {\n this._sentTransactionIds = []\n }\n\n /**\n * The method that captures raw transactions and stores the transaction IDs.\n */\n logRawTransaction(signedTransactions: Uint8Array | Uint8Array[]) {\n if (Array.isArray(signedTransactions)) {\n for (const stxn of signedTransactions) {\n const decoded = decodeSignedTransaction(stxn)\n this._sentTransactionIds.push(decoded.txn.txID())\n }\n } else {\n const decoded = decodeSignedTransaction(signedTransactions)\n this._sentTransactionIds.push(decoded.txn.txID())\n }\n }\n\n /** Return a proxy that wraps the given Algodv2 with this transaction logger.\n *\n * @param algod The `Algodv2` to wrap\n * @returns The wrapped `Algodv2`, any transactions sent using this algod instance will be logged by this transaction logger\n */\n capture(algod: Algodv2): Algodv2 {\n return new Proxy<Algodv2>(algod, new TransactionLoggingAlgodv2ProxyHandler(this))\n }\n\n /** Wait until all logged transactions IDs appear in the given `Indexer`. */\n async waitForIndexer(indexer: Indexer) {\n
|
|
1
|
+
{"version":3,"file":"transaction-logger.js","sources":["../../src/testing/transaction-logger.ts"],"sourcesContent":["import algosdk from 'algosdk'\nimport { runWhenIndexerCaughtUp } from './indexer'\nimport Algodv2 = algosdk.Algodv2\nimport decodeSignedTransaction = algosdk.decodeSignedTransaction\nimport Indexer = algosdk.Indexer\n\n/**\n * Allows you to keep track of Algorand transaction IDs by wrapping an `Algodv2` in a proxy.\n * Useful for automated tests.\n */\nexport class TransactionLogger {\n private _sentTransactionIds: string[] = []\n\n /**\n * The list of transaction IDs that has been logged thus far.\n */\n get sentTransactionIds(): Readonly<string[]> {\n return this._sentTransactionIds\n }\n\n /**\n * Clear all logged IDs.\n */\n clear() {\n this._sentTransactionIds = []\n }\n\n /**\n * The method that captures raw transactions and stores the transaction IDs.\n */\n logRawTransaction(signedTransactions: Uint8Array | Uint8Array[]) {\n if (Array.isArray(signedTransactions)) {\n for (const stxn of signedTransactions) {\n const decoded = decodeSignedTransaction(stxn)\n this._sentTransactionIds.push(decoded.txn.txID())\n }\n } else {\n const decoded = decodeSignedTransaction(signedTransactions)\n this._sentTransactionIds.push(decoded.txn.txID())\n }\n }\n\n /** Return a proxy that wraps the given Algodv2 with this transaction logger.\n *\n * @param algod The `Algodv2` to wrap\n * @returns The wrapped `Algodv2`, any transactions sent using this algod instance will be logged by this transaction logger\n */\n capture(algod: Algodv2): Algodv2 {\n return new Proxy<Algodv2>(algod, new TransactionLoggingAlgodv2ProxyHandler(this))\n }\n\n /** Wait until all logged transactions IDs appear in the given `Indexer`. */\n async waitForIndexer(indexer: Indexer) {\n if (this._sentTransactionIds.length === 0) return\n const lastTxId = this._sentTransactionIds[this._sentTransactionIds.length - 1]\n await runWhenIndexerCaughtUp(() => indexer.lookupTransactionByID(lastTxId).do())\n }\n}\n\nclass TransactionLoggingAlgodv2ProxyHandler implements ProxyHandler<Algodv2> {\n private transactionLogger: TransactionLogger\n\n constructor(transactionLogger: TransactionLogger) {\n this.transactionLogger = transactionLogger\n }\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n get(target: Algodv2, property: string | symbol, receiver: any) {\n if (property === 'sendRawTransaction') {\n return (stxOrStxs: Uint8Array | Uint8Array[]) => {\n this.transactionLogger.logRawTransaction(stxOrStxs)\n return target[property].call(receiver, stxOrStxs)\n }\n }\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n return (target as any)[property]\n }\n}\n"],"names":["indexer","runWhenIndexerCaughtUp"],"mappings":";;;;;AAGA,IAAO,uBAAuB,GAAG,OAAO,CAAC,uBAAuB;AAGhE;;;AAGG;MACU,iBAAiB,CAAA;AAA9B,IAAA,WAAA,GAAA;QACU,IAAmB,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AG,iBAAiB;;;AAI5C,IAAA,GAAG,CAAC,MAAe,EAAE,QAAyB,EAAE,QAAa,EAAA;AAC3D,QAAA,IAAI,QAAQ,KAAK,oBAAoB,EAAE;YACrC,OAAO,CAAC,SAAoC,KAAI;AAC9C,gBAAA,IAAI,CAAC,iBAAiB,CAAC,iBAAiB,CAAC,SAAS,CAAC;gBACnD,OAAO,MAAM,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,QAAQ,EAAE,SAAS,CAAC;AACnD,aAAC;;;AAGH,QAAA,OAAQ,MAAc,CAAC,QAAQ,CAAC;;AAEnC;;;;"}
|
|
@@ -47,7 +47,10 @@ class TransactionLogger {
|
|
|
47
47
|
}
|
|
48
48
|
/** Wait until all logged transactions IDs appear in the given `Indexer`. */
|
|
49
49
|
async waitForIndexer(indexer) {
|
|
50
|
-
|
|
50
|
+
if (this._sentTransactionIds.length === 0)
|
|
51
|
+
return;
|
|
52
|
+
const lastTxId = this._sentTransactionIds[this._sentTransactionIds.length - 1];
|
|
53
|
+
await runWhenIndexerCaughtUp(() => indexer.lookupTransactionByID(lastTxId).do());
|
|
51
54
|
}
|
|
52
55
|
}
|
|
53
56
|
class TransactionLoggingAlgodv2ProxyHandler {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transaction-logger.mjs","sources":["../../src/testing/transaction-logger.ts"],"sourcesContent":["import algosdk from 'algosdk'\nimport { runWhenIndexerCaughtUp } from './indexer'\nimport Algodv2 = algosdk.Algodv2\nimport decodeSignedTransaction = algosdk.decodeSignedTransaction\nimport Indexer = algosdk.Indexer\n\n/**\n * Allows you to keep track of Algorand transaction IDs by wrapping an `Algodv2` in a proxy.\n * Useful for automated tests.\n */\nexport class TransactionLogger {\n private _sentTransactionIds: string[] = []\n\n /**\n * The list of transaction IDs that has been logged thus far.\n */\n get sentTransactionIds(): Readonly<string[]> {\n return this._sentTransactionIds\n }\n\n /**\n * Clear all logged IDs.\n */\n clear() {\n this._sentTransactionIds = []\n }\n\n /**\n * The method that captures raw transactions and stores the transaction IDs.\n */\n logRawTransaction(signedTransactions: Uint8Array | Uint8Array[]) {\n if (Array.isArray(signedTransactions)) {\n for (const stxn of signedTransactions) {\n const decoded = decodeSignedTransaction(stxn)\n this._sentTransactionIds.push(decoded.txn.txID())\n }\n } else {\n const decoded = decodeSignedTransaction(signedTransactions)\n this._sentTransactionIds.push(decoded.txn.txID())\n }\n }\n\n /** Return a proxy that wraps the given Algodv2 with this transaction logger.\n *\n * @param algod The `Algodv2` to wrap\n * @returns The wrapped `Algodv2`, any transactions sent using this algod instance will be logged by this transaction logger\n */\n capture(algod: Algodv2): Algodv2 {\n return new Proxy<Algodv2>(algod, new TransactionLoggingAlgodv2ProxyHandler(this))\n }\n\n /** Wait until all logged transactions IDs appear in the given `Indexer`. */\n async waitForIndexer(indexer: Indexer) {\n
|
|
1
|
+
{"version":3,"file":"transaction-logger.mjs","sources":["../../src/testing/transaction-logger.ts"],"sourcesContent":["import algosdk from 'algosdk'\nimport { runWhenIndexerCaughtUp } from './indexer'\nimport Algodv2 = algosdk.Algodv2\nimport decodeSignedTransaction = algosdk.decodeSignedTransaction\nimport Indexer = algosdk.Indexer\n\n/**\n * Allows you to keep track of Algorand transaction IDs by wrapping an `Algodv2` in a proxy.\n * Useful for automated tests.\n */\nexport class TransactionLogger {\n private _sentTransactionIds: string[] = []\n\n /**\n * The list of transaction IDs that has been logged thus far.\n */\n get sentTransactionIds(): Readonly<string[]> {\n return this._sentTransactionIds\n }\n\n /**\n * Clear all logged IDs.\n */\n clear() {\n this._sentTransactionIds = []\n }\n\n /**\n * The method that captures raw transactions and stores the transaction IDs.\n */\n logRawTransaction(signedTransactions: Uint8Array | Uint8Array[]) {\n if (Array.isArray(signedTransactions)) {\n for (const stxn of signedTransactions) {\n const decoded = decodeSignedTransaction(stxn)\n this._sentTransactionIds.push(decoded.txn.txID())\n }\n } else {\n const decoded = decodeSignedTransaction(signedTransactions)\n this._sentTransactionIds.push(decoded.txn.txID())\n }\n }\n\n /** Return a proxy that wraps the given Algodv2 with this transaction logger.\n *\n * @param algod The `Algodv2` to wrap\n * @returns The wrapped `Algodv2`, any transactions sent using this algod instance will be logged by this transaction logger\n */\n capture(algod: Algodv2): Algodv2 {\n return new Proxy<Algodv2>(algod, new TransactionLoggingAlgodv2ProxyHandler(this))\n }\n\n /** Wait until all logged transactions IDs appear in the given `Indexer`. */\n async waitForIndexer(indexer: Indexer) {\n if (this._sentTransactionIds.length === 0) return\n const lastTxId = this._sentTransactionIds[this._sentTransactionIds.length - 1]\n await runWhenIndexerCaughtUp(() => indexer.lookupTransactionByID(lastTxId).do())\n }\n}\n\nclass TransactionLoggingAlgodv2ProxyHandler implements ProxyHandler<Algodv2> {\n private transactionLogger: TransactionLogger\n\n constructor(transactionLogger: TransactionLogger) {\n this.transactionLogger = transactionLogger\n }\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n get(target: Algodv2, property: string | symbol, receiver: any) {\n if (property === 'sendRawTransaction') {\n return (stxOrStxs: Uint8Array | Uint8Array[]) => {\n this.transactionLogger.logRawTransaction(stxOrStxs)\n return target[property].call(receiver, stxOrStxs)\n }\n }\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n return (target as any)[property]\n }\n}\n"],"names":[],"mappings":";;;AAGA,IAAO,uBAAuB,GAAG,OAAO,CAAC,uBAAuB;AAGhE;;;AAGG;MACU,iBAAiB,CAAA;AAA9B,IAAA,WAAA,GAAA;QACU,IAAmB,CAAA,mBAAA,GAAa,EAAE;;AAE1C;;AAEG;AACH,IAAA,IAAI,kBAAkB,GAAA;QACpB,OAAO,IAAI,CAAC,mBAAmB;;AAGjC;;AAEG;IACH,KAAK,GAAA;AACH,QAAA,IAAI,CAAC,mBAAmB,GAAG,EAAE;;AAG/B;;AAEG;AACH,IAAA,iBAAiB,CAAC,kBAA6C,EAAA;AAC7D,QAAA,IAAI,KAAK,CAAC,OAAO,CAAC,kBAAkB,CAAC,EAAE;AACrC,YAAA,KAAK,MA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H,QAAA,OAAQ,MAAc,CAAC,QAAQ,CAAC;;AAEnC;;;;"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import algosdk from 'algosdk';
|
|
2
2
|
import { AlgoAmount } from '../types/amount';
|
|
3
3
|
import { ABIReturn } from '../types/app';
|
|
4
|
-
import { AtomicTransactionComposerToSend, SendAtomicTransactionComposerResults, SendTransactionFrom, SendTransactionParams, SendTransactionResult, TransactionGroupToSend, TransactionNote, TransactionToSign } from '../types/transaction';
|
|
4
|
+
import { AdditionalAtomicTransactionComposerContext, AtomicTransactionComposerToSend, SendAtomicTransactionComposerResults, SendParams, SendTransactionFrom, SendTransactionParams, SendTransactionResult, TransactionGroupToSend, TransactionNote, TransactionToSign } from '../types/transaction';
|
|
5
5
|
import Algodv2 = algosdk.Algodv2;
|
|
6
6
|
import AtomicTransactionComposer = algosdk.AtomicTransactionComposer;
|
|
7
7
|
import modelsv2 = algosdk.modelsv2;
|
|
@@ -100,11 +100,11 @@ export declare const sendTransaction: (send: {
|
|
|
100
100
|
}, algod: Algodv2) => Promise<SendTransactionResult>;
|
|
101
101
|
/**
|
|
102
102
|
* Take an existing Atomic Transaction Composer and return a new one with the required
|
|
103
|
-
*
|
|
103
|
+
* app call resources populated into it
|
|
104
104
|
*
|
|
105
105
|
* @param algod The algod client to use for the simulation
|
|
106
106
|
* @param atc The ATC containing the txn group
|
|
107
|
-
* @returns A new ATC with the resources
|
|
107
|
+
* @returns A new ATC with the resources populated into the transactions
|
|
108
108
|
*
|
|
109
109
|
* @privateRemarks
|
|
110
110
|
*
|
|
@@ -116,6 +116,21 @@ export declare const sendTransaction: (send: {
|
|
|
116
116
|
*
|
|
117
117
|
*/
|
|
118
118
|
export declare function populateAppCallResources(atc: algosdk.AtomicTransactionComposer, algod: algosdk.Algodv2): Promise<algosdk.AtomicTransactionComposer>;
|
|
119
|
+
/**
|
|
120
|
+
* Take an existing Atomic Transaction Composer and return a new one with changes applied to the transactions
|
|
121
|
+
* based on the supplied sendParams to ensure the transaction group is ready for sending.
|
|
122
|
+
*
|
|
123
|
+
* @param algod The algod client to use for the simulation
|
|
124
|
+
* @param atc The ATC containing the txn group
|
|
125
|
+
* @param sendParams The send params for the transaction group
|
|
126
|
+
* @param additionalAtcContext Additional ATC context used to determine how best to change the transactions in the group
|
|
127
|
+
* @returns A new ATC with the changes applied
|
|
128
|
+
*
|
|
129
|
+
* @privateRemarks
|
|
130
|
+
* Parts of this function will eventually be implemented in algod. Namely:
|
|
131
|
+
* - Simulate will return information on how to populate reference arrays, see https://github.com/algorand/go-algorand/pull/6015
|
|
132
|
+
*/
|
|
133
|
+
export declare function prepareGroupForSending(atc: algosdk.AtomicTransactionComposer, algod: algosdk.Algodv2, sendParams: SendParams, additionalAtcContext?: AdditionalAtomicTransactionComposerContext): Promise<algosdk.AtomicTransactionComposer>;
|
|
119
134
|
/**
|
|
120
135
|
* Signs and sends transactions that have been collected by an `AtomicTransactionComposer`.
|
|
121
136
|
* @param atcSend The parameters controlling the send, including `atc` The `AtomicTransactionComposer` and params to control send behaviour
|