@algorandfoundation/algorand-typescript-testing 1.0.0-alpha.2 → 1.0.0-alpha.20

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (114) hide show
  1. package/README.md +285 -0
  2. package/abi-metadata.d.ts +13 -6
  3. package/application-spy.d.ts +33 -0
  4. package/arc4-CC8mc2EI.js +104 -0
  5. package/arc4-CC8mc2EI.js.map +1 -0
  6. package/asset-params-C0sz_Aya.js +201 -0
  7. package/asset-params-C0sz_Aya.js.map +1 -0
  8. package/collections/custom-key-map.d.ts +30 -0
  9. package/constants.d.ts +25 -0
  10. package/context-helpers/context-manager.d.ts +7 -0
  11. package/context-helpers/context-util.d.ts +3 -0
  12. package/context-helpers/internal-context.d.ts +12 -10
  13. package/crypto-DumZR3uP.js +2380 -0
  14. package/crypto-DumZR3uP.js.map +1 -0
  15. package/decode-logs.d.ts +2 -1
  16. package/encoders.d.ts +11 -0
  17. package/errors.d.ts +28 -2
  18. package/impl/acct-params.d.ts +7 -5
  19. package/impl/app-global.d.ts +2 -0
  20. package/impl/app-local.d.ts +2 -0
  21. package/impl/app-params.d.ts +4 -3
  22. package/impl/asset-holding.d.ts +2 -2
  23. package/impl/asset-params.d.ts +4 -3
  24. package/impl/base-32.d.ts +2 -0
  25. package/impl/base-contract.d.ts +9 -0
  26. package/impl/base.d.ts +19 -0
  27. package/impl/block.d.ts +15 -0
  28. package/impl/box.d.ts +2 -0
  29. package/impl/c2c.d.ts +11 -0
  30. package/impl/compiled.d.ts +3 -0
  31. package/impl/contract.d.ts +14 -0
  32. package/impl/crypto.d.ts +22 -12
  33. package/impl/emit.d.ts +1 -0
  34. package/impl/encoded-types.d.ts +191 -0
  35. package/impl/ensure-budget.d.ts +3 -0
  36. package/impl/global.d.ts +7 -3
  37. package/impl/gtxn.d.ts +9 -2
  38. package/impl/index.d.ts +12 -4
  39. package/impl/inner-transactions.d.ts +30 -21
  40. package/impl/itxn.d.ts +5 -5
  41. package/impl/log.d.ts +3 -0
  42. package/impl/logicSigArg.d.ts +3 -0
  43. package/impl/match.d.ts +3 -0
  44. package/impl/method-selector.d.ts +6 -0
  45. package/impl/mutable-array.d.ts +42 -0
  46. package/impl/online-stake.d.ts +2 -0
  47. package/impl/primitives.d.ts +212 -0
  48. package/impl/pure.d.ts +37 -29
  49. package/impl/reference.d.ts +96 -0
  50. package/impl/scratch.d.ts +4 -2
  51. package/impl/state.d.ts +100 -0
  52. package/impl/template-var.d.ts +1 -0
  53. package/impl/transactions.d.ts +49 -50
  54. package/impl/txn.d.ts +4 -3
  55. package/impl/urange.d.ts +2 -0
  56. package/impl/voter-params.d.ts +7 -0
  57. package/index.d.ts +4 -0
  58. package/index.mjs +1225 -3250
  59. package/index.mjs.map +1 -1
  60. package/inner-transactions-DrYPl6aW.js +1183 -0
  61. package/inner-transactions-DrYPl6aW.js.map +1 -0
  62. package/internal/arc4.d.ts +4 -0
  63. package/internal/arc4.mjs +17 -0
  64. package/internal/arc4.mjs.map +1 -0
  65. package/internal/index.d.ts +37 -0
  66. package/internal/index.mjs +250 -0
  67. package/internal/index.mjs.map +1 -0
  68. package/internal/op.d.ts +19 -0
  69. package/internal/op.mjs +17 -0
  70. package/internal/op.mjs.map +1 -0
  71. package/op-gBBDFbF6.js +1813 -0
  72. package/op-gBBDFbF6.js.map +1 -0
  73. package/package.json +28 -12
  74. package/program-factory-7SPe2HW0.js +542 -0
  75. package/program-factory-7SPe2HW0.js.map +1 -0
  76. package/pure-A1MFEXtY.js +650 -0
  77. package/pure-A1MFEXtY.js.map +1 -0
  78. package/runtime-helpers-BszTaREL.js +463 -0
  79. package/runtime-helpers-BszTaREL.js.map +1 -0
  80. package/runtime-helpers.d.ts +6 -2
  81. package/runtime-helpers.mjs +11 -1
  82. package/runtime-helpers.mjs.map +1 -1
  83. package/set-up.d.ts +31 -0
  84. package/subcontexts/contract-context.d.ts +28 -6
  85. package/subcontexts/ledger-context.d.ts +152 -14
  86. package/subcontexts/transaction-context.d.ts +189 -28
  87. package/test-execution-context.d.ts +130 -33
  88. package/test-transformer/helpers.d.ts +1 -0
  89. package/test-transformer/jest-transformer.d.ts +37 -0
  90. package/test-transformer/jest-transformer.mjs +52 -0
  91. package/test-transformer/jest-transformer.mjs.map +1 -0
  92. package/test-transformer/node-factory.d.ts +9 -3
  93. package/test-transformer/program-factory.d.ts +7 -0
  94. package/test-transformer/supported-binary-op-string.d.ts +1 -0
  95. package/test-transformer/visitors.d.ts +1 -1
  96. package/test-transformer/vitest-transformer.d.ts +34 -0
  97. package/test-transformer/vitest-transformer.mjs +56 -0
  98. package/test-transformer/vitest-transformer.mjs.map +1 -0
  99. package/typescript-helpers-CAukFXpp.js +18 -0
  100. package/typescript-helpers-CAukFXpp.js.map +1 -0
  101. package/typescript-helpers.d.ts +16 -0
  102. package/util.d.ts +53 -17
  103. package/value-generators/arc4.d.ts +70 -0
  104. package/value-generators/avm.d.ts +54 -13
  105. package/value-generators/index.d.ts +2 -0
  106. package/value-generators/txn.d.ts +37 -3
  107. package/impl/account.d.ts +0 -31
  108. package/impl/application.d.ts +0 -24
  109. package/impl/asset.d.ts +0 -23
  110. package/runtime-helpers-B6YRp95T.js +0 -460
  111. package/runtime-helpers-B6YRp95T.js.map +0 -1
  112. package/test-transformer/index.d.ts +0 -6
  113. package/test-transformer.mjs +0 -297
  114. package/test-transformer.mjs.map +0 -1
