@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.
- package/account.d.ts +91 -0
- package/account.d.ts.map +1 -0
- package/account.js +158 -0
- package/account.js.map +1 -0
- package/amount.d.ts +8 -0
- package/amount.d.ts.map +1 -0
- package/amount.js +24 -0
- package/amount.js.map +1 -0
- package/app.d.ts +108 -0
- package/app.d.ts.map +1 -0
- package/app.js +423 -0
- package/app.js.map +1 -0
- package/application-client.d.ts +10 -0
- package/application-client.d.ts.map +1 -0
- package/application-client.js +15 -0
- package/application-client.js.map +1 -0
- package/deploy-app.d.ts +93 -0
- package/deploy-app.d.ts.map +1 -0
- package/deploy-app.js +410 -0
- package/deploy-app.js.map +1 -0
- package/index.d.ts +14 -0
- package/index.d.ts.map +1 -0
- package/index.js +5 -2
- package/index.js.map +1 -0
- package/indexer-lookup.d.ts +31 -0
- package/indexer-lookup.d.ts.map +1 -0
- package/indexer-lookup.js +96 -0
- package/indexer-lookup.js.map +1 -0
- package/localnet.d.ts +54 -0
- package/localnet.d.ts.map +1 -0
- package/localnet.js +121 -0
- package/localnet.js.map +1 -0
- package/network-client.d.ts +93 -0
- package/network-client.d.ts.map +1 -0
- package/network-client.js +182 -0
- package/network-client.js.map +1 -0
- package/package.json +3 -3
- package/testing/account.d.ts +14 -0
- package/testing/account.d.ts.map +1 -0
- package/testing/account.js +31 -0
- package/testing/account.js.map +1 -0
- package/testing/fixtures/algokit-log-capture-fixture.d.ts +19 -0
- package/testing/fixtures/algokit-log-capture-fixture.d.ts.map +1 -0
- package/testing/fixtures/algokit-log-capture-fixture.js +43 -0
- package/testing/fixtures/algokit-log-capture-fixture.js.map +1 -0
- package/testing/fixtures/algorand-fixture.d.ts +20 -0
- package/testing/fixtures/algorand-fixture.d.ts.map +1 -0
- package/testing/fixtures/algorand-fixture.js +49 -0
- package/testing/fixtures/algorand-fixture.js.map +1 -0
- package/testing/fixtures/index.d.ts +3 -0
- package/testing/fixtures/index.d.ts.map +1 -0
- package/testing/fixtures/index.js +19 -0
- package/testing/fixtures/index.js.map +1 -0
- package/testing/index.d.ts +6 -0
- package/testing/index.d.ts.map +1 -0
- package/testing/index.js +22 -0
- package/testing/index.js.map +1 -0
- package/testing/indexer.d.ts +12 -0
- package/testing/indexer.d.ts.map +1 -0
- package/testing/indexer.js +39 -0
- package/testing/indexer.js.map +1 -0
- package/testing/test-logger.d.ts +39 -0
- package/testing/test-logger.d.ts.map +1 -0
- package/testing/test-logger.js +69 -0
- package/testing/test-logger.js.map +1 -0
- package/testing/transaction-logger.d.ts +29 -0
- package/testing/transaction-logger.d.ts.map +1 -0
- package/testing/transaction-logger.js +71 -0
- package/testing/transaction-logger.js.map +1 -0
- package/transaction.d.ts +80 -0
- package/transaction.d.ts.map +1 -0
- package/transaction.js +256 -0
- package/transaction.js.map +1 -0
- package/transfer.d.ts +21 -0
- package/transfer.d.ts.map +1 -0
- package/transfer.js +65 -0
- package/transfer.js.map +1 -0
- package/types/account.d.ts +52 -0
- package/types/account.d.ts.map +1 -0
- package/types/account.js +86 -0
- package/types/account.js.map +1 -0
- package/types/algo-http-client-with-retry.d.ts +14 -0
- package/types/algo-http-client-with-retry.d.ts.map +1 -0
- package/types/algo-http-client-with-retry.js +62 -0
- package/types/algo-http-client-with-retry.js.map +1 -0
- package/types/algod.d.ts +137 -0
- package/types/algod.d.ts.map +1 -0
- package/types/algod.js +3 -0
- package/types/algod.js.map +1 -0
- package/types/amount.d.ts +20 -0
- package/types/amount.d.ts.map +1 -0
- package/types/amount.js +37 -0
- package/types/amount.js.map +1 -0
- package/types/app.d.ts +279 -0
- package/types/app.d.ts.map +1 -0
- package/types/app.js +32 -0
- package/types/app.js.map +1 -0
- package/types/application-client.d.ts +229 -0
- package/types/application-client.d.ts.map +1 -0
- package/types/application-client.js +470 -0
- package/types/application-client.js.map +1 -0
- package/types/appspec.d.ts +77 -0
- package/types/appspec.d.ts.map +1 -0
- package/types/appspec.js +15 -0
- package/types/appspec.js.map +1 -0
- package/types/config.d.ts +15 -0
- package/types/config.d.ts.map +1 -0
- package/types/config.js +27 -0
- package/types/config.js.map +1 -0
- package/types/indexer.d.ts +313 -0
- package/types/indexer.d.ts.map +1 -0
- package/types/indexer.js +25 -0
- package/types/indexer.js.map +1 -0
- package/types/logging.d.ts +13 -0
- package/types/logging.d.ts.map +1 -0
- package/types/logging.js +27 -0
- package/types/logging.js.map +1 -0
- package/types/logic-error.d.ts +33 -0
- package/types/logic-error.d.ts.map +1 -0
- package/types/logic-error.js +46 -0
- package/types/logic-error.js.map +1 -0
- package/types/network-client.d.ts +11 -0
- package/types/network-client.d.ts.map +1 -0
- package/types/network-client.js +3 -0
- package/types/network-client.js.map +1 -0
- package/types/testing.d.ts +89 -0
- package/types/testing.d.ts.map +1 -0
- package/types/testing.js +3 -0
- package/types/testing.js.map +1 -0
- package/types/transaction.d.ts +67 -0
- package/types/transaction.d.ts.map +1 -0
- package/types/transaction.js +3 -0
- package/types/transaction.js.map +1 -0
- package/types/transfer.d.ts +32 -0
- package/types/transfer.d.ts.map +1 -0
- package/types/transfer.js +3 -0
- package/types/transfer.js.map +1 -0
- package/types/urlTokenBaseHTTPClient.d.ts +41 -0
- package/types/urlTokenBaseHTTPClient.d.ts.map +1 -0
- package/types/urlTokenBaseHTTPClient.js +151 -0
- package/types/urlTokenBaseHTTPClient.js.map +1 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"algorand-fixture.d.ts","sourceRoot":"","sources":["../../../src/testing/fixtures/algorand-fixture.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,eAAe,EAAE,qBAAqB,EAAuD,MAAM,qBAAqB,CAAA;AAEjI;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,eAAe,mBAAoB,qBAAqB,KAAG,eA0BvE,CAAA"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.algorandFixture = void 0;
|
|
4
|
+
const __1 = require("../");
|
|
5
|
+
const __2 = require("../../");
|
|
6
|
+
/**
|
|
7
|
+
* Creates a test fixture for automated testing against Algorand.
|
|
8
|
+
* 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.
|
|
9
|
+
*
|
|
10
|
+
* @example ```typescript
|
|
11
|
+
* const algorand = algorandFixture()
|
|
12
|
+
*
|
|
13
|
+
* beforeEach(algorand.beforeEach, 10_000)
|
|
14
|
+
*
|
|
15
|
+
* test('My test', () => {
|
|
16
|
+
* const {algod, indexer, testAccount, ...} = algorand.context
|
|
17
|
+
* })
|
|
18
|
+
* ```
|
|
19
|
+
*
|
|
20
|
+
* @param fixtureConfig The fixture configuration
|
|
21
|
+
* @returns The fixture
|
|
22
|
+
*/
|
|
23
|
+
const algorandFixture = (fixtureConfig) => {
|
|
24
|
+
const algod = fixtureConfig?.algod ?? (0, __2.getAlgoClient)((0, __2.getDefaultLocalNetConfig)('algod'));
|
|
25
|
+
const indexer = fixtureConfig?.indexer ?? (0, __2.getAlgoIndexerClient)((0, __2.getDefaultLocalNetConfig)('indexer'));
|
|
26
|
+
const kmd = fixtureConfig?.kmd ?? (0, __2.getAlgoKmdClient)((0, __2.getDefaultLocalNetConfig)('kmd'));
|
|
27
|
+
let context;
|
|
28
|
+
const beforeEach = async () => {
|
|
29
|
+
const transactionLogger = new __1.TransactionLogger();
|
|
30
|
+
context = {
|
|
31
|
+
algod: transactionLogger.capture(algod),
|
|
32
|
+
indexer: indexer,
|
|
33
|
+
kmd: kmd,
|
|
34
|
+
testAccount: await (0, __1.getTestAccount)({ initialFunds: fixtureConfig?.testAccountFunding ?? (0, __2.algos)(10), suppressLog: true }, algod, kmd),
|
|
35
|
+
generateAccount: (params) => (0, __1.getTestAccount)(params, algod, kmd),
|
|
36
|
+
transactionLogger: transactionLogger,
|
|
37
|
+
waitForIndexer: () => transactionLogger.waitForIndexer(indexer),
|
|
38
|
+
waitForIndexerTransaction: (transactionId) => (0, __1.runWhenIndexerCaughtUp)(() => (0, __2.lookupTransactionById)(transactionId, indexer)),
|
|
39
|
+
};
|
|
40
|
+
};
|
|
41
|
+
return {
|
|
42
|
+
get context() {
|
|
43
|
+
return context;
|
|
44
|
+
},
|
|
45
|
+
beforeEach,
|
|
46
|
+
};
|
|
47
|
+
};
|
|
48
|
+
exports.algorandFixture = algorandFixture;
|
|
49
|
+
//# sourceMappingURL=algorand-fixture.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"algorand-fixture.js","sourceRoot":"","sources":["../../../src/testing/fixtures/algorand-fixture.ts"],"names":[],"mappings":";;;AAAA,2BAA+E;AAC/E,8BAAsI;AAGtI;;;;;;;;;;;;;;;;GAgBG;AACI,MAAM,eAAe,GAAG,CAAC,aAAqC,EAAmB,EAAE;IACxF,MAAM,KAAK,GAAG,aAAa,EAAE,KAAK,IAAI,IAAA,iBAAa,EAAC,IAAA,4BAAwB,EAAC,OAAO,CAAC,CAAC,CAAA;IACtF,MAAM,OAAO,GAAG,aAAa,EAAE,OAAO,IAAI,IAAA,wBAAoB,EAAC,IAAA,4BAAwB,EAAC,SAAS,CAAC,CAAC,CAAA;IACnG,MAAM,GAAG,GAAG,aAAa,EAAE,GAAG,IAAI,IAAA,oBAAgB,EAAC,IAAA,4BAAwB,EAAC,KAAK,CAAC,CAAC,CAAA;IACnF,IAAI,OAAsC,CAAA;IAE1C,MAAM,UAAU,GAAG,KAAK,IAAI,EAAE;QAC5B,MAAM,iBAAiB,GAAG,IAAI,qBAAiB,EAAE,CAAA;QACjD,OAAO,GAAG;YACR,KAAK,EAAE,iBAAiB,CAAC,OAAO,CAAC,KAAK,CAAC;YACvC,OAAO,EAAE,OAAO;YAChB,GAAG,EAAE,GAAG;YACR,WAAW,EAAE,MAAM,IAAA,kBAAc,EAAC,EAAE,YAAY,EAAE,aAAa,EAAE,kBAAkB,IAAI,IAAA,SAAK,EAAC,EAAE,CAAC,EAAE,WAAW,EAAE,IAAI,EAAE,EAAE,KAAK,EAAE,GAAG,CAAC;YAClI,eAAe,EAAE,CAAC,MAA4B,EAAE,EAAE,CAAC,IAAA,kBAAc,EAAC,MAAM,EAAE,KAAK,EAAE,GAAG,CAAC;YACrF,iBAAiB,EAAE,iBAAiB;YACpC,cAAc,EAAE,GAAG,EAAE,CAAC,iBAAiB,CAAC,cAAc,CAAC,OAAO,CAAC;YAC/D,yBAAyB,EAAE,CAAC,aAAqB,EAAE,EAAE,CAAC,IAAA,0BAAsB,EAAC,GAAG,EAAE,CAAC,IAAA,yBAAqB,EAAC,aAAa,EAAE,OAAO,CAAC,CAAC;SAClI,CAAA;IACH,CAAC,CAAA;IAED,OAAO;QACL,IAAI,OAAO;YACT,OAAO,OAAO,CAAA;QAChB,CAAC;QACD,UAAU;KACX,CAAA;AACH,CAAC,CAAA;AA1BY,QAAA,eAAe,mBA0B3B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/testing/fixtures/index.ts"],"names":[],"mappings":"AAAA,cAAc,+BAA+B,CAAA;AAC7C,cAAc,oBAAoB,CAAA"}
|
|
@@ -0,0 +1,19 @@
|
|
|
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./algokit-log-capture-fixture"), exports);
|
|
18
|
+
__exportStar(require("./algorand-fixture"), exports);
|
|
19
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/testing/fixtures/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,gEAA6C;AAC7C,qDAAkC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/testing/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAA;AACzB,cAAc,YAAY,CAAA;AAC1B,cAAc,WAAW,CAAA;AACzB,cAAc,eAAe,CAAA;AAC7B,cAAc,sBAAsB,CAAA"}
|
package/testing/index.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./account"), exports);
|
|
18
|
+
__exportStar(require("./fixtures"), exports);
|
|
19
|
+
__exportStar(require("./indexer"), exports);
|
|
20
|
+
__exportStar(require("./test-logger"), exports);
|
|
21
|
+
__exportStar(require("./transaction-logger"), exports);
|
|
22
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/testing/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,4CAAyB;AACzB,6CAA0B;AAC1B,4CAAyB;AACzB,gDAA6B;AAC7B,uDAAoC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Runs the given indexer call until a 404 error is no longer returned.
|
|
3
|
+
* Tried every 200ms up to 20 times.
|
|
4
|
+
* Very rudimentary implementation designed for automated testing.
|
|
5
|
+
* @example ```typescript
|
|
6
|
+
* const transaction = await runWhenIndexerCaughtUp(() => indexer.lookupTransactionByID(txnId).do())
|
|
7
|
+
* ```
|
|
8
|
+
* @param run The code to run
|
|
9
|
+
* @returns The result (as a promise), or throws if the indexer didn't catch up in time
|
|
10
|
+
*/
|
|
11
|
+
export declare function runWhenIndexerCaughtUp<T>(run: () => Promise<T>): Promise<T>;
|
|
12
|
+
//# sourceMappingURL=indexer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"indexer.d.ts","sourceRoot":"","sources":["../../src/testing/indexer.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,wBAAsB,sBAAsB,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAsBjF"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.runWhenIndexerCaughtUp = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Runs the given indexer call until a 404 error is no longer returned.
|
|
6
|
+
* Tried every 200ms up to 20 times.
|
|
7
|
+
* Very rudimentary implementation designed for automated testing.
|
|
8
|
+
* @example ```typescript
|
|
9
|
+
* const transaction = await runWhenIndexerCaughtUp(() => indexer.lookupTransactionByID(txnId).do())
|
|
10
|
+
* ```
|
|
11
|
+
* @param run The code to run
|
|
12
|
+
* @returns The result (as a promise), or throws if the indexer didn't catch up in time
|
|
13
|
+
*/
|
|
14
|
+
async function runWhenIndexerCaughtUp(run) {
|
|
15
|
+
let result = null;
|
|
16
|
+
let ok = false;
|
|
17
|
+
let tries = 0;
|
|
18
|
+
while (!ok) {
|
|
19
|
+
try {
|
|
20
|
+
result = await run();
|
|
21
|
+
ok = true;
|
|
22
|
+
}
|
|
23
|
+
catch (e) {
|
|
24
|
+
if (e?.status === 404) {
|
|
25
|
+
tries++;
|
|
26
|
+
if (tries > 20) {
|
|
27
|
+
throw e;
|
|
28
|
+
}
|
|
29
|
+
await new Promise((resolve) => setTimeout(resolve, 200));
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
throw e;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return result;
|
|
37
|
+
}
|
|
38
|
+
exports.runWhenIndexerCaughtUp = runWhenIndexerCaughtUp;
|
|
39
|
+
//# sourceMappingURL=indexer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"indexer.js","sourceRoot":"","sources":["../../src/testing/indexer.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;GASG;AACI,KAAK,UAAU,sBAAsB,CAAI,GAAqB;IACnE,IAAI,MAAM,GAAa,IAAI,CAAA;IAC3B,IAAI,EAAE,GAAG,KAAK,CAAA;IACd,IAAI,KAAK,GAAG,CAAC,CAAA;IACb,OAAO,CAAC,EAAE,EAAE;QACV,IAAI;YACF,MAAM,GAAG,MAAM,GAAG,EAAE,CAAA;YACpB,EAAE,GAAG,IAAI,CAAA;SACV;QAAC,OAAO,CAAM,EAAE;YACf,IAAI,CAAC,EAAE,MAAM,KAAK,GAAG,EAAE;gBACrB,KAAK,EAAE,CAAA;gBACP,IAAI,KAAK,GAAG,EAAE,EAAE;oBACd,MAAM,CAAC,CAAA;iBACR;gBACD,MAAM,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC,CAAA;aAC/D;iBAAM;gBACL,MAAM,CAAC,CAAA;aACR;SACF;KACF;IAED,OAAO,MAAW,CAAA;AACpB,CAAC;AAtBD,wDAsBC"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { Logger } from '../types/logging';
|
|
2
|
+
import { LogSnapshotConfig } from '../types/testing';
|
|
3
|
+
/** Exposes an AlgoKit logger which captures log messages, while wrapping an original logger.
|
|
4
|
+
* This is useful for automated testing.
|
|
5
|
+
*/
|
|
6
|
+
export declare class TestLogger implements Logger {
|
|
7
|
+
private originalLogger;
|
|
8
|
+
private logs;
|
|
9
|
+
/**
|
|
10
|
+
* Create a new test logger that wraps the given logger if provided.
|
|
11
|
+
* @param originalLogger The optional original logger to wrap.
|
|
12
|
+
*/
|
|
13
|
+
constructor(originalLogger?: Logger);
|
|
14
|
+
/** Returns all logs captured thus far. */
|
|
15
|
+
get capturedLogs(): string[];
|
|
16
|
+
/** Clears all logs captured so far. */
|
|
17
|
+
clear(): void;
|
|
18
|
+
/**
|
|
19
|
+
* Returns a captured log snapshot.
|
|
20
|
+
* This helps ensure that the provided configuration items won't appear
|
|
21
|
+
* with random values in the log snapshot, but rather will get substituted with predictable ids.
|
|
22
|
+
* @see https://jestjs.io/docs/snapshot-testing#2-tests-should-be-deterministic
|
|
23
|
+
* @example Jest Example
|
|
24
|
+
* ```typescript
|
|
25
|
+
* const logger = new TestLogger()
|
|
26
|
+
* ...
|
|
27
|
+
* expect(logger.getLogSnapshot()).toMatchSnapshot()
|
|
28
|
+
* ```
|
|
29
|
+
* @param config The snapshot configuration
|
|
30
|
+
* @returns The snapshotted logs.
|
|
31
|
+
*/
|
|
32
|
+
getLogSnapshot(config?: LogSnapshotConfig): string;
|
|
33
|
+
error(message: string, ...optionalParams: unknown[]): void;
|
|
34
|
+
warn(message: string, ...optionalParams: unknown[]): void;
|
|
35
|
+
info(message: string, ...optionalParams: unknown[]): void;
|
|
36
|
+
verbose(message: string, ...optionalParams: unknown[]): void;
|
|
37
|
+
debug(message: string, ...optionalParams: unknown[]): void;
|
|
38
|
+
}
|
|
39
|
+
//# sourceMappingURL=test-logger.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"test-logger.d.ts","sourceRoot":"","sources":["../../src/testing/test-logger.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAA;AACzC,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAA;AAEpD;;GAEG;AACH,qBAAa,UAAW,YAAW,MAAM;IACvC,OAAO,CAAC,cAAc,CAAoB;IAC1C,OAAO,CAAC,IAAI,CAAU;IAEtB;;;OAGG;gBACS,cAAc,CAAC,EAAE,MAAM;IAKnC,0CAA0C;IAC1C,IAAI,YAAY,IAAI,MAAM,EAAE,CAE3B;IAED,uCAAuC;IACvC,KAAK;IAIL;;;;;;;;;;;;;OAaG;IACH,cAAc,CAAC,MAAM,CAAC,EAAE,iBAAiB;IAczC,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,cAAc,EAAE,OAAO,EAAE,GAAG,IAAI;IAI1D,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,cAAc,EAAE,OAAO,EAAE,GAAG,IAAI;IAIzD,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,cAAc,EAAE,OAAO,EAAE,GAAG,IAAI;IAIzD,OAAO,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,cAAc,EAAE,OAAO,EAAE,GAAG,IAAI;IAI5D,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,cAAc,EAAE,OAAO,EAAE,GAAG,IAAI;CAI3D"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TestLogger = void 0;
|
|
4
|
+
const __1 = require("../");
|
|
5
|
+
/** Exposes an AlgoKit logger which captures log messages, while wrapping an original logger.
|
|
6
|
+
* This is useful for automated testing.
|
|
7
|
+
*/
|
|
8
|
+
class TestLogger {
|
|
9
|
+
/**
|
|
10
|
+
* Create a new test logger that wraps the given logger if provided.
|
|
11
|
+
* @param originalLogger The optional original logger to wrap.
|
|
12
|
+
*/
|
|
13
|
+
constructor(originalLogger) {
|
|
14
|
+
this.originalLogger = originalLogger;
|
|
15
|
+
this.logs = [];
|
|
16
|
+
}
|
|
17
|
+
/** Returns all logs captured thus far. */
|
|
18
|
+
get capturedLogs() {
|
|
19
|
+
return this.logs;
|
|
20
|
+
}
|
|
21
|
+
/** Clears all logs captured so far. */
|
|
22
|
+
clear() {
|
|
23
|
+
this.logs = [];
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Returns a captured log snapshot.
|
|
27
|
+
* This helps ensure that the provided configuration items won't appear
|
|
28
|
+
* with random values in the log snapshot, but rather will get substituted with predictable ids.
|
|
29
|
+
* @see https://jestjs.io/docs/snapshot-testing#2-tests-should-be-deterministic
|
|
30
|
+
* @example Jest Example
|
|
31
|
+
* ```typescript
|
|
32
|
+
* const logger = new TestLogger()
|
|
33
|
+
* ...
|
|
34
|
+
* expect(logger.getLogSnapshot()).toMatchSnapshot()
|
|
35
|
+
* ```
|
|
36
|
+
* @param config The snapshot configuration
|
|
37
|
+
* @returns The snapshotted logs.
|
|
38
|
+
*/
|
|
39
|
+
getLogSnapshot(config) {
|
|
40
|
+
const { transactions: transactionIds, accounts, apps } = config ?? {};
|
|
41
|
+
let snapshot = this.capturedLogs.join('\n');
|
|
42
|
+
transactionIds?.forEach((txn, id) => (snapshot = snapshot.replace(new RegExp(typeof txn === 'string' ? txn : txn.txID(), 'g'), `TXID_${id + 1}`)));
|
|
43
|
+
accounts?.forEach((sender, id) => (snapshot = snapshot.replace(new RegExp(typeof sender === 'string' ? sender : (0, __1.getSenderAddress)(sender), 'g'), `ACCOUNT_${id + 1}`)));
|
|
44
|
+
apps?.forEach((app, id) => (snapshot = snapshot.replace(new RegExp(`\\b${app.toString()}\\b`, 'g'), `APP_${id + 1}`)));
|
|
45
|
+
return snapshot;
|
|
46
|
+
}
|
|
47
|
+
error(message, ...optionalParams) {
|
|
48
|
+
this.originalLogger?.error(message, ...optionalParams);
|
|
49
|
+
this.logs.push(`ERROR: ${message}${optionalParams.length ? ` | ${JSON.stringify(optionalParams)}` : ''}`);
|
|
50
|
+
}
|
|
51
|
+
warn(message, ...optionalParams) {
|
|
52
|
+
this.originalLogger?.warn(message, ...optionalParams);
|
|
53
|
+
this.logs.push(`WARN: ${message}${optionalParams.length ? ` | ${JSON.stringify(optionalParams)}` : ''}`);
|
|
54
|
+
}
|
|
55
|
+
info(message, ...optionalParams) {
|
|
56
|
+
this.originalLogger?.info(message, ...optionalParams);
|
|
57
|
+
this.logs.push(`INFO: ${message}${optionalParams.length ? ` | ${JSON.stringify(optionalParams)}` : ''}`);
|
|
58
|
+
}
|
|
59
|
+
verbose(message, ...optionalParams) {
|
|
60
|
+
this.originalLogger?.verbose(message, ...optionalParams);
|
|
61
|
+
this.logs.push(`VERBOSE: ${message}${optionalParams.length ? ` | ${JSON.stringify(optionalParams)}` : ''}`);
|
|
62
|
+
}
|
|
63
|
+
debug(message, ...optionalParams) {
|
|
64
|
+
this.originalLogger?.debug(message, ...optionalParams);
|
|
65
|
+
this.logs.push(`DEBUG: ${message}${optionalParams.length ? ` | ${JSON.stringify(optionalParams)}` : ''}`);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
exports.TestLogger = TestLogger;
|
|
69
|
+
//# sourceMappingURL=test-logger.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"test-logger.js","sourceRoot":"","sources":["../../src/testing/test-logger.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { Algodv2, Indexer } from 'algosdk';
|
|
2
|
+
/**
|
|
3
|
+
* Allows you to keep track of Algorand transaction IDs by wrapping an @see Algodv2 in a proxy.
|
|
4
|
+
* Useful for automated tests.
|
|
5
|
+
*/
|
|
6
|
+
export declare class TransactionLogger {
|
|
7
|
+
private _sentTransactionIds;
|
|
8
|
+
/**
|
|
9
|
+
* The list of transaction IDs that has been logged thus far.
|
|
10
|
+
*/
|
|
11
|
+
get sentTransactionIds(): Readonly<string[]>;
|
|
12
|
+
/**
|
|
13
|
+
* Clear all logged IDs.
|
|
14
|
+
*/
|
|
15
|
+
clear(): void;
|
|
16
|
+
/**
|
|
17
|
+
* The method that captures raw transactions and stores the transaction IDs.
|
|
18
|
+
*/
|
|
19
|
+
logRawTransaction(signedTransactions: Uint8Array | Uint8Array[]): void;
|
|
20
|
+
/** Return a proxy that wraps the given Algodv2 with this transaction logger.
|
|
21
|
+
*
|
|
22
|
+
* @param algod The @see Algodv2 to wrap
|
|
23
|
+
* @returns The wrapped @see Algodv2, any transactions sent using this algod instance will be logged by this transaction logger
|
|
24
|
+
*/
|
|
25
|
+
capture(algod: Algodv2): Algodv2;
|
|
26
|
+
/** Wait until all logged transactions IDs appear in the given @see Indexer. */
|
|
27
|
+
waitForIndexer(indexer: Indexer): Promise<void>;
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=transaction-logger.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transaction-logger.d.ts","sourceRoot":"","sources":["../../src/testing/transaction-logger.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAA2B,OAAO,EAAE,MAAM,SAAS,CAAA;AAGnE;;;GAGG;AACH,qBAAa,iBAAiB;IAC5B,OAAO,CAAC,mBAAmB,CAAe;IAE1C;;OAEG;IACH,IAAI,kBAAkB,IAAI,QAAQ,CAAC,MAAM,EAAE,CAAC,CAE3C;IAED;;OAEG;IACH,KAAK;IAIL;;OAEG;IACH,iBAAiB,CAAC,kBAAkB,EAAE,UAAU,GAAG,UAAU,EAAE;IAY/D;;;;OAIG;IACH,OAAO,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO;IAIhC,+EAA+E;IACzE,cAAc,CAAC,OAAO,EAAE,OAAO;CAGtC"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TransactionLogger = void 0;
|
|
4
|
+
const algosdk_1 = require("algosdk");
|
|
5
|
+
const _1 = require("./");
|
|
6
|
+
/**
|
|
7
|
+
* Allows you to keep track of Algorand transaction IDs by wrapping an @see Algodv2 in a proxy.
|
|
8
|
+
* Useful for automated tests.
|
|
9
|
+
*/
|
|
10
|
+
class TransactionLogger {
|
|
11
|
+
constructor() {
|
|
12
|
+
this._sentTransactionIds = [];
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* The list of transaction IDs that has been logged thus far.
|
|
16
|
+
*/
|
|
17
|
+
get sentTransactionIds() {
|
|
18
|
+
return this._sentTransactionIds;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Clear all logged IDs.
|
|
22
|
+
*/
|
|
23
|
+
clear() {
|
|
24
|
+
this._sentTransactionIds = [];
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* The method that captures raw transactions and stores the transaction IDs.
|
|
28
|
+
*/
|
|
29
|
+
logRawTransaction(signedTransactions) {
|
|
30
|
+
if (Array.isArray(signedTransactions)) {
|
|
31
|
+
for (const stxn of signedTransactions) {
|
|
32
|
+
const decoded = (0, algosdk_1.decodeSignedTransaction)(stxn);
|
|
33
|
+
this._sentTransactionIds.push(decoded.txn.txID());
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
const decoded = (0, algosdk_1.decodeSignedTransaction)(signedTransactions);
|
|
38
|
+
this._sentTransactionIds.push(decoded.txn.txID());
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
/** Return a proxy that wraps the given Algodv2 with this transaction logger.
|
|
42
|
+
*
|
|
43
|
+
* @param algod The @see Algodv2 to wrap
|
|
44
|
+
* @returns The wrapped @see Algodv2, any transactions sent using this algod instance will be logged by this transaction logger
|
|
45
|
+
*/
|
|
46
|
+
capture(algod) {
|
|
47
|
+
return new Proxy(algod, new TransactionLoggingAlgodv2ProxyHandler(this));
|
|
48
|
+
}
|
|
49
|
+
/** Wait until all logged transactions IDs appear in the given @see Indexer. */
|
|
50
|
+
async waitForIndexer(indexer) {
|
|
51
|
+
await Promise.all(this._sentTransactionIds.map((txnId) => (0, _1.runWhenIndexerCaughtUp)(() => indexer.lookupTransactionByID(txnId).do())));
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
exports.TransactionLogger = TransactionLogger;
|
|
55
|
+
class TransactionLoggingAlgodv2ProxyHandler {
|
|
56
|
+
constructor(transactionLogger) {
|
|
57
|
+
this.transactionLogger = transactionLogger;
|
|
58
|
+
}
|
|
59
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
60
|
+
get(target, property, receiver) {
|
|
61
|
+
if (property === 'sendRawTransaction') {
|
|
62
|
+
return (stxOrStxs) => {
|
|
63
|
+
this.transactionLogger.logRawTransaction(stxOrStxs);
|
|
64
|
+
return target[property].call(receiver, stxOrStxs);
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
68
|
+
return target[property];
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
//# sourceMappingURL=transaction-logger.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transaction-logger.js","sourceRoot":"","sources":["../../src/testing/transaction-logger.ts"],"names":[],"mappings":";;;AAAA,qCAAmE;AACnE,yBAA2C;AAE3C;;;GAGG;AACH,MAAa,iBAAiB;IAA9B;QACU,wBAAmB,GAAa,EAAE,CAAA;IA4C5C,CAAC;IA1CC;;OAEG;IACH,IAAI,kBAAkB;QACpB,OAAO,IAAI,CAAC,mBAAmB,CAAA;IACjC,CAAC;IAED;;OAEG;IACH,KAAK;QACH,IAAI,CAAC,mBAAmB,GAAG,EAAE,CAAA;IAC/B,CAAC;IAED;;OAEG;IACH,iBAAiB,CAAC,kBAA6C;QAC7D,IAAI,KAAK,CAAC,OAAO,CAAC,kBAAkB,CAAC,EAAE;YACrC,KAAK,MAAM,IAAI,IAAI,kBAAkB,EAAE;gBACrC,MAAM,OAAO,GAAG,IAAA,iCAAuB,EAAC,IAAI,CAAC,CAAA;gBAC7C,IAAI,CAAC,mBAAmB,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC,CAAA;aAClD;SACF;aAAM;YACL,MAAM,OAAO,GAAG,IAAA,iCAAuB,EAAC,kBAAkB,CAAC,CAAA;YAC3D,IAAI,CAAC,mBAAmB,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC,CAAA;SAClD;IACH,CAAC;IAED;;;;OAIG;IACH,OAAO,CAAC,KAAc;QACpB,OAAO,IAAI,KAAK,CAAU,KAAK,EAAE,IAAI,qCAAqC,CAAC,IAAI,CAAC,CAAC,CAAA;IACnF,CAAC;IAED,+EAA+E;IAC/E,KAAK,CAAC,cAAc,CAAC,OAAgB;QACnC,MAAM,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,mBAAmB,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,IAAA,yBAAsB,EAAC,GAAG,EAAE,CAAC,OAAO,CAAC,qBAAqB,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAA;IACrI,CAAC;CACF;AA7CD,8CA6CC;AAED,MAAM,qCAAqC;IAGzC,YAAY,iBAAoC;QAC9C,IAAI,CAAC,iBAAiB,GAAG,iBAAiB,CAAA;IAC5C,CAAC;IAED,8DAA8D;IAC9D,GAAG,CAAC,MAAe,EAAE,QAAyB,EAAE,QAAa;QAC3D,IAAI,QAAQ,KAAK,oBAAoB,EAAE;YACrC,OAAO,CAAC,SAAoC,EAAE,EAAE;gBAC9C,IAAI,CAAC,iBAAiB,CAAC,iBAAiB,CAAC,SAAS,CAAC,CAAA;gBACnD,OAAO,MAAM,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAA;YACnD,CAAC,CAAA;SACF;QACD,8DAA8D;QAC9D,OAAQ,MAAc,CAAC,QAAQ,CAAC,CAAA;IAClC,CAAC;CACF"}
|
package/transaction.d.ts
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import algosdk, { Algodv2, SuggestedParams, Transaction } from 'algosdk';
|
|
2
|
+
import { PendingTransactionResponse } from './types/algod';
|
|
3
|
+
import { AlgoAmount } from './types/amount';
|
|
4
|
+
import { SendTransactionFrom, SendTransactionParams, SendTransactionResult, TransactionGroupToSend, TransactionNote } from './types/transaction';
|
|
5
|
+
/** Encodes a transaction note into a byte array ready to be included in an Algorand transaction.
|
|
6
|
+
*
|
|
7
|
+
* @param note The transaction note
|
|
8
|
+
* @returns the transaction note ready for inclusion in a transaction
|
|
9
|
+
*
|
|
10
|
+
* Case on the value of `data` this either either be:
|
|
11
|
+
* * `null` | `undefined`: `undefined`
|
|
12
|
+
* * `string`: The string value
|
|
13
|
+
* * Uint8Array: passthrough
|
|
14
|
+
* * Arc2TransactionNote object: ARC-0002 compatible transaction note
|
|
15
|
+
* * Else: The object/value converted into a JSON string representation
|
|
16
|
+
*/
|
|
17
|
+
export declare function encodeTransactionNote(note?: TransactionNote): Uint8Array | undefined;
|
|
18
|
+
/**
|
|
19
|
+
* Returns the public address of the given transaction sender.
|
|
20
|
+
* @param sender A transaction sender
|
|
21
|
+
* @returns The public address
|
|
22
|
+
*/
|
|
23
|
+
export declare const getSenderAddress: (sender: SendTransactionFrom) => string;
|
|
24
|
+
/** Signs and sends the given transaction to the chain
|
|
25
|
+
*
|
|
26
|
+
* @param send The details for the transaction to send, including:
|
|
27
|
+
* * `transaction`: The unsigned transaction
|
|
28
|
+
* * `from`: The account to sign the transaction with: either an account with private key loaded or a logic signature account
|
|
29
|
+
* * `config`: The sending configuration for this transaction
|
|
30
|
+
* @param algod An algod client
|
|
31
|
+
*
|
|
32
|
+
* @returns An object with transaction (`transaction`) and (if `skipWaiting` is `false` or unset) confirmation (`confirmation`)
|
|
33
|
+
*/
|
|
34
|
+
export declare const sendTransaction: (send: {
|
|
35
|
+
transaction: Transaction;
|
|
36
|
+
from: SendTransactionFrom;
|
|
37
|
+
sendParams?: SendTransactionParams;
|
|
38
|
+
}, algod: Algodv2) => Promise<SendTransactionResult>;
|
|
39
|
+
/**
|
|
40
|
+
* Signs and sends a group of [up to 16](https://developer.algorand.org/docs/get-details/atomic_transfers/#create-transactions) transactions to the chain
|
|
41
|
+
*
|
|
42
|
+
* @param groupSend The group details to send, with:
|
|
43
|
+
* * `transactions`: The array of transactions to send along with their signing account
|
|
44
|
+
* * `sendParams`: The parameters to dictate how the group is sent
|
|
45
|
+
* @param algod An algod client
|
|
46
|
+
* @returns An object with group transaction ID (`groupTransactionId`) and (if `skipWaiting` is `false` or unset) confirmation (`confirmation`)
|
|
47
|
+
*/
|
|
48
|
+
export declare const sendGroupOfTransactions: (groupSend: TransactionGroupToSend, algod: Algodv2) => Promise<{
|
|
49
|
+
groupId: string;
|
|
50
|
+
confirmations: PendingTransactionResponse[] | undefined;
|
|
51
|
+
txIds: string[];
|
|
52
|
+
}>;
|
|
53
|
+
/**
|
|
54
|
+
* Wait until the transaction is confirmed or rejected, or until `timeout`
|
|
55
|
+
* number of rounds have passed.
|
|
56
|
+
*
|
|
57
|
+
* @param algod An algod client
|
|
58
|
+
* @param transactionId The transaction ID to wait for
|
|
59
|
+
* @param maxRoundsToWait Maximum number of rounds to wait
|
|
60
|
+
*
|
|
61
|
+
* @return Pending transaction information
|
|
62
|
+
* @throws Throws an error if the transaction is not confirmed or rejected in the next `timeout` rounds
|
|
63
|
+
*/
|
|
64
|
+
export declare const waitForConfirmation: (transactionId: string, maxRoundsToWait: number, algod: Algodv2) => Promise<PendingTransactionResponse>;
|
|
65
|
+
/**
|
|
66
|
+
* Limit the acceptable fee to a defined amount of µALGOs.
|
|
67
|
+
* This also sets the transaction to be flatFee to ensure the transaction only succeeds at
|
|
68
|
+
* the estimated rate.
|
|
69
|
+
* @param transaction The transaction to cap
|
|
70
|
+
* @param maxAcceptableFee The maximum acceptable fee to pay
|
|
71
|
+
*/
|
|
72
|
+
export declare function capTransactionFee(transaction: algosdk.Transaction, maxAcceptableFee: AlgoAmount): void;
|
|
73
|
+
/**
|
|
74
|
+
* Returns suggested transaction parameters from algod unless some are already provided.
|
|
75
|
+
* @param params Optionally provide parameters to use
|
|
76
|
+
* @param algod Algod algod
|
|
77
|
+
* @returns The suggested transaction parameters
|
|
78
|
+
*/
|
|
79
|
+
export declare function getTransactionParams(params: SuggestedParams | undefined, algod: Algodv2): Promise<algosdk.SuggestedParams>;
|
|
80
|
+
//# sourceMappingURL=transaction.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transaction.d.ts","sourceRoot":"","sources":["../src/transaction.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,EAAE,EAAE,OAAO,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,SAAS,CAAA;AAIxE,OAAO,EAAE,0BAA0B,EAAE,MAAM,eAAe,CAAA;AAC1D,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAC3C,OAAO,EACL,mBAAmB,EACnB,qBAAqB,EACrB,qBAAqB,EACrB,sBAAsB,EACtB,eAAe,EAChB,MAAM,qBAAqB,CAAA;AAE5B;;;;;;;;;;;GAWG;AACH,wBAAgB,qBAAqB,CAAC,IAAI,CAAC,EAAE,eAAe,GAAG,UAAU,GAAG,SAAS,CAcpF;AAED;;;;GAIG;AACH,eAAO,MAAM,gBAAgB,WAAqB,mBAAmB,WAEpE,CAAA;AAED;;;;;;;;;GASG;AACH,eAAO,MAAM,eAAe,SACpB;IACJ,WAAW,EAAE,WAAW,CAAA;IACxB,IAAI,EAAE,mBAAmB,CAAA;IACzB,UAAU,CAAC,EAAE,qBAAqB,CAAA;CACnC,SACM,OAAO,KACb,QAAQ,qBAAqB,CAmC/B,CAAA;AAQD;;;;;;;;GAQG;AACH,eAAO,MAAM,uBAAuB,cAA8B,sBAAsB,SAAS,OAAO;;;;EAyGvG,CAAA;AAED;;;;;;;;;;GAUG;AACH,eAAO,MAAM,mBAAmB,kBACf,MAAM,mBACJ,MAAM,SAChB,OAAO,KACb,QAAQ,0BAA0B,CAkCpC,CAAA;AAED;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAAC,WAAW,EAAE,OAAO,CAAC,WAAW,EAAE,gBAAgB,EAAE,UAAU,QAgB/F;AAED;;;;;GAKG;AACH,wBAAsB,oBAAoB,CAAC,MAAM,EAAE,eAAe,GAAG,SAAS,EAAE,KAAK,EAAE,OAAO,oCAE7F"}
|