package/README.md ADDED
@@ -0,0 +1,285 @@
1
+ # Algorand TypeScript Testing
2
+
3
+ [![docs-repository](https://img.shields.io/badge/url-repository-74dfdc?logo=github&style=flat.svg)](https://github.com/algorandfoundation/algorand-typescript-testing/)
4
+ [![learn-AlgoKit](https://img.shields.io/badge/learn-AlgoKit-74dfdc?logo=algorand&mac=flat.svg)](https://developer.algorand.org/algokit/)
5
+ [![github-stars](https://img.shields.io/github/stars/algorandfoundation/algorand-typescript-testing?color=74dfdc&logo=star&style=flat)](https://github.com/algorandfoundation/algorand-typescript-testing)
6
+ [![visitor-badge](https://api.visitorbadge.io/api/visitors?path=https%3A%2F%2Fgithub.com%2Falgorandfoundation%2Falgorand-typescript-testing&countColor=%2374dfdc&style=flat)](https://github.com/algorandfoundation/algorand-typescript-testing/)
7
+
8
+ `algorand-typescript-testing` is a companion package to [Algorand Typescript](https://github.com/algorandfoundation/puya-ts/tree/main/packages/algo-ts) that enables efficient unit testing of Algorand TypeScript smart contracts in an offline environment. This package emulates key AVM behaviors without requiring a network connection, offering fast and reliable testing capabilities with a familiar TypeScript interface.
9
+
10
+ The `algorand-typescript-testing` package provides:
11
+
12
+ - A simple interface for fast and reliable unit testing
13
+ - An offline testing environment that simulates core AVM functionality
14
+ - A familiar TypeScript experience, compatible with testing frameworks like [vitest](https://vitest.dev/), and [jest](https://jestjs.io/)
15
+
16
+ ## Quick Start
17
+
18
+ `algorand-typescript` is a prerequisite for `algorand-typescript-testing`, providing stubs and type annotations for Algorand TypeScript syntax. It enhances code completion and type checking when writing smart contracts. Note that this code isn't directly executable in standard Node.js environment; it's compiled by `puya-ts` into TEAL for Algorand Network deployment.
19
+
20
+ Traditionally, testing Algorand smart contracts involved deployment on sandboxed networks and interacting with live instances. While robust, this approach can be inefficient and lacks versatility for testing Algorand TypeScript code.
21
+
22
+ Enter `algorand-typescript-testing`: it leverages TypeScript's rich testing ecosystem for unit testing without network deployment. This enables rapid iteration and granular logic testing.
23
+
24
+ > **NOTE**: While `algorand-typescript-testing` offers valuable unit testing capabilities, it's not a replacement for comprehensive testing. Use it alongside other test types, particularly those running against the actual Algorand Network, for thorough contract validation.
25
+
26
+ ### Prerequisites
27
+
28
+ - Python 3.12 or later
29
+ - [Algorand Python](https://github.com/algorandfoundation/puya)
30
+ - Node.js 20.x or later
31
+ - [Algorand TypeScript](https://github.com/algorandfoundation/puya-ts)
32
+
33
+ ### Installation
34
+
35
+ `algorand-typescript-testing` is distributed via [npm](https://www.npmjs.com/package/@algorandfoundation/algorand-typescript-testing/). Install the package using `npm`:
36
+
37
+ ```bash
38
+ npm i @algorandfoundation/algorand-typescript-testing
39
+ ```
40
+
41
+ ### Testing your first contract
42
+
43
+ Let's write a simple contract and test it using the `algorand-typescript-testing` framework.
44
+
45
+ #### Configuring vitest
46
+
47
+ If you are using [vitest](https://vitest.dev/) with [@rollup/plugin-typescript](https://www.npmjs.com/package/@rollup/plugin-typescript) plugin, configure `puyaTsTransformer` as a `before` stage transformer of the `typescript` plugin in `vitest.config.mts` file.
48
+
49
+ ```typescript
50
+ import typescript from '@rollup/plugin-typescript'
51
+ import { defineConfig } from 'vitest/config'
52
+ import { puyaTsTransformer } from '@algorandfoundation/algorand-typescript-testing/vitest-transformer'
53
+
54
+ export default defineConfig({
55
+ esbuild: {},
56
+ test: {
57
+ setupFiles: 'vitest.setup.ts',
58
+ },
59
+ plugins: [
60
+ typescript({
61
+ transformers: {
62
+ before: [puyaTsTransformer],
63
+ },
64
+ }),
65
+ ],
66
+ })
67
+ ```
68
+
69
+ `algorand-typescript-testing` package also exposes additional equality testers which enables the smart contract developers to write terser test by avoiding type casting in assertions. It can setup in `beforeAll` hook point in the setup file, `vitest.setup.ts`.
70
+
71
+ ```typescript
72
+ import { beforeAll, expect } from 'vitest'
73
+ import { addEqualityTesters } from '@algorandfoundation/algorand-typescript-testing'
74
+
75
+ beforeAll(() => {
76
+ addEqualityTesters({ expect })
77
+ })
78
+ ```
79
+
80
+ #### Configuring jest
81
+
82
+ If you are using [jest](https://jestjs.io/) with [ts-jest](https://www.npmjs.com/package/ts-jest), [@jest/globals](https://www.npmjs.com/package/@jest/globals) and [ts-node](https://www.npmjs.com/package/ts-node) plugins, configure `puyaTsTransformer` as a `before` stage transformer of the `typescript` plugin in `jest.config.ts` file.
83
+
84
+ ```typescript
85
+ import { createDefaultEsmPreset, type JestConfigWithTsJest } from 'ts-jest'
86
+
87
+ const presetConfig = createDefaultEsmPreset({})
88
+ const jestConfig: JestConfigWithTsJest = {
89
+ ...presetConfig,
90
+ testMatch: ['**/*.test.ts'],
91
+ setupFilesAfterEnv: ['<rootDir>/jest.setup.ts'],
92
+ transform: {
93
+ '^.+\\.tsx?$': [
94
+ 'ts-jest',
95
+ {
96
+ useESM: true,
97
+ astTransformers: {
98
+ before: ['node_modules/@algorandfoundation/algorand-typescript-testing/test-transformer/jest-transformer.mjs'],
99
+ },
100
+ },
101
+ ],
102
+ },
103
+ extensionsToTreatAsEsm: ['.ts'],
104
+ }
105
+ export default jestConfig
106
+ ```
107
+
108
+ `algorand-typescript-testing` package also exposes additional equality testers which enables the smart contract developers to write terser test by avoiding type casting in assertions. It can setup in `beforeAll` hook point in the setup file, `jest.setup.ts`.
109
+
110
+ ```typescript
111
+ import { beforeAll, expect } from '@jest/globals'
112
+ import { addEqualityTesters } from '@algorandfoundation/algorand-typescript-testing'
113
+
114
+ beforeAll(() => {
115
+ addEqualityTesters({ expect })
116
+ })
117
+ ```
118
+
119
+ You'll also need to run `jest` with the `--experimental-vm-modules` and `--experimental-require-module` flags in the `package.json`. This requires node 20.17 or greater.
120
+
121
+ ```json
122
+ {
123
+ "name": "puya-ts-demo",
124
+ "scripts": {
125
+ "test:jest": "tsc && node --experimental-vm-modules --experimental-require-module node_modules/jest/bin/jest"
126
+ },
127
+ "engines": {
128
+ "node": ">=20.17"
129
+ }
130
+ }
131
+ ```
132
+
133
+ There is also a patch file `ts-jest+29.2.5.patch` that needs to be applied to `ts-jest` package to for the `puyaTsTransformer` to work with the test files.
134
+
135
+ 1. Place the file in `<rootDir>\patches` folder.
136
+ 1. Install [patch-package](https://www.npmjs.com/package/patch-package) package as a dev dependency.
137
+ 1. Add `"postinstall": "patch-package",` script in `package.json` file.
138
+ The patch will then be applied with every `npm install` call.
139
+
140
+ ```patch
141
+ diff --git a/node_modules/ts-jest/dist/legacy/compiler/ts-compiler.js b/node_modules/ts-jest/dist/legacy/compiler/ts-compiler.js
142
+ index 5198f8f..addb47c 100644
143
+ --- a/node_modules/ts-jest/dist/legacy/compiler/ts-compiler.js
144
+ +++ b/node_modules/ts-jest/dist/legacy/compiler/ts-compiler.js
145
+ @@ -234,7 +234,7 @@ var TsCompiler = /** @class */ (function () {
146
+ var _a;
147
+ // Initialize memory cache for typescript compiler
148
+ this._parsedTsConfig.fileNames
149
+ - .filter(function (fileName) { return constants_1.TS_TSX_REGEX.test(fileName) && !_this.configSet.isTestFile(fileName); })
150
+ + .filter(function (fileName) { return constants_1.TS_TSX_REGEX.test(fileName); })
151
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
152
+ .forEach(function (fileName) { return _this._fileVersionCache.set(fileName, 0); });
153
+ /* istanbul ignore next */
154
+
155
+ ```
156
+
157
+ After the setup, the examples provided using `vitest` can be converted to work with `jest` by simply swapping the `import {...} from 'vitest'` with `import {...} from '@jest/globals'`.
158
+
159
+ #### Contract Definition
160
+
161
+ ```typescript
162
+ import { arc4, assert, Bytes, GlobalState, gtxn, LocalState, op, Txn, uint64, Uint64 } from '@algorandfoundation/algorand-typescript'
163
+
164
+ export default class VotingContract extends arc4.Contract {
165
+ topic = GlobalState({ initialValue: 'default_topic', key: Bytes('topic') })
166
+ votes = GlobalState({ initialValue: Uint64(0), key: Bytes('votes') })
167
+ voted = LocalState<uint64>({ key: Bytes('voted') })
168
+
169
+ @arc4.abimethod()
170
+ public setTopic(topic: string): void {
171
+ this.topic.value = topic
172
+ }
173
+ @arc4.abimethod()
174
+ public vote(pay: gtxn.PaymentTxn): boolean {
175
+ assert(op.Global.groupSize === 2, 'Expected 2 transactions')
176
+ assert(pay.amount === 10_000, 'Incorrect payment amount')
177
+ assert(pay.sender === Txn.sender, 'Payment sender must match transaction sender')
178
+
179
+ if (this.voted(Txn.sender).hasValue) {
180
+ return false // Already voted
181
+ }
182
+
183
+ this.votes.value = this.votes.value + 1
184
+ this.voted(Txn.sender).value = 1
185
+ return true
186
+ }
187
+
188
+ @arc4.abimethod({ readonly: true })
189
+ public getVotes(): uint64 {
190
+ return this.votes.value
191
+ }
192
+
193
+ public clearStateProgram(): boolean {
194
+ return true
195
+ }
196
+ }
197
+ ```
198
+
199
+ #### Test Definition
200
+
201
+ ```typescript
202
+ import { Uint64 } from '@algorandfoundation/algorand-typescript'
203
+ import { TestExecutionContext } from '@algorandfoundation/algorand-typescript-testing'
204
+ import { afterEach, describe, expect, test } from 'vitest'
205
+ import VotingContract from './contract.algo'
206
+
207
+ describe('Voting contract', () => {
208
+ const ctx = new TestExecutionContext()
209
+ afterEach(() => {
210
+ ctx.reset()
211
+ })
212
+
213
+ test('vote function', () => {
214
+ // Initialize the contract within the testing context
215
+ const contract = ctx.contract.create(VotingContract)
216
+
217
+ const voter = ctx.defaultSender
218
+ const payment = ctx.any.txn.payment({
219
+ sender: voter,
220
+ amount: 10_000,
221
+ })
222
+
223
+ const result = contract.vote(payment)
224
+ expect(result).toEqual(true)
225
+ expect(contract.votes.value).toEqual(1)
226
+ expect(contract.voted(voter).value).toEqual(1)
227
+ })
228
+
229
+ test('setTopic function', () => {
230
+ // Initialize the contract within the testing context
231
+ const contract = ctx.contract.create(VotingContract)
232
+
233
+ const newTopic = ctx.any.string(10)
234
+ contract.setTopic(newTopic)
235
+ expect(contract.topic.value).toEqual(newTopic)
236
+ })
237
+
238
+ test('getVotes function', () => {
239
+ // Initialize the contract within the testing context
240
+ const contract = ctx.contract.create(VotingContract)
241
+
242
+ contract.votes.value = 5
243
+ const votes = contract.getVotes()
244
+ expect(votes).toEqual(5)
245
+ })
246
+ })
247
+ ```
248
+
249
+ This example demonstrates key aspects of testing with `algorand-typescript-testing` for ARC4-based contracts:
250
+
251
+ 1. ARC4 Contract Features:
252
+
253
+ - Use of `arc4.Contract` as the base class for the contract.
254
+ - ABI methods defined using the `@arc4.abimethod` decorator.
255
+ - Readonly method annotation with `@arc4.abimethod({readonly: true})`.
256
+
257
+ 2. Testing ARC4 Contracts:
258
+
259
+ - Creation of an `arc4.Contract` instance within the test context.
260
+ - Use of `ctx.any` for generating random test data.
261
+ - Direct invocation of ABI methods on the contract instance.
262
+
263
+ 3. Transaction Handling:
264
+
265
+ - Use of `ctx.any.txn` to create test transactions.
266
+ - Passing transaction objects as parameters to contract methods.
267
+
268
+ 4. State Verification:
269
+ - Checking global and local state changes after method execution.
270
+ - Verifying return values from ABI methods.
271
+
272
+ > **NOTE**: Thorough testing is crucial in smart contract development due to their immutable nature post-deployment. Comprehensive unit and integration tests ensure contract validity and reliability. Optimizing for efficiency can significantly improve user experience by reducing transaction fees and simplifying interactions. Investing in robust testing and optimization practices is crucial and offers many benefits in the long run.
273
+
274
+ ### Next steps
275
+
276
+ To dig deeper into the capabilities of `algorand-typescript-testing`, continue with the following sections.
277
+
278
+ #### Contents
279
+
280
+ - [Testing Guide](./docs/testing-guide/index.md)
281
+ - [Examples](./docs/examples.md)
282
+ - [Coverage](./docs/coverage.md)
283
+ - [FQA](./docs/faq.md)
284
+ - [API Reference](./docs/api.md)
285
+ - [Algorand TypeScript](./docs/algots.md)
package/abi-metadata.d.ts CHANGED
@@ -1,8 +1,10 @@
1
- import { Contract } from '@algorandfoundation/algorand-typescript';
2
- import { AbiMethodConfig, BareMethodConfig, CreateOptions, OnCompleteActionStr } from '@algorandfoundation/algorand-typescript/arc4';
1
+ import type { OnCompleteActionStr } from '@algorandfoundation/algorand-typescript';
2
+ import type { CreateOptions } from '@algorandfoundation/algorand-typescript/arc4';
3
+ import { Contract } from './impl/contract';
3
4
  export interface AbiMetadata {
4
5
  methodName: string;
5
- methodSelector: string;
6
+ name?: string;
7
+ methodSignature: string | undefined;
6
8
  argTypes: string[];
7
9
  returnType: string;
8
10
  onCreate?: CreateOptions;
@@ -11,6 +13,11 @@ export interface AbiMetadata {
11
13
  export declare const attachAbiMetadata: (contract: {
12
14
  new (): Contract;
13
15
  }, methodName: string, metadata: AbiMetadata) => void;
14
- export declare const captureMethodConfig: <T extends Contract>(contract: T, methodName: string, config?: AbiMethodConfig<T> | BareMethodConfig) => void;
15
- export declare const hasAbiMetadata: <T extends Contract>(contract: T) => boolean;
16
- export declare const getAbiMetadata: <T extends Contract>(contract: T, methodName: string) => AbiMetadata;
16
+ export declare const getContractAbiMetadata: <T extends Contract>(contract: T | {
17
+ new (): T;
18
+ }) => Record<string, AbiMetadata>;
19
+ export declare const getContractMethodAbiMetadata: <T extends Contract>(contract: T | {
20
+ new (): T;
21
+ }, methodName: string) => AbiMetadata;
22
+ export declare const getArc4Signature: (metadata: AbiMetadata) => string;
23
+ export declare const getArc4Selector: (metadata: AbiMetadata) => Uint8Array;
@@ -0,0 +1,33 @@
1
+ import type { bytes, Contract } from '@algorandfoundation/algorand-typescript';
2
+ import { OnCompleteAction } from '@algorandfoundation/algorand-typescript';
3
+ import type { ApplicationCallInnerTxnContext } from './impl/inner-transactions';
4
+ import type { AnyFunction, ConstructorFor } from './typescript-helpers';
5
+ export type AppSpyCb = (itxnContext: ApplicationCallInnerTxnContext) => void;
6
+ export declare class ApplicationSpy<TContract extends Contract = Contract> {
7
+ #private;
8
+ /**
9
+ * The `on` property is a proxy that allows you to register callbacks for specific method signatures.
10
+ * It dynamically creates methods based on the contract's methods.
11
+ */
12
+ readonly on: _TypedApplicationSpyCallBacks<TContract>;
13
+ constructor(contract?: TContract | ConstructorFor<TContract>);
14
+ /**
15
+ * Registers a callback for a bare call (no arguments).
16
+ * @param callback - The callback to be executed when a bare call is detected.
17
+ */
18
+ onBareCall(callback: AppSpyCb): void;
19
+ onBareCall(ocas: OnCompleteAction[], callback: AppSpyCb): void;
20
+ /**
21
+ * Registers a callback for a specific method signature.
22
+ * @param methodSignature
23
+ * @param callback
24
+ */
25
+ onAbiCall(methodSignature: bytes, callback: AppSpyCb): void;
26
+ onAbiCall(methodSignature: bytes, ocas: OnCompleteAction[], callback: AppSpyCb): void;
27
+ private _tryGetMethod;
28
+ private createOnProxy;
29
+ }
30
+ type _TypedApplicationSpyCallBacks<TContract> = {
31
+ [key in keyof TContract as key extends 'approvalProgram' | 'clearStateProgram' ? never : TContract[key] extends AnyFunction ? key extends string ? key : never : never]: (callback: AppSpyCb) => void;
32
+ };
33
+ export {};
@@ -0,0 +1,104 @@
1
+ import * as arc4$1 from '@algorandfoundation/algorand-typescript/arc4';
2
+ import { OnCompleteAction } from '@algorandfoundation/algorand-typescript';
3
+ import { g as getContractMethodAbiMetadata, C as Contract, b as abimethod, c as baremethod } from './runtime-helpers-BszTaREL.js';
4
+ import { v as lazyContext } from './crypto-DumZR3uP.js';
5
+ import { m as methodSelector, q as ApplicationCallInnerTxnContext } from './inner-transactions-DrYPl6aW.js';
6
+
7
+ function _mergeNamespaces(n, m) {
8
+ m.forEach(function (e) {
9
+ e && typeof e !== 'string' && !Array.isArray(e) && Object.keys(e).forEach(function (k) {
10
+ if (k !== 'default' && !(k in n)) {
11
+ var d = Object.getOwnPropertyDescriptor(e, k);
12
+ Object.defineProperty(n, k, d.get ? d : {
13
+ enumerable: true,
14
+ get: function () { return e[k]; }
15
+ });
16
+ }
17
+ });
18
+ });
19
+ return Object.freeze(n);
20
+ }
21
+
22
+ function compileArc4(contract, options) {
23
+ let app;
24
+ const compiledAppEntry = lazyContext.value.getCompiledAppEntry(contract);
25
+ if (compiledAppEntry !== undefined) {
26
+ app = lazyContext.ledger.applicationDataMap.get(compiledAppEntry.value);
27
+ }
28
+ if (options?.templateVars) {
29
+ Object.entries(options.templateVars).forEach(([key, value]) => {
30
+ lazyContext.value.setTemplateVar(key, value, options.templateVarsPrefix);
31
+ });
32
+ }
33
+ return {
34
+ call: new Proxy({}, {
35
+ get: (_target, prop) => {
36
+ return (methodArgs) => {
37
+ const selector = methodSelector(prop, contract);
38
+ const abiMetadata = getContractMethodAbiMetadata(contract, prop);
39
+ const onCompleteActions = abiMetadata?.allowActions?.map((action) => OnCompleteAction[action]);
40
+ const itxnContext = ApplicationCallInnerTxnContext.createFromTypedApplicationCallFields({
41
+ ...getCommonApplicationCallFields(app, options),
42
+ onCompletion: onCompleteActions?.[0],
43
+ ...methodArgs,
44
+ }, selector);
45
+ invokeCallback(itxnContext);
46
+ return {
47
+ itxn: itxnContext,
48
+ returnValue: itxnContext.loggedReturnValue,
49
+ };
50
+ };
51
+ },
52
+ }),
53
+ bareCreate: (methodArgs) => {
54
+ const itxnContext = ApplicationCallInnerTxnContext.createFromBareCreateApplicationCallFields({
55
+ ...getCommonApplicationCallFields(app, options),
56
+ ...methodArgs,
57
+ });
58
+ invokeCallback(itxnContext);
59
+ return itxnContext;
60
+ },
61
+ approvalProgram: app?.application.approvalProgram ?? [lazyContext.any.bytes(10), lazyContext.any.bytes(10)],
62
+ clearStateProgram: app?.application.clearStateProgram ?? [lazyContext.any.bytes(10), lazyContext.any.bytes(10)],
63
+ extraProgramPages: options?.extraProgramPages ?? app?.application.extraProgramPages ?? lazyContext.any.uint64(),
64
+ globalUints: options?.globalUints ?? app?.application.globalNumUint ?? lazyContext.any.uint64(),
65
+ globalBytes: options?.globalBytes ?? app?.application.globalNumBytes ?? lazyContext.any.uint64(),
66
+ localUints: options?.localUints ?? app?.application.localNumUint ?? lazyContext.any.uint64(),
67
+ localBytes: options?.localBytes ?? app?.application.localNumBytes ?? lazyContext.any.uint64(),
68
+ };
69
+ }
70
+ const invokeCallback = (itxnContext) => {
71
+ lazyContext.value.notifyApplicationSpies(itxnContext);
72
+ lazyContext.txn.activeGroup.addInnerTransactionGroup(...(itxnContext.itxns ?? []), itxnContext);
73
+ };
74
+ const getCommonApplicationCallFields = (app, options) => ({
75
+ approvalProgram: app?.application.approvalProgram ?? [lazyContext.any.bytes(10), lazyContext.any.bytes(10)],
76
+ clearStateProgram: app?.application.clearStateProgram ?? [lazyContext.any.bytes(10), lazyContext.any.bytes(10)],
77
+ extraProgramPages: options?.extraProgramPages ?? app?.application.extraProgramPages ?? lazyContext.any.uint64(),
78
+ globalNumUint: options?.globalUints ?? app?.application.globalNumUint ?? lazyContext.any.uint64(),
79
+ globalNumBytes: options?.globalBytes ?? app?.application.globalNumBytes ?? lazyContext.any.uint64(),
80
+ localNumUint: options?.localUints ?? app?.application.localNumUint ?? lazyContext.any.uint64(),
81
+ localNumBytes: options?.localBytes ?? app?.application.localNumBytes ?? lazyContext.any.uint64(),
82
+ });
83
+ function abiCall(method, methodArgs, contract) {
84
+ const selector = methodSelector(method, contract);
85
+ const itxnContext = ApplicationCallInnerTxnContext.createFromTypedApplicationCallFields(methodArgs, selector);
86
+ invokeCallback(itxnContext);
87
+ return {
88
+ itxn: itxnContext,
89
+ returnValue: itxnContext.loggedReturnValue,
90
+ };
91
+ }
92
+
93
+ var arc4 = /*#__PURE__*/_mergeNamespaces({
94
+ __proto__: null,
95
+ Contract: Contract,
96
+ abiCall: abiCall,
97
+ abimethod: abimethod,
98
+ baremethod: baremethod,
99
+ compileArc4: compileArc4,
100
+ methodSelector: methodSelector
101
+ }, [arc4$1]);
102
+
103
+ export { arc4 as a, abiCall as b, compileArc4 as c };
104
+ //# sourceMappingURL=arc4-CC8mc2EI.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"arc4-CC8mc2EI.js","sources":["../src/impl/c2c.ts"],"sourcesContent":["import { type CompileContractOptions, type Contract, OnCompleteAction } from '@algorandfoundation/algorand-typescript'\nimport type {\n BareCreateApplicationCallFields,\n ContractProxy,\n TypedApplicationCallFields,\n} from '@algorandfoundation/algorand-typescript/arc4'\nimport { getContractMethodAbiMetadata } from '../abi-metadata'\nimport { lazyContext } from '../context-helpers/internal-context'\nimport type { ConstructorFor, DeliberateAny, InstanceMethod } from '../typescript-helpers'\nimport type { ApplicationCallInnerTxn } from './inner-transactions'\nimport { ApplicationCallInnerTxnContext } from './inner-transactions'\nimport { methodSelector } from './method-selector'\nimport type { ApplicationData } from './reference'\n\nexport function compileArc4<TContract extends Contract>(\n contract: ConstructorFor<TContract>,\n options?: CompileContractOptions,\n): ContractProxy<TContract> {\n let app: ApplicationData | undefined\n const compiledAppEntry = lazyContext.value.getCompiledAppEntry(contract)\n if (compiledAppEntry !== undefined) {\n app = lazyContext.ledger.applicationDataMap.get(compiledAppEntry.value)\n }\n\n if (options?.templateVars) {\n Object.entries(options.templateVars).forEach(([key, value]) => {\n lazyContext.value.setTemplateVar(key, value, options.templateVarsPrefix)\n })\n }\n\n return {\n call: new Proxy({} as unknown as TContract, {\n get: (_target, prop) => {\n return (methodArgs: TypedApplicationCallFields<DeliberateAny[]>) => {\n const selector = methodSelector(prop as string, contract)\n const abiMetadata = getContractMethodAbiMetadata(contract, prop as string)\n const onCompleteActions = abiMetadata?.allowActions?.map((action) => OnCompleteAction[action])\n const itxnContext = ApplicationCallInnerTxnContext.createFromTypedApplicationCallFields(\n {\n ...getCommonApplicationCallFields(app, options),\n onCompletion: onCompleteActions?.[0],\n ...methodArgs,\n },\n selector,\n )\n invokeCallback(itxnContext)\n return {\n itxn: itxnContext,\n returnValue: itxnContext.loggedReturnValue,\n }\n }\n },\n }),\n\n bareCreate: (methodArgs?: BareCreateApplicationCallFields) => {\n const itxnContext = ApplicationCallInnerTxnContext.createFromBareCreateApplicationCallFields({\n ...getCommonApplicationCallFields(app, options),\n ...methodArgs,\n })\n invokeCallback(itxnContext)\n return itxnContext\n },\n approvalProgram: app?.application.approvalProgram ?? [lazyContext.any.bytes(10), lazyContext.any.bytes(10)],\n clearStateProgram: app?.application.clearStateProgram ?? [lazyContext.any.bytes(10), lazyContext.any.bytes(10)],\n extraProgramPages: options?.extraProgramPages ?? app?.application.extraProgramPages ?? lazyContext.any.uint64(),\n globalUints: options?.globalUints ?? app?.application.globalNumUint ?? lazyContext.any.uint64(),\n globalBytes: options?.globalBytes ?? app?.application.globalNumBytes ?? lazyContext.any.uint64(),\n localUints: options?.localUints ?? app?.application.localNumUint ?? lazyContext.any.uint64(),\n localBytes: options?.localBytes ?? app?.application.localNumBytes ?? lazyContext.any.uint64(),\n } as unknown as ContractProxy<TContract>\n}\n\nconst invokeCallback = (itxnContext: ApplicationCallInnerTxnContext) => {\n lazyContext.value.notifyApplicationSpies(itxnContext)\n lazyContext.txn.activeGroup.addInnerTransactionGroup(...(itxnContext.itxns ?? []), itxnContext)\n}\nconst getCommonApplicationCallFields = (app: ApplicationData | undefined, options: CompileContractOptions | undefined) => ({\n approvalProgram: app?.application.approvalProgram ?? [lazyContext.any.bytes(10), lazyContext.any.bytes(10)],\n clearStateProgram: app?.application.clearStateProgram ?? [lazyContext.any.bytes(10), lazyContext.any.bytes(10)],\n extraProgramPages: options?.extraProgramPages ?? app?.application.extraProgramPages ?? lazyContext.any.uint64(),\n globalNumUint: options?.globalUints ?? app?.application.globalNumUint ?? lazyContext.any.uint64(),\n globalNumBytes: options?.globalBytes ?? app?.application.globalNumBytes ?? lazyContext.any.uint64(),\n localNumUint: options?.localUints ?? app?.application.localNumUint ?? lazyContext.any.uint64(),\n localNumBytes: options?.localBytes ?? app?.application.localNumBytes ?? lazyContext.any.uint64(),\n})\n\nexport function abiCall<TArgs extends DeliberateAny[], TReturn>(\n method: InstanceMethod<Contract, TArgs, TReturn>,\n methodArgs: TypedApplicationCallFields<TArgs>,\n contract?: Contract | { new (): Contract },\n): { itxn: ApplicationCallInnerTxn; returnValue: TReturn | undefined } {\n const selector = methodSelector(method, contract)\n const itxnContext = ApplicationCallInnerTxnContext.createFromTypedApplicationCallFields<TReturn>(methodArgs, selector)\n invokeCallback(itxnContext)\n\n return {\n itxn: itxnContext,\n returnValue: itxnContext.loggedReturnValue,\n }\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;AAcgB,SAAA,WAAW,CACzB,QAAmC,EACnC,OAAgC,EAAA;AAEhC,IAAA,IAAI,GAAgC;IACpC,MAAM,gBAAgB,GAAG,WAAW,CAAC,KAAK,CAAC,mBAAmB,CAAC,QAAQ,CAAC;AACxE,IAAA,IAAI,gBAAgB,KAAK,SAAS,EAAE;AAClC,QAAA,GAAG,GAAG,WAAW,CAAC,MAAM,CAAC,kBAAkB,CAAC,GAAG,CAAC,gBAAgB,CAAC,KAAK,CAAC;;AAGzE,IAAA,IAAI,OAAO,EAAE,YAAY,EAAE;AACzB,QAAA,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,KAAI;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W,CAAC,iBAAiB;KAC3C;AACH;;;;;;;;;;;;;;"}
@@ -0,0 +1,201 @@
1
+ import { ARC4Encoded } from '@algorandfoundation/algorand-typescript/arc4';
2
+ import { encodingUtil } from '@algorandfoundation/puya-ts';
3
+ import { k as asMaybeUint64Cls, r as asMaybeBytesCls, a6 as asMaybeBigUintCls, a4 as BytesBackedCls, a5 as Uint64BackedCls, l as asUint64Cls, ai as encodeArc4Impl, I as InternalError, an as nameOfType, aD as getArc4Encoder, aC as arc4Encoders, H as AssetCls, t as ApplicationCls, A as AccountCls, x as Uint64, s as asUint8Array, f as asBytes, C as BigUint, F as Account, E as Bytes, v as lazyContext, h as asUint64 } from './crypto-DumZR3uP.js';
4
+
5
+ const booleanFromBytes = (val) => {
6
+ return encodingUtil.uint8ArrayToBigInt(asUint8Array(val)) > 0n;
7
+ };
8
+ const bigUintFromBytes = (val) => {
9
+ return BigUint(encodingUtil.uint8ArrayToBigInt(asUint8Array(val)));
10
+ };
11
+ const bytesFromBytes = (val) => {
12
+ return asBytes(val);
13
+ };
14
+ const stringFromBytes = (val) => {
15
+ return asBytes(val).toString();
16
+ };
17
+ const uint64FromBytes = (val) => {
18
+ return Uint64(encodingUtil.uint8ArrayToBigInt(asUint8Array(val)));
19
+ };
20
+ const onCompletionFromBytes = (val) => {
21
+ return Uint64(encodingUtil.uint8ArrayToBigInt(asUint8Array(val)));
22
+ };
23
+ const transactionTypeFromBytes = (val) => {
24
+ return Uint64(encodingUtil.uint8ArrayToBigInt(asUint8Array(val)));
25
+ };
26
+ const encoders = {
27
+ account: AccountCls.fromBytes,
28
+ application: ApplicationCls.fromBytes,
29
+ asset: AssetCls.fromBytes,
30
+ boolean: booleanFromBytes,
31
+ biguint: bigUintFromBytes,
32
+ bytes: bytesFromBytes,
33
+ string: stringFromBytes,
34
+ uint64: uint64FromBytes,
35
+ OnCompleteAction: onCompletionFromBytes,
36
+ TransactionType: transactionTypeFromBytes,
37
+ ...arc4Encoders,
38
+ };
39
+ const getEncoder = (typeInfo) => {
40
+ return getArc4Encoder(typeInfo, encoders);
41
+ };
42
+ const toBytes = (val) => {
43
+ const uint64Val = asMaybeUint64Cls(val);
44
+ if (uint64Val !== undefined) {
45
+ return uint64Val.toBytes().asAlgoTs();
46
+ }
47
+ const bytesVal = asMaybeBytesCls(val);
48
+ if (bytesVal !== undefined) {
49
+ return bytesVal.asAlgoTs();
50
+ }
51
+ const bigUintVal = asMaybeBigUintCls(val);
52
+ if (bigUintVal !== undefined) {
53
+ return bigUintVal.toBytes().asAlgoTs();
54
+ }
55
+ if (val instanceof BytesBackedCls) {
56
+ return val.bytes;
57
+ }
58
+ if (val instanceof Uint64BackedCls) {
59
+ return asUint64Cls(val.uint64).toBytes().asAlgoTs();
60
+ }
61
+ if (val instanceof ARC4Encoded) {
62
+ return val.bytes;
63
+ }
64
+ if (Array.isArray(val) || typeof val === 'object') {
65
+ return encodeArc4Impl('', val);
66
+ }
67
+ throw new InternalError(`Invalid type for bytes: ${nameOfType(val)}`);
68
+ };
69
+
70
+ const resolveAppIndex = (appIdOrIndex) => {
71
+ const input = asUint64(appIdOrIndex);
72
+ if (input >= 1001) {
73
+ return input;
74
+ }
75
+ const txn = lazyContext.activeGroup.activeTransaction;
76
+ return txn.apps(input).id;
77
+ };
78
+ const getApp = (app) => {
79
+ try {
80
+ const appId = asMaybeUint64Cls(app);
81
+ if (appId !== undefined) {
82
+ return lazyContext.ledger.getApplication(resolveAppIndex(appId));
83
+ }
84
+ return app;
85
+ }
86
+ catch {
87
+ return undefined;
88
+ }
89
+ };
90
+ const AppParams = {
91
+ appApprovalProgram(a) {
92
+ const app = getApp(a);
93
+ return app === undefined ? [Bytes(), false] : [app.approvalProgram, true];
94
+ },
95
+ appClearStateProgram(a) {
96
+ const app = getApp(a);
97
+ return app === undefined ? [Bytes(), false] : [app.clearStateProgram, true];
98
+ },
99
+ appGlobalNumUint(a) {
100
+ const app = getApp(a);
101
+ return app === undefined ? [Uint64(0), false] : [app.globalNumUint, true];
102
+ },
103
+ appGlobalNumByteSlice(a) {
104
+ const app = getApp(a);
105
+ return app === undefined ? [Uint64(0), false] : [app.globalNumBytes, true];
106
+ },
107
+ appLocalNumUint(a) {
108
+ const app = getApp(a);
109
+ return app === undefined ? [Uint64(0), false] : [app.localNumUint, true];
110
+ },
111
+ appLocalNumByteSlice(a) {
112
+ const app = getApp(a);
113
+ return app === undefined ? [Uint64(0), false] : [app.localNumBytes, true];
114
+ },
115
+ appExtraProgramPages(a) {
116
+ const app = getApp(a);
117
+ return app === undefined ? [Uint64(0), false] : [app.extraProgramPages, true];
118
+ },
119
+ appCreator(a) {
120
+ const app = getApp(a);
121
+ return app === undefined ? [Account(), false] : [app.creator, true];
122
+ },
123
+ appAddress(a) {
124
+ const app = getApp(a);
125
+ return app === undefined ? [Account(), false] : [app.address, true];
126
+ },
127
+ };
128
+
129
+ const resolveAssetIndex = (assetIdOrIndex) => {
130
+ const input = asUint64(assetIdOrIndex);
131
+ if (input >= 1001) {
132
+ return input;
133
+ }
134
+ const txn = lazyContext.activeGroup.activeTransaction;
135
+ return txn.assets(input).id;
136
+ };
137
+ const getAsset = (asset) => {
138
+ try {
139
+ const assetId = asMaybeUint64Cls(asset);
140
+ if (assetId !== undefined) {
141
+ return lazyContext.ledger.getAsset(resolveAssetIndex(assetId));
142
+ }
143
+ return asset;
144
+ }
145
+ catch {
146
+ return undefined;
147
+ }
148
+ };
149
+ const AssetParams = {
150
+ assetTotal(a) {
151
+ const asset = getAsset(a);
152
+ return asset === undefined ? [Uint64(0), false] : [asset.total, true];
153
+ },
154
+ assetDecimals(a) {
155
+ const asset = getAsset(a);
156
+ return asset === undefined ? [Uint64(0), false] : [asset.decimals, true];
157
+ },
158
+ assetDefaultFrozen(a) {
159
+ const asset = getAsset(a);
160
+ return asset === undefined ? [false, false] : [asset.defaultFrozen, true];
161
+ },
162
+ assetUnitName(a) {
163
+ const asset = getAsset(a);
164
+ return asset === undefined ? [Bytes(), false] : [asset.unitName, true];
165
+ },
166
+ assetName(a) {
167
+ const asset = getAsset(a);
168
+ return asset === undefined ? [Bytes(), false] : [asset.name, true];
169
+ },
170
+ assetUrl(a) {
171
+ const asset = getAsset(a);
172
+ return asset === undefined ? [Bytes(), false] : [asset.url, true];
173
+ },
174
+ assetMetadataHash(a) {
175
+ const asset = getAsset(a);
176
+ return asset === undefined ? [Bytes(), false] : [asset.metadataHash, true];
177
+ },
178
+ assetManager(a) {
179
+ const asset = getAsset(a);
180
+ return asset === undefined ? [Account(), false] : [asset.manager, true];
181
+ },
182
+ assetReserve(a) {
183
+ const asset = getAsset(a);
184
+ return asset === undefined ? [Account(), false] : [asset.reserve, true];
185
+ },
186
+ assetFreeze(a) {
187
+ const asset = getAsset(a);
188
+ return asset === undefined ? [Account(), false] : [asset.freeze, true];
189
+ },
190
+ assetClawback(a) {
191
+ const asset = getAsset(a);
192
+ return asset === undefined ? [Account(), false] : [asset.clawback, true];
193
+ },
194
+ assetCreator(a) {
195
+ const asset = getAsset(a);
196
+ return asset === undefined ? [Account(), false] : [asset.creator, true];
197
+ },
198
+ };
199
+
200
+ export { AppParams as A, getApp as a, getAsset as b, AssetParams as c, getEncoder as g, toBytes as t };
201
+ //# sourceMappingURL=asset-params-C0sz_Aya.js.map